[vtkusers] Finding neighboring points
Sara Rolfe
smrolfe at u.washington.edu
Sat Jan 22 17:20:16 EST 2011
> Thanks for your reply. I thought I had done this, but when I
> checked back I had done so incorrectly, without New().
>
> This fixed my problem :)
On Jan 22, 2011, at 12:25 PM, David Doria wrote:
> Have you created the vtkIdList object before passing it to the
> function? i.e.
>
> vtkSmartPointer<vtkIdList> connectedVertices =
> vtkSmartPointer<vtkIdList>::New()
>
> ?
>
> I'm asking this off-list because I believe people sometimes see a
> reply and don't bother to read the original question, and I feel like
> you may need a better response than this!
>
> David
>
>
> On Sat, Jan 22, 2011 at 3:07 PM, Sara Rolfe
> <smrolfe at u.washington.edu> wrote:
>>
>> 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
>> }
>> }
>> }
>> }
>> }
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK 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