I'm trying to extract the underlying 2-manifold (closed surface) from a non-manifold mesh. I'm using CGAL for mesh manipulation.I want to achieve that by deleting 'free faces'.By free I mean, a face whose at least one edge is a boundary edge.Deleting a free face eventually may create new 'free faces'. I want to keep deleting them unless no face has boundary edge.For example, if I have a 2-sphere and a fin like structure attached to it, I want to get the 2-sphere by deleting all the faces of the fin.
In CGAL, I kept on iterating over the half-edges and if I get a half-edge whose opposite is_border, I delete the face incident(more precisely using make_hole(h)), to the half edge. I keep on iterating when no such deletion is possible.
typedef CGAL::Exact_predicates_inexact_constructions_kernel I;
typedef CGAL::Polyhedron_3<I> Polyhedron;
Polyhedron mesh;
//
int in_this_iter = 0;
do {
in_this_iter = 0;
for (auto h = mesh.halfedges_begin(); h != mesh.halfedges_end(); h++) {
//cout << e->is_border() << endl;
if (h->opposite()->is_border() && !h->is_border()) {
mesh.make_hole(h);
/*CGAL::Euler::remove_face(h,mesh);
*gives trouble*/
in_this_iter++;
}
else if (h->is_border() && !h->opposite()->is_border()) {
mesh.make_hole(h->opposite());
in_this_iter++;
}
}
//mesh.normalize_border();
count = count + in_this_iter;
std::cout << "Face Deleted in this iter: " << in_this_iter<<endl;
} while (in_this_iter != 0);
std::cout << "Face Deleted: " << count<<endl;
The structure I am testing is:
OFF
7 8 0
0.0 0.0 0.0
1.0 0.0 0.0
2.0 0.0 0.0
0.0 1.0 0.0
1.0 1.0 0.0
2.0 1.0 0.0
0.0 0.0 1.0
3 0 1 3
3 3 1 4
3 1 4 2
3 2 4 5
3 1 2 4
3 3 1 6
3 3 4 6
3 1 4 6
My algorithm does not delete any free face. But the ideal one should capture the 4 faces of tetrahedron deleting the others. P.S: Appreciate your help! And please forgive me if I didn't follow the decorum as this is my first post.