Repository navigation
Expand file tree
/
Copy pathCurvatureStreamlinesCF.xml
More file actions
66 lines (52 loc) · 4.25 KB
/
Copy pathCurvatureStreamlinesCF.xml
File metadata and controls
66 lines (52 loc) · 4.25 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="CurvatureStreamlines" class="vtkPythonProgrammableFilter" label="Curvature Streamlines">
<Documentation
long_help="Create curvature vector for streamlines"
short_help="Create curvature vector for streamlines">
</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="stepsize"
label="stepsize"
initial_string="stepsize"
command="SetParameter"
animateable="1"
default_values="100000"
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
from math import ceil

isl = self.GetUnstructuredGridInput()
osl = self.GetUnstructuredGridOutput()

nisl = dsa.WrapDataObject(isl)
nosl = dsa.WrapDataObject(osl)

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

cell_locations = nisl.GetCellLocations()

lines = []
cells = nisl.Cells
while (len(cells)) > 0:
 n = cells[0]
 s = 1
 e = n + 1
 lines.append(cells[s:e])
 cells = cells[n+1:]

if 'arclen' in nisl.PointData.keys():
 arclen = nisl.PointData['arclen']
else:
 arclen = np.zeros(nisl.GetNumberOfPoints())
 nosl.PointData.append(arclen, 'arclen')

 for line in lines:
 points = nisl.Points[line]
 seglen = np.linalg.norm(points[1:] - points[:-1], axis=1)
 arclen[line] = np.concatenate(([0], np.cumsum(seglen)))

curvature = np.zeros(len(nisl.Points)*3).reshape((-1, 3))
binormal = np.zeros(len(nisl.Points)*3).reshape((-1, 3))

for indx,line in enumerate(lines):
 line_points = nisl.Points[line]
 line_arclen = arclen[line]
 llen = line_arclen[-1]
 nsteps = ceil(llen / stepsize)
 if nsteps < 3:
 nsteps = 3
 samples = np.linspace(0.0, llen, nsteps)
 sampled_points = np.column_stack([np.interp(samples, line_arclen, line_points[:,i]) for i in range(3)])
 vectors = sampled_points[1:] - sampled_points[:-1]
 d = np.linalg.norm(vectors, axis=1)
 d = np.where(d == 0.0, 1.0, d)
 vectors = vectors / d[:,np.newaxis]
 crosses = np.cross(vectors[1:], vectors[:-1], axis=1)
 crosses = np.concatenate(([crosses[0]], crosses, [crosses[-1]]))
 crosses = np.column_stack([np.interp(line_arclen, samples, crosses[:,i]) for i in range(3)])
 binorm = 0.5 * (vectors[1:] - vectors[:-1])
 binorm = np.concatenate(([binorm[0]], binorm, [binorm[-1]]))
 binorm = np.column_stack([np.interp(line_arclen, samples, binorm[:,i]) for i in range(3)])
 binormal[line] = binorm
 curvature[line] = crosses

nosl.PointData.append(curvature, 'curvature')
nosl.PointData.append(binormal, 'binormal')
nosl.CellData.append(np.arange(len(binormal)), 'cellID')
"
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>