Add is_valid_*_descriptor() overloads for Surface_mesh

This commit is contained in:
Mael Rouxel-Labbé 2022-10-04 22:19:35 +02:00
parent 60ecc51ba7
commit b597aa8aab
2 changed files with 85 additions and 25 deletions

View File

@ -29,6 +29,7 @@
#include <CGAL/Named_function_parameters.h> #include <CGAL/Named_function_parameters.h>
#include <CGAL/circulator.h> #include <CGAL/circulator.h>
#include <CGAL/Handle_hash_function.h> #include <CGAL/Handle_hash_function.h>
#include <CGAL/IO/Verbose_ostream.h>
#include <CGAL/Iterator_range.h> #include <CGAL/Iterator_range.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
@ -1578,13 +1579,17 @@ public:
} }
/// performs a validity check on a single vertex. /// 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)) if(!has_valid_index(v))
return false; return false;
Halfedge_index h = vconn_[v].halfedge_; Halfedge_index h = vconn_[v].halfedge_;
if(h!= null_halfedge() && (!has_valid_index(h) || is_removed(h))) { if(h != null_halfedge() && (!has_valid_index(h) || is_removed(h))) {
std::cerr << "Vertex connectivity halfedge error in " << (size_type)v verr << "Vertex connectivity halfedge error: Vertex " << (size_type)v
<< " with " << (size_type)h << std::endl; << " with " << (size_type)h << std::endl;
return false; return false;
} }
@ -1592,7 +1597,11 @@ public:
} }
/// performs a validity check on a single halfedge. /// 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)) if(!has_valid_index(h))
return false; return false;
@ -1605,7 +1614,7 @@ public:
// don't validate the face if this is a border halfedge // don't validate the face if this is a border halfedge
if(!is_border(h)) { if(!is_border(h)) {
if(!has_valid_index(f) || is_removed(f)) { if(!has_valid_index(f) || is_removed(f)) {
std::cerr << "Halfedge connectivity Face " verr << "Halfedge connectivity error: Face "
<< (!has_valid_index(f) ? "invalid" : "removed") << (!has_valid_index(f) ? "invalid" : "removed")
<< " in " << (size_type)h << std::endl; << " in " << (size_type)h << std::endl;
valid = false; valid = false;
@ -1613,20 +1622,20 @@ public:
} }
if(!has_valid_index(v) || is_removed(v)) { if(!has_valid_index(v) || is_removed(v)) {
std::cerr << "Halfedge connectivity Vertex " verr << "Halfedge connectivity error: Vertex "
<< (!has_valid_index(v) ? "invalid" : "removed") << (!has_valid_index(v) ? "invalid" : "removed")
<< " in " << (size_type)h << std::endl; << " in " << (size_type)h << std::endl;
valid = false; valid = false;
} }
if(!has_valid_index(hn) || is_removed(hn)) { if(!has_valid_index(hn) || is_removed(hn)) {
std::cerr << "Halfedge connectivity hnext " verr << "Halfedge connectivity error: hnext "
<< (!has_valid_index(hn) ? "invalid" : "removed") << (!has_valid_index(hn) ? "invalid" : "removed")
<< " in " << (size_type)h << std::endl; << " in " << (size_type)h << std::endl;
valid = false; valid = false;
} }
if(!has_valid_index(hp) || is_removed(hp)) { if(!has_valid_index(hp) || is_removed(hp)) {
std::cerr << "Halfedge connectivity hprev " verr << "Halfedge connectivity error: hprev "
<< (!has_valid_index(hp) ? "invalid" : "removed") << (!has_valid_index(hp) ? "invalid" : "removed")
<< " in " << (size_type)h << std::endl; << " in " << (size_type)h << std::endl;
valid = false; valid = false;
@ -1636,23 +1645,29 @@ public:
/// performs a validity check on a single edge. /// 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)) if(!has_valid_index(e))
return false; return false;
Halfedge_index h = halfedge(e); 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. /// 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)) if(!has_valid_index(f))
return false; return false;
Halfedge_index h = fconn_[f].halfedge_; Halfedge_index h = fconn_[f].halfedge_;
if(!has_valid_index(h) || is_removed(h)) { if(!has_valid_index(h) || is_removed(h)) {
std::cerr << "Face connectivity halfedge error in " << (size_type)f verr << "Face connectivity halfedge error: Face " << (size_type)f
<< " with " << (size_type)h << std::endl; << " with " << (size_type)h << std::endl;
return false; return false;
} }

View File

@ -528,6 +528,51 @@ template<typename P>
void normalize_border(const CGAL::Surface_mesh<P>&) void normalize_border(const CGAL::Surface_mesh<P>&)
{} {}
template <typename P>
bool is_valid_vertex_descriptor(typename boost::graph_traits<CGAL::Surface_mesh<P> >::vertex_descriptor v,
const CGAL::Surface_mesh<P>& g,
const bool verbose = false)
{
if(!g.is_valid(v, verbose))
return false;
return BGL::is_valid_vertex_descriptor(v, g, verbose);
}
template <typename P>
bool is_valid_halfedge_descriptor(typename boost::graph_traits<CGAL::Surface_mesh<P> >::halfedge_descriptor h,
const CGAL::Surface_mesh<P>& g,
const bool verbose = false)
{
if(!g.is_valid(h, verbose))
return false;
return BGL::is_valid_halfedge_descriptor(h, g, verbose);
}
template <typename P>
bool is_valid_edge_descriptor(typename boost::graph_traits<CGAL::Surface_mesh<P> >::edge_descriptor e,
const CGAL::Surface_mesh<P>& g,
const bool verbose = false)
{
if(!g.is_valid(e, verbose))
return false;
return BGL::is_valid_edge_descriptor(e, g, verbose);
}
template <typename P>
bool is_valid_face_descriptor(typename boost::graph_traits<CGAL::Surface_mesh<P> >::face_descriptor f,
const CGAL::Surface_mesh<P>& g,
const bool verbose = false)
{
if(!g.is_valid(f, verbose))
return false;
return BGL::is_valid_face_descriptor(f, g, verbose);
}
} // namespace CGAL } // namespace CGAL
#endif // DOXYGEN_RUNNING #endif // DOXYGEN_RUNNING