1#!/usr/bin/env python
2import sys
3import vtk
4from vtk.test import Testing
5from vtk.util.misc import vtkGetDataRoot
6VTK_DATA_ROOT = vtkGetDataRoot()
7
8# Prevent .pyc files being created.
9# Stops the vtk source being polluted
10# by .pyc files.
11sys.dont_write_bytecode = True
12
13import backdrop
14
15# Contour every cell type
16
17# Since some of our actors are a single vertex, we need to remove all
18# cullers so the single vertex actors will render
19ren1 = vtk.vtkRenderer()
20ren1.GetCullers().RemoveAllItems()
21
22renWin = vtk.vtkRenderWindow()
23renWin.AddRenderer(ren1)
24iren = vtk.vtkRenderWindowInteractor()
25iren.SetRenderWindow(renWin)
26
27# create a scene with one of each cell type
28# Voxel
29voxelPoints = vtk.vtkPoints()
30voxelPoints.SetNumberOfPoints(8)
31voxelPoints.InsertPoint(0, 0, 0, 0)
32voxelPoints.InsertPoint(1, 1, 0, 0)
33voxelPoints.InsertPoint(2, 0, 1, 0)
34voxelPoints.InsertPoint(3, 1, 1, 0)
35voxelPoints.InsertPoint(4, 0, 0, 1)
36voxelPoints.InsertPoint(5, 1, 0, 1)
37voxelPoints.InsertPoint(6, 0, 1, 1)
38voxelPoints.InsertPoint(7, 1, 1, 1)
39
40voxelScalars = vtk.vtkFloatArray()
41voxelScalars.SetNumberOfTuples(8)
42voxelScalars.InsertValue(0, 0)
43voxelScalars.InsertValue(1, 1)
44voxelScalars.InsertValue(2, 0)
45voxelScalars.InsertValue(3, 0)
46voxelScalars.InsertValue(4, 0)
47voxelScalars.InsertValue(5, 0)
48voxelScalars.InsertValue(6, 0)
49voxelScalars.InsertValue(7, 0)
50
51aVoxel = vtk.vtkVoxel()
52aVoxel.GetPointIds().SetId(0, 0)
53aVoxel.GetPointIds().SetId(1, 1)
54aVoxel.GetPointIds().SetId(2, 2)
55aVoxel.GetPointIds().SetId(3, 3)
56aVoxel.GetPointIds().SetId(4, 4)
57aVoxel.GetPointIds().SetId(5, 5)
58aVoxel.GetPointIds().SetId(6, 6)
59aVoxel.GetPointIds().SetId(7, 7)
60
61aVoxelGrid = vtk.vtkUnstructuredGrid()
62aVoxelGrid.Allocate(1, 1)
63aVoxelGrid.InsertNextCell(aVoxel.GetCellType(), aVoxel.GetPointIds())
64aVoxelGrid.SetPoints(voxelPoints)
65aVoxelGrid.GetPointData().SetScalars(voxelScalars)
66
67voxelContours = vtk.vtkContourFilter()
68voxelContours.SetInputData(aVoxelGrid)
69voxelContours.SetValue(0, .5)
70
71aVoxelContourMapper = vtk.vtkDataSetMapper()
72aVoxelContourMapper.SetInputConnection(voxelContours.GetOutputPort())
73aVoxelContourMapper.ScalarVisibilityOff()
74
75aVoxelMapper = vtk.vtkDataSetMapper()
76aVoxelMapper.SetInputData(aVoxelGrid)
77aVoxelMapper.ScalarVisibilityOff()
78
79aVoxelActor = vtk.vtkActor()
80aVoxelActor.SetMapper(aVoxelMapper)
81aVoxelActor.GetProperty().SetRepresentationToWireframe()
82
83aVoxelContourActor = vtk.vtkActor()
84aVoxelContourActor.SetMapper(aVoxelContourMapper)
85aVoxelContourActor.GetProperty().BackfaceCullingOn()
86
87# Hexahedron
88
89hexahedronPoints = vtk.vtkPoints()
90hexahedronPoints.SetNumberOfPoints(8)
91hexahedronPoints.InsertPoint(0, 0, 0, 0)
92hexahedronPoints.InsertPoint(1, 1, 0, 0)
93hexahedronPoints.InsertPoint(2, 1, 1, 0)
94hexahedronPoints.InsertPoint(3, 0, 1, 0)
95hexahedronPoints.InsertPoint(4, 0, 0, 1)
96hexahedronPoints.InsertPoint(5, 1, 0, 1)
97hexahedronPoints.InsertPoint(6, 1, 1, 1)
98hexahedronPoints.InsertPoint(7, 0, 1, 1)
99
100hexahedronScalars = vtk.vtkFloatArray()
101hexahedronScalars.SetNumberOfTuples(8)
102hexahedronScalars.InsertValue(0, 0)
103hexahedronScalars.InsertValue(1, 1)
104hexahedronScalars.InsertValue(2, 0)
105hexahedronScalars.InsertValue(3, 0)
106hexahedronScalars.InsertValue(4, 0)
107hexahedronScalars.InsertValue(5, 0)
108hexahedronScalars.InsertValue(6, 0)
109hexahedronScalars.InsertValue(7, 0)
110
111aHexahedron = vtk.vtkHexahedron()
112aHexahedron.GetPointIds().SetId(0, 0)
113aHexahedron.GetPointIds().SetId(1, 1)
114aHexahedron.GetPointIds().SetId(2, 2)
115aHexahedron.GetPointIds().SetId(3, 3)
116aHexahedron.GetPointIds().SetId(4, 4)
117aHexahedron.GetPointIds().SetId(5, 5)
118aHexahedron.GetPointIds().SetId(6, 6)
119aHexahedron.GetPointIds().SetId(7, 7)
120
121aHexahedronGrid = vtk.vtkUnstructuredGrid()
122aHexahedronGrid.Allocate(1, 1)
123aHexahedronGrid.InsertNextCell(aHexahedron.GetCellType(), aHexahedron.GetPointIds())
124aHexahedronGrid.SetPoints(hexahedronPoints)
125aHexahedronGrid.GetPointData().SetScalars(hexahedronScalars)
126
127hexahedronContours = vtk.vtkContourFilter()
128hexahedronContours.SetInputData(aHexahedronGrid)
129hexahedronContours.SetValue(0, .5)
130
131aHexahedronContourMapper = vtk.vtkDataSetMapper()
132aHexahedronContourMapper.SetInputConnection(hexahedronContours.GetOutputPort())
133aHexahedronContourMapper.ScalarVisibilityOff()
134
135aHexahedronMapper = vtk.vtkDataSetMapper()
136aHexahedronMapper.SetInputData(aHexahedronGrid)
137aHexahedronMapper.ScalarVisibilityOff()
138
139aHexahedronActor = vtk.vtkActor()
140aHexahedronActor.SetMapper(aHexahedronMapper)
141aHexahedronActor.GetProperty().BackfaceCullingOn()
142aHexahedronActor.GetProperty().SetRepresentationToWireframe()
143
144aHexahedronContourActor = vtk.vtkActor()
145aHexahedronContourActor.SetMapper(aHexahedronContourMapper)
146aHexahedronContourActor.GetProperty().BackfaceCullingOn()
147
148# Tetra
149
150tetraPoints = vtk.vtkPoints()
151tetraPoints.SetNumberOfPoints(4)
152tetraPoints.InsertPoint(0, 0, 0, 0)
153tetraPoints.InsertPoint(1, 1, 0, 0)
154tetraPoints.InsertPoint(2, .5, 1, 0)
155tetraPoints.InsertPoint(3, .5, .5, 1)
156
157tetraScalars = vtk.vtkFloatArray()
158tetraScalars.SetNumberOfTuples(4)
159tetraScalars.InsertValue(0, 1)
160tetraScalars.InsertValue(1, 0)
161tetraScalars.InsertValue(2, 0)
162tetraScalars.InsertValue(3, 0)
163
164aTetra = vtk.vtkTetra()
165aTetra.GetPointIds().SetId(0, 0)
166aTetra.GetPointIds().SetId(1, 1)
167aTetra.GetPointIds().SetId(2, 2)
168aTetra.GetPointIds().SetId(3, 3)
169
170aTetraGrid = vtk.vtkUnstructuredGrid()
171aTetraGrid.Allocate(1, 1)
172aTetraGrid.InsertNextCell(aTetra.GetCellType(), aTetra.GetPointIds())
173aTetraGrid.SetPoints(tetraPoints)
174aTetraGrid.GetPointData().SetScalars(tetraScalars)
175
176tetraContours = vtk.vtkContourFilter()
177tetraContours.SetInputData(aTetraGrid)
178tetraContours.SetValue(0, .5)
179
180aTetraContourMapper = vtk.vtkDataSetMapper()
181aTetraContourMapper.SetInputConnection(tetraContours.GetOutputPort())
182aTetraContourMapper.ScalarVisibilityOff()
183
184aTetraMapper = vtk.vtkDataSetMapper()
185aTetraMapper.SetInputData(aTetraGrid)
186aTetraMapper.ScalarVisibilityOff()
187
188aTetraContourActor = vtk.vtkActor()
189aTetraContourActor.SetMapper(aTetraContourMapper)
190
191aTetraActor = vtk.vtkActor()
192aTetraActor.SetMapper(aTetraMapper)
193aTetraActor.GetProperty().SetRepresentationToWireframe()
194
195# Wedge
196
197wedgePoints = vtk.vtkPoints()
198wedgePoints.SetNumberOfPoints(6)
199wedgePoints.InsertPoint(0, 0, 1, 0)
200wedgePoints.InsertPoint(1, 0, 0, 0)
201wedgePoints.InsertPoint(2, 0, .5, .5)
202wedgePoints.InsertPoint(3, 1, 1, 0)
203wedgePoints.InsertPoint(4, 1, 0, 0)
204wedgePoints.InsertPoint(5, 1, .5, .5)
205
206wedgeScalars = vtk.vtkFloatArray()
207wedgeScalars.SetNumberOfTuples(6)
208wedgeScalars.InsertValue(0, 1)
209wedgeScalars.InsertValue(1, 1)
210wedgeScalars.InsertValue(2, 0)
211wedgeScalars.InsertValue(3, 1)
212wedgeScalars.InsertValue(4, 1)
213wedgeScalars.InsertValue(5, 0)
214
215aWedge = vtk.vtkWedge()
216aWedge.GetPointIds().SetId(0, 0)
217aWedge.GetPointIds().SetId(1, 1)
218aWedge.GetPointIds().SetId(2, 2)
219aWedge.GetPointIds().SetId(3, 3)
220aWedge.GetPointIds().SetId(4, 4)
221aWedge.GetPointIds().SetId(5, 5)
222
223aWedgeGrid = vtk.vtkUnstructuredGrid()
224aWedgeGrid.Allocate(1, 1)
225aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds())
226aWedgeGrid.SetPoints(wedgePoints)
227aWedgeGrid.GetPointData().SetScalars(wedgeScalars)
228
229wedgeContours = vtk.vtkContourFilter()
230wedgeContours.SetInputData(aWedgeGrid)
231wedgeContours.SetValue(0, .5)
232
233aWedgeContourMapper = vtk.vtkDataSetMapper()
234aWedgeContourMapper.SetInputConnection(wedgeContours.GetOutputPort())
235aWedgeContourMapper.ScalarVisibilityOff()
236
237aWedgeMapper = vtk.vtkDataSetMapper()
238aWedgeMapper.SetInputData(aWedgeGrid)
239aWedgeMapper.ScalarVisibilityOff()
240
241aWedgeContourActor = vtk.vtkActor()
242aWedgeContourActor.SetMapper(aWedgeContourMapper)
243
244aWedgeActor = vtk.vtkActor()
245aWedgeActor.SetMapper(aWedgeMapper)
246aWedgeActor.GetProperty().SetRepresentationToWireframe()
247
248# Pyramid
249
250pyramidPoints = vtk.vtkPoints()
251pyramidPoints.SetNumberOfPoints(5)
252pyramidPoints.InsertPoint(0, 0, 0, 0)
253pyramidPoints.InsertPoint(1, 1, 0, 0)
254pyramidPoints.InsertPoint(2, 1, 1, 0)
255pyramidPoints.InsertPoint(3, 0, 1, 0)
256pyramidPoints.InsertPoint(4, .5, .5, 1)
257
258pyramidScalars = vtk.vtkFloatArray()
259pyramidScalars.SetNumberOfTuples(5)
260pyramidScalars.InsertValue(0, 1)
261pyramidScalars.InsertValue(1, 1)
262pyramidScalars.InsertValue(2, 1)
263pyramidScalars.InsertValue(3, 1)
264pyramidScalars.InsertValue(4, 0)
265
266aPyramid = vtk.vtkPyramid()
267aPyramid.GetPointIds().SetId(0, 0)
268aPyramid.GetPointIds().SetId(1, 1)
269aPyramid.GetPointIds().SetId(2, 2)
270aPyramid.GetPointIds().SetId(3, 3)
271aPyramid.GetPointIds().SetId(4, 4)
272
273aPyramidGrid = vtk.vtkUnstructuredGrid()
274aPyramidGrid.Allocate(1, 1)
275aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds())
276aPyramidGrid.SetPoints(pyramidPoints)
277aPyramidGrid.GetPointData().SetScalars(pyramidScalars)
278
279pyramidContours = vtk.vtkContourFilter()
280pyramidContours.SetInputData(aPyramidGrid)
281pyramidContours.SetValue(0, .5)
282
283aPyramidContourMapper = vtk.vtkDataSetMapper()
284aPyramidContourMapper.SetInputConnection(pyramidContours.GetOutputPort())
285aPyramidContourMapper.ScalarVisibilityOff()
286
287aPyramidMapper = vtk.vtkDataSetMapper()
288aPyramidMapper.SetInputData(aPyramidGrid)
289aPyramidMapper.ScalarVisibilityOff()
290
291aPyramidContourActor = vtk.vtkActor()
292aPyramidContourActor.SetMapper(aPyramidContourMapper)
293
294aPyramidActor = vtk.vtkActor()
295aPyramidActor.SetMapper(aPyramidMapper)
296aPyramidActor.GetProperty().SetRepresentationToWireframe()
297
298# Pixel
299
300pixelPoints = vtk.vtkPoints()
301pixelPoints.SetNumberOfPoints(4)
302pixelPoints.InsertPoint(0, 0, 0, 0)
303pixelPoints.InsertPoint(1, 1, 0, 0)
304pixelPoints.InsertPoint(2, 0, 1, 0)
305pixelPoints.InsertPoint(3, 1, 1, 0)
306
307pixelScalars = vtk.vtkFloatArray()
308pixelScalars.SetNumberOfTuples(4)
309pixelScalars.InsertValue(0, 1)
310pixelScalars.InsertValue(1, 0)
311pixelScalars.InsertValue(2, 0)
312pixelScalars.InsertValue(3, 0)
313
314aPixel = vtk.vtkPixel()
315aPixel.GetPointIds().SetId(0, 0)
316aPixel.GetPointIds().SetId(1, 1)
317aPixel.GetPointIds().SetId(2, 2)
318aPixel.GetPointIds().SetId(3, 3)
319
320aPixelGrid = vtk.vtkUnstructuredGrid()
321aPixelGrid.Allocate(1, 1)
322aPixelGrid.InsertNextCell(aPixel.GetCellType(), aPixel.GetPointIds())
323aPixelGrid.SetPoints(pixelPoints)
324aPixelGrid.GetPointData().SetScalars(pixelScalars)
325
326pixelContours = vtk.vtkContourFilter()
327pixelContours.SetInputData(aPixelGrid)
328pixelContours.SetValue(0, .5)
329
330aPixelContourMapper = vtk.vtkDataSetMapper()
331aPixelContourMapper.SetInputConnection(pixelContours.GetOutputPort())
332aPixelContourMapper.ScalarVisibilityOff()
333
334aPixelMapper = vtk.vtkDataSetMapper()
335aPixelMapper.SetInputData(aPixelGrid)
336aPixelMapper.ScalarVisibilityOff()
337
338aPixelContourActor = vtk.vtkActor()
339aPixelContourActor.SetMapper(aPixelContourMapper)
340
341aPixelActor = vtk.vtkActor()
342aPixelActor.SetMapper(aPixelMapper)
343aPixelActor.GetProperty().BackfaceCullingOn()
344aPixelActor.GetProperty().SetRepresentationToWireframe()
345
346# Quad
347
348quadPoints = vtk.vtkPoints()
349quadPoints.SetNumberOfPoints(4)
350quadPoints.InsertPoint(0, 0, 0, 0)
351quadPoints.InsertPoint(1, 1, 0, 0)
352quadPoints.InsertPoint(2, 1, 1, 0)
353quadPoints.InsertPoint(3, 0, 1, 0)
354
355quadScalars = vtk.vtkFloatArray()
356quadScalars.SetNumberOfTuples(4)
357quadScalars.InsertValue(0, 1)
358quadScalars.InsertValue(1, 0)
359quadScalars.InsertValue(2, 0)
360quadScalars.InsertValue(3, 0)
361
362aQuad = vtk.vtkQuad()
363aQuad.GetPointIds().SetId(0, 0)
364aQuad.GetPointIds().SetId(1, 1)
365aQuad.GetPointIds().SetId(2, 2)
366aQuad.GetPointIds().SetId(3, 3)
367
368aQuadGrid = vtk.vtkUnstructuredGrid()
369aQuadGrid.Allocate(1, 1)
370aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds())
371aQuadGrid.SetPoints(quadPoints)
372aQuadGrid.GetPointData().SetScalars(quadScalars)
373
374quadContours = vtk.vtkContourFilter()
375quadContours.SetInputData(aQuadGrid)
376quadContours.SetValue(0, .5)
377
378aQuadContourMapper = vtk.vtkDataSetMapper()
379aQuadContourMapper.SetInputConnection(quadContours.GetOutputPort())
380aQuadContourMapper.ScalarVisibilityOff()
381
382aQuadMapper = vtk.vtkDataSetMapper()
383aQuadMapper.SetInputData(aQuadGrid)
384aQuadMapper.ScalarVisibilityOff()
385
386aQuadContourActor = vtk.vtkActor()
387aQuadContourActor.SetMapper(aQuadContourMapper)
388
389aQuadActor = vtk.vtkActor()
390aQuadActor.SetMapper(aQuadMapper)
391aQuadActor.GetProperty().BackfaceCullingOn()
392aQuadActor.GetProperty().SetRepresentationToWireframe()
393
394# Triangle
395
396trianglePoints = vtk.vtkPoints()
397trianglePoints.SetNumberOfPoints(3)
398trianglePoints.InsertPoint(0, 0, 0, 0)
399trianglePoints.InsertPoint(1, 1, 0, 0)
400trianglePoints.InsertPoint(2, .5, .5, 0)
401
402triangleScalars = vtk.vtkFloatArray()
403triangleScalars.SetNumberOfTuples(3)
404triangleScalars.InsertValue(0, 1)
405triangleScalars.InsertValue(1, 0)
406triangleScalars.InsertValue(2, 0)
407
408aTriangle = vtk.vtkTriangle()
409aTriangle.GetPointIds().SetId(0, 0)
410aTriangle.GetPointIds().SetId(1, 1)
411aTriangle.GetPointIds().SetId(2, 2)
412
413aTriangleGrid = vtk.vtkUnstructuredGrid()
414aTriangleGrid.Allocate(1, 1)
415aTriangleGrid.InsertNextCell(aTriangle.GetCellType(), aTriangle.GetPointIds())
416aTriangleGrid.SetPoints(trianglePoints)
417aTriangleGrid.GetPointData().SetScalars(triangleScalars)
418
419triangleContours = vtk.vtkContourFilter()
420triangleContours.SetInputData(aTriangleGrid)
421triangleContours.SetValue(0, .5)
422
423aTriangleContourMapper = vtk.vtkDataSetMapper()
424aTriangleContourMapper.SetInputConnection(triangleContours.GetOutputPort())
425aTriangleContourMapper.ScalarVisibilityOff()
426
427aTriangleContourActor = vtk.vtkActor()
428aTriangleContourActor.SetMapper(aTriangleContourMapper)
429
430aTriangleMapper = vtk.vtkDataSetMapper()
431aTriangleMapper.SetInputData(aTriangleGrid)
432aTriangleMapper.ScalarVisibilityOff()
433
434aTriangleActor = vtk.vtkActor()
435aTriangleActor.SetMapper(aTriangleMapper)
436aTriangleActor.GetProperty().BackfaceCullingOn()
437aTriangleActor.GetProperty().SetRepresentationToWireframe()
438
439# Polygon
440
441polygonPoints = vtk.vtkPoints()
442polygonPoints.SetNumberOfPoints(4)
443polygonPoints.InsertPoint(0, 0, 0, 0)
444polygonPoints.InsertPoint(1, 1, 0, 0)
445polygonPoints.InsertPoint(2, 1, 1, 0)
446polygonPoints.InsertPoint(3, 0, 1, 0)
447
448polygonScalars = vtk.vtkFloatArray()
449polygonScalars.SetNumberOfTuples(4)
450polygonScalars.InsertValue(0, 1)
451polygonScalars.InsertValue(1, 0)
452polygonScalars.InsertValue(2, 0)
453polygonScalars.InsertValue(3, 0)
454
455aPolygon = vtk.vtkPolygon()
456aPolygon.GetPointIds().SetNumberOfIds(4)
457aPolygon.GetPointIds().SetId(0, 0)
458aPolygon.GetPointIds().SetId(1, 1)
459aPolygon.GetPointIds().SetId(2, 2)
460aPolygon.GetPointIds().SetId(3, 3)
461
462aPolygonGrid = vtk.vtkUnstructuredGrid()
463aPolygonGrid.Allocate(1, 1)
464aPolygonGrid.InsertNextCell(aPolygon.GetCellType(), aPolygon.GetPointIds())
465aPolygonGrid.SetPoints(polygonPoints)
466aPolygonGrid.GetPointData().SetScalars(polygonScalars)
467
468polygonContours = vtk.vtkContourFilter()
469polygonContours.SetInputData(aPolygonGrid)
470polygonContours.SetValue(0, .5)
471
472aPolygonContourMapper = vtk.vtkDataSetMapper()
473aPolygonContourMapper.SetInputConnection(polygonContours.GetOutputPort())
474aPolygonContourMapper.ScalarVisibilityOff()
475
476aPolygonMapper = vtk.vtkDataSetMapper()
477aPolygonMapper.SetInputData(aPolygonGrid)
478aPolygonMapper.ScalarVisibilityOff()
479
480aPolygonContourActor = vtk.vtkActor()
481aPolygonContourActor.SetMapper(aPolygonContourMapper)
482
483aPolygonActor = vtk.vtkActor()
484aPolygonActor.SetMapper(aPolygonMapper)
485aPolygonActor.GetProperty().BackfaceCullingOn()
486aPolygonActor.GetProperty().SetRepresentationToWireframe()
487
488# Triangle strip
489
490triangleStripPoints = vtk.vtkPoints()
491triangleStripPoints.SetNumberOfPoints(5)
492triangleStripPoints.InsertPoint(0, 0, 1, 0)
493triangleStripPoints.InsertPoint(1, 0, 0, 0)
494triangleStripPoints.InsertPoint(2, 1, 1, 0)
495triangleStripPoints.InsertPoint(3, 1, 0, 0)
496triangleStripPoints.InsertPoint(4, 2, 1, 0)
497
498triangleStripScalars = vtk.vtkFloatArray()
499triangleStripScalars.SetNumberOfTuples(5)
500triangleStripScalars.InsertValue(0, 1)
501triangleStripScalars.InsertValue(1, 0)
502triangleStripScalars.InsertValue(2, 0)
503triangleStripScalars.InsertValue(3, 0)
504triangleStripScalars.InsertValue(4, 0)
505
506aTriangleStrip = vtk.vtkTriangleStrip()
507aTriangleStrip.GetPointIds().SetNumberOfIds(5)
508aTriangleStrip.GetPointIds().SetId(0, 0)
509aTriangleStrip.GetPointIds().SetId(1, 1)
510aTriangleStrip.GetPointIds().SetId(2, 2)
511aTriangleStrip.GetPointIds().SetId(3, 3)
512aTriangleStrip.GetPointIds().SetId(4, 4)
513
514aTriangleStripGrid = vtk.vtkUnstructuredGrid()
515aTriangleStripGrid.Allocate(1, 1)
516aTriangleStripGrid.InsertNextCell(aTriangleStrip.GetCellType(), aTriangleStrip.GetPointIds())
517aTriangleStripGrid.SetPoints(triangleStripPoints)
518aTriangleStripGrid.GetPointData().SetScalars(triangleStripScalars)
519
520aTriangleStripMapper = vtk.vtkDataSetMapper()
521aTriangleStripMapper.SetInputData(aTriangleStripGrid)
522aTriangleStripMapper.ScalarVisibilityOff()
523
524triangleStripContours = vtk.vtkContourFilter()
525triangleStripContours.SetInputData(aTriangleStripGrid)
526triangleStripContours.SetValue(0, .5)
527
528aTriangleStripContourMapper = vtk.vtkDataSetMapper()
529aTriangleStripContourMapper.SetInputConnection(triangleStripContours.GetOutputPort())
530aTriangleStripContourMapper.ScalarVisibilityOff()
531
532aTriangleStripContourActor = vtk.vtkActor()
533aTriangleStripContourActor.SetMapper(aTriangleStripContourMapper)
534
535aTriangleStripActor = vtk.vtkActor()
536aTriangleStripActor.SetMapper(aTriangleStripMapper)
537aTriangleStripActor.GetProperty().BackfaceCullingOn()
538aTriangleStripActor.GetProperty().SetRepresentationToWireframe()
539
540# Line
541
542linePoints = vtk.vtkPoints()
543linePoints.SetNumberOfPoints(2)
544linePoints.InsertPoint(0, 0, 0, 0)
545linePoints.InsertPoint(1, 1, 1, 0)
546lineScalars = vtk.vtkFloatArray()
547lineScalars.SetNumberOfTuples(2)
548lineScalars.InsertValue(0, 1)
549lineScalars.InsertValue(1, 0)
550
551aLine = vtk.vtkLine()
552aLine.GetPointIds().SetId(0, 0)
553aLine.GetPointIds().SetId(1, 1)
554aLineGrid = vtk.vtkUnstructuredGrid()
555
556aLineGrid.Allocate(1, 1)
557aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds())
558aLineGrid.SetPoints(linePoints)
559aLineGrid.GetPointData().SetScalars(lineScalars)
560
561lineContours = vtk.vtkContourFilter()
562lineContours.SetInputData(aLineGrid)
563lineContours.SetValue(0, .5)
564
565aLineContourMapper = vtk.vtkDataSetMapper()
566aLineContourMapper.SetInputConnection(lineContours.GetOutputPort())
567aLineContourMapper.ScalarVisibilityOff()
568
569aLineContourActor = vtk.vtkActor()
570aLineContourActor.SetMapper(aLineContourMapper)
571
572aLineMapper = vtk.vtkDataSetMapper()
573aLineMapper.SetInputData(aLineGrid)
574aLineMapper.ScalarVisibilityOff()
575
576aLineActor = vtk.vtkActor()
577aLineActor.SetMapper(aLineMapper)
578aLineActor.GetProperty().BackfaceCullingOn()
579aLineActor.GetProperty().SetRepresentationToWireframe()
580
581# Polyline
582
583polyLinePoints = vtk.vtkPoints()
584polyLinePoints.SetNumberOfPoints(3)
585polyLinePoints.InsertPoint(0, 0, 0, 0)
586polyLinePoints.InsertPoint(1, 1, 1, 0)
587polyLinePoints.InsertPoint(2, 1, 0, 0)
588
589polyLineScalars = vtk.vtkFloatArray()
590polyLineScalars.SetNumberOfTuples(3)
591polyLineScalars.InsertValue(0, 1)
592polyLineScalars.InsertValue(1, 0)
593polyLineScalars.InsertValue(2, 0)
594
595aPolyLine = vtk.vtkPolyLine()
596aPolyLine.GetPointIds().SetNumberOfIds(3)
597aPolyLine.GetPointIds().SetId(0, 0)
598aPolyLine.GetPointIds().SetId(1, 1)
599aPolyLine.GetPointIds().SetId(2, 2)
600
601aPolyLineGrid = vtk.vtkUnstructuredGrid()
602aPolyLineGrid.Allocate(1, 1)
603aPolyLineGrid.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())
604aPolyLineGrid.SetPoints(polyLinePoints)
605aPolyLineGrid.GetPointData().SetScalars(polyLineScalars)
606
607polyLineContours = vtk.vtkContourFilter()
608polyLineContours.SetInputData(aPolyLineGrid)
609polyLineContours.SetValue(0, .5)
610
611aPolyLineContourMapper = vtk.vtkDataSetMapper()
612aPolyLineContourMapper.SetInputConnection(polyLineContours.GetOutputPort())
613aPolyLineContourMapper.ScalarVisibilityOff()
614
615aPolyLineContourActor = vtk.vtkActor()
616aPolyLineContourActor.SetMapper(aPolyLineContourMapper)
617
618aPolyLineMapper = vtk.vtkDataSetMapper()
619aPolyLineMapper.SetInputData(aPolyLineGrid)
620aPolyLineMapper.ScalarVisibilityOff()
621
622aPolyLineActor = vtk.vtkActor()
623aPolyLineActor.SetMapper(aPolyLineMapper)
624aPolyLineActor.GetProperty().BackfaceCullingOn()
625aPolyLineActor.GetProperty().SetRepresentationToWireframe()
626
627# Vertex
628
629vertexPoints = vtk.vtkPoints()
630vertexPoints.SetNumberOfPoints(1)
631vertexPoints.InsertPoint(0, 0, 0, 0)
632
633vertexScalars = vtk.vtkFloatArray()
634vertexScalars.SetNumberOfTuples(1)
635vertexScalars.InsertValue(0, 1)
636
637aVertex = vtk.vtkVertex()
638aVertex.GetPointIds().SetId(0, 0)
639
640aVertexGrid = vtk.vtkUnstructuredGrid()
641aVertexGrid.Allocate(1, 1)
642aVertexGrid.InsertNextCell(aVertex.GetCellType(), aVertex.GetPointIds())
643aVertexGrid.SetPoints(vertexPoints)
644aVertexGrid.GetPointData().SetScalars(vertexScalars)
645
646vertexContours = vtk.vtkContourFilter()
647vertexContours.SetInputData(aVertexGrid)
648vertexContours.SetValue(0, 1)
649
650aVertexContourMapper = vtk.vtkDataSetMapper()
651aVertexContourMapper.SetInputConnection(vertexContours.GetOutputPort())
652aVertexContourMapper.ScalarVisibilityOff()
653
654aVertexContourActor = vtk.vtkActor()
655aVertexContourActor.SetMapper(aVertexContourMapper)
656aVertexContourActor.GetProperty().SetRepresentationToWireframe()
657
658aVertexMapper = vtk.vtkDataSetMapper()
659aVertexMapper.SetInputData(aVertexGrid)
660aVertexMapper.ScalarVisibilityOff()
661
662aVertexActor = vtk.vtkActor()
663aVertexActor.SetMapper(aVertexMapper)
664aVertexActor.GetProperty().BackfaceCullingOn()
665
666# Poly Vertex
667
668polyVertexPoints = vtk.vtkPoints()
669polyVertexPoints.SetNumberOfPoints(3)
670polyVertexPoints.InsertPoint(0, 0, 0, 0)
671polyVertexPoints.InsertPoint(1, 1, 0, 0)
672polyVertexPoints.InsertPoint(2, 1, 1, 0)
673
674polyVertexScalars = vtk.vtkFloatArray()
675polyVertexScalars.SetNumberOfTuples(3)
676polyVertexScalars.InsertValue(0, 1)
677polyVertexScalars.InsertValue(1, 0)
678polyVertexScalars.InsertValue(2, 0)
679
680aPolyVertex = vtk.vtkPolyVertex()
681aPolyVertex.GetPointIds().SetNumberOfIds(3)
682aPolyVertex.GetPointIds().SetId(0, 0)
683aPolyVertex.GetPointIds().SetId(1, 1)
684aPolyVertex.GetPointIds().SetId(2, 2)
685
686aPolyVertexGrid = vtk.vtkUnstructuredGrid()
687aPolyVertexGrid.Allocate(1, 1)
688aPolyVertexGrid.InsertNextCell(aPolyVertex.GetCellType(), aPolyVertex.GetPointIds())
689aPolyVertexGrid.SetPoints(polyVertexPoints)
690aPolyVertexGrid.GetPointData().SetScalars(polyVertexScalars)
691
692polyVertexContours = vtk.vtkContourFilter()
693polyVertexContours.SetInputData(aPolyVertexGrid)
694polyVertexContours.SetValue(0, 0)
695
696aPolyVertexContourMapper = vtk.vtkDataSetMapper()
697aPolyVertexContourMapper.SetInputConnection(polyVertexContours.GetOutputPort())
698aPolyVertexContourMapper.ScalarVisibilityOff()
699
700aPolyVertexContourActor = vtk.vtkActor()
701aPolyVertexContourActor.SetMapper(aPolyVertexContourMapper)
702aPolyVertexContourActor.GetProperty().SetRepresentationToWireframe()
703
704aPolyVertexMapper = vtk.vtkDataSetMapper()
705aPolyVertexMapper.SetInputData(aPolyVertexGrid)
706aPolyVertexMapper.ScalarVisibilityOff()
707
708aPolyVertexActor = vtk.vtkActor()
709aPolyVertexActor.SetMapper(aPolyVertexMapper)
710
711# Pentagonal prism
712
713pentaPoints = vtk.vtkPoints()
714pentaPoints.SetNumberOfPoints(10)
715pentaPoints.InsertPoint(0, 0.25, 0.0, 0.0)
716pentaPoints.InsertPoint(1, 0.75, 0.0, 0.0)
717pentaPoints.InsertPoint(2, 1.0, 0.5, 0.0)
718pentaPoints.InsertPoint(3, 0.5, 1.0, 0.0)
719pentaPoints.InsertPoint(4, 0.0, 0.5, 0.0)
720pentaPoints.InsertPoint(5, 0.25, 0.0, 1.0)
721pentaPoints.InsertPoint(6, 0.75, 0.0, 1.0)
722pentaPoints.InsertPoint(7, 1.0, 0.5, 1.0)
723pentaPoints.InsertPoint(8, 0.5, 1.0, 1.0)
724pentaPoints.InsertPoint(9, 0.0, 0.5, 1.0)
725
726pentaScalars = vtk.vtkFloatArray()
727pentaScalars.SetNumberOfTuples(10)
728pentaScalars.InsertValue(0, 1)
729pentaScalars.InsertValue(1, 1)
730pentaScalars.InsertValue(2, 1)
731pentaScalars.InsertValue(3, 1)
732pentaScalars.InsertValue(4, 1)
733pentaScalars.InsertValue(5, 0)
734pentaScalars.InsertValue(6, 0)
735pentaScalars.InsertValue(7, 0)
736pentaScalars.InsertValue(8, 0)
737pentaScalars.InsertValue(9, 0)
738
739aPenta = vtk.vtkPentagonalPrism()
740aPenta.GetPointIds().SetId(0, 0)
741aPenta.GetPointIds().SetId(1, 1)
742aPenta.GetPointIds().SetId(2, 2)
743aPenta.GetPointIds().SetId(3, 3)
744aPenta.GetPointIds().SetId(4, 4)
745aPenta.GetPointIds().SetId(5, 5)
746aPenta.GetPointIds().SetId(6, 6)
747aPenta.GetPointIds().SetId(7, 7)
748aPenta.GetPointIds().SetId(8, 8)
749aPenta.GetPointIds().SetId(9, 9)
750
751aPentaGrid = vtk.vtkUnstructuredGrid()
752aPentaGrid.Allocate(1, 1)
753aPentaGrid.InsertNextCell(aPenta.GetCellType(), aPenta.GetPointIds())
754aPentaGrid.SetPoints(pentaPoints)
755aPentaGrid.GetPointData().SetScalars(pentaScalars)
756
757pentaContours = vtk.vtkContourFilter()
758pentaContours.SetInputData(aPentaGrid)
759pentaContours.SetValue(0, .5)
760
761aPentaContourMapper = vtk.vtkDataSetMapper()
762aPentaContourMapper.SetInputConnection(pentaContours.GetOutputPort())
763aPentaContourMapper.ScalarVisibilityOff()
764
765aPentaMapper = vtk.vtkDataSetMapper()
766aPentaMapper.SetInputData(aPentaGrid)
767aPentaMapper.ScalarVisibilityOff()
768
769aPentaActor = vtk.vtkActor()
770aPentaActor.SetMapper(aPentaMapper)
771aPentaActor.GetProperty().BackfaceCullingOn()
772aPentaActor.GetProperty().SetRepresentationToWireframe()
773
774aPentaContourActor = vtk.vtkActor()
775aPentaContourActor.SetMapper(aPentaContourMapper)
776aPentaContourActor.GetProperty().BackfaceCullingOn()
777
778# Hexagonal prism
779
780hexaPoints = vtk.vtkPoints()
781hexaPoints.SetNumberOfPoints(12)
782hexaPoints.InsertPoint(0, 0.0, 0.0, 0.0)
783hexaPoints.InsertPoint(1, 0.5, 0.0, 0.0)
784hexaPoints.InsertPoint(2, 1.0, 0.5, 0.0)
785hexaPoints.InsertPoint(3, 1.0, 1.0, 0.0)
786hexaPoints.InsertPoint(4, 0.5, 1.0, 0.0)
787hexaPoints.InsertPoint(5, 0.0, 0.5, 0.0)
788hexaPoints.InsertPoint(6, 0.0, 0.0, 1.0)
789hexaPoints.InsertPoint(7, 0.5, 0.0, 1.0)
790hexaPoints.InsertPoint(8, 1.0, 0.5, 1.0)
791hexaPoints.InsertPoint(9, 1.0, 1.0, 1.0)
792hexaPoints.InsertPoint(10, 0.5, 1.0, 1.0)
793hexaPoints.InsertPoint(11, 0.0, 0.5, 1.0)
794
795hexaScalars = vtk.vtkFloatArray()
796hexaScalars.SetNumberOfTuples(12)
797hexaScalars.InsertValue(0, 1)
798hexaScalars.InsertValue(1, 1)
799hexaScalars.InsertValue(2, 1)
800hexaScalars.InsertValue(3, 1)
801hexaScalars.InsertValue(4, 1)
802hexaScalars.InsertValue(5, 1)
803hexaScalars.InsertValue(6, 0)
804hexaScalars.InsertValue(7, 0)
805hexaScalars.InsertValue(8, 0)
806hexaScalars.InsertValue(9, 0)
807hexaScalars.InsertValue(10, 0)
808hexaScalars.InsertValue(11, 0)
809
810aHexa = vtk.vtkHexagonalPrism()
811aHexa.GetPointIds().SetId(0, 0)
812aHexa.GetPointIds().SetId(1, 1)
813aHexa.GetPointIds().SetId(2, 2)
814aHexa.GetPointIds().SetId(3, 3)
815aHexa.GetPointIds().SetId(4, 4)
816aHexa.GetPointIds().SetId(5, 5)
817aHexa.GetPointIds().SetId(6, 6)
818aHexa.GetPointIds().SetId(7, 7)
819aHexa.GetPointIds().SetId(8, 8)
820aHexa.GetPointIds().SetId(9, 9)
821aHexa.GetPointIds().SetId(10, 10)
822aHexa.GetPointIds().SetId(11, 11)
823
824aHexaGrid = vtk.vtkUnstructuredGrid()
825aHexaGrid.Allocate(1, 1)
826aHexaGrid.InsertNextCell(aHexa.GetCellType(), aHexa.GetPointIds())
827aHexaGrid.SetPoints(hexaPoints)
828aHexaGrid.GetPointData().SetScalars(hexaScalars)
829
830hexaContours = vtk.vtkContourFilter()
831hexaContours.SetInputData(aHexaGrid)
832hexaContours.SetValue(0, .5)
833
834aHexaContourMapper = vtk.vtkDataSetMapper()
835aHexaContourMapper.SetInputConnection(hexaContours.GetOutputPort())
836aHexaContourMapper.ScalarVisibilityOff()
837
838aHexaMapper = vtk.vtkDataSetMapper()
839aHexaMapper.SetInputData(aHexaGrid)
840aHexaMapper.ScalarVisibilityOff()
841
842aHexaActor = vtk.vtkActor()
843aHexaActor.SetMapper(aHexaMapper)
844aHexaActor.GetProperty().BackfaceCullingOn()
845aHexaActor.GetProperty().SetRepresentationToWireframe()
846
847aHexaContourActor = vtk.vtkActor()
848aHexaContourActor.SetMapper(aHexaContourMapper)
849aHexaContourActor.GetProperty().BackfaceCullingOn()
850
851ren1.SetBackground(.1, .2, .3)
852renWin.SetSize(400, 400)
853
854ren1.AddActor(aVoxelActor)
855aVoxelActor.GetProperty().SetDiffuseColor(1, 0, 0)
856
857ren1.AddActor(aVoxelContourActor)
858aVoxelContourActor.GetProperty().SetDiffuseColor(1, 0, 0)
859
860ren1.AddActor(aHexahedronActor)
861aHexahedronActor.GetProperty().SetDiffuseColor(1, 1, 0)
862
863ren1.AddActor(aHexahedronContourActor)
864aHexahedronContourActor.GetProperty().SetDiffuseColor(1, 1, 0)
865
866ren1.AddActor(aTetraActor)
867aTetraActor.GetProperty().SetDiffuseColor(0, 1, 0)
868
869ren1.AddActor(aTetraContourActor)
870aTetraContourActor.GetProperty().SetDiffuseColor(0, 1, 0)
871
872ren1.AddActor(aWedgeActor)
873aWedgeActor.GetProperty().SetDiffuseColor(0, 1, 1)
874
875ren1.AddActor(aWedgeContourActor)
876aWedgeContourActor.GetProperty().SetDiffuseColor(0, 1, 1)
877
878ren1.AddActor(aPyramidActor)
879aPyramidActor.GetProperty().SetDiffuseColor(1, 0, 1)
880
881ren1.AddActor(aPyramidContourActor)
882aPyramidContourActor.GetProperty().SetDiffuseColor(1, 0, 1)
883
884ren1.AddActor(aPixelActor)
885aPixelActor.GetProperty().SetDiffuseColor(0, 1, 1)
886
887ren1.AddActor(aPixelContourActor)
888aPixelContourActor.GetProperty().SetDiffuseColor(0, 1, 1)
889
890ren1.AddActor(aQuadActor)
891aQuadActor.GetProperty().SetDiffuseColor(1, 0, 1)
892
893ren1.AddActor(aQuadContourActor)
894aQuadContourActor.GetProperty().SetDiffuseColor(1, 0, 1)
895
896ren1.AddActor(aTriangleActor)
897aTriangleActor.GetProperty().SetDiffuseColor(.3, 1, .5)
898
899ren1.AddActor(aTriangleContourActor)
900aTriangleContourActor.GetProperty().SetDiffuseColor(.3, 1, .5)
901
902ren1.AddActor(aPolygonActor)
903aPolygonActor.GetProperty().SetDiffuseColor(1, .4, .5)
904
905ren1.AddActor(aPolygonContourActor)
906aPolygonContourActor.GetProperty().SetDiffuseColor(1, .4, .5)
907
908ren1.AddActor(aTriangleStripActor)
909aTriangleStripActor.GetProperty().SetDiffuseColor(.3, .7, 1)
910
911ren1.AddActor(aTriangleStripContourActor)
912aTriangleStripContourActor.GetProperty().SetDiffuseColor(.3, .7, 1)
913
914ren1.AddActor(aLineActor)
915aLineActor.GetProperty().SetDiffuseColor(.2, 1, 1)
916
917ren1.AddActor(aLineContourActor)
918aLineContourActor.GetProperty().SetDiffuseColor(.2, 1, 1)
919
920ren1.AddActor(aPolyLineActor)
921aPolyLineActor.GetProperty().SetDiffuseColor(1, 1, 1)
922
923ren1.AddActor(aPolyLineContourActor)
924aPolyLineContourActor.GetProperty().SetDiffuseColor(1, 1, 1)
925
926ren1.AddActor(aVertexActor)
927aVertexActor.GetProperty().SetDiffuseColor(1, 1, 1)
928
929ren1.AddActor(aVertexContourActor)
930aVertexContourActor.GetProperty().SetDiffuseColor(1, 1, 1)
931
932ren1.AddActor(aPolyVertexActor)
933aPolyVertexActor.GetProperty().SetDiffuseColor(1, 1, 1)
934
935ren1.AddActor(aPolyVertexContourActor)
936aPolyVertexContourActor.GetProperty().SetDiffuseColor(1, 1, 1)
937
938ren1.AddActor(aPentaActor)
939aPentaActor.GetProperty().SetDiffuseColor(.2, .4, .7)
940
941ren1.AddActor(aPentaContourActor)
942aPentaContourActor.GetProperty().SetDiffuseColor(.2, .4, .7)
943
944ren1.AddActor(aHexaActor)
945aHexaActor.GetProperty().SetDiffuseColor(.7, .5, 1)
946
947ren1.AddActor(aHexaContourActor)
948aHexaContourActor.GetProperty().SetDiffuseColor(.7, .5, 1)
949
950# places everyone!!
951
952aVoxelContourActor.AddPosition(0, 0, 0)
953aVoxelContourActor.AddPosition(0, 2, 0)
954aHexahedronContourActor.AddPosition(2, 0, 0)
955aHexahedronContourActor.AddPosition(0, 2, 0)
956aHexahedronActor.AddPosition(2, 0, 0)
957aTetraContourActor.AddPosition(4, 0, 0)
958aTetraContourActor.AddPosition(0, 2, 0)
959aTetraActor.AddPosition(4, 0, 0)
960aWedgeContourActor.AddPosition(6, 0, 0)
961aWedgeContourActor.AddPosition(0, 2, 0)
962aWedgeActor.AddPosition(6, 0, 0)
963aPyramidContourActor.AddPosition(8, 0, 0)
964aPyramidContourActor.AddPosition(0, 2, 0)
965aPyramidActor.AddPosition(8, 0, 0)
966
967aPixelContourActor.AddPosition(0, 4, 0)
968aPixelContourActor.AddPosition(0, 2, 0)
969aPixelActor.AddPosition(0, 4, 0)
970aQuadContourActor.AddPosition(2, 4, 0)
971aQuadContourActor.AddPosition(0, 2, 0)
972aQuadActor.AddPosition(2, 4, 0)
973aTriangleContourActor.AddPosition(4, 4, 0)
974aTriangleContourActor.AddPosition(0, 2, 0)
975aTriangleActor.AddPosition(4, 4, 0)
976aPolygonContourActor.AddPosition(6, 4, 0)
977aPolygonContourActor.AddPosition(0, 2, 0)
978aPolygonActor.AddPosition(6, 4, 0)
979aTriangleStripContourActor.AddPosition(8, 4, 0)
980aTriangleStripContourActor.AddPosition(0, 2, 0)
981aTriangleStripActor.AddPosition(8, 4, 0)
982
983aLineContourActor.AddPosition(0, 8, 0)
984aLineContourActor.AddPosition(0, 2, 0)
985aLineActor.AddPosition(0, 8, 0)
986aPolyLineContourActor.AddPosition(2, 8, 0)
987aPolyLineContourActor.AddPosition(0, 2, 0)
988aPolyLineActor.AddPosition(2, 8, 0)
989
990aVertexContourActor.AddPosition(0, 12, 0)
991aVertexContourActor.AddPosition(0, 2, 0)
992aVertexActor.AddPosition(0, 12, 0)
993aPolyVertexContourActor.AddPosition(2, 12, 0)
994aPolyVertexContourActor.AddPosition(0, 2, 0)
995aPolyVertexActor.AddPosition(2, 12, 0)
996
997aPentaContourActor.AddPosition(4, 8, 0)
998aPentaContourActor.AddPosition(0, 2, 0)
999aPentaActor.AddPosition(4, 8, 0)
1000aHexaContourActor.AddPosition(6, 8, 0)
1001aHexaContourActor.AddPosition(0, 2, 0)
1002aHexaActor.AddPosition(6, 8, 0)
1003
1004[base, back, left] = backdrop.BuildBackdrop(-1, 11, -1, 16, -1, 2, .1)
1005
1006ren1.AddActor(base)
1007base.GetProperty().SetDiffuseColor(.2, .2, .2)
1008ren1.AddActor(left)
1009left.GetProperty().SetDiffuseColor(.2, .2, .2)
1010ren1.AddActor(back)
1011back.GetProperty().SetDiffuseColor(.2, .2, .2)
1012
1013ren1.ResetCamera()
1014ren1.GetActiveCamera().Dolly(1.5)
1015ren1.ResetCameraClippingRange()
1016
1017renWin.Render()
1018
1019# render the image
1020#
1021iren.Initialize()
1022#iren.Start()
1023