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

Godofredo godofredoiii at gmail.com
Mon Sep 3 07:49:13 EDT 2007


Hi. This is the code I use to extract the triangles of a Delaunay
triangulation:
        //The input of this code is the triangulated polydata "oPolyDataDel"
       // the output is an array with the indexes to the points "vTriangles"
	int j=0;
	int h;
	int npts=3,*pts;
	vtkCellArray* oCellArr= vtkCellArray::New();
	oCellArr=oPolyDataDel->GetPolys();
	 for(int i=0;i<oPolyDataDel->GetNumberOfPolys();i++)
	 {
			h=oCellArr->GetNextCell(npts,pts);
			
			if(h==0){
				break;
			}
			if(npts==3){
			vTriangles[j]= pts[0];
			vTriangles[j+1]= pts[1];
			vTriangles[j+2]= pts[2];
			j+=3;
			}

	 }

HDH.




Grant Edwards wrote:
> 
> 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            
> 
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 

-- 
View this message in context: http://www.nabble.com/How-do-I-get-triangles-from-the-vtkPolyData-that-vtkDelaunay2D-produces--tf4364875.html#a12460413
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list