From 9de41310fd27bd8d55a7a9b75914f5c2d60f2a1f Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Thu, 30 Jul 2020 16:23:03 +0200 Subject: [PATCH] use boost::optional instead of a bool and a double # Conflicts: # Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h --- .../Isotropic_remeshing/Sizing_field.h | 14 ++--- .../Uniform_sizing_field.h | 35 ++++++++----- .../Isotropic_remeshing/remesh_impl.h | 51 ++++++++++--------- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Sizing_field.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Sizing_field.h index 3df70524fec..fc6b14a984f 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Sizing_field.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Sizing_field.h @@ -10,12 +10,13 @@ // // Author(s) : Jane Tournois -#ifndef CGAL_SIZING_FIELD_H -#define CGAL_SIZING_FIELD_H +#ifndef CGAL_PMP_REMESHING_SIZING_FIELD_H +#define CGAL_PMP_REMESHING_SIZING_FIELD_H #include #include +#include namespace CGAL { @@ -38,13 +39,14 @@ public: typedef typename K::FT FT; public: - virtual bool is_too_long(const halfedge_descriptor& h, FT& sql) const = 0; - virtual bool is_too_long(const vertex_descriptor& va, const vertex_descriptor& vb) const = 0; - virtual bool is_too_short(const halfedge_descriptor& h, FT& sqlen) const = 0; + virtual boost::optional is_too_long(const halfedge_descriptor& h) const = 0; + virtual boost::optional is_too_long(const vertex_descriptor& va, + const vertex_descriptor& vb) const = 0; + virtual boost::optional is_too_short(const halfedge_descriptor& h) const = 0; virtual Point_3 split_placement(const halfedge_descriptor& h) const = 0; }; }//end namespace CGAL -#endif //CGAL_SIZING_FIELD_H +#endif //CGAL_PMP_REMESHING_SIZING_FIELD_H diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Uniform_sizing_field.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Uniform_sizing_field.h index 7b00635ff54..8704c84ef11 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Uniform_sizing_field.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/Uniform_sizing_field.h @@ -10,8 +10,8 @@ // // Author(s) : Jane Tournois -#ifndef CGAL_UNIFORM_SIZING_FIELD_H -#define CGAL_UNIFORM_SIZING_FIELD_H +#ifndef CGAL_PMP_REMESHING_UNIFORM_SIZING_FIELD_H +#define CGAL_PMP_REMESHING_UNIFORM_SIZING_FIELD_H #include @@ -54,23 +54,32 @@ private: } public: - bool is_too_long(const halfedge_descriptor& h, FT& sqlen) const + boost::optional is_too_long(const halfedge_descriptor& h) const { - sqlen = sqlength(h); - return sqlen > m_sq_long; + const FT sqlen = sqlength(h); + if(sqlen > m_sq_long) + return sqlen; + else + return boost::none; } - bool is_too_long(const vertex_descriptor& va, - const vertex_descriptor& vb) const + boost::optional is_too_long(const vertex_descriptor& va, + const vertex_descriptor& vb) const { - FT sqlen = sqlength(va, vb); - return sqlen > m_sq_long; + const FT sqlen = sqlength(va, vb); + if (sqlen > m_sq_long) + return sqlen; + else + return boost::none; } - bool is_too_short(const halfedge_descriptor& h, FT& sqlen) const + boost::optional is_too_short(const halfedge_descriptor& h) const { - sqlen = sqlength(h); - return sqlen < m_sq_short; + const FT sqlen = sqlength(h); + if (sqlen < m_sq_long) + return sqlen; + else + return boost::none; } virtual Point_3 split_placement(const halfedge_descriptor& h) const @@ -89,4 +98,4 @@ private: }//end namespace CGAL -#endif //CGAL_UNIFORM_SIZING_FIELD_H +#endif //CGAL_PMP_REMESHING_UNIFORM_SIZING_FIELD_H diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h index e6911102a68..ed95352bab9 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Isotropic_remeshing/remesh_impl.h @@ -496,9 +496,9 @@ namespace internal { { if (!is_split_allowed(e)) continue; - double sqlen; - if(sizing.is_too_long(halfedge(e, mesh_), sqlen)) - long_edges.emplace(halfedge(e, mesh_), sqlen); + boost::optional sqlen = sizing.is_too_long(halfedge(e, mesh_)); + if(sqlen != boost::none) + long_edges.emplace(halfedge(e, mesh_), sqlen.get()); } //split long edges @@ -548,11 +548,13 @@ namespace internal { //check sub-edges //if it was more than twice the "long" threshold, insert them - double sqlen_new; - if(sizing.is_too_long(hnew, sqlen_new)) - long_edges.emplace(hnew, sqlen_new); - if(sizing.is_too_long(next(hnew, mesh_), sqlen_new)) - long_edges.insert(long_edge(next(hnew, mesh_), sqlen_new)); + boost::optional sqlen_new = sizing.is_too_long(hnew); + if(sqlen_new != boost::none) + long_edges.emplace(hnew, sqlen_new.get()); + + sqlen_new = sizing.is_too_long(next(hnew, mesh_)); + if (sqlen_new != boost::none) + long_edges.emplace(next(hnew, mesh_), sqlen_new.get()); //insert new edges to keep triangular faces, and update long_edges if (!is_on_border(hnew)) @@ -571,9 +573,9 @@ namespace internal { if (snew == PATCH) { - double sql; - if(sizing.is_too_long(hnew2, sql)) - long_edges.emplace(hnew2, sql); + boost::optional sql = sizing.is_too_long(hnew2); + if(sql != boost::none) + long_edges.emplace(hnew2, sql.get()); } } @@ -594,9 +596,9 @@ namespace internal { if (snew == PATCH) { - double sql; - if (sizing.is_too_long(hnew2, sql)) - long_edges.emplace(hnew2, sql); + boost::optional sql = sizing.is_too_long(hnew2); + if (sql != boost::none) + long_edges.emplace(hnew2, sql.get()); } } } @@ -639,10 +641,10 @@ namespace internal { Boost_bimap short_edges; for(edge_descriptor e : edges(mesh_)) { - double sqlen; - if( sizing.is_too_short(halfedge(e, mesh_), sqlen) + boost::optional sqlen = sizing.is_too_short(halfedge(e, mesh_)); + if(sqlen != boost::none && is_collapse_allowed(e, collapse_constraints)) - short_edges.insert(short_edge(halfedge(e, mesh_), sqlen)); + short_edges.insert(short_edge(halfedge(e, mesh_), sqlen.get())); } #ifdef CGAL_PMP_REMESHING_VERBOSE_PROGRESS std::cout << "done." << std::endl; @@ -738,7 +740,8 @@ namespace internal { for(halfedge_descriptor ha : halfedges_around_target(va, mesh_)) { vertex_descriptor va_i = source(ha, mesh_); - if (sizing.is_too_long(vb, va_i)) + boost::optional sqha = sizing.is_too_long(vb, va_i); + if (sqha != boost::none) { collapse_ok = false; break; @@ -803,10 +806,10 @@ namespace internal { //insert new/remaining short edges for (halfedge_descriptor ht : halfedges_around_target(vkept, mesh_)) { - double sqlen; - if (sizing.is_too_short(ht, sqlen) + boost::optional sqlen = sizing.is_too_short(ht); + if (sqlen != boost::none && is_collapse_allowed(edge(ht, mesh_), collapse_constraints)) - short_edges.insert(short_edge(ht, sqlen)); + short_edges.insert(short_edge(ht, sqlen.get())); } } }//end if(collapse_ok) @@ -1724,9 +1727,9 @@ private: //insert new edges in 'short_edges' if (is_collapse_allowed(edge(hf, mesh_), collapse_constraints)) { - double sqlen; - if (sizing.is_too_short(hf, sqlen)) - short_edges.insert(typename Bimap::value_type(hf, sqlen)); + boost::optional sqlen = sizing.is_too_short(hf); + if (sqlen != boost::none) + short_edges.insert(typename Bimap::value_type(hf, sqlen.get())); } if(!is_border(hf, mesh_) &&