[vtkusers] getcellneighbours of polydata

Andy Bauer andy.bauer at kitware.com
Tue Jun 1 13:03:45 EDT 2010


I'm pretty sure that GetCellNeighbors is the function that you want.  The
confusion probably stems from the fact that people may define a neighbor of
a cell differently.  By specifying what points are shared between the cells,
this clears up that confusion.  As an example, if you have triangle cell A
with point X, Y, and Z, you could find the "edge" neighbors (neighbors that
share an edge of the triangle) by using GetCellNeighbor(A, {X,Y}, <list of
cell ids>), GetCellNeighbor(A, {X,Z}, <list of cell ids>),
GetCellNeighbor(A, {Y,Z}, <list of cell ids>).  To get the "point" neighbors
it would be GetCellNeighbor(A, {X}, <list of cell ids>),GetCellNeighbor(A,
{Y}, <list of cell ids>),GetCellNeighbor(A, {Z}, <list of cell ids>).

The GetCellNeighbor function doesn't require that the return cells don't use
other points, just that the returned cells must use the list points in the
input.

Andy

Date: Tue, 1 Jun 2010 03:56:18 -0700 (PDT)
> From: rashedk <rashed.vtk at googlemail.com>
> Subject: Re: [vtkusers] getcellneighbours of polydata
> To: vtkusers at vtk.org
> Message-ID: <28740248.post at talk.nabble.com>
> Content-Type: text/plain; charset=us-ascii
>
>
> It is strange why this function is called getcellneighbours, if you what
> you
> mentioned is correct. It is then really returning cells which use (ALL) the
> points specified. I am still looking for a function that would return
> cellIds of a cell's neighbours, surely there must be some function out
> there!
>
> Rashed.
>
>
> Andy Bauer wrote:
> >
> > 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/20100601/4938e833/attachment.htm>


More information about the vtkusers mailing list