PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Rendering/Core/Testing/Python/cells.py

http://github.com/Kitware/VTK
Python | 754 lines | 557 code | 150 blank | 47 comment | 3 complexity | 49e5235e288044e9f716fca1d61225e2 MD5 | raw file
Possible License(s): JSON, BSD-3-Clause, LGPL-2.0, LGPL-3.0, GPL-2.0, Apache-2.0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. =========================================================================
  5. Program: Visualization Toolkit
  6. Module: TestNamedColorsIntegration.py
  7. Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  8. All rights reserved.
  9. See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
  10. This software is distributed WITHOUT ANY WARRANTY; without even
  11. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12. PURPOSE. See the above copyright notice for more information.
  13. =========================================================================
  14. '''
  15. import os
  16. import vtk
  17. import vtk.test.Testing
  18. from vtk.util.misc import vtkGetDataRoot, vtkGetTempDir
  19. VTK_DATA_ROOT = vtkGetDataRoot()
  20. VTK_TEMP_DIR = vtkGetTempDir()
  21. class cells(vtk.test.Testing.vtkTest):
  22. def testCells(self):
  23. # Demonstrates all cell types
  24. #
  25. # NOTE: the use of NewInstance/DeepCopy is included to increase
  26. # regression coverage. It is not required in most applications.
  27. ren = vtk.vtkRenderer()
  28. # turn off all cullers
  29. ren.GetCullers().RemoveAllItems()
  30. renWin = vtk.vtkRenderWindow()
  31. renWin.AddRenderer(ren)
  32. renWin.SetSize(300, 150)
  33. iRen = vtk.vtkRenderWindowInteractor()
  34. iRen.SetRenderWindow(renWin);
  35. # create a scene with one of each cell type
  36. # Voxel
  37. voxelPoints = vtk.vtkPoints()
  38. voxelPoints.SetNumberOfPoints(8)
  39. voxelPoints.InsertPoint(0, 0, 0, 0)
  40. voxelPoints.InsertPoint(1, 1, 0, 0)
  41. voxelPoints.InsertPoint(2, 0, 1, 0)
  42. voxelPoints.InsertPoint(3, 1, 1, 0)
  43. voxelPoints.InsertPoint(4, 0, 0, 1)
  44. voxelPoints.InsertPoint(5, 1, 0, 1)
  45. voxelPoints.InsertPoint(6, 0, 1, 1)
  46. voxelPoints.InsertPoint(7, 1, 1, 1)
  47. aVoxel = vtk.vtkVoxel()
  48. aVoxel.GetPointIds().SetId(0, 0)
  49. aVoxel.GetPointIds().SetId(1, 1)
  50. aVoxel.GetPointIds().SetId(2, 2)
  51. aVoxel.GetPointIds().SetId(3, 3)
  52. aVoxel.GetPointIds().SetId(4, 4)
  53. aVoxel.GetPointIds().SetId(5, 5)
  54. aVoxel.GetPointIds().SetId(6, 6)
  55. aVoxel.GetPointIds().SetId(7, 7)
  56. bVoxel = aVoxel.NewInstance()
  57. bVoxel.DeepCopy(aVoxel)
  58. aVoxelGrid = vtk.vtkUnstructuredGrid()
  59. aVoxelGrid.Allocate(1, 1)
  60. aVoxelGrid.InsertNextCell(aVoxel.GetCellType(), aVoxel.GetPointIds())
  61. aVoxelGrid.SetPoints(voxelPoints)
  62. aVoxelMapper = vtk.vtkDataSetMapper()
  63. aVoxelMapper.SetInputData(aVoxelGrid)
  64. aVoxelActor = vtk.vtkActor()
  65. aVoxelActor.SetMapper(aVoxelMapper)
  66. aVoxelActor.GetProperty().BackfaceCullingOn()
  67. # Hexahedron
  68. hexahedronPoints = vtk.vtkPoints()
  69. hexahedronPoints.SetNumberOfPoints(8)
  70. hexahedronPoints.InsertPoint(0, 0, 0, 0)
  71. hexahedronPoints.InsertPoint(1, 1, 0, 0)
  72. hexahedronPoints.InsertPoint(2, 1, 1, 0)
  73. hexahedronPoints.InsertPoint(3, 0, 1, 0)
  74. hexahedronPoints.InsertPoint(4, 0, 0, 1)
  75. hexahedronPoints.InsertPoint(5, 1, 0, 1)
  76. hexahedronPoints.InsertPoint(6, 1, 1, 1)
  77. hexahedronPoints.InsertPoint(7, 0, 1, 1)
  78. aHexahedron = vtk.vtkHexahedron()
  79. aHexahedron.GetPointIds().SetId(0, 0)
  80. aHexahedron.GetPointIds().SetId(1, 1)
  81. aHexahedron.GetPointIds().SetId(2, 2)
  82. aHexahedron.GetPointIds().SetId(3, 3)
  83. aHexahedron.GetPointIds().SetId(4, 4)
  84. aHexahedron.GetPointIds().SetId(5, 5)
  85. aHexahedron.GetPointIds().SetId(6, 6)
  86. aHexahedron.GetPointIds().SetId(7, 7)
  87. bHexahedron = aHexahedron.NewInstance()
  88. bHexahedron.DeepCopy(aHexahedron)
  89. aHexahedronGrid = vtk.vtkUnstructuredGrid()
  90. aHexahedronGrid.Allocate(1, 1)
  91. aHexahedronGrid.InsertNextCell(aHexahedron.GetCellType(), aHexahedron.GetPointIds())
  92. aHexahedronGrid.SetPoints(hexahedronPoints)
  93. aHexahedronMapper = vtk.vtkDataSetMapper()
  94. aHexahedronMapper.SetInputData(aHexahedronGrid)
  95. aHexahedronActor = vtk.vtkActor()
  96. aHexahedronActor.SetMapper(aHexahedronMapper)
  97. aHexahedronActor.AddPosition(2, 0, 0)
  98. aHexahedronActor.GetProperty().BackfaceCullingOn()
  99. # Tetra
  100. tetraPoints = vtk.vtkPoints()
  101. tetraPoints.SetNumberOfPoints(4)
  102. tetraPoints.InsertPoint(0, 0, 0, 0)
  103. tetraPoints.InsertPoint(1, 1, 0, 0)
  104. tetraPoints.InsertPoint(2, .5, 1, 0)
  105. tetraPoints.InsertPoint(3, .5, .5, 1)
  106. aTetra = vtk.vtkTetra()
  107. aTetra.GetPointIds().SetId(0, 0)
  108. aTetra.GetPointIds().SetId(1, 1)
  109. aTetra.GetPointIds().SetId(2, 2)
  110. aTetra.GetPointIds().SetId(3, 3)
  111. bTetra = aTetra.NewInstance()
  112. bTetra.DeepCopy(aTetra)
  113. aTetraGrid = vtk.vtkUnstructuredGrid()
  114. aTetraGrid.Allocate(1, 1)
  115. aTetraGrid.InsertNextCell(aTetra.GetCellType(), aTetra.GetPointIds())
  116. aTetraGrid.SetPoints(tetraPoints)
  117. aTetraCopy = vtk.vtkUnstructuredGrid()
  118. aTetraCopy.ShallowCopy(aTetraGrid)
  119. aTetraMapper = vtk.vtkDataSetMapper()
  120. aTetraMapper.SetInputData(aTetraCopy)
  121. aTetraActor = vtk.vtkActor()
  122. aTetraActor.SetMapper(aTetraMapper)
  123. aTetraActor.AddPosition(4, 0, 0)
  124. aTetraActor.GetProperty().BackfaceCullingOn()
  125. # Wedge
  126. wedgePoints = vtk.vtkPoints()
  127. wedgePoints.SetNumberOfPoints(6)
  128. wedgePoints.InsertPoint(0, 0, 1, 0)
  129. wedgePoints.InsertPoint(1, 0, 0, 0)
  130. wedgePoints.InsertPoint(2, 0, .5, .5)
  131. wedgePoints.InsertPoint(3, 1, 1, 0)
  132. wedgePoints.InsertPoint(4, 1, 0, 0)
  133. wedgePoints.InsertPoint(5, 1, .5, .5)
  134. aWedge = vtk.vtkWedge()
  135. aWedge.GetPointIds().SetId(0, 0)
  136. aWedge.GetPointIds().SetId(1, 1)
  137. aWedge.GetPointIds().SetId(2, 2)
  138. aWedge.GetPointIds().SetId(3, 3)
  139. aWedge.GetPointIds().SetId(4, 4)
  140. aWedge.GetPointIds().SetId(5, 5)
  141. bWedge = aWedge.NewInstance()
  142. bWedge.DeepCopy(aWedge)
  143. aWedgeGrid = vtk.vtkUnstructuredGrid()
  144. aWedgeGrid.Allocate(1, 1)
  145. aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds())
  146. aWedgeGrid.SetPoints(wedgePoints)
  147. aWedgeCopy = vtk.vtkUnstructuredGrid()
  148. aWedgeCopy.DeepCopy(aWedgeGrid)
  149. aWedgeMapper = vtk.vtkDataSetMapper()
  150. aWedgeMapper.SetInputData(aWedgeCopy)
  151. aWedgeActor = vtk.vtkActor()
  152. aWedgeActor.SetMapper(aWedgeMapper)
  153. aWedgeActor.AddPosition(6, 0, 0)
  154. aWedgeActor.GetProperty().BackfaceCullingOn()
  155. # Pyramid
  156. pyramidPoints = vtk.vtkPoints()
  157. pyramidPoints.SetNumberOfPoints(5)
  158. pyramidPoints.InsertPoint(0, 0, 0, 0)
  159. pyramidPoints.InsertPoint(1, 1, 0, 0)
  160. pyramidPoints.InsertPoint(2, 1, 1, 0)
  161. pyramidPoints.InsertPoint(3, 0, 1, 0)
  162. pyramidPoints.InsertPoint(4, .5, .5, 1)
  163. aPyramid = vtk.vtkPyramid()
  164. aPyramid.GetPointIds().SetId(0, 0)
  165. aPyramid.GetPointIds().SetId(1, 1)
  166. aPyramid.GetPointIds().SetId(2, 2)
  167. aPyramid.GetPointIds().SetId(3, 3)
  168. aPyramid.GetPointIds().SetId(4, 4)
  169. bPyramid = aPyramid.NewInstance()
  170. bPyramid.DeepCopy(aPyramid)
  171. aPyramidGrid = vtk.vtkUnstructuredGrid()
  172. aPyramidGrid.Allocate(1, 1)
  173. aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds())
  174. aPyramidGrid.SetPoints(pyramidPoints)
  175. aPyramidMapper = vtk.vtkDataSetMapper()
  176. aPyramidMapper.SetInputData(aPyramidGrid)
  177. aPyramidActor = vtk.vtkActor()
  178. aPyramidActor.SetMapper(aPyramidMapper)
  179. aPyramidActor.AddPosition(8, 0, 0)
  180. aPyramidActor.GetProperty().BackfaceCullingOn()
  181. # Pixel
  182. pixelPoints = vtk.vtkPoints()
  183. pixelPoints.SetNumberOfPoints(4)
  184. pixelPoints.InsertPoint(0, 0, 0, 0)
  185. pixelPoints.InsertPoint(1, 1, 0, 0)
  186. pixelPoints.InsertPoint(2, 0, 1, 0)
  187. pixelPoints.InsertPoint(3, 1, 1, 0)
  188. aPixel = vtk.vtkPixel()
  189. aPixel.GetPointIds().SetId(0, 0)
  190. aPixel.GetPointIds().SetId(1, 1)
  191. aPixel.GetPointIds().SetId(2, 2)
  192. aPixel.GetPointIds().SetId(3, 3)
  193. bPixel = aPixel.NewInstance()
  194. bPixel.DeepCopy(aPixel)
  195. aPixelGrid = vtk.vtkUnstructuredGrid()
  196. aPixelGrid.Allocate(1, 1)
  197. aPixelGrid.InsertNextCell(aPixel.GetCellType(), aPixel.GetPointIds())
  198. aPixelGrid.SetPoints(pixelPoints)
  199. aPixelMapper = vtk.vtkDataSetMapper()
  200. aPixelMapper.SetInputData(aPixelGrid)
  201. aPixelActor = vtk.vtkActor()
  202. aPixelActor.SetMapper(aPixelMapper)
  203. aPixelActor.AddPosition(0, 0, 2)
  204. aPixelActor.GetProperty().BackfaceCullingOn()
  205. # Quad
  206. quadPoints = vtk.vtkPoints()
  207. quadPoints.SetNumberOfPoints(4)
  208. quadPoints.InsertPoint(0, 0, 0, 0)
  209. quadPoints.InsertPoint(1, 1, 0, 0)
  210. quadPoints.InsertPoint(2, 1, 1, 0)
  211. quadPoints.InsertPoint(3, 0, 1, 0)
  212. aQuad = vtk.vtkQuad()
  213. aQuad.GetPointIds().SetId(0, 0)
  214. aQuad.GetPointIds().SetId(1, 1)
  215. aQuad.GetPointIds().SetId(2, 2)
  216. aQuad.GetPointIds().SetId(3, 3)
  217. bQuad = aQuad.NewInstance()
  218. bQuad.DeepCopy(aQuad)
  219. aQuadGrid = vtk.vtkUnstructuredGrid()
  220. aQuadGrid.Allocate(1, 1)
  221. aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds())
  222. aQuadGrid.SetPoints(quadPoints)
  223. aQuadMapper = vtk.vtkDataSetMapper()
  224. aQuadMapper.SetInputData(aQuadGrid)
  225. aQuadActor = vtk.vtkActor()
  226. aQuadActor.SetMapper(aQuadMapper)
  227. aQuadActor.AddPosition(2, 0, 2)
  228. aQuadActor.GetProperty().BackfaceCullingOn()
  229. # Triangle
  230. trianglePoints = vtk.vtkPoints()
  231. trianglePoints.SetNumberOfPoints(3)
  232. trianglePoints.InsertPoint(0, 0, 0, 0)
  233. trianglePoints.InsertPoint(1, 1, 0, 0)
  234. trianglePoints.InsertPoint(2, .5, .5, 0)
  235. triangleTCoords = vtk.vtkFloatArray()
  236. triangleTCoords.SetNumberOfComponents(2)
  237. triangleTCoords.SetNumberOfTuples(3)
  238. triangleTCoords.InsertTuple2(0, 1, 1)
  239. triangleTCoords.InsertTuple2(1, 2, 2)
  240. triangleTCoords.InsertTuple2(2, 3, 3)
  241. aTriangle = vtk.vtkTriangle()
  242. aTriangle.GetPointIds().SetId(0, 0)
  243. aTriangle.GetPointIds().SetId(1, 1)
  244. aTriangle.GetPointIds().SetId(2, 2)
  245. bTriangle = aTriangle.NewInstance()
  246. bTriangle.DeepCopy(aTriangle)
  247. aTriangleGrid = vtk.vtkUnstructuredGrid()
  248. aTriangleGrid.Allocate(1, 1)
  249. aTriangleGrid.InsertNextCell(aTriangle.GetCellType(), aTriangle.GetPointIds())
  250. aTriangleGrid.SetPoints(trianglePoints)
  251. aTriangleGrid.GetPointData().SetTCoords(triangleTCoords)
  252. aTriangleMapper = vtk.vtkDataSetMapper()
  253. aTriangleMapper.SetInputData(aTriangleGrid)
  254. aTriangleActor = vtk.vtkActor()
  255. aTriangleActor.SetMapper(aTriangleMapper)
  256. aTriangleActor.AddPosition(4, 0, 2)
  257. aTriangleActor.GetProperty().BackfaceCullingOn()
  258. # Polygon
  259. polygonPoints = vtk.vtkPoints()
  260. polygonPoints.SetNumberOfPoints(4)
  261. polygonPoints.InsertPoint(0, 0, 0, 0)
  262. polygonPoints.InsertPoint(1, 1, 0, 0)
  263. polygonPoints.InsertPoint(2, 1, 1, 0)
  264. polygonPoints.InsertPoint(3, 0, 1, 0)
  265. aPolygon = vtk.vtkPolygon()
  266. aPolygon.GetPointIds().SetNumberOfIds(4)
  267. aPolygon.GetPointIds().SetId(0, 0)
  268. aPolygon.GetPointIds().SetId(1, 1)
  269. aPolygon.GetPointIds().SetId(2, 2)
  270. aPolygon.GetPointIds().SetId(3, 3)
  271. bPolygon = aPolygon.NewInstance()
  272. bPolygon.DeepCopy(aPolygon)
  273. aPolygonGrid = vtk.vtkUnstructuredGrid()
  274. aPolygonGrid.Allocate(1, 1)
  275. aPolygonGrid.InsertNextCell(aPolygon.GetCellType(), aPolygon.GetPointIds())
  276. aPolygonGrid.SetPoints(polygonPoints)
  277. aPolygonMapper = vtk.vtkDataSetMapper()
  278. aPolygonMapper.SetInputData(aPolygonGrid)
  279. aPolygonActor = vtk.vtkActor()
  280. aPolygonActor.SetMapper(aPolygonMapper)
  281. aPolygonActor.AddPosition(6, 0, 2)
  282. aPolygonActor.GetProperty().BackfaceCullingOn()
  283. # Triangle Strip
  284. triangleStripPoints = vtk.vtkPoints()
  285. triangleStripPoints.SetNumberOfPoints(5)
  286. triangleStripPoints.InsertPoint(0, 0, 1, 0)
  287. triangleStripPoints.InsertPoint(1, 0, 0, 0)
  288. triangleStripPoints.InsertPoint(2, 1, 1, 0)
  289. triangleStripPoints.InsertPoint(3, 1, 0, 0)
  290. triangleStripPoints.InsertPoint(4, 2, 1, 0)
  291. triangleStripTCoords = vtk.vtkFloatArray()
  292. triangleStripTCoords.SetNumberOfComponents(2)
  293. triangleStripTCoords.SetNumberOfTuples(3)
  294. triangleStripTCoords.InsertTuple2(0, 1, 1)
  295. triangleStripTCoords.InsertTuple2(1, 2, 2)
  296. triangleStripTCoords.InsertTuple2(2, 3, 3)
  297. triangleStripTCoords.InsertTuple2(3, 4, 4)
  298. triangleStripTCoords.InsertTuple2(4, 5, 5)
  299. aTriangleStrip = vtk.vtkTriangleStrip()
  300. aTriangleStrip.GetPointIds().SetNumberOfIds(5)
  301. aTriangleStrip.GetPointIds().SetId(0, 0)
  302. aTriangleStrip.GetPointIds().SetId(1, 1)
  303. aTriangleStrip.GetPointIds().SetId(2, 2)
  304. aTriangleStrip.GetPointIds().SetId(3, 3)
  305. aTriangleStrip.GetPointIds().SetId(4, 4)
  306. bTriangleStrip = aTriangleStrip.NewInstance()
  307. bTriangleStrip.DeepCopy(aTriangleStrip)
  308. aTriangleStripGrid = vtk.vtkUnstructuredGrid()
  309. aTriangleStripGrid.Allocate(1, 1)
  310. aTriangleStripGrid.InsertNextCell(aTriangleStrip.GetCellType(), aTriangleStrip.GetPointIds())
  311. aTriangleStripGrid.SetPoints(triangleStripPoints)
  312. aTriangleStripGrid.GetPointData().SetTCoords(triangleStripTCoords)
  313. aTriangleStripMapper = vtk.vtkDataSetMapper()
  314. aTriangleStripMapper.SetInputData(aTriangleStripGrid)
  315. aTriangleStripActor = vtk.vtkActor()
  316. aTriangleStripActor.SetMapper(aTriangleStripMapper)
  317. aTriangleStripActor.AddPosition(8, 0, 2)
  318. aTriangleStripActor.GetProperty().BackfaceCullingOn()
  319. # Line
  320. linePoints = vtk.vtkPoints()
  321. linePoints.SetNumberOfPoints(2)
  322. linePoints.InsertPoint(0, 0, 0, 0)
  323. linePoints.InsertPoint(1, 1, 1, 0)
  324. aLine = vtk.vtkLine()
  325. aLine.GetPointIds().SetId(0, 0)
  326. aLine.GetPointIds().SetId(1, 1)
  327. bLine = aLine.NewInstance()
  328. bLine.DeepCopy(aLine)
  329. aLineGrid = vtk.vtkUnstructuredGrid()
  330. aLineGrid.Allocate(1, 1)
  331. aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds())
  332. aLineGrid.SetPoints(linePoints)
  333. aLineMapper = vtk.vtkDataSetMapper()
  334. aLineMapper.SetInputData(aLineGrid)
  335. aLineActor = vtk.vtkActor()
  336. aLineActor.SetMapper(aLineMapper)
  337. aLineActor.AddPosition(0, 0, 4)
  338. aLineActor.GetProperty().BackfaceCullingOn()
  339. # Poly line
  340. polyLinePoints = vtk.vtkPoints()
  341. polyLinePoints.SetNumberOfPoints(3)
  342. polyLinePoints.InsertPoint(0, 0, 0, 0)
  343. polyLinePoints.InsertPoint(1, 1, 1, 0)
  344. polyLinePoints.InsertPoint(2, 1, 0, 0)
  345. aPolyLine = vtk.vtkPolyLine()
  346. aPolyLine.GetPointIds().SetNumberOfIds(3)
  347. aPolyLine.GetPointIds().SetId(0, 0)
  348. aPolyLine.GetPointIds().SetId(1, 1)
  349. aPolyLine.GetPointIds().SetId(2, 2)
  350. bPolyLine = aPolyLine.NewInstance()
  351. bPolyLine.DeepCopy(aPolyLine)
  352. aPolyLineGrid = vtk.vtkUnstructuredGrid()
  353. aPolyLineGrid.Allocate(1, 1)
  354. aPolyLineGrid.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())
  355. aPolyLineGrid.SetPoints(polyLinePoints)
  356. aPolyLineMapper = vtk.vtkDataSetMapper()
  357. aPolyLineMapper.SetInputData(aPolyLineGrid)
  358. aPolyLineActor = vtk.vtkActor()
  359. aPolyLineActor.SetMapper(aPolyLineMapper)
  360. aPolyLineActor.AddPosition(2, 0, 4)
  361. aPolyLineActor.GetProperty().BackfaceCullingOn()
  362. # Vertex
  363. vertexPoints = vtk.vtkPoints()
  364. vertexPoints.SetNumberOfPoints(1)
  365. vertexPoints.InsertPoint(0, 0, 0, 0)
  366. aVertex = vtk.vtkVertex()
  367. aVertex.GetPointIds().SetId(0, 0)
  368. bVertex = aVertex.NewInstance()
  369. bVertex.DeepCopy(aVertex)
  370. aVertexGrid = vtk.vtkUnstructuredGrid()
  371. aVertexGrid.Allocate(1, 1)
  372. aVertexGrid.InsertNextCell(aVertex.GetCellType(), aVertex.GetPointIds())
  373. aVertexGrid.SetPoints(vertexPoints)
  374. aVertexMapper = vtk.vtkDataSetMapper()
  375. aVertexMapper.SetInputData(aVertexGrid)
  376. aVertexActor = vtk.vtkActor()
  377. aVertexActor.SetMapper(aVertexMapper)
  378. aVertexActor.AddPosition(0, 0, 6)
  379. aVertexActor.GetProperty().BackfaceCullingOn()
  380. # Poly Vertex
  381. polyVertexPoints = vtk.vtkPoints()
  382. polyVertexPoints.SetNumberOfPoints(3)
  383. polyVertexPoints.InsertPoint(0, 0, 0, 0)
  384. polyVertexPoints.InsertPoint(1, 1, 0, 0)
  385. polyVertexPoints.InsertPoint(2, 1, 1, 0)
  386. aPolyVertex = vtk.vtkPolyVertex()
  387. aPolyVertex.GetPointIds().SetNumberOfIds(3)
  388. aPolyVertex.GetPointIds().SetId(0, 0)
  389. aPolyVertex.GetPointIds().SetId(1, 1)
  390. aPolyVertex.GetPointIds().SetId(2, 2)
  391. bPolyVertex = aPolyVertex.NewInstance()
  392. bPolyVertex.DeepCopy(aPolyVertex)
  393. aPolyVertexGrid = vtk.vtkUnstructuredGrid()
  394. aPolyVertexGrid.Allocate(1, 1)
  395. aPolyVertexGrid.InsertNextCell(aPolyVertex.GetCellType(), aPolyVertex.GetPointIds())
  396. aPolyVertexGrid.SetPoints(polyVertexPoints)
  397. aPolyVertexMapper = vtk.vtkDataSetMapper()
  398. aPolyVertexMapper.SetInputData(aPolyVertexGrid)
  399. aPolyVertexActor = vtk.vtkActor()
  400. aPolyVertexActor.SetMapper(aPolyVertexMapper)
  401. aPolyVertexActor.AddPosition(2, 0, 6)
  402. aPolyVertexActor.GetProperty().BackfaceCullingOn()
  403. # Pentagonal prism
  404. pentaPoints = vtk.vtkPoints()
  405. pentaPoints.SetNumberOfPoints(10)
  406. pentaPoints.InsertPoint(0, 0.25, 0.0, 0.0)
  407. pentaPoints.InsertPoint(1, 0.75, 0.0, 0.0)
  408. pentaPoints.InsertPoint(2, 1.0, 0.5, 0.0)
  409. pentaPoints.InsertPoint(3, 0.5, 1.0, 0.0)
  410. pentaPoints.InsertPoint(4, 0.0, 0.5, 0.0)
  411. pentaPoints.InsertPoint(5, 0.25, 0.0, 1.0)
  412. pentaPoints.InsertPoint(6, 0.75, 0.0, 1.0)
  413. pentaPoints.InsertPoint(7, 1.0, 0.5, 1.0)
  414. pentaPoints.InsertPoint(8, 0.5, 1.0, 1.0)
  415. pentaPoints.InsertPoint(9, 0.0, 0.5, 1.0)
  416. aPenta = vtk.vtkPentagonalPrism()
  417. aPenta.GetPointIds().SetId(0, 0)
  418. aPenta.GetPointIds().SetId(1, 1)
  419. aPenta.GetPointIds().SetId(2, 2)
  420. aPenta.GetPointIds().SetId(3, 3)
  421. aPenta.GetPointIds().SetId(4, 4)
  422. aPenta.GetPointIds().SetId(5, 5)
  423. aPenta.GetPointIds().SetId(6, 6)
  424. aPenta.GetPointIds().SetId(7, 7)
  425. aPenta.GetPointIds().SetId(8, 8)
  426. aPenta.GetPointIds().SetId(9, 9)
  427. bPenta = aPenta.NewInstance()
  428. bPenta.DeepCopy(aPenta)
  429. aPentaGrid = vtk.vtkUnstructuredGrid()
  430. aPentaGrid.Allocate(1, 1)
  431. aPentaGrid.InsertNextCell(aPenta.GetCellType(), aPenta.GetPointIds())
  432. aPentaGrid.SetPoints(pentaPoints)
  433. aPentaCopy = vtk.vtkUnstructuredGrid()
  434. aPentaCopy.DeepCopy(aPentaGrid)
  435. aPentaMapper = vtk.vtkDataSetMapper()
  436. aPentaMapper.SetInputData(aPentaCopy)
  437. aPentaActor = vtk.vtkActor()
  438. aPentaActor.SetMapper(aPentaMapper)
  439. aPentaActor.AddPosition(10, 0, 0)
  440. aPentaActor.GetProperty().BackfaceCullingOn()
  441. # Hexagonal prism
  442. hexaPoints = vtk.vtkPoints()
  443. hexaPoints.SetNumberOfPoints(12)
  444. hexaPoints.InsertPoint(0, 0.0, 0.0, 0.0)
  445. hexaPoints.InsertPoint(1, 0.5, 0.0, 0.0)
  446. hexaPoints.InsertPoint(2, 1.0, 0.5, 0.0)
  447. hexaPoints.InsertPoint(3, 1.0, 1.0, 0.0)
  448. hexaPoints.InsertPoint(4, 0.5, 1.0, 0.0)
  449. hexaPoints.InsertPoint(5, 0.0, 0.5, 0.0)
  450. hexaPoints.InsertPoint(6, 0.0, 0.0, 1.0)
  451. hexaPoints.InsertPoint(7, 0.5, 0.0, 1.0)
  452. hexaPoints.InsertPoint(8, 1.0, 0.5, 1.0)
  453. hexaPoints.InsertPoint(9, 1.0, 1.0, 1.0)
  454. hexaPoints.InsertPoint(10, 0.5, 1.0, 1.0)
  455. hexaPoints.InsertPoint(11, 0.0, 0.5, 1.0)
  456. aHexa = vtk.vtkHexagonalPrism()
  457. aHexa.GetPointIds().SetId(0, 0)
  458. aHexa.GetPointIds().SetId(1, 1)
  459. aHexa.GetPointIds().SetId(2, 2)
  460. aHexa.GetPointIds().SetId(3, 3)
  461. aHexa.GetPointIds().SetId(4, 4)
  462. aHexa.GetPointIds().SetId(5, 5)
  463. aHexa.GetPointIds().SetId(6, 6)
  464. aHexa.GetPointIds().SetId(7, 7)
  465. aHexa.GetPointIds().SetId(8, 8)
  466. aHexa.GetPointIds().SetId(9, 9)
  467. aHexa.GetPointIds().SetId(10, 10)
  468. aHexa.GetPointIds().SetId(11, 11)
  469. bHexa = aHexa.NewInstance()
  470. bHexa.DeepCopy(aHexa)
  471. aHexaGrid = vtk.vtkUnstructuredGrid()
  472. aHexaGrid.Allocate(1, 1)
  473. aHexaGrid.InsertNextCell(aHexa.GetCellType(), aHexa.GetPointIds())
  474. aHexaGrid.SetPoints(hexaPoints)
  475. aHexaCopy = vtk.vtkUnstructuredGrid()
  476. aHexaCopy.DeepCopy(aHexaGrid)
  477. aHexaMapper = vtk.vtkDataSetMapper()
  478. aHexaMapper.SetInputData(aHexaCopy)
  479. aHexaActor = vtk.vtkActor()
  480. aHexaActor.SetMapper(aHexaMapper)
  481. aHexaActor.AddPosition(12, 0, 0)
  482. aHexaActor.GetProperty().BackfaceCullingOn()
  483. # RIB property
  484. if hasattr(vtk, 'vtkRIBProperty'):
  485. aRIBProperty = vtk.vtkRIBProperty()
  486. aRIBProperty.SetVariable("Km", "float")
  487. aRIBProperty.SetSurfaceShader("LGVeinedmarble")
  488. aRIBProperty.SetVariable("veinfreq", "float")
  489. aRIBProperty.AddVariable("warpfreq", "float")
  490. aRIBProperty.AddVariable("veincolor", "color")
  491. aRIBProperty.AddSurfaceShaderParameter("veinfreq", " 2")
  492. aRIBProperty.AddSurfaceShaderParameter("veincolor", "1.0000 1.0000 0.9412")
  493. bRIBProperty = vtk.vtkRIBProperty()
  494. bRIBProperty.SetVariable("Km", "float")
  495. bRIBProperty.SetSurfaceShaderParameter("Km", "1.0")
  496. bRIBProperty.SetDisplacementShader("dented")
  497. bRIBProperty.SetSurfaceShader("plastic")
  498. aProperty = vtk.vtkProperty()
  499. bProperty = vtk.vtkProperty()
  500. aTriangleActor.SetProperty(aProperty)
  501. aTriangleStripActor.SetProperty(bProperty)
  502. ren.SetBackground(.1, .2, .4)
  503. ren.AddActor(aVoxelActor);aVoxelActor.GetProperty().SetDiffuseColor(1, 0, 0)
  504. ren.AddActor(aHexahedronActor);aHexahedronActor.GetProperty().SetDiffuseColor(1, 1, 0)
  505. ren.AddActor(aTetraActor);aTetraActor.GetProperty().SetDiffuseColor(0, 1, 0)
  506. ren.AddActor(aWedgeActor);aWedgeActor.GetProperty().SetDiffuseColor(0, 1, 1)
  507. ren.AddActor(aPyramidActor);aPyramidActor.GetProperty().SetDiffuseColor(1, 0, 1)
  508. ren.AddActor(aPixelActor);aPixelActor.GetProperty().SetDiffuseColor(0, 1, 1)
  509. ren.AddActor(aQuadActor);aQuadActor.GetProperty().SetDiffuseColor(1, 0, 1)
  510. ren.AddActor(aTriangleActor);aTriangleActor.GetProperty().SetDiffuseColor(.3, 1, .5)
  511. ren.AddActor(aPolygonActor);aPolygonActor.GetProperty().SetDiffuseColor(1, .4, .5)
  512. ren.AddActor(aTriangleStripActor);aTriangleStripActor.GetProperty().SetDiffuseColor(.3, .7, 1)
  513. ren.AddActor(aLineActor);aLineActor.GetProperty().SetDiffuseColor(.2, 1, 1)
  514. ren.AddActor(aPolyLineActor);aPolyLineActor.GetProperty().SetDiffuseColor(1, 1, 1)
  515. ren.AddActor(aVertexActor);aVertexActor.GetProperty().SetDiffuseColor(1, 1, 1)
  516. ren.AddActor(aPolyVertexActor);aPolyVertexActor.GetProperty().SetDiffuseColor(1, 1, 1)
  517. ren.AddActor(aPentaActor);aPentaActor.GetProperty().SetDiffuseColor(.2, .4, .7)
  518. ren.AddActor(aHexaActor);aHexaActor.GetProperty().SetDiffuseColor(.7, .5, 1)
  519. aRIBLight = vtk.vtkRIBLight()
  520. aRIBLight.SetIntensity(0.7)
  521. ren.AddLight(aRIBLight)
  522. aLight = vtk.vtkLight()
  523. aLight.PositionalOn()
  524. aLight.SetConeAngle(10.0)
  525. aLight.SetIntensity(0.7)
  526. ren.AddLight(aLight)
  527. ren.ResetCamera()
  528. ren.GetActiveCamera().Azimuth(30)
  529. ren.GetActiveCamera().Elevation(20)
  530. ren.GetActiveCamera().Dolly(2.8)
  531. ren.ResetCameraClippingRange()
  532. dir = VTK_TEMP_DIR
  533. atext = vtk.vtkTexture()
  534. pnmReader = vtk.vtkBMPReader()
  535. pnmReader.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp")
  536. atext.SetInputConnection(pnmReader.GetOutputPort())
  537. atext.InterpolateOff()
  538. aTriangleActor.SetTexture(atext)
  539. aRIBLight.SetFocalPoint(ren.GetActiveCamera().GetFocalPoint())
  540. aRIBLight.SetPosition(ren.GetActiveCamera().GetPosition())
  541. aLight.SetFocalPoint(ren.GetActiveCamera().GetFocalPoint())
  542. aLight.SetPosition(ren.GetActiveCamera().GetPosition())
  543. # bascially have IO/Export ?
  544. if hasattr(vtk, 'vtkRIBExporter'):
  545. rib = vtk.vtkRIBExporter()
  546. rib.SetInput(renWin)
  547. rib.SetFilePrefix(dir + '/cells')
  548. rib.SetTexturePrefix(dir + '/cells')
  549. rib.Write()
  550. iv = vtk.vtkIVExporter()
  551. iv.SetInput(renWin)
  552. iv.SetFileName(dir + "/cells.iv")
  553. iv.Write()
  554. os.remove(dir + '/cells.iv')
  555. obj = vtk.vtkOBJExporter()
  556. obj.SetInput(renWin)
  557. obj.SetFilePrefix(dir + "/cells")
  558. obj.Write()
  559. os.remove(dir + '/cells.obj')
  560. os.remove(dir + '/cells.mtl')
  561. vrml = vtk.vtkVRMLExporter()
  562. vrml.SetInput(renWin)
  563. #vrml.SetStartWrite(vrml.SetFileName(dir + "/cells.wrl"))
  564. #vrml.SetEndWrite(vrml.SetFileName("/a/acells.wrl"))
  565. vrml.SetFileName(dir + "/cells.wrl")
  566. vrml.SetSpeed(5.5)
  567. vrml.Write()
  568. os.remove(dir + '/cells.wrl')
  569. oogl = vtk.vtkOOGLExporter()
  570. oogl.SetInput(renWin)
  571. oogl.SetFileName(dir + "/cells.oogl")
  572. oogl.Write()
  573. os.remove(dir + '/cells.oogl')
  574. # the UnRegister calls are because make object is the same as New,
  575. # and causes memory leaks. (Python does not treat NewInstance the same as New).
  576. def DeleteCopies():
  577. bVoxel.UnRegister(None)
  578. bHexahedron.UnRegister(None)
  579. bTetra.UnRegister(None)
  580. bWedge.UnRegister(None)
  581. bPyramid.UnRegister(None)
  582. bPixel.UnRegister(None)
  583. bQuad.UnRegister(None)
  584. bTriangle.UnRegister(None)
  585. bPolygon.UnRegister(None)
  586. bTriangleStrip.UnRegister(None)
  587. bLine.UnRegister(None)
  588. bPolyLine.UnRegister(None)
  589. bVertex.UnRegister(None)
  590. bPolyVertex.UnRegister(None)
  591. bPenta.UnRegister(None)
  592. bHexa.UnRegister(None)
  593. DeleteCopies()
  594. # render and interact with data
  595. renWin.Render()
  596. img_file = "cells.png"
  597. vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file))
  598. vtk.test.Testing.interact()
  599. if __name__ == "__main__":
  600. vtk.test.Testing.main([(cells, 'test')])