Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
generate_default_color_node_property_table.py
Go to the documentation of this file.
1 #
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 """
20 This script allows to generate the markdown table displayed in doxygen
21 documentation of vtkMRMLColorLogic::AddDefaultColorNodes()
22 """
23 
24 nodes = slicer.mrmlScene.GetNodesByClass("vtkMRMLColorNode")
25 nodes.UnRegister(slicer.mrmlScene)
26 
27 template = "/// | {family} | {category} | {_type} | {node_name} | {singleton_tag} | {node_id} |"
28 
29 table = []
30 for 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 
40 titles = {'family': 'Family',
41  'category': 'Category',
42  '_type': 'Type',
43  'node_name': 'Node name',
44  'singleton_tag': 'Singleton Tag',
45  'node_id': 'Node ID'}
46 max_row_widths = {column_name: len(column_title) for (column_name, column_title) in titles.items()}
47 
48 for row in table:
49  for column_name in max_row_widths.keys():
50  column_width = len(str(row[column_name]))
51  if column_width > max_row_widths[column_name]:
52  max_row_widths[column_name] = column_width
53 
54 # Update template with widths
55 for (column_name, column_width) in max_row_widths.items():
56  template = template.replace(column_name, column_name + ":%d" % column_width)
57 
58 # Print headers
59 print(template.format(**titles))
60 
61 # Print separator
62 print(template.format(**{column_name: '-' * column_width for column_name, column_width in max_row_widths.items()}))
63 
64 # Print content
65 for row in table:
66  print(template.format(**row))