File: TestRemovePolyData2.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,992 kB
  • sloc: cpp: 2,336,570; 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: 185; javascript: 165; objc: 153; tcl: 59
file content (156 lines) | stat: -rwxr-xr-x 3,701 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env python
from vtkmodules.vtkCommonCore import vtkIdTypeArray
from vtkmodules.vtkCommonDataModel import (
    vtkCellArray,
    vtkPolyData,
)
from vtkmodules.vtkFiltersGeneral import vtkRemovePolyData
from vtkmodules.vtkFiltersSources import vtkPlaneSource
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer,
)
import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingFreeType
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Test the removal of polydata using cell ids, point ids, and
# cells, and a combination of all three.

# Control test size
res = 3

# Create a grid of cells
plane = vtkPlaneSource()
plane.SetResolution(res,res)
plane.Update()

# Mark the cells to be deleted. Add one bogus cell
# that should not be deleted.
pd = vtkPolyData()
pd.SetPoints(plane.GetOutput().GetPoints())
cells = vtkCellArray()
npts = 4
cell = [1,2,6,5]
cells.InsertNextCell(npts,cell)
cell = [1,2,6,4]
cells.InsertNextCell(npts,cell)
cell = [4,5,9,8]
cells.InsertNextCell(npts,cell)
cell = [6,7,11,10]
cells.InsertNextCell(npts,cell)
cell = [9,10,14,13]
cells.InsertNextCell(npts,cell)
cell = [0,3,15,12]
cells.InsertNextCell(npts,cell)
pd.SetPolys(cells)

# Subtract the cells
remove1 = vtkRemovePolyData()
remove1.AddInputConnection(plane.GetOutputPort())
remove1.AddInputData(pd)
remove1.Update()

m1 = vtkPolyDataMapper()
m1.SetInputConnection(remove1.GetOutputPort())

a1 = vtkActor()
a1.SetMapper(m1)

# Now remove using point ids
ptIds = vtkIdTypeArray()
ptIds.SetNumberOfTuples(4)
ptIds.SetTuple1(0,0)
ptIds.SetTuple1(1,3)
ptIds.SetTuple1(2,12)
ptIds.SetTuple1(3,15)

remove2 = vtkRemovePolyData()
remove2.AddInputConnection(plane.GetOutputPort())
remove2.SetPointIds(ptIds)
remove2.Update()

m2 = vtkPolyDataMapper()
m2.SetInputConnection(remove2.GetOutputPort())

a2 = vtkActor()
a2.SetMapper(m2)

# Now remove using cell ids
cellIds = vtkIdTypeArray()
cellIds.SetNumberOfTuples(1)
cellIds.SetTuple1(0,4)

remove3 = vtkRemovePolyData()
remove3.AddInputConnection(plane.GetOutputPort())
remove3.SetCellIds(cellIds)
remove3.Update()

m3 = vtkPolyDataMapper()
m3.SetInputConnection(remove3.GetOutputPort())

a3 = vtkActor()
a3.SetMapper(m3)

# Now remove using a combination - should produce nothing
remove4 = vtkRemovePolyData()
remove4.AddInputConnection(plane.GetOutputPort())
remove4.AddInputData(pd)
remove4.SetCellIds(cellIds)
remove4.SetPointIds(ptIds)
remove4.Update()

m4 = vtkPolyDataMapper()
m4.SetInputConnection(remove4.GetOutputPort())

a4 = vtkActor()
a4.SetMapper(m4)

# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtkRenderer()
ren1.SetViewport(0,0,0.25,1.0)
ren2 = vtkRenderer()
ren2.SetViewport(0.25,0,0.5,1.0)
ren3 = vtkRenderer()
ren3.SetViewport(0.5,0,0.75,1.0)
ren4 = vtkRenderer()
ren4.SetViewport(0.75,0,1.0,1.0)
renWin = vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.AddRenderer(ren2)
renWin.AddRenderer(ren3)
renWin.AddRenderer(ren4)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Add the actors to the renderer, set the background and size
#
ren1.AddActor(a1)
ren2.AddActor(a2)
ren3.AddActor(a3)
ren4.AddActor(a4)

renWin.SetSize(600,150)
ren1.SetBackground(0.1, 0.2, 0.4)
ren2.SetBackground(0.1, 0.2, 0.4)
ren3.SetBackground(0.1, 0.2, 0.4)
ren4.SetBackground(0.1, 0.2, 0.4)
ren2.SetActiveCamera(ren1.GetActiveCamera())
ren3.SetActiveCamera(ren1.GetActiveCamera())
ren4.SetActiveCamera(ren1.GetActiveCamera())

ren1.GetActiveCamera().SetPosition(0,0,1)
ren1.ResetCamera()

iren.Initialize()

# render the image
#
renWin.Render()
iren.Start()