[vtkusers] polyhedron in python

Bill Lorensen bill.lorensen at gmail.com
Sun Nov 2 12:16:44 EST 2014


This example might be useful:
http://vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/Polyhedron


On Sun, Nov 2, 2014 at 10:41 AM, George <george.gerber at gmail.com> wrote:
> 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.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/vtkusers



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list