[vtkusers] Delete Cells from vtkPolyData
Mike Jackson
imikejackson at gmail.com
Wed Feb 28 17:41:12 EST 2007
So, just how do I actually delete a cell from a vtkPolyData? I have
tried a few things but nothing seems to be working. Here is some
example code of what I am doing:
void removeDuplicateTriangles(vtkPolyData *data)
{
vtkSmartPointer<vtkIdList> ptList = vtkSmartPointer<vtkIdList>::New
();
vtkIdType v0, v1, v2, vv0, vv1, vv2; //vertex Ids
int count = data->GetNumberOfPolys();
vtkSmartPointer<vtkIdList> neighbors =
vtkSmartPointer<vtkIdList>::New();
neighbors->Allocate(VTK_CELL_SIZE);
vtkSmartPointer<vtkIdList> cellList =
vtkSmartPointer<vtkIdList>::New();
int duplicateCount = 0;
vtkSmartPointer<vtkIdList> deadCells =
vtkSmartPointer<vtkIdList>::New();
std::cout << "Cell Count: " << count << std::endl;
for (vtkIdType cellId = 0; cellId < count; ++cellId ) //Main loop
on all polys
{
cellList->Reset();
data->GetCellPoints(cellId, ptList);
v0 = ptList->GetId(0);
v1 = ptList->GetId(1);
v2 = ptList->GetId(2);
data->GetCellEdgeNeighbors(cellId, v0, v1, neighbors);
for (int i = 0; i < neighbors->GetNumberOfIds(); ++i)
{ cellList->InsertUniqueId(neighbors->GetId(i)); }
data->GetCellEdgeNeighbors(cellId, v1, v2, neighbors);
for (int i = 0; i < neighbors->GetNumberOfIds(); ++i)
{ cellList->InsertUniqueId(neighbors->GetId(i)); }
data->GetCellEdgeNeighbors(cellId, v2, v0, neighbors);
for (int i = 0; i < neighbors->GetNumberOfIds(); ++i)
{ cellList->InsertUniqueId(neighbors->GetId(i)); }
// Now we have a list of Unique Cells, where each cell is a
triangle
for (vtkIdType i = 0; i < cellList->GetNumberOfIds(); ++i)
{
data->GetCellPoints( cellList->GetId(i), ptList);
vv0 = ptList->GetId(0);
vv1 = ptList->GetId(1);
vv2 = ptList->GetId(2);
if ( (v0==vv0 || v0==vv1 || v0==vv2) &&
(v1==vv0 || v1==vv1 || v1==vv2) &&
(v2==vv0 || v2==vv1 || v2==vv2) )
{
std::cout << "Removing Duplicate Triangle {" << cellId << ",
" << cellList->GetId(i) << "}" << std::endl;
if (cellId < cellList->GetId(i)) {
deadCells->InsertUniqueId(cellId);
} else {
deadCells->InsertUniqueId(cellList->GetId(i));
}
}
}
}
for (vtkIdType i = 0; i < deadCells->GetNumberOfIds(); ++i)
{
data->RemoveCellReference(deadCells->GetId(i));
data->DeleteCell(deadCells->GetId(i));
}
std::cout << "Dead Cells: " << deadCells->GetNumberOfIds() <<
std::endl;
vtkSmartPointer<vtkCleanPolyData> cleaner =
vtkSmartPointer<vtkCleanPolyData>::New();
cleaner->SetInput(data);
cleaner->Update();
std::cout << "Cell Count: " << cleaner->GetOutput()-
>GetNumberOfPolys() << std::endl;
}
The triangle counts at the start and end are the same. So anyone tell
me where I am screwing up?
I did read some archive threads where it was suggested to just build
a new vtkPolyData object instead of trying to change the first
vtkPolyData Object. Is there truth to that?
Thanks for any help.
--
Mike Jackson
imikejackson & gmail * com
More information about the vtkusers
mailing list