Advertisement
Guest User

vtkExtractUnstructuredGrid with polyhedron bug

a guest
Mar 24th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.68 KB | None | 0 0
  1. import vtk
  2.  
  3. # Prepare the unstructured grid --------------------------------------------------------------------
  4. grid = vtk.vtkUnstructuredGrid()
  5.  
  6. points = vtk.vtkPoints()
  7. points.SetNumberOfPoints(8)
  8. points.SetPoint(0, 0, 0, 0)
  9. points.SetPoint(1, 1, 0, 0)
  10. points.SetPoint(2, 1, 1, 0)
  11. points.SetPoint(3, 0, 1, 0)
  12. points.SetPoint(4, 0, 0, 1)
  13. points.SetPoint(5, 1, 0, 1)
  14. points.SetPoint(6, 1, 1, 1)
  15. points.SetPoint(7, 0, 1, 1)
  16. grid.SetPoints(points)
  17.  
  18. grid.Allocate(1)
  19.  
  20. def AddPolyhedronTo(grid):
  21.     polyhedron = [
  22.         [0, 3, 2, 1],
  23.         [0, 4, 7, 3],
  24.         [4, 5, 6, 7],
  25.         [5, 1, 2, 6],
  26.         [0, 1, 5, 4],
  27.         [2, 3, 7, 6],
  28.     ]
  29.     polygon_faces = vtk.vtkCellArray()
  30.     for face in polyhedron:
  31.         q = vtk.vtkPolygon()
  32.         q.GetPointIds().SetNumberOfIds(len(face))
  33.         for index, edge in enumerate(face):
  34.             q.GetPointIds().SetId(index, edge)
  35.         polygon_faces.InsertNextCell(q)
  36.  
  37.     face_stream = vtk.vtkIdList()
  38.     face_stream.InsertNextId(polygon_faces.GetNumberOfCells())
  39.     vertex_list = vtk.vtkIdList()
  40.  
  41.     polygon_faces.InitTraversal()
  42.     while polygon_faces.GetNextCell(vertex_list) == 1:
  43.         face_stream.InsertNextId(vertex_list.GetNumberOfIds())
  44.         for j in xrange(vertex_list.GetNumberOfIds()):
  45.             face_stream.InsertNextId(vertex_list.GetId(j))
  46.     grid.InsertNextCell(vtk.VTK_POLYHEDRON, face_stream)
  47.  
  48. def AddHexahedronTo(grid):
  49.     aHexahedron = vtk.vtkHexahedron()
  50.     aHexahedron.GetPointIds().SetId(0, 0)
  51.     aHexahedron.GetPointIds().SetId(1, 1)
  52.     aHexahedron.GetPointIds().SetId(2, 2)
  53.     aHexahedron.GetPointIds().SetId(3, 3)
  54.     aHexahedron.GetPointIds().SetId(4, 4)
  55.     aHexahedron.GetPointIds().SetId(5, 5)
  56.     aHexahedron.GetPointIds().SetId(6, 6)
  57.     aHexahedron.GetPointIds().SetId(7, 7)
  58.     grid.InsertNextCell(aHexahedron.GetCellType(), aHexahedron.GetPointIds())
  59.  
  60. # Choose one of them, comment the other ------------------------------------------------------------
  61. AddPolyhedronTo(grid)
  62. # AddHexahedronTo(grid)
  63.  
  64. # Test the algorithm -------------------------------------------------------------------------------
  65. unstructured_grid_extractor = vtk.vtkExtractUnstructuredGrid()
  66. unstructured_grid_extractor.SetInputData(grid)
  67. unstructured_grid_extractor.SetCellMinimum(0)
  68. unstructured_grid_extractor.SetCellMaximum(0)
  69. unstructured_grid_extractor.PointClippingOff()
  70. unstructured_grid_extractor.CellClippingOn()
  71. unstructured_grid_extractor.ExtentClippingOff()
  72. unstructured_grid_extractor.MergingOff()
  73. unstructured_grid_extractor.Update()
  74. output = unstructured_grid_extractor.GetOutput()
  75.  
  76. assert grid.GetCell(0).GetNumberOfPoints() == output.GetCell(0).GetNumberOfPoints()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement