Retreive triangle from Flying edges mesh

Hi;

I have closed surface generated from segmentation using Flying edges. I want retreive triangle and points from each cell

here is my code:

for(int i = 0; i < FEMesh->GetNumberOfCells(); i++)
{
vtkSmartPointer cell = FEMesh->GetCell(i);
vtkSmartPointer triangle = vtkTriangle::SafeDownCast(cell);
double p0[3];
double p1[3];
double p2[3];
triangle->GetPoints()->GetPoint(0, p0);
triangle->GetPoints()->GetPoint(1, p1);
triangle->GetPoints()->GetPoint(2, p2);

   triangle_points->InsertNextPoint(p0[0], p0[1], p0[2]);
   triangle_points->InsertNextPoint(p1[0], p1[1], p1[2]);
   triangle_points->InsertNextPoint(p2[0], p2[1], p2[2]);
   
   triangles->InsertNextCell(triangle);

}

in order to check if all triangle and points are well recovered, I stored points and triangles in vtkPolydata (the mesh is deformed, I want keep the initial form how can I obtain this). see attached figure of deformed mesh

Polydata->SetPoints(triangle_points);
Polydata->SetPolys(triangles);

mesh

Thank’s in advance

I found my bug!

here is solution:

FEMesh->GetPolys()->InitTraversal();
vtkSmartPointer idList = vtkSmartPointer::New();
while( FEMesh->GetPolys()->GetNextCell(idList))
{
for(vtkIdType pointId = 0; pointId < idList->GetNumberOfIds(); pointId++){
FEMesh->GetPoint(idList->GetId(pointId), pt);
triangle_points->InsertNextPoint(pt[0], pt[1], pt[2]);

}
}

// Insert all cells (triangles)
 for (int i = 0 ; i < triangle_points->GetNumberOfPoints() ; i += 3) {

     const vtkIdType cellPoints[] = {i, i + 1, i + 2};
     triangles->InsertNextCell(3, cellPoints);
 }



Polydata->SetPoints(triangle_points);
Polydata->SetPolys(triangles);

thank’s!