[vtkusers] Re: How do I get triangles from the vtkPolyData that vtkDelaunay2D produces?
Grant Edwards
grante at visi.com
Tue Sep 4 12:25:20 EDT 2007
On 2007-09-04, Grant Edwards <grante at visi.com> wrote:
> On 2007-09-03, Sylvain Jaume <sylvain.jaume at kitware.com> wrote:
>> Hi Edwards,
>>
>> You can use:
>>
>> vtkIdType npts, *pts;
>>
>> o->GetPolys()->InitTraversal();
>>
>> while(o->GetPolys()->GetNextCell(npts,pts))
>> {
>> cout << "triangle [" << pts[0] << " " << pts[1] << " " << pts[2] << "]" << endl;
>> }
>
> Thanks for the example.
>
> The Python binding of the vtk library doesn't support the
> GetNextCell() and GetCell() methods for the vtkCellArray object
> returned by o->GetPolys(). Is there any other way to get the
> triangle info out?
I ended up having to call GetData and parse the polygon indexes
out of the raw data:
o = delny.GetOutput()
vertexes = [o.GetPoint(i) for i in xrange(o.GetNumberOfPoints())]
pdata = polys.GetPolys().GetData()
values = [int(pdata.GetTuple1(i)) for i in xrange(pdata.GetNumberOfTuples())]
triangles = []
while values:
n = values[0] # number of points in the polygon
triangles.append(values[1:n+1])
del values[0:n+1]
IMO, it's pretty lame to have to do it this way, but it seems
to work.
--
Grant Edwards grante Yow! I've read SEVEN
at MILLION books!!
visi.com
More information about the vtkusers
mailing list