1111#include < CGAL/Surface_mesh.h>
1212#include < CGAL/Polygon_mesh_processing/IO/polygon_mesh_io.h>
1313#include < CGAL/Polygon_mesh_processing/connected_components.h>
14+ #include < CGAL/Polygon_mesh_processing/repair.h>
1415
1516typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
1617
@@ -24,6 +25,7 @@ typedef Reconstruction::Facet_const_iterator Facet_iterator;
2425
2526typedef CGAL::Surface_mesh<Point> SurfaceMesh;
2627typedef boost::graph_traits<SurfaceMesh>::face_descriptor face_descriptor;
28+ typedef boost::graph_traits<SurfaceMesh>::vertex_descriptor vertex_descriptor;
2729
2830typedef CGAL::Timer Timer;
2931
@@ -83,23 +85,37 @@ int main(int argc, char** argv)
8385 if (!CGAL::Polygon_mesh_processing::IO::read_polygon_mesh (outfile, mesh))
8486 {
8587 std::cerr << " Failed loading back mesh" << std::endl;
86- return 1 ;
88+ return EXIT_FAILURE ;
8789 }
90+ std::cerr << " Loaded mesh with " << num_vertices (mesh) << " vertices (after repair)." << std::endl;
8891
8992 SurfaceMesh::Property_map<face_descriptor, std::size_t > fccmap =
9093 mesh.add_property_map <face_descriptor, std::size_t >(" f:CC" ).first ;
9194 std::size_t numcc = CGAL::Polygon_mesh_processing::connected_components (mesh, fccmap);
92- std::cerr << " Have " << numcc << " connected components" << std::endl;
95+ std::cerr << " Mesh has " << numcc << " connected components" << std::endl;
9396
94- if (numcc > 1 ) {
97+ if (numcc > 1 ) { // Keep largest connected component only
9598 std::size_t nrem = CGAL::Polygon_mesh_processing::keep_largest_connected_components (mesh, 1 );
9699 std::cerr << " Keeping largest connected component (" << nrem << " removed)" << std::endl;
97100 }
98101
102+ // Count non manifold vertices
103+ int counter = 0 ;
104+ for (vertex_descriptor v : vertices (mesh))
105+ {
106+ if (CGAL::Polygon_mesh_processing::is_non_manifold_vertex (v, mesh))
107+ {
108+ std::cerr << " vertex " << v << " is non-manifold" << std::endl;
109+ ++counter;
110+ }
111+ }
112+ std::cerr << " Mesh has " << counter << " non-manifold vertices" << std::endl;
113+ if (counter > 0 ) return EXIT_FAILURE;
114+
99115 { // Write mesh again
100116 std::ofstream out (outfile);
101117 out << mesh;
102- std::cerr << " Done saving back as " << outfile << std::endl;
118+ std::cerr << " Done saving back mesh as " << outfile << std::endl;
103119 }
104120
105121 return EXIT_SUCCESS;
0 commit comments