Hi all,
I have a mesh with some designated facets needed to be subdivided. To make topology consistent, first I remove the involved facet (with cell id), and then insert the new points and the new facets. Here is a code snippet:
vtkNew<vtkPolyData> pd;
pd->ShallowCopy(reader->GetOutput());
pd->Modified();
pd->BuildCells();
pd->DeleteCell(fid);//!!!
pd->RemoveDeletedCells();
pd->Modified();
double p1[3] = { sigs[0],sigs[1],sigs[2] };
double p2[3] = { sigs[3],sigs[4],sigs[5] }; //break points
pd->BuildLinks();
vtkIdType pid1 = -1, pid2=-1;
retrive(p1, pid1); retrive(p2,pid2);
if(pid1<0) pid1= pd->InsertNextLinkedPoint(p1, 1);
if(pid2<0) pid2= pd->InsertNextLinkedPoint(p2, 1);
vtkIdType tids1[3] = { pid1,int(np[1]),int(np[2]) };//existing vertex ids
vtkIdType tids2[3] = { pid1,int(np[1]),pid2 };
vtkIdType tids3[3] = { pid1,int(np[3]),pid2 };
pd->InsertNextLinkedCell(VTK_TRIANGLE, 3, tids1);
pd->InsertNextLinkedCell(VTK_TRIANGLE, 3, tids2);
pd->InsertNextLinkedCell(VTK_TRIANGLE, 3, tids3);
As I know, since points and new IDs are APPENDED while no point IDs deleted, I won’t worry about the original topological relationships with vertice IDs.
However, facets are removed and new IDs APPENDED. At the removal stage, the cell IDs behind the removed one, are moved forward a step?
Suppose cells with IDs as (cells, ids):
c1 c2 c3 c4 c5
1 2 3 4 5
where the cell c3 (with ID 3) is removed, and now, cells c4 and c5 are moved forward a step as their IDs are changed as:
c1 c2 c4 c5 cNew1 cNew2 …
1 2 3 4 5 6
If it works like this, things would be quite simple. But I cannot make sure (though I had made a few tests).
At present, I retrived the original facet ID by recording & comparing its 3 incident vertice IDs. This is rather inefficient, since the mesh may contains tens of million facets.