forked from simboden/BVtkNodes
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathinfo.py
148 lines (131 loc) · 5.04 KB
/
info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
from .core import l # Import logging
from .core import *
class BVTK_Node_Info(Node, BVTK_Node):
"""BVTK Info Node"""
bl_idname = "BVTK_Node_InfoType"
bl_label = "Info"
def m_properties(self):
return []
def m_connections(self):
return (["input"], ["output"], [], [])
def apply_properties_special(self):
"""Special update function to generate info text from VTK objects
"""
text = ""
fs1 = "{:.5g}"
fs2 = "{k} [{i}] ({data_type_name}{n_comps}): '{name}': {range_text}"
(
input_node,
vtk_output_obj,
vtk_connection,
) = self.get_input_node_and_output_vtk_objects("input")
text += "Type: " + vtk_output_obj.__class__.__name__ + "\n"
# Print block names for vtkMultiBlockDataSet
if hasattr(vtk_output_obj, "GetNumberOfBlocks"):
for i in range(vtk_output_obj.GetNumberOfBlocks()):
block = vtk_output_obj.GetBlock(i)
if not hasattr(vtk_output_obj, "GetMetaData"):
text += " Block " + str(i) + ": No meta data available\n"
continue
meta_data = vtk_output_obj.GetMetaData(i)
if not meta_data:
continue
block_name = meta_data.Get(vtk.vtkCompositeDataSet.NAME())
text += (
" Block "
+ str(i)
+ ": %r" % block_name
+ " ("
+ (block.__class__.__name__ if block else "Empty Block")
+ ")\n"
)
if hasattr(vtk_output_obj, "GetNumberOfPoints"):
text += "Points: " + str(vtk_output_obj.GetNumberOfPoints()) + "\n"
if hasattr(vtk_output_obj, "GetNumberOfCells"):
text += "Cells: " + str(vtk_output_obj.GetNumberOfCells()) + "\n"
if hasattr(vtk_output_obj, "GetBounds"):
# GetBounds() can fail, so use try-except for getting bounds
try:
bounds = vtk_output_obj.GetBounds()
text += (
"X range: "
+ fs1.format(bounds[0])
+ " - "
+ fs1.format(bounds[1])
+ "\n"
)
text += (
"Y range: "
+ fs1.format(bounds[2])
+ " - "
+ fs1.format(bounds[3])
+ "\n"
)
text += (
"Z range: "
+ fs1.format(bounds[4])
+ " - "
+ fs1.format(bounds[5])
+ "\n"
)
except:
pass
data = {}
if hasattr(vtk_output_obj, "GetPointData"):
data["Point data"] = vtk_output_obj.GetPointData()
if hasattr(vtk_output_obj, "GetCellData"):
data["Cell data"] = vtk_output_obj.GetCellData()
if hasattr(vtk_output_obj, "GetFieldData"):
data["Field data"] = vtk_output_obj.GetFieldData()
for k in data:
d = data[k]
for i in range(d.GetNumberOfArrays()):
arr = d.GetArray(i)
data_type_name = arr.GetDataTypeAsString()
n_comps = arr.GetNumberOfComponents()
name = arr.GetName()
if name is None or data_type_name is None or n_comps is None:
text += (
"Warning: Invalid array encountered: number="
+ str(i)
+ " name="
+ str(name)
+ " data_type_name="
+ str(data_type_name)
+ " n_comps="
+ str(n_comps)
+ "\n"
)
range_text = ""
for n in range(n_comps):
r = arr.GetRange(n)
range_text += (
"[" + fs1.format(r[0]) + ", " + fs1.format(r[1]) + "] "
)
text += fs2.format(
k=k,
i=i,
data_type_name=data_type_name,
n_comps=n_comps,
name=name,
range_text=range_text,
)
text += "\n"
self.ui_message = text
return "up-to-date"
def get_vtk_output_object_special(self, socketname="output"):
"""Pass on VTK output from input as output"""
(
input_node,
vtk_output_obj,
vtk_connection,
) = self.get_input_node_and_output_vtk_objects()
return vtk_output_obj
def init_vtk(self):
self.set_vtk_status("out-of-date")
return None
TYPENAMES = []
add_class(BVTK_Node_Info)
TYPENAMES.append("BVTK_Node_InfoType")
menu_items = [NodeItem(x) for x in TYPENAMES]
CATEGORIES.append(BVTK_NodeCategory("Debug", "Debug", items=menu_items))