[vtkusers] Traverse cells in unstructured grid, keep cellId

Jeff Lee jeff at cdnorthamerica.com
Fri Jun 2 08:32:13 EDT 2006

Have a look at Graphics/vtkContourGrid.cxx to see how to iterate through 
a vtkCellArray.  It involves some pointer gymnastics, but it is much 
less inefficient than GetNextCell.

Markus Ringlander wrote:
> Hi,
> I am traversing cells in an unstructured grid the following way:
> vtkCellArray *cells = vtkCellArray::New();
> cells->InitTraversal();
> int npts, *pts;
> while(cells->GetNextCell(npts, pts))
> {
> ...
> }
> This way I obtain the cell with points "pts" in constant time O(1), 
> but I lose any kind of direct cell identification. I need to use many 
> of the functions where I need cellId's, like GetCellNeighbors(cellId, 
> ...).
> I could use another approach with the function ugrid->GetCell(cellId) 
> in a for-loop to get my cells, where I simply loop over an increasing 
> index "cellId", and later obtain the pointId's and coordinates, etc. 
> But the call to GetCell is supposed to be worst case O(n) (really 
> true?) in time, and if I traverse a grid of n cells, this might end up 
> being worst case O(n^2) in time. With a large number of cells this 
> probably is not a good idea.
> So my question is, is there a (fast) way to keep an identification of 
> which cell I just got the points from in the above GetNextCell-method 
> using a vtkCellArray? Or any other recommendation.
> Thanks,
> /Mark
> ------------------------------------------------------------------------
> _______________________________________________
> 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

More information about the vtkusers mailing list