Slicer  4.13
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 from __future__ import print_function
24 
25 nodes = slicer.mrmlScene.GetNodesByClass("vtkMRMLColorNode")
26 nodes.UnRegister(slicer.mrmlScene)
27 
28 template = "/// | {family} | {category} | {_type} | {node_name} | {singleton_tag} | {node_id} |"
29 
30 table = []
31 for index in range(nodes.GetNumberOfItems()):
32  n = nodes.GetItemAsObject(index)
33  table.append({
34  'family': n.GetClassName().replace('vtkMRML', '').replace('Node', ''),
35  'category': n.GetAttribute("Category"),
36  '_type': n.GetTypeAsString(),
37  'node_name': n.GetName(),
38  'singleton_tag': n.GetSingletonTag(),
39  'node_id': n.GetID()})
40 
41 titles = {'family': 'Family',
42  'category': 'Category',
43  '_type': 'Type',
44  'node_name': 'Node name',
45  'singleton_tag': 'Singleton Tag',
46  'node_id': 'Node ID'}
47 max_row_widths = {column_name: len(column_title) for (column_name, column_title) in titles.items()}
48 
49 for row in table:
50  for column_name in max_row_widths.keys():
51  column_width = len(str(row[column_name]))
52  if column_width > max_row_widths[column_name]:
53  max_row_widths[column_name] = column_width
54 
55 # Update template with widths
56 for (column_name, column_width) in max_row_widths.items():
57  template = template.replace(column_name, column_name + ":%d" % column_width)
58 
59 # Print headers
60 print(template.format(**titles))
61 
62 # Print separator
63 print(template.format(**{column_name: '-'*column_width for column_name, column_width in max_row_widths.items()}))
64 
65 # Print content
66 for row in table:
67  print(template.format(**row) )