[vtkusers] How do I get triangles from the vtkPolyData that vtkDelaunay2D produces?

Sylvain Jaume sylvain.jaume at kitware.com
Mon Sep 3 09:50:48 EDT 2007


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;
   }

Sincerely,
Sylvain

Date: Sat, 1 Sep 2007 15:23:08 +0000 (UTC)
From: Grant Edwards <grante at visi.com>
Subject: [vtkusers] How do I get triangles from the vtkPolyData that
	vtkDelaunay2D produces?
To: vtkusers at public.kitware.com
Message-ID: <fbc04s$f17$1 at sea.gmane.org>

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())]

When I use vtkPolyDataWriter to write output to a file, 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.  What I'm
ultimately looking for is a list/array of 3-tuples containing
indexes into the vertex list obtained via the alls to GetPoint().

[I've probably stumbled past the answer multiple times but
didn't recognize because I don't really grok C++.]

-- Grant Edwards grante Yow! ! The land of the at rising SONY!! visi.com



More information about the vtkusers mailing list