[vtkusers] polyhedron in python

George george.gerber at gmail.com
Sun Nov 2 10:41:52 EST 2014


Good day,

I have not managed to create a single cell polyhedron. Can somebody see
where I am going wrong with my code (it is very likely the input arguments
for insertnextcell)? When I open the file in paraview I can see the vertices
with the glyph filter, but there is no cell.
Best regards,
George

import vtk 
vertex_locations = vtk.vtkPoints()

vertex_locations.SetNumberOfPoints(4)
vertex_locations.SetPoint( 0, (-0.816497, -0.816497,  0.00000))
vertex_locations.SetPoint( 1, (-0.816497,  0.000000, -0.57735))
vertex_locations.SetPoint( 2, (-0.816497,  0.000000,  0.57735))
vertex_locations.SetPoint( 3, (-0.816497,  0.816497,  0.00000))

polygon_faces = vtk.vtkCellArray()

q = vtk.vtkQuad()
q.GetPointIds().SetId(0, 0)
q.GetPointIds().SetId(1, 1)
q.GetPointIds().SetId(2, 2)
q.GetPointIds().SetId(3, 3)
polygon_faces.InsertNextCell(q)

vertex_list = vtk.vtkIdList()
face_info = vtk.vtkIdList()

polygon_faces.InitTraversal()
while polygon_faces.GetNextCell(vertex_list) == 1:
    face_info.InsertNextId(vertex_list.GetNumberOfIds())
    
    for j in range(vertex_list.GetNumberOfIds()):
        face_info.InsertNextId(vertex_list.GetId(j))

ug = vtk.vtkUnstructuredGrid()
ug.InsertNextCell(vtk.VTK_POLYHEDRON,polygon_faces.GetNumberOfCells(),face_info)
ug.SetPoints(vertex_locations)

writer = vtk.vtkUnstructuredGridWriter()
writer.SetFileName("polyhedron.vtu")
writer.SetInputData(ug)
writer.Write() 



--
View this message in context: http://vtk.1045678.n5.nabble.com/polyhedron-in-python-tp5728643p5729314.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list