How do I get triangles from a vtkPolyData object?

G

Grant Edwards

I posted this question to the vtk mailing list last week:

I've been Googling and wandering through the class references
most of the afternoon, but I can't figure out how to get the
triangles out of the vtkPolyData that vtkDelaunay2D produces?

I can get the vertex corredinates like this:

delny = vtk.vtkDelaunay2D()
delny.SetInput(profile)
delny.SetTolerance(0.001)
delny.Update()

o = delny.GetOutput()

vertexes = [o.GetPoint(i) for i in xrange(o.GetNumberOfPoints())]

I can see that there are 84 triangles, and 'o' is a vtkPolyData
object that has 84 cells and 84 polygons, so they obviously
represent the triangles, but I can't figure out how to get
something useful out of the cells or polys.

I got multiple replies telling me that I need to make calls to
o.GetNextCell(). The posters were even kind enough to include
examples in C++ showing how to do a delaunay triangulation and
retrieve the triangle info.

However, the Python version of a vtkCellArray object (which is
what's created as output from the Delaunay triangulation
module) doesn't make the GetNextCell() (or GetCell()) method
visible. It does have a GetNumberOfCells() object, and methods
to set and insert cells, but how do I _get_ a cell?
 
G

Grant Edwards

Is there _any_ documentation for the Python bindings to the vtk
library? I'm still beating my head against a wall trying to
figure out how to get the actual data out of vtk objects when
Python doesn't make visible the required "Get" methods....


I posted this question to the vtk mailing list last week:

I've been Googling and wandering through the class references
most of the afternoon, but I can't figure out how to get the
triangles out of the vtkPolyData that vtkDelaunay2D produces?

I can get the vertex corredinates like this:

delny = vtk.vtkDelaunay2D()
delny.SetInput(profile)
delny.SetTolerance(0.001)
delny.Update()

o = delny.GetOutput()

vertexes = [o.GetPoint(i) for i in xrange(o.GetNumberOfPoints())]

I can see that there are 84 triangles, and 'o' is a vtkPolyData
object that has 84 cells and 84 polygons, so they obviously
represent the triangles, but I can't figure out how to get
something useful out of the cells or polys.

I got multiple replies telling me that I need to make calls to
o.GetNextCell(). The posters were even kind enough to include
examples in C++ showing how to do a delaunay triangulation and
retrieve the triangle info.

I accidentally left out a step -- it's actually a vtkCellArray
object obtained by calling o.GetPolys() that is missing the
GetCell() and GetNextCell() methods which I need to call.
 
G

Grant Edwards

Is there _any_ documentation for the Python bindings to the vtk
library? I'm still beating my head against a wall trying to
figure out how to get the actual data out of vtk objects when
Python doesn't make visible the required "Get" methods....

I found a way to get at the object's "raw data" (a raw list of
floats) and parse out the cell/polygon information, but it's
bafflingly lame that Python doesn't make the normal "Get"
methods available so that one can actually retrieve the
individual cell elements of the vtkCellArray object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top