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

Grant Edwards grante at visi.com
Mon Sep 3 09:36:25 EDT 2007


In gmane.comp.lib.vtk.user, you 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?
>
> 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;
> 			}
>
> 	 }

Thatnks for the example, but I can't figure out how to do the
equivalent in Python.  Calling oPolyDataDel->GetPolys() returns
a vtkCellArray object (which agrees with your C++ example).
However, the returned vtkCellArray object doesn't have a
GetNextCell() method.

I also just tried indexing (e.g. cell = oCellArr[i]).  Common
sense would indicate that since it's an array it should be
subscriptable, but I guess not.

Unfortunately there seems to be zero documentation for the
Python binding of the vtk library. :/

Here are the visible attributes/methods of a vtkCellArray
object:

AddObserver
Allocate
BreakOnError
DebugOff
DebugOn
DeepCopy
EstimateSize
FastDelete
GetActualMemorySize
GetAddressAsString
GetClassName
GetData
GetDebug
GetGlobalWarningDisplay
GetInsertLocation
GetMTime
GetMaxCellSize
GetNumberOfCells
GetNumberOfConnectivityEntries
GetReferenceCount
GetSize
GetTraversalLocation
GlobalWarningDisplayOff
GlobalWarningDisplayOn
HasObserver
InitTraversal
Initialize
InsertCellPoint
InsertNextCell
InvokeEvent
IsA
IsTypeOf
Modified
NewInstance
PrintRevisions
Register
RemoveObserver
RemoveObservers
Reset
ReverseCell
SafeDownCast
SetCells
SetDebug
SetGlobalWarningDisplay
SetNumberOfCells
SetReferenceCount
SetTraversalLocation
Squeeze
UnRegister
UpdateCellCount

-- 
Grant Edwards                   grante             Yow!  I request a weekend
                                  at               in Havana with Phil
                               visi.com            Silvers!




More information about the vtkusers mailing list