[vtkusers] getcellneighbours of polydata

Andy Bauer andy.bauer at kitware.com
Sat May 29 12:04:28 EDT 2010


You may be getting confused by the fact that a cell is not considered
to be its own neighbor.  The reason your code didn't work is that you
are passing in all the points of cellId to get its points.  Unless you
have another cell that hsa those same exact points (and maybe others)
you won't get any cells.

As an example, if you wanted to get all cells which use pointId,
except for cellId the code would look like:
  vtkSmartPointer<vtkIdList> ptIds =
    vtkSmartPointer<vtkIdList>::New();
  sphereSource->GetOutput()->GetCellPoints(cellId, ptIds);
  vtkSmartPointer<vtkIdList> pointIds =
    vtkSmartPointer<vtkIdList>::New();
  pointIds->InsertNextId(ptIds->GetId(0));

  sphereSource->GetOutput()->GetCellNeighbors(cellId, pointIds,
neighborCellIds);
  std::cout << "There are " << neighborCellIds->GetNumberOfIds() << "
neighbors." << std::endl;

If you wanted the neighbors of cellId to share more points (e.g. edge
neighbor, face neighbor) you'd have to add in more points to pointIds.

On Fri, May 28, 2010 at 12:38 PM, rashedk <rashed.vtk at
googlemail.com <http://www.vtk.org/mailman/listinfo/vtkusers>> wrote:
>*
*>* Now that's interesting. It seems we are having the same problem then. Does
*>* that mean there isn't an easy way of getting a cell's neighbours?
*>*
*>* Rashed.
*
The documentation of this function:
void vtkDataSet::GetCellNeighbors

says:
Topological inquiry to get all cells using list of points exclusive of
cell specified (e.g., cellId). Note that the list consists of only
cells that use ALL the points provided.

I don't understand what that means? After looking at some use cases in
VTK, I came up with this:

  vtkSmartPointer<vtkIdList> ptIds =
    vtkSmartPointer<vtkIdList>::New();
  sphereSource->GetOutput()->GetCellPoints(cellId, ptIds);

  sphereSource->GetOutput()->GetCellNeighbors(cellId, ptIds, neighborCellIds);
  std::cout << "There are " << neighborCellIds->GetNumberOfIds() << "
neighbors." << std::endl;

It doesn't segfault, but it says there are 0 neighbors, which is not
true (it's a sphere!).

Can anyone explain what is going on here?

Thanks,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100529/aefaabb8/attachment.htm>


More information about the vtkusers mailing list