MCPcopy Create free account
hub / github.com/Kitware/VTK / mesh

Function mesh

Web/Python/vtkmodules/web/utils.py:112–180  ·  view source on GitHub ↗

Expect any dataset and extract its surface into a dash_vtk.Mesh state property

(dataset, field_to_keep=None, point_arrays=None, cell_arrays=None)

Source from the content-addressed store, hash-verified

110
111
112def mesh(dataset, field_to_keep=None, point_arrays=None, cell_arrays=None):
113 """Expect any dataset and extract its surface into a dash_vtk.Mesh state property"""
114 if dataset is None:
115 return None
116
117 # Make sure we have a polydata to export
118 polydata = None
119 if dataset.IsA("vtkPolyData"):
120 polydata = dataset
121 else:
122 extractSkinFilter = vtkDataSetSurfaceFilter()
123 extractSkinFilter.SetInputData(dataset)
124 extractSkinFilter.Update()
125 polydata = extractSkinFilter.GetOutput()
126
127 if polydata.GetPoints() is None:
128 return None
129
130 # Extract mesh
131 state = {"mesh": {}}
132
133 points = mesh_array(polydata.GetPoints())
134 if points:
135 state["mesh"]["points"] = points
136
137 verts = mesh_array(polydata.GetVerts())
138 if verts:
139 state["mesh"]["verts"] = verts
140
141 lines = mesh_array(polydata.GetLines())
142 if lines:
143 state["mesh"]["lines"] = lines
144
145 polys = mesh_array(polydata.GetPolys())
146 if polys:
147 state["mesh"]["polys"] = polys
148
149 strips = mesh_array(polydata.GetStrips())
150 if strips:
151 state["mesh"]["strips"] = strips
152
153 # Scalars
154 if field_to_keep is not None:
155 field = None
156 p_array = polydata.GetPointData().GetArray(field_to_keep)
157 c_array = polydata.GetCellData().GetArray(field_to_keep)
158
159 if c_array:
160 field = data_array(c_array, location="CellData", name=field_to_keep)
161
162 if p_array:
163 field = data_array(p_array, location="PointData", name=field_to_keep)
164
165 if field:
166 state.update({"field": field})
167
168 # PointData Fields
169 if point_arrays:

Callers 2

Calls 15

mesh_arrayFunction · 0.85
data_arrayFunction · 0.85
field_dataFunction · 0.85
IsAMethod · 0.80
GetVertsMethod · 0.80
GetPolysMethod · 0.80
GetStripsMethod · 0.80
SetInputDataMethod · 0.45
UpdateMethod · 0.45
GetOutputMethod · 0.45
GetPointsMethod · 0.45

Tested by

no test coverage detected