-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSampleSurfaceCF.xml
More file actions
66 lines (52 loc) · 3.33 KB
/
SampleSurfaceCF.xml
File metadata and controls
66 lines (52 loc) · 3.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
<ServerManagerConfiguration>
<ProxyGroup name="filters">
<SourceProxy name="RandomSampleSurface" class="vtkPythonProgrammableFilter" label="Sample Surface">
<Documentation
long_help="Sample a surface randomly"
short_help="Sample a surface randomly">
</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="nsamples"
label="nsamples"
initial_string="nsamples"
command="SetParameter"
animateable="1"
default_values="100"
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 random
from vtk.numpy_interface import dataset_adapter as dsa
from numpy import cross, ascontiguousarray, array, column_stack, arange
from numpy.linalg import norm

inp = inputs[0]

tf = vtk.vtkTriangleFilter()
tf.SetInputData(inp.VTKObject)
tf.Update()

dobj = dsa.WrapDataObject(tf.GetOutput())

nCells = dobj.GetNumberOfCells()

tris = dobj.GetPolygons().reshape((-1, 4))[:,1:]

points = dobj.GetPoints()

p0 = points[tris[:,0]]
p1 = points[tris[:,1]]
p2 = points[tris[:,2]]

areas = norm(cross(p1-p0, p2-p0), axis=1)/2.0
area_per_sample = sum(areas) / nsamples
samples_per_triangle = [(a / area_per_sample) for a in areas]
samples_per_triangle = [(int(i) + 1) if (random.random() < (i - int(i))) else int(i) for i in samples_per_triangle]
sampled_triangles = [[i]*j for i,j in enumerate(samples_per_triangle)]
sampled_triangles = [j for i in sampled_triangles for j in i]
selected_triangles = tris[sampled_triangles,:]

p = points[selected_triangles[:,0]]
q = points[selected_triangles[:,1]]
r = points[selected_triangles[:,2]]

qp = q - p
rp = r - p

unit = [[random.random(), random.random()] for i in range(len(selected_triangles))]
unit = [u if (u[0]+u[1]) < 1 else [1-u[0], 1-u[1]] for u in unit]

v = [u[0]*q + u[1]*r for u,q,r in zip(unit, qp, rp)]
samples = p + v

output.SetPoints(dsa.VTKArray(samples))
"
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>