[vtkusers] GetCellNeighbors in for loop

pjozog pjozog at gmail.com
Fri Jan 30 16:52:14 EST 2015


I am trying to compute a 2D delaunay triangulation and determine which
triangles are on the "outside" of the mesh.  By that I mean: a triangle is
on the outside if one of its edges does not have a neighboring triangle. 
First of all, is there a quick way to do this?

I couldn't find such a function, so I'm trying to write one myself. 
Eventually I'd like to iterate over each triangle, and then access that
triangle's neighbors.

I've written the following code, which just gets the neighbor of the first
two vertices encountered on the first triangle.  The problem I see is that
once I call GetCellNeighbors(), the call to GetNextCell() immediately
returns 0 and the loop only iterates once!  If I take out the call to
GetCellNeighbors(), the loop iterates as I would expect it to.

    vtkSmartPointer<vtkPolyData> data = (read a mesh from disk)
    vtkSmartPointer<vtkCellArray> polys = data->GetPolys ();

    vtkIdType npoints, *pointIds, polyId=0;
    for (polys->InitTraversal (); polys->GetNextCell (npoints, pointIds);
++polyId) {
        vtkSmartPointer<vtkIdList> vertexIds =
vtkSmartPointer<vtkIdList>::New ();
        vertexIds->InsertNextId (pointIds[0]);
        vertexIds->InsertNextId (pointIds[1]);
        vtkSmartPointer<vtkIdList> neighIds =
vtkSmartPointer<vtkIdList>::New ();
        cout << "BEFORE GetCellNeighbors" << endl;
        polys->PrintSelf (cout, vtkIndent (0));
        data->GetCellNeighbors (polyId, vertexIds, neighIds);                                                                         
        cout << "AFTER GetCellNeighbors" << endl;
        polys->PrintSelf (cout, vtkIndent (0));

This is the relavent output of the program:
BEFORE GetCellNeighbors ()
Traversal Location: 4
AFTER GetCellNeighbors ()
Traversal Location: 128

I've uploaded the mesh I've been using to test the above code.  So what am I
doing wrong?  Thanks.

View this message in context: http://vtk.1045678.n5.nabble.com/GetCellNeighbors-in-for-loop-tp5730274.html
Sent from the VTK - Users mailing list archive at Nabble.com.

More information about the vtkusers mailing list