Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
generate_default_color_node_property_table.py
Go to the documentation of this file.
2# Program: 3D Slicer
3#
4# Copyright (c) Kitware Inc.
5#
6# See COPYRIGHT.txt
7# or http://www.slicer.org/copyright/copyright.txt for details.
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
16# and was partially funded by NIH grant 1U24CA194354-01
17#
18
19"""
20This script allows to generate the markdown table displayed in doxygen
21documentation of vtkMRMLColorLogic::AddDefaultColorNodes()
22"""
23
24nodes = slicer.mrmlScene.GetNodesByClass("vtkMRMLColorNode")
25nodes.UnRegister(slicer.mrmlScene)
26
27template = "/// | {family} | {category} | {_type} | {node_name} | {singleton_tag} | {node_id} |"
28
29table = []
30for index in range(nodes.GetNumberOfItems()):
31 n = nodes.GetItemAsObject(index)
32 table.append({
33 "family": n.GetClassName().replace("vtkMRML", "").replace("Node", ""),
34 "category": n.GetAttribute("Category"),
35 "_type": n.GetTypeAsString(),
36 "node_name": n.GetName(),
37 "singleton_tag": n.GetSingletonTag(),
38 "node_id": n.GetID()})
39
40titles = {"family": "Family",
41 "category": "Category",
42 "_type": "Type",
43 "node_name": "Node name",
44 "singleton_tag": "Singleton Tag",
45 "node_id": "Node ID"}
46max_row_widths = {column_name: len(column_title) for (column_name, column_title) in titles.items()}
47
48for row in table:
49 for column_name, max_row_width in max_row_widths.items():
50 column_width = len(str(row[column_name]))
51 max_row_widths[column_name] = max(column_width, max_row_width)
52
53# Update template with widths
54for column_name, column_width in max_row_widths.items():
55 template = template.replace(column_name, column_name + ":%d" % column_width)
56
57# Print headers
58print(template.format(**titles))
59
60# Print separator
61print(template.format(**{column_name: "-" * column_width for column_name, column_width in max_row_widths.items()}))
62
63# Print content
64for row in table:
65 print(template.format(**row))