[vtkusers] Generating a polyhedron cell from polydata in Python

Guðni Karl Rosenkjær grosenkj at eos.ubc.ca
Mon Jun 24 05:13:26 EDT 2013


Hello all vtk users,

I am trying to make a polyhedron cell (vtkUnstructuredGrid) from a
polydata. Googling for information on how to do this I have found these C++
test and used the as a guide.

However when I run my code on Fedora 17 64bit, using python 2.7.3 and vtk
5.10.1 (self compiled), I get an error when using InsertNextCell call of
the vtkUnstructuredGrid object.

Here is a example code I am using:
import vtk

# Read the polyData
cube = vtk.vtkCubeSource()
Poly = cube.GetOutput()

# Extract the information needed from the poly data
numPts = vtk.vtkIdTypeArray()
numPts.InsertNextValue(Poly.GetNumberOfPoints())
ptsIds = vtk.vtkIdTypeArray()
for cP in range(numPts.GetValue(0)): ptsIds.InsertNextValue(cP)
numCellFaces = vtk.vtkIdTypeArray()
numCellFaces.InsertNextValue(Poly.GetNumberOfPolys())
faces = vtk.vtkIdTypeArray()
for cF in range(numCellFaces.GetValue(0)):
    numPtsInFace = vtk.vtkIdTypeArray()
    numPtsInFace.InsertNextValue( Poly.GetCell(cF).GetNumberOfPoints())
    faces.InsertNextValue(numPtsInFace)
    for cPF in range(numPtsInFace.GetValue(0)):
        faces.InsertNextValue(Poly.GetCell(cF).GetPointId(cPF))

# Make the grid
UnstructPolyHed = vtk.vtkUnstructuredGrid()
UnstructPolyHed.SetPoints(Poly.GetPoints())
UnstructPolyHed.InsertNextCell(vtk.VTK_POLYHEDRON,numPts,ptsIds,numCellFaces,faces)


But I always end with this error: InsertNextCell() takes exactly 2
arguments (5 given)

The example used 5 inputs as follows
InsertNextCell(int type, vtkIdType npts, vtkIdType *ptIds, vtkIdType
nfaces, vtkIdType *faces)


What am I doing incorrectly?

Thanks in advance.

Cheers,
Gudni Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130624/c805ba42/attachment.htm>


More information about the vtkusers mailing list