-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJoinStreamlinesCF.xml
More file actions
66 lines (52 loc) · 4.59 KB
/
JoinStreamlinesCF.xml
File metadata and controls
66 lines (52 loc) · 4.59 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
<ServerManagerConfiguration>
<ProxyGroup name="filters">
<SourceProxy name="JoinStreamlines" class="vtkPythonProgrammableFilter" label="Join Streamlines">
<Documentation
long_help="Join forward and backward fragments of streamlines. Set flag to 0 to zero the integration time at the seed points, 1 to start each streamline at integrationTime = 0"
short_help="Join forward and backward fragments of streamlines. Set flag to 0 to zero the integration time at the seed points, 1 to start each streamline at integrationTime = 0">
</Documentation>
<InputProperty
name="Input"
command="SetInputConnection">
<ProxyGroupDomain name="groups">
<Group name="sources"/>
<Group name="filters"/>
</ProxyGroupDomain>
<DataTypeDomain name="input_type">
<DataType value="vtkPolyData"/>
</DataTypeDomain>
</InputProperty>
<IntVectorProperty
name="flag"
label="flag"
initial_string="flag"
command="SetParameter"
animateable="1"
default_values="0"
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)

osl = vtk.vtkUnstructuredGrid()

osl.SetPoints(sl.GetPoints())
for i in range(sl.GetPointData().GetNumberOfArrays()):
 osl.GetPointData().AddArray(sl.GetPointData().GetArray(i))

arclen = np.zeros(len(nsl.Points))

sids = nsl.CellData['SeedIds']
unique_sids = np.unique(sids)

polylines = []
idlists = [vtk.vtkIdList() for i in range(2)]

if 'IntegrationTime' not in nsl.PointData.keys() or 'Normals' not in nsl.PointData.keys():
 print("need integration time and Normals variables")
 return

for indx, seed in enumerate(unique_sids):
 parts = np.where(sids == seed)[0]
 sl.GetCellPoints(parts[0], idlists[0])
 w0 = [idlists[0].GetId(i) for i in range(idlists[0].GetNumberOfIds())]
 if len(parts) == 2:
 sl.GetCellPoints(parts[1], idlists[1])
 w1 = [idlists[1].GetId(i) for i in range(1, idlists[1].GetNumberOfIds())]
 nsl.PointData['Normals'][w1] = 0 - nsl.PointData['Normals'][w1]
 t0 = nsl.PointData['IntegrationTime'][w0[-1]]
 t1 = nsl.PointData['IntegrationTime'][w1[-1]]
 if t0 > t1:
 tmin = t1
 ids = w1[::-1] + w0
 else:
 tmin = t0
 nsl.PointData['Normals'][w0] = 0 - nsl.PointData['Normals'][w0]
 ids = w0[::-1] + w1
 else:
 ids = w0
 if flag:
 nsl.PointData['IntegrationTime'][ids] = nsl.PointData['IntegrationTime'][ids] - tmin
 polylines.append(ids)
 p = nsl.Points[ids]
 pv = p[1:] - p[:-1]
 l = np.linalg.norm(pv, axis=1)
 arclen[ids] = np.hstack(([0], np.cumsum(l)))

ct = dsa.numpyTovtkDataArray(np.array([vtk.VTK_POLY_LINE]*len(polylines)).astype('u1'))
line_lengths = [len(p)+1 for p in polylines] # number of vertices + 1 for count
co = dsa.numpy_support.numpy_to_vtkIdTypeArray(np.hstack(([0], np.cumsum(line_lengths)[:-1])).astype('i8'))

ca = vtk.vtkCellArray()
for pl in polylines:
 ca.InsertNextCell(len(pl), pl)

osl.SetCells(ct, co, ca)

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

al = dsa.numpyTovtkDataArray(arclen.astype('f4'))
al.SetName('arclen')
osl.GetPointData().AddArray(al)

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