[vtkusers] Neighbours of a point in a mesh
David Doria
daviddoria+vtk at gmail.com
Sat Apr 24 08:36:19 EDT 2010
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
More information about the vtkusers
mailing list