-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDecimateStreamlines.xml
More file actions
68 lines (54 loc) · 3.2 KB
/
DecimateStreamlines.xml
File metadata and controls
68 lines (54 loc) · 3.2 KB
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
<ServerManagerConfiguration>
<ProxyGroup name="filters">
<SourceProxy name="DecimateStreamlines" class="vtkPythonProgrammableFilter" label="DecimateStreamlines">
<Documentation
long_help=""
short_help="">
</Documentation>
<InputProperty
name="Input"
command="SetInputConnection">
<ProxyGroupDomain name="groups">
<Group name="sources"/>
<Group name="filters"/>
</ProxyGroupDomain>
<DataTypeDomain name="input_type">
<DataType value="vtkPolyData"/>
<DataType value="vtkUnstructuredGrid"/>
<DataType value="vtkImageData"/>
</DataTypeDomain>
</InputProperty>
<IntVectorProperty
name="factor"
label="factor"
initial_string="factor"
command="SetParameter"
animateable="1"
default_values="5"
number_of_elements="1">
<Documentation></Documentation>
</IntVectorProperty>
<!-- Output data type: "vtkUnstructuredGrid" -->
<IntVectorProperty command="SetOutputDataSetType"
default_values="4"
name="OutputDataSetType"
number_of_elements="1"
panel_visibility="never">
<Documentation>The value of this property determines the dataset type
for the output of the programmable filter.</Documentation>
</IntVectorProperty>
<StringVectorProperty
name="Script"
command="SetScript"
number_of_elements="1"
default_values="import vtk
import numpy as np
from vtk.numpy_interface import dataset_adapter as dsa

inpt = inputs[0]

cl = inpt.GetCellLocations()
ct = inpt.GetCellTypes()
cells = inpt.GetCells()

ncl = []
ncells = []
remap = []

while len(cells) > 0:
 onids = cells[0]
 oids = cells[1:onids+1]
 nids = [oids[0]] + list(oids[factor:-1:factor]) + [oids[-1]]
 nnids = len(nids)
 ncell = [nnids] + list(range(len(remap), len(remap)+len(nids)))
 remap = remap + nids
 ncells = ncells + ncell
 cells = cells[onids+1:]

new_points = inpt.GetPoints()[remap]
ncells = dsa.VTKArray(ncells).astype('i8')
ncl = dsa.VTKArray(np.array(ncl)).astype('i8')

o = dsa.WrapDataObject(vtk.vtkUnstructuredGrid())
o.SetPoints(dsa.VTKArray(np.array(new_points).astype('f4')))
o.SetCells(ct, ncl, ncells)

ipd = inpt.GetPointData()
opd = o.GetPointData()
for i in ipd.keys():
 opd.append(ipd[i][remap], i)

icd = inpt.GetCellData()
ocd = o.GetCellData()
for i in icd.keys():
 ocd.append(icd[i], i)

if 0 == 1:
 wrtr = vtk.vtkXMLUnstructuredGridWriter()
 wrtr.SetFileName('reduced.vtu')
 wrtr.SetInputData(o.VTKObject)
 wrtr.Write()
else:
 output.VTKObject.ShallowCopy(o.VTKObject)
"
panel_visibility="advanced">
<Hints>
<Widget type="multi_line"/>
</Hints>
<Documentation>This property contains the text of a python program that
the programmable source runs.</Documentation>
</StringVectorProperty>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>