diff --git a/Polygon_mesh_processing/examples/Polygon_mesh_processing/connected_component.cpp b/Polygon_mesh_processing/examples/Polygon_mesh_processing/connected_component.cpp index 1cde09f74c6..817b95f57b8 100644 --- a/Polygon_mesh_processing/examples/Polygon_mesh_processing/connected_component.cpp +++ b/Polygon_mesh_processing/examples/Polygon_mesh_processing/connected_component.cpp @@ -4,54 +4,64 @@ #include #include - namespace PMP = CGAL::Polygon_mesh_processing; -typedef CGAL::Simple_cartesian Kernel; -typedef Kernel::Point_3 Point; -typedef CGAL::Surface_mesh Mesh; - - -typedef boost::graph_traits::vertex_descriptor vertex_descriptor; -typedef boost::graph_traits::face_descriptor face_descriptor; -typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; -typedef boost::graph_traits::edge_descriptor edge_descriptor; +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; +typedef Kernel::Compare_dihedral_angle_3 Compare_dihedral_angle_3; +typedef CGAL::Surface_mesh Mesh; template struct Constraint { - Constraint() { } + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + typedef typename boost::graph_traits::edge_descriptor edge_descriptor; - Constraint(G & g) : g(&g) { } + Constraint() + {} - bool operator[](const edge_descriptor&) const { - return false; // no constraint + Constraint(G & g, double bound) + : g(&g), bound(bound) + { } + + bool operator[](edge_descriptor e) const { + return compare((*g).point(source(e,*g)), + (*g).point(target(e,*g)), + (*g).point(target(next(halfedge(e,*g),*g),*g)), + (*g).point(target(next(opposite(halfedge(e,*g),*g),*g),*g)), + bound) == CGAL::SMALLER; } G* g; + Compare_dihedral_angle_3 compare; + double bound; }; int main(int, char* argv[]) { + typedef boost::graph_traits::face_descriptor face_descriptor; + const double bound = std::cos(0.7* CGAL_PI); Mesh sm; std::ifstream in(argv[1]); in >> sm; - + std::vector cc; face_descriptor fd = *faces(sm).first; CGAL::Polygon_mesh_processing::connected_component(fd, sm, std::back_inserter(cc)); - + std::cerr << "connected components without edge constraints" << std::endl; std::cerr << cc.size() << " faces in the CC of " << fd << std::endl; + + std::cerr << "\nconnected components with edge constraints (dihedral angle < 3/4 pi)" << std::endl; Mesh::Property_map fccmap; fccmap = sm.add_property_map("f:CC").first; std::size_t num = PMP::connected_components(sm, fccmap, - CGAL::parameters::edge_is_constrained_map(Constraint()) + CGAL::parameters::edge_is_constrained_map(Constraint(sm,bound)) ); std::cerr << "The graph has " << num << " connected components (face connectivity)" << std::endl; @@ -59,7 +69,8 @@ int main(int, char* argv[]) std::cout << f << " in connected component " << fccmap[f] << std::endl; } - CGAL::Polygon_mesh_processing::keep_largest_connected_components(sm,2); + std::cerr << "We keep the two largest components" << std::endl; + PMP::keep_largest_connected_components(sm,2,CGAL::parameters::edge_is_constrained_map(Constraint(sm,bound))); std::cout << "mesh:\n" << sm << std::endl; return 0; diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h index d32cb894b91..ca9b330a6bf 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/Connected_components.h @@ -620,7 +620,6 @@ std::size_t keep_largest_connected_components(PolygonMesh& pmesh, // don't care about connectivity // As vertices are not kept the faces and vertices will be removed later remove_edge(e,pmesh); - std::cerr << "after remove_edge"<< std::endl; } else if( keep_vertex[v] && keep_vertex[w]){ face_descriptor fh = face(h,pmesh), ofh = face(oh,pmesh); if(is_border(h,pmesh) && is_border(oh,pmesh)){