[vtkusers] GetPointCells -- number of cells returned not as expected?

Gordon Stevenson gordon.stevenson at lmh.ox.ac.uk
Fri Sep 17 08:00:43 EDT 2010


Sorry for this prior email, the behaviour of the function is as intended. It
was actually my mistake, there was a duplicate cell lurking underneath those
that where returning an number of cells equaling 2. Doing a quick check of
whether for when ncells returns 2 that the point ids of these triangles are
the same sorts everything out.

Some like adding into the function I sent previously...
if(ncells == 2.0){
//may be a duplicate cell lurking underneath.
if( pd->IsPointUsedByCell(pointIds->GetId(0),dummyIDT[0]) &&
           pd->IsPointUsedByCell(pointIds->GetId(1),dummyIDT[0]) &&
pd->IsPointUsedByCell(pointIds->GetId(2),dummyIDT[0])
&&    pd->IsPointUsedByCell(pointIds->GetId(0),dummyIDT[1]) &&
pd->IsPointUsedByCell(pointIds->GetId(1),dummyIDT[1])
&&    pd->IsPointUsedByCell(pointIds->GetId(2),dummyIDT[1]) ){ lonevertex++;
}
}

Bit of a hack, as I could use vtkCleanPolyData, but it works. This code may
be of use to anyone who comes accross the same problem.

Cheers,

G.

On Fri, Sep 17, 2010 at 10:28 AM, Gordon Stevenson <
gordon.stevenson at lmh.ox.ac.uk> wrote:

> Hi,
>
> I'm using polydata and the GetPointCells function to return for a given
> point the number of cells that use that point. I want to mark these point
> and so the cells where corners exist, so i can remove these cells.
>
> This works great in the most part, but for a few given corners (which I can
> visualise both the cell id and point id in ParaView) I know that it is a
> vertex that is used solely by one cell.
>
> pd->GetPointCells(pointIds->GetId(j),ncells,dummyIDT);
>
> returns ncells as 2. (when I believe it should be one?)
>
> Can anyone explain why that may be? Incidentally, I only use data that has
> been run through vtkTriangleFilter before doing this. I enclose the function
> I use below.
>
> Any help would be greatly appreciated.
>
> Gordon.
>
> vtkSmartPointer<vtkPolyData> CleanMesh(vtkSmartPointer<vtkPolyData> pd){
> // want to take in a polydata pd, and remove any cells (triangles) that are
>  // have vertices that have no links to other cells.
>  //show user current EC.
>  //GetEulerCharacteristic(pd);
>
> //for each cell in the mesh
> unsigned short ncells;
>  int lonevertex,badcellcount;
> //variable to store number of cells that are deleted.
>  badcellcount = 0.0;
> int a = 0;
> bool cornersfound = true;
>  while(cornersfound){
> //create connectivity list for cells. --required for GetPointCells calls.
>  pd->BuildLinks();
>
>  cornersfound = false;
>  int b;
> //for each cell.
>  for(vtkIdType i = 0; i<pd->GetNumberOfCells(); i++){
>  //generate the points each that cell.
>  vtkSmartPointer<vtkIdList> pointIds = vtkSmartPointer<vtkIdList>::New();
> pointIds = pd->GetCell(i)->GetPointIds();
>  if (pointIds->GetNumberOfIds() > 3) {
> std::cout << "Polygon got more than 3 vertices!" << std::endl;
>  }
>
> vtkIdType *dummyIDT;
> lonevertex = 0;
>  ncells = 0.0;
> //so for each point in the triangle, check that the vertex has more than
> one cell
>  //that uses it.
>  //loop over each vertex in the cell.
>  for(vtkIdType j = 0; j < pointIds->GetNumberOfIds(); j++){
> //get the number of cells that use this vertex.
>  b = pointIds->GetId(j);
> pd->GetPointCells(pointIds->GetId(j),ncells,dummyIDT);
>  //if vertex is not used by any other cells then -- including itself.
> if (ncells == 1.0){
>  //vertex is a corner, and therefore a candidate for deletion.
> lonevertex++;
>  }
> }
>
> //have we got any lone vertices?
>  if(lonevertex!=0){
> badcellcount++;
> //put up cell as candidate for deletion.
>  pd->DeleteCell(i);
> //need to loop back over the cells again checking for more corners
>  //that may have been revealed.
> cornersfound = true;
> }
>  }
> pd->RemoveDeletedCells();
> pd->Modified();
>  }
> std::cout << "\n Corner cells removed = " << badcellcount << std::endl;
>  //GetEulerCharacteristic(pd);
> return pd;
> }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100917/8488a567/attachment.htm>


More information about the vtkusers mailing list