-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrimStreamlinesCF.xml
More file actions
78 lines (62 loc) · 4.33 KB
/
Copy pathTrimStreamlinesCF.xml
File metadata and controls
78 lines (62 loc) · 4.33 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
69
70
71
72
73
74
75
76
77
78
<ServerManagerConfiguration>
<ProxyGroup name="filters">
<SourceProxy name="TrimStreamlines" class="vtkPythonProgrammableFilter" label="Trim Streamlines">
<Documentation
long_help="Trim streamlines based to a range of IntegrationTime"
short_help="Trim streamlines based to a range of IntegrationTime">
</Documentation>
<InputProperty
name="Input"
command="SetInputConnection">
<ProxyGroupDomain name="groups">
<Group name="sources"/>
<Group name="filters"/>
</ProxyGroupDomain>
<DataTypeDomain name="input_type">
<DataType value="vtkUnstructuredGrid"/>
</DataTypeDomain>
</InputProperty>
<IntVectorProperty
name="end"
label="end"
initial_string="end"
command="SetParameter"
animateable="1"
default_values="-1"
number_of_elements="1">
<Documentation></Documentation>
</IntVectorProperty>
<IntVectorProperty
name="start"
label="start"
initial_string="start"
command="SetParameter"
animateable="1"
default_values="-1"
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 numpy as np
from vtk.numpy_interface import dataset_adapter as dsa

sl = self.GetPolyDataInput()
nsl = dsa.WrapDataObject(sl)

itime = nsl.PointData['IntegrationTime']

nv = nsl.Cells[nsl.CellLocations] # number of verts in each line
ns = nsl.CellLocations + 1 # index of first vertex in each line
ne = ns + nv # index one past the last vertex
olines = [nsl.Cells[i:j] for i,j in zip(ns, ne)]
nlines = []

iarrays = {'points': nsl.Points} # initialize source arrays with input points
oarrays = {'points': []}
for n in nsl.PointData.keys():
 iarrays[n] = nsl.PointData[n] # add input point data arrays to source arrays
 oarrays[n] = [] # add empty destination arrays

knt = 0
for line in olines:
 if start != -1: line = [l for l in line if itime[l] > start]
 if end != -1: line = [l for l in line if itime[l] < end]
 for n in iarrays.keys(): oarrays[n].append(iarrays[n][line])
 nlines.append(range(knt, knt+len(line)))
 knt = knt + len(line)

tsl = vtk.vtkUnstructuredGrid()

line_lengths = [len(l)+1 for l in nlines] # number of vertices + 1 for count

ct = dsa.numpyTovtkDataArray(np.array([vtk.VTK_POLY_LINE]*len(nlines)).astype('u1'))
co = dsa.numpy_support.numpy_to_vtkIdTypeArray(np.hstack(([0], np.cumsum(line_lengths)[:-1])))

ca = vtk.vtkCellArray()
for l in nlines:
 ca.InsertNextCell(len(l), l)

tsl.SetCells(ct, co, ca)

cid = dsa.numpyTovtkDataArray(np.arange(len(nlines)).astype('i4'))
cid.SetName('cell id')
tsl.GetCellData().AddArray(cid)

ptsa = np.concatenate(oarrays['points']).reshape((-1, 3)).astype('f4')

op = vtk.vtkPoints()
op.SetNumberOfPoints(ptsa.shape[0])

for i, p in enumerate(ptsa):
 op.InsertPoint(i, p[0], p[1], p[2])

tsl.SetPoints(op)

for n in oarrays:
 if n != 'points':
 a = dsa.numpyTovtkDataArray(np.concatenate(oarrays[n]))
 a.SetName(n)
 tsl.GetPointData().AddArray(a)

self.GetUnstructuredGridOutput().ShallowCopy(tsl)
"
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>