[vtkusers] Finding neighboring points
Sara Rolfe
smrolfe at u.washington.edu
Sat Jan 22 15:07:52 EST 2011
Hello,
I'm trying to find all the points connected to a vertex point in a
polydata mesh. I've followed the example here,
http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/CellPointNeighbors
And the email thread below, which both seem like what I want to do.
http://vtk.1045678.n5.nabble.com/Neighbours-of-a-point-in-a-mesh-td1236245.html
However, I'm having a problem when I try to use InsertNextId to add a
point to the list of connected points. I'm getting a bus error when I
get to this line in the code. Does anyone have an idea where this
might be coming from? I've checked that the ID I'm inserting is an
int type, and the list is an empty vtkIdList.
Thanks,
Sara
my subroutine to find connected neighbors is below.
void GetConnectedVertices(vtkSmartPointer<vtkPolyData> mesh, int seed,
vtkSmartPointer<vtkIdList> connectedVertices)
{
vtkSmartPointer<vtkIdList> cellIdList =
vtkSmartPointer<vtkIdList>::New(); //get all connected cells
mesh->GetPointCells(seed, cellIdList);
cout << "Got " << cellIdList->GetNumberOfIds() << " cells using point
" << seed << endl;
for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++){ // loop
through each cell using the seed point
cout << "Checking cell " << i << endl;
vtkCell* cell = mesh->GetCell(cellIdList->GetId(i)); // get current
cell
if(cell->GetNumberOfEdges() <= 0){ //if the cell doesn't have any
edges, it is a line, so skip
continue;
}
for(vtkIdType e = 0; e < cell->GetNumberOfEdges(); e++) // loop
through each edge of the cell
{
cout << "Checking edge " << e << endl;
vtkCell* edge = cell->GetEdge(e); // get current edge
vtkIdList* pointIdList = edge->GetPointIds(); // get list of
points on edge
if(pointIdList->GetId(0) == seed || pointIdList->GetId(1) ==
seed) // if one of the points on the edge are the vertex point
{
cout << "Writing connected point" << endl;
if(pointIdList->GetId(0) == seed) // if first point on edge is
vertex
{
int temp = pointIdList->GetId(1); // get second point from list
cout << "Adding " << temp << " to list" << endl;
connectedVertices->InsertNextId(temp); // and insert it into
connected point list
}
else
{
int temp = pointIdList->GetId(0); // get second point from list
cout << "Adding " << temp << " to list" << endl;
connectedVertices->InsertNextId(temp); // else insert first
point into connected point list
}
}
}
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110122/1b766ac7/attachment.htm>
More information about the vtkusers
mailing list