diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index dc30f94af43..a08689efaeb 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -1466,7 +1467,7 @@ public: /// perform an expensive validity check on the data structure and /// print found errors to `std::cerr` when `verbose == true`. - bool is_valid(bool verbose = true) const + bool is_valid(bool verbose = true) const { bool valid = true; size_type vcount = 0, hcount = 0, fcount = 0; @@ -1578,21 +1579,29 @@ public: } /// performs a validity check on a single vertex. - bool is_valid(Vertex_index v) const { + bool is_valid(Vertex_index v, + bool verbose = true) const + { + Verbose_ostream verr(verbose); + if(!has_valid_index(v)) return false; Halfedge_index h = vconn_[v].halfedge_; - if(h!= null_halfedge() && (!has_valid_index(h) || is_removed(h))) { - std::cerr << "Vertex connectivity halfedge error in " << (size_type)v - << " with " << (size_type)h << std::endl; - return false; + if(h != null_halfedge() && (!has_valid_index(h) || is_removed(h))) { + verr << "Vertex connectivity halfedge error: Vertex " << (size_type)v + << " with " << (size_type)h << std::endl; + return false; } return true; } /// performs a validity check on a single halfedge. - bool is_valid(Halfedge_index h) const { + bool is_valid(Halfedge_index h, + bool verbose = true) const + { + Verbose_ostream verr(verbose); + if(!has_valid_index(h)) return false; @@ -1605,30 +1614,30 @@ public: // don't validate the face if this is a border halfedge if(!is_border(h)) { if(!has_valid_index(f) || is_removed(f)) { - std::cerr << "Halfedge connectivity Face " - << (!has_valid_index(f) ? "invalid" : "removed") - << " in " << (size_type)h << std::endl; + verr << "Halfedge connectivity error: Face " + << (!has_valid_index(f) ? "invalid" : "removed") + << " in " << (size_type)h << std::endl; valid = false; } } if(!has_valid_index(v) || is_removed(v)) { - std::cerr << "Halfedge connectivity Vertex " - << (!has_valid_index(v) ? "invalid" : "removed") - << " in " << (size_type)h << std::endl; + verr << "Halfedge connectivity error: Vertex " + << (!has_valid_index(v) ? "invalid" : "removed") + << " in " << (size_type)h << std::endl; valid = false; } if(!has_valid_index(hn) || is_removed(hn)) { - std::cerr << "Halfedge connectivity hnext " - << (!has_valid_index(hn) ? "invalid" : "removed") - << " in " << (size_type)h << std::endl; + verr << "Halfedge connectivity error: hnext " + << (!has_valid_index(hn) ? "invalid" : "removed") + << " in " << (size_type)h << std::endl; valid = false; } if(!has_valid_index(hp) || is_removed(hp)) { - std::cerr << "Halfedge connectivity hprev " - << (!has_valid_index(hp) ? "invalid" : "removed") - << " in " << (size_type)h << std::endl; + verr << "Halfedge connectivity error: hprev " + << (!has_valid_index(hp) ? "invalid" : "removed") + << " in " << (size_type)h << std::endl; valid = false; } return valid; @@ -1636,25 +1645,31 @@ public: /// performs a validity check on a single edge. - bool is_valid(Edge_index e) const { + bool is_valid(Edge_index e, + bool verbose = true) const + { if(!has_valid_index(e)) return false; Halfedge_index h = halfedge(e); - return is_valid(h) && is_valid(opposite(h)); + return is_valid(h, verbose) && is_valid(opposite(h), verbose); } /// performs a validity check on a single face. - bool is_valid(Face_index f) const { + bool is_valid(Face_index f, + bool verbose = true) const + { + Verbose_ostream verr(verbose); + if(!has_valid_index(f)) return false; Halfedge_index h = fconn_[f].halfedge_; if(!has_valid_index(h) || is_removed(h)) { - std::cerr << "Face connectivity halfedge error in " << (size_type)f - << " with " << (size_type)h << std::endl; - return false; + verr << "Face connectivity halfedge error: Face " << (size_type)f + << " with " << (size_type)h << std::endl; + return false; } return true; } diff --git a/Surface_mesh/include/CGAL/boost/graph/graph_traits_Surface_mesh.h b/Surface_mesh/include/CGAL/boost/graph/graph_traits_Surface_mesh.h index 547b8374776..d044c38a557 100644 --- a/Surface_mesh/include/CGAL/boost/graph/graph_traits_Surface_mesh.h +++ b/Surface_mesh/include/CGAL/boost/graph/graph_traits_Surface_mesh.h @@ -528,6 +528,51 @@ template void normalize_border(const CGAL::Surface_mesh

&) {} + +template +bool is_valid_vertex_descriptor(typename boost::graph_traits >::vertex_descriptor v, + const CGAL::Surface_mesh

& g, + const bool verbose = false) +{ + if(!g.is_valid(v, verbose)) + return false; + + return BGL::is_valid_vertex_descriptor(v, g, verbose); +} + +template +bool is_valid_halfedge_descriptor(typename boost::graph_traits >::halfedge_descriptor h, + const CGAL::Surface_mesh

& g, + const bool verbose = false) +{ + if(!g.is_valid(h, verbose)) + return false; + + return BGL::is_valid_halfedge_descriptor(h, g, verbose); +} + +template +bool is_valid_edge_descriptor(typename boost::graph_traits >::edge_descriptor e, + const CGAL::Surface_mesh

& g, + const bool verbose = false) +{ + if(!g.is_valid(e, verbose)) + return false; + + return BGL::is_valid_edge_descriptor(e, g, verbose); +} + +template +bool is_valid_face_descriptor(typename boost::graph_traits >::face_descriptor f, + const CGAL::Surface_mesh

& g, + const bool verbose = false) +{ + if(!g.is_valid(f, verbose)) + return false; + + return BGL::is_valid_face_descriptor(f, g, verbose); +} + } // namespace CGAL #endif // DOXYGEN_RUNNING