1#!/usr/bin/env python
2import sys
3import vtk
4from vtk.util.misc import vtkGetDataRoot
5
6VTK_DATA_ROOT = vtkGetDataRoot()
7
8try:
9    import numpy as np
10    from vtk.util.numpy_support import numpy_to_vtk as ntov
11except ImportError:
12    print("WARNING: This test requires Numeric Python: http://numpy.sf.net")
13    from vtk.test import Testing
14
15    Testing.skip()
16
17# Prevent .pyc files being created.
18# Stops the vtk source being polluted
19# by .pyc files.
20sys.dont_write_bytecode = True
21
22import backdrop
23
24# clip every quadratic cell type
25# Create a scene with one of each cell type.
26
27# QuadraticEdge
28edgePoints = vtk.vtkPoints()
29edgePoints.SetNumberOfPoints(3)
30edgePointsCoords = np.array([
31    [0, 0, 0],
32    [1.0, 0, 0],
33    [0.5, 0.25, 0]])
34edgePoints.SetData(ntov(edgePointsCoords))
35edgeScalars = vtk.vtkFloatArray()
36edgeScalars.SetNumberOfTuples(3)
37edgeScalars.InsertValue(0, 0.0)
38edgeScalars.InsertValue(1, 0.0)
39edgeScalars.InsertValue(2, 0.9)
40aEdge = vtk.vtkQuadraticEdge()
41for i in range(aEdge.GetNumberOfPoints()):
42    aEdge.GetPointIds().SetId(i, i)
43aEdgeGrid = vtk.vtkUnstructuredGrid()
44aEdgeGrid.Allocate(1, 1)
45aEdgeGrid.InsertNextCell(aEdge.GetCellType(), aEdge.GetPointIds())
46aEdgeGrid.SetPoints(edgePoints)
47aEdgeGrid.GetPointData().SetScalars(edgeScalars)
48edgeclips = vtk.vtkClipDataSet()
49edgeclips.SetInputData(aEdgeGrid)
50edgeclips.SetValue(0.5)
51aEdgeclipMapper = vtk.vtkDataSetMapper()
52aEdgeclipMapper.SetInputConnection(edgeclips.GetOutputPort())
53aEdgeclipMapper.ScalarVisibilityOff()
54aEdgeMapper = vtk.vtkDataSetMapper()
55aEdgeMapper.SetInputData(aEdgeGrid)
56aEdgeMapper.ScalarVisibilityOff()
57aEdgeActor = vtk.vtkActor()
58aEdgeActor.SetMapper(aEdgeMapper)
59aEdgeActor.GetProperty().SetRepresentationToWireframe()
60aEdgeActor.GetProperty().SetAmbient(1.0)
61aEdgeclipActor = vtk.vtkActor()
62aEdgeclipActor.SetMapper(aEdgeclipMapper)
63aEdgeclipActor.GetProperty().BackfaceCullingOn()
64aEdgeclipActor.GetProperty().SetAmbient(1.0)
65
66# Quadratic triangle
67triPoints = vtk.vtkPoints()
68triPoints.SetNumberOfPoints(6)
69triPointsCoords = np.array([
70    [0.0, 0.0, 0.0],
71    [1.0, 0.0, 0.0],
72    [0.5, 0.8, 0.0],
73    [0.5, 0.0, 0.0],
74    [0.75, 0.4, 0.0],
75    [0.25, 0.4, 0.0]])
76triPoints.SetData(ntov(triPointsCoords))
77triScalars = vtk.vtkFloatArray()
78triScalars.SetNumberOfTuples(6)
79triScalars.InsertValue(0, 0.0)
80triScalars.InsertValue(1, 0.0)
81triScalars.InsertValue(2, 0.0)
82triScalars.InsertValue(3, 1.0)
83triScalars.InsertValue(4, 0.0)
84triScalars.InsertValue(5, 0.0)
85aTri = vtk.vtkQuadraticTriangle()
86for i in range(aTri.GetNumberOfPoints()):
87    aTri.GetPointIds().SetId(i, i)
88aTriGrid = vtk.vtkUnstructuredGrid()
89aTriGrid.Allocate(1, 1)
90aTriGrid.InsertNextCell(aTri.GetCellType(), aTri.GetPointIds())
91aTriGrid.SetPoints(triPoints)
92aTriGrid.GetPointData().SetScalars(triScalars)
93triclips = vtk.vtkClipDataSet()
94triclips.SetInputData(aTriGrid)
95triclips.SetValue(0.5)
96aTriclipMapper = vtk.vtkDataSetMapper()
97aTriclipMapper.SetInputConnection(triclips.GetOutputPort())
98aTriclipMapper.ScalarVisibilityOff()
99aTriMapper = vtk.vtkDataSetMapper()
100aTriMapper.SetInputData(aTriGrid)
101aTriMapper.ScalarVisibilityOff()
102aTriActor = vtk.vtkActor()
103aTriActor.SetMapper(aTriMapper)
104aTriActor.GetProperty().SetRepresentationToWireframe()
105aTriActor.GetProperty().SetAmbient(1.0)
106aTriclipActor = vtk.vtkActor()
107aTriclipActor.SetMapper(aTriclipMapper)
108aTriclipActor.GetProperty().BackfaceCullingOn()
109aTriclipActor.GetProperty().SetAmbient(1.0)
110
111# Quadratic quadrilateral
112quadPoints = vtk.vtkPoints()
113quadPoints.SetNumberOfPoints(8)
114quadPointsCoords = np.array([
115    [0.0, 0.0, 0.0],
116    [1.0, 0.0, 0.0],
117    [1.0, 1.0, 0.0],
118    [0.0, 1.0, 0.0],
119    [0.5, 0.0, 0.0],
120    [1.0, 0.5, 0.0],
121    [0.5, 1.0, 0.0],
122    [0.0, 0.5, 0.0]])
123quadPoints.SetData(ntov(quadPointsCoords))
124quadScalars = vtk.vtkFloatArray()
125quadScalars.SetNumberOfTuples(8)
126quadScalars.InsertValue(0, 0.0)
127quadScalars.InsertValue(1, 0.0)
128quadScalars.InsertValue(2, 1.0)
129quadScalars.InsertValue(3, 1.0)
130quadScalars.InsertValue(4, 1.0)
131quadScalars.InsertValue(5, 0.0)
132quadScalars.InsertValue(6, 0.0)
133quadScalars.InsertValue(7, 0.0)
134aQuad = vtk.vtkQuadraticQuad()
135for i in range(aQuad.GetNumberOfPoints()):
136    aQuad.GetPointIds().SetId(i, i)
137aQuadGrid = vtk.vtkUnstructuredGrid()
138aQuadGrid.Allocate(1, 1)
139aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds())
140aQuadGrid.SetPoints(quadPoints)
141aQuadGrid.GetPointData().SetScalars(quadScalars)
142quadclips = vtk.vtkClipDataSet()
143quadclips.SetInputData(aQuadGrid)
144quadclips.SetValue(0.5)
145aQuadclipMapper = vtk.vtkDataSetMapper()
146aQuadclipMapper.SetInputConnection(quadclips.GetOutputPort())
147aQuadclipMapper.ScalarVisibilityOff()
148aQuadMapper = vtk.vtkDataSetMapper()
149aQuadMapper.SetInputData(aQuadGrid)
150aQuadMapper.ScalarVisibilityOff()
151aQuadActor = vtk.vtkActor()
152aQuadActor.SetMapper(aQuadMapper)
153aQuadActor.GetProperty().SetRepresentationToWireframe()
154aQuadActor.GetProperty().SetAmbient(1.0)
155aQuadclipActor = vtk.vtkActor()
156aQuadclipActor.SetMapper(aQuadclipMapper)
157aQuadclipActor.GetProperty().BackfaceCullingOn()
158aQuadclipActor.GetProperty().SetAmbient(1.0)
159
160# BiQuadratic quadrilateral
161BquadPoints = vtk.vtkPoints()
162BquadPoints.SetNumberOfPoints(9)
163BquadPointsCoords = np.array([
164    [0.0, 0.0, 0.0],
165    [1.0, 0.0, 0.0],
166    [1.0, 1.0, 0.0],
167    [0.0, 1.0, 0.0],
168    [0.5, 0.0, 0.0],
169    [1.0, 0.5, 0.0],
170    [0.5, 1.0, 0.0],
171    [0.0, 0.5, 0.0],
172    [0.5, 0.5, 0.0]])
173BquadPoints.SetData(ntov(BquadPointsCoords))
174BquadScalars = vtk.vtkFloatArray()
175BquadScalars.SetNumberOfTuples(9)
176BquadScalars.InsertValue(0, 1.0)
177BquadScalars.InsertValue(1, 1.0)
178BquadScalars.InsertValue(2, 1.0)
179BquadScalars.InsertValue(3, 1.0)
180BquadScalars.InsertValue(4, 0.0)
181BquadScalars.InsertValue(5, 0.0)
182BquadScalars.InsertValue(6, 0.0)
183BquadScalars.InsertValue(7, 0.0)
184BquadScalars.InsertValue(8, 1.0)
185BQuad = vtk.vtkBiQuadraticQuad()
186for i in range(BQuad.GetNumberOfPoints()):
187    BQuad.GetPointIds().SetId(i, i)
188BQuadGrid = vtk.vtkUnstructuredGrid()
189BQuadGrid.Allocate(1, 1)
190BQuadGrid.InsertNextCell(BQuad.GetCellType(), BQuad.GetPointIds())
191BQuadGrid.SetPoints(BquadPoints)
192BQuadGrid.GetPointData().SetScalars(BquadScalars)
193Bquadclips = vtk.vtkClipDataSet()
194Bquadclips.SetInputData(BQuadGrid)
195Bquadclips.SetValue(0.5)
196BQuadclipMapper = vtk.vtkDataSetMapper()
197BQuadclipMapper.SetInputConnection(Bquadclips.GetOutputPort())
198BQuadclipMapper.ScalarVisibilityOff()
199BQuadMapper = vtk.vtkDataSetMapper()
200BQuadMapper.SetInputData(BQuadGrid)
201BQuadMapper.ScalarVisibilityOff()
202BQuadActor = vtk.vtkActor()
203BQuadActor.SetMapper(BQuadMapper)
204BQuadActor.GetProperty().SetRepresentationToWireframe()
205BQuadActor.GetProperty().SetAmbient(1.0)
206BQuadclipActor = vtk.vtkActor()
207BQuadclipActor.SetMapper(BQuadclipMapper)
208BQuadclipActor.GetProperty().BackfaceCullingOn()
209BQuadclipActor.GetProperty().SetAmbient(1.0)
210
211# Quadratic linear quadrilateral
212QLquadPoints = vtk.vtkPoints()
213QLquadPoints.SetNumberOfPoints(6)
214QLquadPointsCoords = np.array([
215    [0.0, 0.0, 0.0],
216    [1.0, 0.0, 0.0],
217    [1.0, 1.0, 0.0],
218    [0.0, 1.0, 0.0],
219    [0.5, 0.0, 0.0],
220    [0.5, 1.0, 0.0]])
221QLquadPoints.SetData(ntov(QLquadPointsCoords))
222QLquadScalars = vtk.vtkFloatArray()
223QLquadScalars.SetNumberOfTuples(6)
224QLquadScalars.InsertValue(0, 1.0)
225QLquadScalars.InsertValue(1, 1.0)
226QLquadScalars.InsertValue(2, 0.0)
227QLquadScalars.InsertValue(3, 0.0)
228QLquadScalars.InsertValue(4, 0.0)
229QLquadScalars.InsertValue(5, 1.0)
230QLQuad = vtk.vtkQuadraticLinearQuad()
231for i in range(QLQuad.GetNumberOfPoints()):
232    QLQuad.GetPointIds().SetId(i, i)
233QLQuadGrid = vtk.vtkUnstructuredGrid()
234QLQuadGrid.Allocate(1, 1)
235QLQuadGrid.InsertNextCell(QLQuad.GetCellType(), QLQuad.GetPointIds())
236QLQuadGrid.SetPoints(QLquadPoints)
237QLQuadGrid.GetPointData().SetScalars(QLquadScalars)
238QLquadclips = vtk.vtkClipDataSet()
239QLquadclips.SetInputData(QLQuadGrid)
240QLquadclips.SetValue(0.5)
241QLQuadclipMapper = vtk.vtkDataSetMapper()
242QLQuadclipMapper.SetInputConnection(QLquadclips.GetOutputPort())
243QLQuadclipMapper.ScalarVisibilityOff()
244QLQuadMapper = vtk.vtkDataSetMapper()
245QLQuadMapper.SetInputData(QLQuadGrid)
246QLQuadMapper.ScalarVisibilityOff()
247QLQuadActor = vtk.vtkActor()
248QLQuadActor.SetMapper(QLQuadMapper)
249QLQuadActor.GetProperty().SetRepresentationToWireframe()
250QLQuadActor.GetProperty().SetAmbient(1.0)
251QLQuadclipActor = vtk.vtkActor()
252QLQuadclipActor.SetMapper(QLQuadclipMapper)
253QLQuadclipActor.GetProperty().BackfaceCullingOn()
254QLQuadclipActor.GetProperty().SetAmbient(1.0)
255
256# Quadratic tetrahedron
257tetPoints = vtk.vtkPoints()
258tetPoints.SetNumberOfPoints(10)
259tetPointsCoords = np.array([
260    [0.0, 0.0, 0.0],
261    [1.0, 0.0, 0.0],
262    [0.5, 0.8, 0.0],
263    [0.5, 0.4, 1.0],
264    [0.5, 0.0, 0.0],
265    [0.75, 0.4, 0.0],
266    [0.25, 0.4, 0.0],
267    [0.25, 0.2, 0.5],
268    [0.75, 0.2, 0.5],
269    [0.50, 0.6, 0.5]])
270tetPoints.SetData(ntov(tetPointsCoords))
271tetScalars = vtk.vtkFloatArray()
272tetScalars.SetNumberOfTuples(10)
273tetScalars.InsertValue(0, 1.0)
274tetScalars.InsertValue(1, 1.0)
275tetScalars.InsertValue(2, 1.0)
276tetScalars.InsertValue(3, 1.0)
277tetScalars.InsertValue(4, 0.0)
278tetScalars.InsertValue(5, 0.0)
279tetScalars.InsertValue(6, 0.0)
280tetScalars.InsertValue(7, 0.0)
281tetScalars.InsertValue(8, 0.0)
282tetScalars.InsertValue(9, 0.0)
283aTet = vtk.vtkQuadraticTetra()
284for i in range(aTet.GetNumberOfPoints()):
285    aTet.GetPointIds().SetId(i, i)
286aTetGrid = vtk.vtkUnstructuredGrid()
287aTetGrid.Allocate(1, 1)
288aTetGrid.InsertNextCell(aTet.GetCellType(), aTet.GetPointIds())
289aTetGrid.SetPoints(tetPoints)
290aTetGrid.GetPointData().SetScalars(tetScalars)
291tetclips = vtk.vtkClipDataSet()
292tetclips.SetInputData(aTetGrid)
293tetclips.SetValue(0.5)
294aTetclipMapper = vtk.vtkDataSetMapper()
295aTetclipMapper.SetInputConnection(tetclips.GetOutputPort())
296aTetclipMapper.ScalarVisibilityOff()
297aTetMapper = vtk.vtkDataSetMapper()
298aTetMapper.SetInputData(aTetGrid)
299aTetMapper.ScalarVisibilityOff()
300aTetActor = vtk.vtkActor()
301aTetActor.SetMapper(aTetMapper)
302aTetActor.GetProperty().SetRepresentationToWireframe()
303aTetActor.GetProperty().SetAmbient(1.0)
304aTetclipActor = vtk.vtkActor()
305aTetclipActor.SetMapper(aTetclipMapper)
306aTetclipActor.GetProperty().SetAmbient(1.0)
307
308# Quadratic hexahedron
309hexPoints = vtk.vtkPoints()
310hexPoints.SetNumberOfPoints(20)
311hexPointsCoords = np.array([
312    [0, 0, 0],
313    [1, 0, 0],
314    [1, 1, 0],
315    [0, 1, 0],
316    [0, 0, 1],
317    [1, 0, 1],
318    [1, 1, 1],
319    [0, 1, 1],
320    [0.5, 0, 0],
321    [1, 0.5, 0],
322    [0.5, 1, 0],
323    [0, 0.5, 0],
324    [0.5, 0, 1],
325    [1, 0.5, 1],
326    [0.5, 1, 1],
327    [0, 0.5, 1],
328    [0, 0, 0.5],
329    [1, 0, 0.5],
330    [1, 1, 0.5],
331    [0, 1, 0.5]])
332hexPoints.SetData(ntov(hexPointsCoords))
333hexScalars = vtk.vtkFloatArray()
334hexScalars.SetNumberOfTuples(20)
335hexScalars.InsertValue(0, 1.0)
336hexScalars.InsertValue(1, 1.0)
337hexScalars.InsertValue(2, 1.0)
338hexScalars.InsertValue(3, 1.0)
339hexScalars.InsertValue(4, 1.0)
340hexScalars.InsertValue(5, 1.0)
341hexScalars.InsertValue(6, 1.0)
342hexScalars.InsertValue(7, 1.0)
343hexScalars.InsertValue(8, 0.0)
344hexScalars.InsertValue(9, 0.0)
345hexScalars.InsertValue(10, 0.0)
346hexScalars.InsertValue(11, 0.0)
347hexScalars.InsertValue(12, 0.0)
348hexScalars.InsertValue(13, 0.0)
349hexScalars.InsertValue(14, 0.0)
350hexScalars.InsertValue(15, 0.0)
351hexScalars.InsertValue(16, 0.0)
352hexScalars.InsertValue(17, 0.0)
353hexScalars.InsertValue(18, 0.0)
354hexScalars.InsertValue(19, 0.0)
355aHex = vtk.vtkQuadraticHexahedron()
356for i in range(aHex.GetNumberOfPoints()):
357    aHex.GetPointIds().SetId(i, i)
358aHexGrid = vtk.vtkUnstructuredGrid()
359aHexGrid.Allocate(1, 1)
360aHexGrid.InsertNextCell(aHex.GetCellType(), aHex.GetPointIds())
361aHexGrid.SetPoints(hexPoints)
362aHexGrid.GetPointData().SetScalars(hexScalars)
363hexclips = vtk.vtkClipDataSet()
364hexclips.SetInputData(aHexGrid)
365hexclips.SetValue(0.5)
366aHexclipMapper = vtk.vtkDataSetMapper()
367aHexclipMapper.SetInputConnection(hexclips.GetOutputPort())
368aHexclipMapper.ScalarVisibilityOff()
369aHexMapper = vtk.vtkDataSetMapper()
370aHexMapper.SetInputData(aHexGrid)
371aHexMapper.ScalarVisibilityOff()
372aHexActor = vtk.vtkActor()
373aHexActor.SetMapper(aHexMapper)
374aHexActor.GetProperty().SetRepresentationToWireframe()
375aHexActor.GetProperty().SetAmbient(1.0)
376aHexclipActor = vtk.vtkActor()
377aHexclipActor.SetMapper(aHexclipMapper)
378aHexclipActor.GetProperty().SetAmbient(1.0)
379
380# TriQuadratic hexahedron
381TQhexPoints = vtk.vtkPoints()
382TQhexPoints.SetNumberOfPoints(27)
383TQhexPointsCoords = np.array([
384    [0, 0, 0],
385    [1, 0, 0],
386    [1, 1, 0],
387    [0, 1, 0],
388    [0, 0, 1],
389    [1, 0, 1],
390    [1, 1, 1],
391    [0, 1, 1],
392    [0.5, 0, 0],
393    [1, 0.5, 0],
394    [0.5, 1, 0],
395    [0, 0.5, 0],
396    [0.5, 0, 1],
397    [1, 0.5, 1],
398    [0.5, 1, 1],
399    [0, 0.5, 1],
400    [0, 0, 0.5],
401    [1, 0, 0.5],
402    [1, 1, 0.5],
403    [0, 1, 0.5],
404    [0, 0.5, 0.5],
405    [1, 0.5, 0.5],
406    [0.5, 0, 0.5],
407    [0.5, 1, 0.5],
408    [0.5, 0.5, 0.0],
409    [0.5, 0.5, 1],
410    [0.5, 0.5, 0.5]])
411TQhexPoints.SetData(ntov(TQhexPointsCoords))
412TQhexScalars = vtk.vtkFloatArray()
413TQhexScalars.SetNumberOfTuples(27)
414TQhexScalars.InsertValue(0, 1.0)
415TQhexScalars.InsertValue(1, 1.0)
416TQhexScalars.InsertValue(2, 1.0)
417TQhexScalars.InsertValue(3, 1.0)
418TQhexScalars.InsertValue(4, 1.0)
419TQhexScalars.InsertValue(5, 1.0)
420TQhexScalars.InsertValue(6, 1.0)
421TQhexScalars.InsertValue(7, 1.0)
422TQhexScalars.InsertValue(8, 0.0)
423TQhexScalars.InsertValue(9, 0.0)
424TQhexScalars.InsertValue(10, 0.0)
425TQhexScalars.InsertValue(11, 0.0)
426TQhexScalars.InsertValue(12, 0.0)
427TQhexScalars.InsertValue(13, 0.0)
428TQhexScalars.InsertValue(14, 0.0)
429TQhexScalars.InsertValue(15, 0.0)
430TQhexScalars.InsertValue(16, 0.0)
431TQhexScalars.InsertValue(17, 0.0)
432TQhexScalars.InsertValue(18, 0.0)
433TQhexScalars.InsertValue(19, 0.0)
434TQhexScalars.InsertValue(20, 0.0)
435TQhexScalars.InsertValue(21, 0.0)
436TQhexScalars.InsertValue(22, 0.0)
437TQhexScalars.InsertValue(23, 0.0)
438TQhexScalars.InsertValue(24, 0.0)
439TQhexScalars.InsertValue(25, 0.0)
440TQhexScalars.InsertValue(26, 0.0)
441TQHex = vtk.vtkTriQuadraticHexahedron()
442for i in range(TQHex.GetNumberOfPoints()):
443    TQHex.GetPointIds().SetId(i, i)
444TQHexGrid = vtk.vtkUnstructuredGrid()
445TQHexGrid.Allocate(1, 1)
446TQHexGrid.InsertNextCell(TQHex.GetCellType(), TQHex.GetPointIds())
447TQHexGrid.SetPoints(TQhexPoints)
448TQHexGrid.GetPointData().SetScalars(TQhexScalars)
449TQhexclips = vtk.vtkClipDataSet()
450TQhexclips.SetInputData(TQHexGrid)
451TQhexclips.SetValue(0.5)
452TQHexclipMapper = vtk.vtkDataSetMapper()
453TQHexclipMapper.SetInputConnection(TQhexclips.GetOutputPort())
454TQHexclipMapper.ScalarVisibilityOff()
455TQHexMapper = vtk.vtkDataSetMapper()
456TQHexMapper.SetInputData(TQHexGrid)
457TQHexMapper.ScalarVisibilityOff()
458TQHexActor = vtk.vtkActor()
459TQHexActor.SetMapper(TQHexMapper)
460TQHexActor.GetProperty().SetRepresentationToWireframe()
461TQHexActor.GetProperty().SetAmbient(1.0)
462TQHexclipActor = vtk.vtkActor()
463TQHexclipActor.SetMapper(TQHexclipMapper)
464TQHexclipActor.GetProperty().SetAmbient(1.0)
465
466# BiQuadratic Quadratic hexahedron
467BQhexPoints = vtk.vtkPoints()
468BQhexPoints.SetNumberOfPoints(24)
469BQhexPointsCoords = np.array([
470    [0, 0, 0],
471    [1, 0, 0],
472    [1, 1, 0],
473    [0, 1, 0],
474    [0, 0, 1],
475    [1, 0, 1],
476    [1, 1, 1],
477    [0, 1, 1],
478    [0.5, 0, 0],
479    [1, 0.5, 0],
480    [0.5, 1, 0],
481    [0, 0.5, 0],
482    [0.5, 0, 1],
483    [1, 0.5, 1],
484    [0.5, 1, 1],
485    [0, 0.5, 1],
486    [0, 0, 0.5],
487    [1, 0, 0.5],
488    [1, 1, 0.5],
489    [0, 1, 0.5],
490    [0, 0.5, 0.5],
491    [1, 0.5, 0.5],
492    [0.5, 0, 0.5],
493    [0.5, 1, 0.5]])
494BQhexPoints.SetData(ntov(BQhexPointsCoords))
495BQhexPoints.InsertPoint(20, 0, 0.5, 0.5)
496BQhexScalars = vtk.vtkFloatArray()
497BQhexScalars.SetNumberOfTuples(24)
498BQhexScalars.InsertValue(0, 1.0)
499BQhexScalars.InsertValue(1, 1.0)
500BQhexScalars.InsertValue(2, 1.0)
501BQhexScalars.InsertValue(3, 1.0)
502BQhexScalars.InsertValue(4, 1.0)
503BQhexScalars.InsertValue(5, 1.0)
504BQhexScalars.InsertValue(6, 1.0)
505BQhexScalars.InsertValue(7, 1.0)
506BQhexScalars.InsertValue(8, 0.0)
507BQhexScalars.InsertValue(9, 0.0)
508BQhexScalars.InsertValue(10, 0.0)
509BQhexScalars.InsertValue(11, 0.0)
510BQhexScalars.InsertValue(12, 0.0)
511BQhexScalars.InsertValue(13, 0.0)
512BQhexScalars.InsertValue(14, 0.0)
513BQhexScalars.InsertValue(15, 0.0)
514BQhexScalars.InsertValue(16, 0.0)
515BQhexScalars.InsertValue(17, 0.0)
516BQhexScalars.InsertValue(18, 0.0)
517BQhexScalars.InsertValue(19, 0.0)
518BQhexScalars.InsertValue(20, 0.0)
519BQhexScalars.InsertValue(21, 0.0)
520BQhexScalars.InsertValue(22, 0.0)
521BQhexScalars.InsertValue(23, 0.0)
522BQHex = vtk.vtkBiQuadraticQuadraticHexahedron()
523for i in range(BQHex.GetNumberOfPoints()):
524    BQHex.GetPointIds().SetId(i, i)
525BQHexGrid = vtk.vtkUnstructuredGrid()
526BQHexGrid.Allocate(1, 1)
527BQHexGrid.InsertNextCell(BQHex.GetCellType(), BQHex.GetPointIds())
528BQHexGrid.SetPoints(BQhexPoints)
529BQHexGrid.GetPointData().SetScalars(BQhexScalars)
530BQhexclips = vtk.vtkClipDataSet()
531BQhexclips.SetInputData(BQHexGrid)
532BQhexclips.SetValue(0.5)
533BQHexclipMapper = vtk.vtkDataSetMapper()
534BQHexclipMapper.SetInputConnection(BQhexclips.GetOutputPort())
535BQHexclipMapper.ScalarVisibilityOff()
536BQHexMapper = vtk.vtkDataSetMapper()
537BQHexMapper.SetInputData(BQHexGrid)
538BQHexMapper.ScalarVisibilityOff()
539BQHexActor = vtk.vtkActor()
540BQHexActor.SetMapper(BQHexMapper)
541BQHexActor.GetProperty().SetRepresentationToWireframe()
542BQHexActor.GetProperty().SetAmbient(1.0)
543BQHexclipActor = vtk.vtkActor()
544BQHexclipActor.SetMapper(BQHexclipMapper)
545BQHexclipActor.GetProperty().SetAmbient(1.0)
546
547# Quadratic wedge
548wedgePoints = vtk.vtkPoints()
549wedgePoints.SetNumberOfPoints(15)
550wedgePointsCoords = np.array([
551    [0, 0, 0],
552    [1, 0, 0],
553    [0, 1, 0],
554    [0, 0, 1],
555    [1, 0, 1],
556    [0, 1, 1],
557    [0.5, 0, 0],
558    [0.5, 0.5, 0],
559    [0, 0.5, 0],
560    [0.5, 0, 1],
561    [0.5, 0.5, 1],
562    [0, 0.5, 1],
563    [0, 0, 0.5],
564    [1, 0, 0.5],
565    [0, 1, 0.5]])
566wedgePoints.SetData(ntov(wedgePointsCoords))
567wedgeScalars = vtk.vtkFloatArray()
568wedgeScalars.SetNumberOfTuples(15)
569wedgeScalars.InsertValue(0, 1.0)
570wedgeScalars.InsertValue(1, 1.0)
571wedgeScalars.InsertValue(2, 1.0)
572wedgeScalars.InsertValue(3, 1.0)
573wedgeScalars.InsertValue(4, 1.0)
574wedgeScalars.InsertValue(5, 1.0)
575wedgeScalars.InsertValue(6, 0.0)
576wedgeScalars.InsertValue(7, 0.0)
577wedgeScalars.InsertValue(8, 0.0)
578wedgeScalars.InsertValue(9, 0.0)
579wedgeScalars.InsertValue(10, 0.0)
580wedgeScalars.InsertValue(11, 0.0)
581wedgeScalars.InsertValue(12, 0.0)
582wedgeScalars.InsertValue(13, 0.0)
583wedgeScalars.InsertValue(14, 0.0)
584aWedge = vtk.vtkQuadraticWedge()
585for i in range(aWedge.GetNumberOfPoints()):
586    aWedge.GetPointIds().SetId(i, i)
587aWedgeGrid = vtk.vtkUnstructuredGrid()
588aWedgeGrid.Allocate(1, 1)
589aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds())
590aWedgeGrid.SetPoints(wedgePoints)
591aWedgeGrid.GetPointData().SetScalars(wedgeScalars)
592wedgeclips = vtk.vtkClipDataSet()
593wedgeclips.SetInputData(aWedgeGrid)
594wedgeclips.SetValue(0.5)
595aWedgeclipMapper = vtk.vtkDataSetMapper()
596aWedgeclipMapper.SetInputConnection(wedgeclips.GetOutputPort())
597aWedgeclipMapper.ScalarVisibilityOff()
598aWedgeMapper = vtk.vtkDataSetMapper()
599aWedgeMapper.SetInputData(aWedgeGrid)
600aWedgeMapper.ScalarVisibilityOff()
601aWedgeActor = vtk.vtkActor()
602aWedgeActor.SetMapper(aWedgeMapper)
603aWedgeActor.GetProperty().SetRepresentationToWireframe()
604aWedgeActor.GetProperty().SetAmbient(1.0)
605aWedgeclipActor = vtk.vtkActor()
606aWedgeclipActor.SetMapper(aWedgeclipMapper)
607aWedgeclipActor.GetProperty().SetAmbient(1.0)
608
609# Quadratic linear wedge
610QLwedgePoints = vtk.vtkPoints()
611QLwedgePoints.SetNumberOfPoints(12)
612QLwedgePointsCoords = np.array([
613    [0, 0, 0],
614    [1, 0, 0],
615    [0, 1, 0],
616    [0, 0, 1],
617    [1, 0, 1],
618    [0, 1, 1],
619    [0.5, 0, 0],
620    [0.5, 0.5, 0],
621    [0, 0.5, 0],
622    [0.5, 0, 1],
623    [0.5, 0.5, 1],
624    [0, 0.5, 1]])
625QLwedgePoints.SetData(ntov(QLwedgePointsCoords))
626QLwedgeScalars = vtk.vtkFloatArray()
627QLwedgeScalars.SetNumberOfTuples(12)
628QLwedgeScalars.InsertValue(0, 1.0)
629QLwedgeScalars.InsertValue(1, 1.0)
630QLwedgeScalars.InsertValue(2, 1.0)
631QLwedgeScalars.InsertValue(3, 1.0)
632QLwedgeScalars.InsertValue(4, 1.0)
633QLwedgeScalars.InsertValue(5, 1.0)
634QLwedgeScalars.InsertValue(6, 0.0)
635QLwedgeScalars.InsertValue(7, 0.0)
636QLwedgeScalars.InsertValue(8, 0.0)
637QLwedgeScalars.InsertValue(9, 0.0)
638QLwedgeScalars.InsertValue(10, 0.0)
639QLwedgeScalars.InsertValue(11, 0.0)
640QLWedge = vtk.vtkQuadraticLinearWedge()
641for i in range(QLWedge.GetNumberOfPoints()):
642    QLWedge.GetPointIds().SetId(i, i)
643QLWedgeGrid = vtk.vtkUnstructuredGrid()
644QLWedgeGrid.Allocate(1, 1)
645QLWedgeGrid.InsertNextCell(QLWedge.GetCellType(), QLWedge.GetPointIds())
646QLWedgeGrid.SetPoints(QLwedgePoints)
647QLWedgeGrid.GetPointData().SetScalars(QLwedgeScalars)
648QLwedgeclips = vtk.vtkClipDataSet()
649QLwedgeclips.SetInputData(QLWedgeGrid)
650QLwedgeclips.SetValue(0.5)
651QLWedgeclipMapper = vtk.vtkDataSetMapper()
652QLWedgeclipMapper.SetInputConnection(QLwedgeclips.GetOutputPort())
653QLWedgeclipMapper.ScalarVisibilityOff()
654QLWedgeMapper = vtk.vtkDataSetMapper()
655QLWedgeMapper.SetInputData(QLWedgeGrid)
656QLWedgeMapper.ScalarVisibilityOff()
657QLWedgeActor = vtk.vtkActor()
658QLWedgeActor.SetMapper(QLWedgeMapper)
659QLWedgeActor.GetProperty().SetRepresentationToWireframe()
660QLWedgeActor.GetProperty().SetAmbient(1.0)
661QLWedgeclipActor = vtk.vtkActor()
662QLWedgeclipActor.SetMapper(QLWedgeclipMapper)
663QLWedgeclipActor.GetProperty().SetAmbient(1.0)
664
665# BiQuadratic wedge
666BQwedgePoints = vtk.vtkPoints()
667BQwedgePoints.SetNumberOfPoints(18)
668BQwedgePointsCoords = np.array([
669    [0, 0, 0],
670    [1, 0, 0],
671    [0, 1, 0],
672    [0, 0, 1],
673    [1, 0, 1],
674    [0, 1, 1],
675    [0.5, 0, 0],
676    [0.5, 0.5, 0],
677    [0, 0.5, 0],
678    [0.5, 0, 1],
679    [0.5, 0.5, 1],
680    [0, 0.5, 1],
681    [0, 0, 0.5],
682    [1, 0, 0.5],
683    [0, 1, 0.5],
684    [0.5, 0, 0.5],
685    [0.5, 0.5, 0.5],
686    [0, 0.5, 0.5]])
687BQwedgePoints.SetData(ntov(BQwedgePointsCoords))
688BQwedgeScalars = vtk.vtkFloatArray()
689BQwedgeScalars.SetNumberOfTuples(18)
690BQwedgeScalars.InsertValue(0, 1.0)
691BQwedgeScalars.InsertValue(1, 1.0)
692BQwedgeScalars.InsertValue(2, 1.0)
693BQwedgeScalars.InsertValue(3, 1.0)
694BQwedgeScalars.InsertValue(4, 1.0)
695BQwedgeScalars.InsertValue(5, 1.0)
696BQwedgeScalars.InsertValue(6, 0.0)
697BQwedgeScalars.InsertValue(7, 0.0)
698BQwedgeScalars.InsertValue(8, 0.0)
699BQwedgeScalars.InsertValue(9, 0.0)
700BQwedgeScalars.InsertValue(10, 0.0)
701BQwedgeScalars.InsertValue(11, 0.0)
702BQwedgeScalars.InsertValue(12, 0.0)
703BQwedgeScalars.InsertValue(13, 0.0)
704BQwedgeScalars.InsertValue(14, 0.0)
705BQwedgeScalars.InsertValue(15, 0.0)
706BQwedgeScalars.InsertValue(16, 0.0)
707BQwedgeScalars.InsertValue(17, 0.0)
708BQWedge = vtk.vtkBiQuadraticQuadraticWedge()
709for i in range(BQWedge.GetNumberOfPoints()):
710    BQWedge.GetPointIds().SetId(i, i)
711BQWedgeGrid = vtk.vtkUnstructuredGrid()
712BQWedgeGrid.Allocate(1, 1)
713BQWedgeGrid.InsertNextCell(BQWedge.GetCellType(), BQWedge.GetPointIds())
714BQWedgeGrid.SetPoints(BQwedgePoints)
715BQWedgeGrid.GetPointData().SetScalars(BQwedgeScalars)
716BQwedgeclips = vtk.vtkClipDataSet()
717BQwedgeclips.SetInputData(BQWedgeGrid)
718BQwedgeclips.SetValue(0.5)
719BQWedgeclipMapper = vtk.vtkDataSetMapper()
720BQWedgeclipMapper.SetInputConnection(BQwedgeclips.GetOutputPort())
721BQWedgeclipMapper.ScalarVisibilityOff()
722BQWedgeMapper = vtk.vtkDataSetMapper()
723BQWedgeMapper.SetInputData(BQWedgeGrid)
724BQWedgeMapper.ScalarVisibilityOff()
725BQWedgeActor = vtk.vtkActor()
726BQWedgeActor.SetMapper(BQWedgeMapper)
727BQWedgeActor.GetProperty().SetRepresentationToWireframe()
728BQWedgeActor.GetProperty().SetAmbient(1.0)
729BQWedgeclipActor = vtk.vtkActor()
730BQWedgeclipActor.SetMapper(BQWedgeclipMapper)
731BQWedgeclipActor.GetProperty().SetAmbient(1.0)
732
733# Quadratic pyramid
734pyraPoints = vtk.vtkPoints()
735pyraPoints.SetNumberOfPoints(13)
736pyraPointsCoords = np.array([
737    [0, 0, 0],
738    [1, 0, 0],
739    [1, 1, 0],
740    [0, 1, 0],
741    [0, 0, 1],
742    [0.5, 0, 0],
743    [1, 0.5, 0],
744    [0.5, 1, 0],
745    [0, 0.5, 0],
746    [0, 0, 0.5],
747    [0.5, 0, 0.5],
748    [0.5, 0.5, 0.5],
749    [0, 0.5, 0.5]])
750pyraPoints.SetData(ntov(pyraPointsCoords))
751pyraScalars = vtk.vtkFloatArray()
752pyraScalars.SetNumberOfTuples(13)
753pyraScalars.InsertValue(0, 1.0)
754pyraScalars.InsertValue(1, 1.0)
755pyraScalars.InsertValue(2, 1.0)
756pyraScalars.InsertValue(3, 1.0)
757pyraScalars.InsertValue(4, 1.0)
758pyraScalars.InsertValue(5, 0.0)
759pyraScalars.InsertValue(6, 0.0)
760pyraScalars.InsertValue(7, 0.0)
761pyraScalars.InsertValue(8, 0.0)
762pyraScalars.InsertValue(9, 0.0)
763pyraScalars.InsertValue(10, 0.0)
764pyraScalars.InsertValue(11, 0.0)
765pyraScalars.InsertValue(12, 0.0)
766aPyramid = vtk.vtkQuadraticPyramid()
767for i in range(aPyramid.GetNumberOfPoints()):
768    aPyramid.GetPointIds().SetId(i, i)
769aPyramidGrid = vtk.vtkUnstructuredGrid()
770aPyramidGrid.Allocate(1, 1)
771aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds())
772aPyramidGrid.SetPoints(pyraPoints)
773aPyramidGrid.GetPointData().SetScalars(pyraScalars)
774pyraclips = vtk.vtkClipDataSet()
775pyraclips.SetInputData(aPyramidGrid)
776pyraclips.SetValue(0.5)
777aPyramidclipMapper = vtk.vtkDataSetMapper()
778aPyramidclipMapper.SetInputConnection(pyraclips.GetOutputPort())
779aPyramidclipMapper.ScalarVisibilityOff()
780aPyramidMapper = vtk.vtkDataSetMapper()
781aPyramidMapper.SetInputData(aPyramidGrid)
782aPyramidMapper.ScalarVisibilityOff()
783aPyramidActor = vtk.vtkActor()
784aPyramidActor.SetMapper(aPyramidMapper)
785aPyramidActor.GetProperty().SetRepresentationToWireframe()
786aPyramidActor.GetProperty().SetAmbient(1.0)
787aPyramidclipActor = vtk.vtkActor()
788aPyramidclipActor.SetMapper(aPyramidclipMapper)
789aPyramidclipActor.GetProperty().SetAmbient(1.0)
790
791# TriQuadratic pyramid
792TQpyraPoints = vtk.vtkPoints()
793TQpyraPoints.SetNumberOfPoints(19)
794TQpyraPointsCoords = np.array([
795    [0, 0, 0],
796    [1, 0, 0],
797    [1, 1, 0],
798    [0, 1, 0],
799    [0, 0, 1],
800    [0.5, 0, 0],
801    [1, 0.5, 0],
802    [0.5, 1, 0],
803    [0, 0.5, 0],
804    [0, 0, 0.5],
805    [0.5, 0, 0.5],
806    [0.5, 0.5, 0.5],
807    [0, 0.5, 0.5],
808    [0.5, 0.5, 0],
809    [1.0 / 3.0, 0, 1.0 / 3.0],
810    [2.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0],
811    [1.0 / 3.0, 2.0 / 3.0, 1.0 / 3.0],
812    [0, 1.0 / 3.0, 1.0 / 3.0],
813    [0.4, 0.4, 0.2]])
814TQpyraPoints.SetData(ntov(TQpyraPointsCoords))
815TQpyraScalars = vtk.vtkFloatArray()
816TQpyraScalars.SetNumberOfTuples(19)
817TQpyraScalars.InsertValue(0, 1.0)
818TQpyraScalars.InsertValue(1, 1.0)
819TQpyraScalars.InsertValue(2, 1.0)
820TQpyraScalars.InsertValue(3, 1.0)
821TQpyraScalars.InsertValue(4, 1.0)
822TQpyraScalars.InsertValue(5, 0.0)
823TQpyraScalars.InsertValue(6, 0.0)
824TQpyraScalars.InsertValue(7, 0.0)
825TQpyraScalars.InsertValue(8, 0.0)
826TQpyraScalars.InsertValue(9, 0.0)
827TQpyraScalars.InsertValue(10, 0.0)
828TQpyraScalars.InsertValue(11, 0.0)
829TQpyraScalars.InsertValue(12, 0.0)
830TQpyraScalars.InsertValue(13, 0.0)
831TQpyraScalars.InsertValue(14, 0.0)
832TQpyraScalars.InsertValue(15, 0.0)
833TQpyraScalars.InsertValue(16, 0.0)
834TQpyraScalars.InsertValue(17, 0.0)
835TQpyraScalars.InsertValue(18, 0.0)
836aTQPyramid = vtk.vtkTriQuadraticPyramid()
837for i in range(aTQPyramid.GetNumberOfPoints()):
838    aTQPyramid.GetPointIds().SetId(i, i)
839aTQPyramidGrid = vtk.vtkUnstructuredGrid()
840aTQPyramidGrid.Allocate(1, 1)
841aTQPyramidGrid.InsertNextCell(aTQPyramid.GetCellType(), aTQPyramid.GetPointIds())
842aTQPyramidGrid.SetPoints(TQpyraPoints)
843aTQPyramidGrid.GetPointData().SetScalars(TQpyraScalars)
844TQpyraClips = vtk.vtkClipDataSet()
845TQpyraClips.SetInputData(aTQPyramidGrid)
846TQpyraClips.SetValue(0.5)
847aTQPyramidClipMapper = vtk.vtkDataSetMapper()
848aTQPyramidClipMapper.SetInputConnection(TQpyraClips.GetOutputPort())
849aTQPyramidClipMapper.ScalarVisibilityOff()
850aTQPyramidMapper = vtk.vtkDataSetMapper()
851aTQPyramidMapper.SetInputData(aTQPyramidGrid)
852aTQPyramidMapper.ScalarVisibilityOff()
853aTQPyramidActor = vtk.vtkActor()
854aTQPyramidActor.SetMapper(aTQPyramidMapper)
855aTQPyramidActor.GetProperty().SetRepresentationToWireframe()
856aTQPyramidActor.GetProperty().SetAmbient(1.0)
857aTQPyramidClipActor = vtk.vtkActor()
858aTQPyramidClipActor.SetMapper(aTQPyramidClipMapper)
859aTQPyramidClipActor.GetProperty().SetAmbient(1.0)
860
861# Create the rendering related stuff.
862# Since some of our actors are a single vertex, we need to remove all
863# cullers so the single vertex actors will render
864ren1 = vtk.vtkRenderer()
865ren1.GetCullers().RemoveAllItems()
866renWin = vtk.vtkRenderWindow()
867renWin.AddRenderer(ren1)
868iren = vtk.vtkRenderWindowInteractor()
869iren.SetRenderWindow(renWin)
870ren1.SetBackground(.1, .2, .3)
871
872renWin.SetSize(400, 200)
873
874# specify properties
875ren1.AddActor(aEdgeActor)
876ren1.AddActor(aEdgeclipActor)
877
878ren1.AddActor(aTriActor)
879ren1.AddActor(aTriclipActor)
880
881ren1.AddActor(aQuadActor)
882ren1.AddActor(aQuadclipActor)
883
884ren1.AddActor(BQuadActor)
885ren1.AddActor(BQuadclipActor)
886
887ren1.AddActor(QLQuadActor)
888ren1.AddActor(QLQuadclipActor)
889
890ren1.AddActor(aTetActor)
891ren1.AddActor(aTetclipActor)
892
893ren1.AddActor(aHexActor)
894ren1.AddActor(aHexclipActor)
895
896ren1.AddActor(TQHexActor)
897ren1.AddActor(TQHexclipActor)
898
899ren1.AddActor(BQHexActor)
900ren1.AddActor(BQHexclipActor)
901
902ren1.AddActor(aWedgeActor)
903ren1.AddActor(aWedgeclipActor)
904
905ren1.AddActor(BQWedgeActor)
906ren1.AddActor(BQWedgeclipActor)
907
908ren1.AddActor(QLWedgeActor)
909ren1.AddActor(QLWedgeclipActor)
910
911ren1.AddActor(aPyramidActor)
912ren1.AddActor(aPyramidclipActor)
913
914ren1.AddActor(aTQPyramidActor)
915ren1.AddActor(aTQPyramidClipActor)
916
917# places everyone!!
918aEdgeclipActor.AddPosition(0, 2, 0)
919aTriActor.AddPosition(2, 0, 0)
920aTriclipActor.AddPosition(2, 2, 0)
921aQuadActor.AddPosition(4, 0, 0)
922BQuadActor.AddPosition(4, 0, 2)
923QLQuadActor.AddPosition(4, 0, 4)
924aQuadclipActor.AddPosition(4, 2, 0)
925BQuadclipActor.AddPosition(4, 2, 2)
926QLQuadclipActor.AddPosition(4, 2, 4)
927aTetActor.AddPosition(6, 0, 0)
928aTetclipActor.AddPosition(6, 2, 0)
929aHexActor.AddPosition(8, 0, 0)
930TQHexActor.AddPosition(8, 0, 2)
931BQHexActor.AddPosition(8, 0, 4)
932aHexclipActor.AddPosition(8, 2, 0)
933TQHexclipActor.AddPosition(8, 2, 2)
934BQHexclipActor.AddPosition(8, 2, 4)
935aWedgeActor.AddPosition(10, 0, 0)
936QLWedgeActor.AddPosition(10, 0, 2)
937BQWedgeActor.AddPosition(10, 0, 4)
938aWedgeclipActor.AddPosition(10, 2, 0)
939QLWedgeclipActor.AddPosition(10, 2, 2)
940BQWedgeclipActor.AddPosition(10, 2, 4)
941aPyramidActor.AddPosition(12, 0, 0)
942aTQPyramidActor.AddPosition(12, 0, 2)
943aPyramidclipActor.AddPosition(12, 2, 0)
944aTQPyramidClipActor.AddPosition(12, 2, 2)
945
946[base, back, left] = backdrop.BuildBackdrop(-1, 15, -1, 4, -1, 6, .1)
947
948ren1.AddActor(base)
949base.GetProperty().SetDiffuseColor(.2, .2, .2)
950ren1.AddActor(left)
951left.GetProperty().SetDiffuseColor(.2, .2, .2)
952ren1.AddActor(back)
953back.GetProperty().SetDiffuseColor(.2, .2, .2)
954
955ren1.ResetCamera()
956ren1.GetActiveCamera().Dolly(2.5)
957ren1.ResetCameraClippingRange()
958
959renWin.Render()
960
961# render the image
962#
963iren.Initialize()
964# iren.Start()
965