[vtkusers] Neighbours of a point in a mesh

rashedk rashed.vtk at googlemail.com
Sat Apr 24 21:20:21 EDT 2010


That's brilliant, thanks! It works well. 

David Doria-2 wrote:
> 
> On Sat, Apr 24, 2010 at 8:31 AM, rashedk <rashed.vtk at googlemail.com>
> wrote:
>>
>> Hi all,
>>
>> A simple question: How do I get the neighbouring points of a point in a
>> vtkpolydata polygonal (strictly triangular) mesh?
>>
>> Thanks,
>>
>> Rashed.
> 
> 
> I just did this last week :)
> 
> I would highly recommend adding it to VTK.
> 
> //mesh is the input polydata, seed is the vertex you want to get the
> neighbors of, and the list of neighbors is returned in
> connectedVertices
> 
> void vtkPolyDataToGraph::GetConnectedVertices(vtkSmartPointer<vtkPolyData>
> mesh, int seed, vtkSmartPointer<vtkIdList> connectedVertices)
> {
> 
>   //get all cells that vertex 'seed' is a part of
>   vtkSmartPointer<vtkIdList> cellIdList =
>       vtkSmartPointer<vtkIdList>::New();
>   mesh->GetPointCells(seed, cellIdList);
> 
>   //cout << "There are " << cellIdList->GetNumberOfIds() << " cells
> that use point " << seed << endl;
> 
>   //loop through all the cells that use the seed point
>   for(vtkIdType i = 0; i < cellIdList->GetNumberOfIds(); i++)
>     {
> 
>     vtkCell* cell = mesh->GetCell(cellIdList->GetId(i));
>     //cout << "The cell has " << cell->GetNumberOfEdges() << " edges." <<
> endl;
> 
>     //if the cell doesn't have any edges, it is a line
>     if(cell->GetNumberOfEdges() <= 0)
>       {
>       continue;
>       }
> 
>     for(vtkIdType e = 0; e < cell->GetNumberOfEdges(); e++)
>       {
>       vtkCell* edge = cell->GetEdge(e);
> 
>       vtkIdList* pointIdList = edge->GetPointIds();
>       //cout << "This cell uses " << pointIdList->GetNumberOfIds() <<
> " points" << endl;
>       /*
>       for(vtkIdType p = 0; p < pointIdList->GetNumberOfIds(); p++)
>         {
>         cout << "Edge " << i << " uses point " << pointIdList->GetId(p) <<
> endl;
>         }
>         */
>       if(pointIdList->GetId(0) == seed || pointIdList->GetId(1) == seed)
>         {
>         if(pointIdList->GetId(0) == seed)
>           {
>           connectedVertices->InsertNextId(pointIdList->GetId(1));
>           }
>         else
>           {
>           connectedVertices->InsertNextId(pointIdList->GetId(0));
>           }
>         }
>       }
> 
> 
>     }
> 
>     //cout << "There are " << connectedVertices->GetNumberOfIds() << "
> points connected to point " << seed << endl;
> }
> 
> Let me know if that does the trick.
> 
> Thanks,
> 
> David
> _______________________________________________
> 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
> 
> 

-- 
View this message in context: http://old.nabble.com/Neighbours-of-a-point-in-a-mesh-tp28350073p28353880.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list