File: TestCookieCutter.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 178; javascript: 165; objc: 153; tcl: 59
file content (182 lines) | stat: -rwxr-xr-x 4,809 bytes parent folder | download | duplicates (5)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python
from vtkmodules.vtkCommonCore import (
    vtkPoints,
    vtkUnsignedCharArray,
)
from vtkmodules.vtkCommonDataModel import (
    vtkCellArray,
    vtkPolyData,
)
from vtkmodules.vtkFiltersCore import vtkGlyph3D
from vtkmodules.vtkFiltersModeling import vtkCookieCutter
from vtkmodules.vtkFiltersSources import vtkPlaneSource
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer,
)
import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingFreeType
import vtkmodules.vtkRenderingOpenGL2

# create planes
# Create the RenderWindow, Renderer
#
ren = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer( ren )

iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# create pipeline. Use a plane source to create an array
# of points; then glyph them. Then cookie cut the glphs.
#
plane = vtkPlaneSource()
plane.SetXResolution(25)
plane.SetYResolution(25)

# Custom glyph
glyphData = vtkPolyData()
glyphPts = vtkPoints()
glyphVerts = vtkCellArray()
glyphLines = vtkCellArray()
glyphPolys = vtkCellArray()
glyphData.SetPoints(glyphPts)
glyphData.SetVerts(glyphVerts)
glyphData.SetLines(glyphLines)
glyphData.SetPolys(glyphPolys)

glyphPts.InsertPoint(0, -0.5,-0.5,0.0)
glyphPts.InsertPoint(1,  0.5,-0.5,0.0)
glyphPts.InsertPoint(2,  0.5, 0.5,0.0)
glyphPts.InsertPoint(3, -0.5, 0.5,0.0)
glyphPts.InsertPoint(4,  0.0,-0.5,0.0)
glyphPts.InsertPoint(5,  0.0,-0.75,0.0)
glyphPts.InsertPoint(6,  0.5, 0.0,0.0)
glyphPts.InsertPoint(7,  0.75, 0.0,0.0)
glyphPts.InsertPoint(8,  0.0, 0.5,0.0)
glyphPts.InsertPoint(9,  0.0, 0.75,0.0)
glyphPts.InsertPoint(10, -0.5,0.0,0.0)
glyphPts.InsertPoint(11, -0.75,0.0,0.0)
glyphPts.InsertPoint(12, 0.0,0.0,0.0)
glyphPts.InsertPoint(13, -0.9,0.0,0.0)

glyphVerts.InsertNextCell(1)
glyphVerts.InsertCellPoint(12)

glyphLines.InsertNextCell(2)
glyphLines.InsertCellPoint(4)
glyphLines.InsertCellPoint(5)
glyphLines.InsertNextCell(2)
glyphLines.InsertCellPoint(6)
glyphLines.InsertCellPoint(7)
glyphLines.InsertNextCell(2)
glyphLines.InsertCellPoint(8)
glyphLines.InsertCellPoint(9)
# The last line is a polyline
glyphLines.InsertNextCell(3)
glyphLines.InsertCellPoint(10)
glyphLines.InsertCellPoint(11)
glyphLines.InsertCellPoint(13)

glyphPolys.InsertNextCell(4)
glyphPolys.InsertCellPoint(0)
glyphPolys.InsertCellPoint(1)
glyphPolys.InsertCellPoint(2)
glyphPolys.InsertCellPoint(3)

glyph = vtkGlyph3D()
glyph.SetInputConnection(plane.GetOutputPort())
glyph.SetSourceData(glyphData)
glyph.SetScaleFactor( 0.02 )

# Create multiple loops for cookie cutting
loops = vtkPolyData()
loopPts = vtkPoints()
loopPolys = vtkCellArray()
loops.SetPoints(loopPts)
loops.SetPolys(loopPolys)

loopPts.SetNumberOfPoints(16)
loopPts.SetPoint(0, -0.35,0.0,0.0)
loopPts.SetPoint(1, 0,-0.35,0.0)
loopPts.SetPoint(2, 0.35,0.0,0.0)
loopPts.SetPoint(3, 0.0,0.35,0.0)

loopPts.SetPoint(4, -0.35,-0.10,0.0)
loopPts.SetPoint(5, -0.35,-0.35,0.0)
loopPts.SetPoint(6, -0.10,-0.35,0.0)

loopPts.SetPoint(7, 0.35,-0.10,0.0)
loopPts.SetPoint(9, 0.35,-0.35,0.0)
loopPts.SetPoint(8, 0.10,-0.35,0.0)

loopPts.SetPoint(10, 0.35,0.10,0.0)
loopPts.SetPoint(11, 0.35,0.35,0.0)
loopPts.SetPoint(12, 0.10,0.35,0.0)

loopPts.SetPoint(13, -0.35,0.10,0.0)
loopPts.SetPoint(14, -0.35,0.35,0.0)
loopPts.SetPoint(15, -0.10,0.35,0.0)

loopPolys.InsertNextCell(4)
loopPolys.InsertCellPoint(0)
loopPolys.InsertCellPoint(1)
loopPolys.InsertCellPoint(2)
loopPolys.InsertCellPoint(3)

loopPolys.InsertNextCell(3)
loopPolys.InsertCellPoint(4)
loopPolys.InsertCellPoint(5)
loopPolys.InsertCellPoint(6)

loopPolys.InsertNextCell(3)
loopPolys.InsertCellPoint(7)
loopPolys.InsertCellPoint(8)
loopPolys.InsertCellPoint(9)

loopPolys.InsertNextCell(3)
loopPolys.InsertCellPoint(10)
loopPolys.InsertCellPoint(11)
loopPolys.InsertCellPoint(12)

loopPolys.InsertNextCell(3)
loopPolys.InsertCellPoint(13)
loopPolys.InsertCellPoint(14)
loopPolys.InsertCellPoint(15)

cookie = vtkCookieCutter()
cookie.SetInputConnection(glyph.GetOutputPort())
cookie.SetLoopsData(loops)

cookie.Update()
numCells = glyph.GetOutput().GetNumberOfCells()
glyphScalars = vtkUnsignedCharArray()
glyphScalars.SetNumberOfComponents( 4 )
glyphScalars.SetNumberOfTuples( numCells )
for i in range(numCells):
    glyphScalars.SetTuple4(i, 127, 207, 80, 127)
cookie.GetOutput().GetCellData().SetScalars(glyphScalars)

mapper = vtkPolyDataMapper()
mapper.SetInputConnection(cookie.GetOutputPort())

actor = vtkActor()
actor.SetMapper(mapper)

loopMapper = vtkPolyDataMapper()
loopMapper.SetInputData(loops)

loopActor = vtkActor()
loopActor.SetMapper(loopMapper)
loopActor.GetProperty().SetColor(1,0,0)
loopActor.GetProperty().SetRepresentationToWireframe()

ren.AddActor(actor)
ren.AddActor(loopActor)

renWin.Render()
iren.Start()