Skip to content

Commit

Permalink
use boost::optional<double> instead of a bool and a double
Browse files Browse the repository at this point in the history
  • Loading branch information
janetournois committed Apr 11, 2021
1 parent bec0e47 commit 9f06bfc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CGAL/license/Polygon_mesh_processing/meshing_hole_filling.h>

#include <CGAL/Kernel_traits.h>
#include <boost/optional.hpp>

namespace CGAL
{
Expand All @@ -38,13 +39,14 @@ class Sizing_field
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<FT> is_too_long(const halfedge_descriptor& h) const = 0;
virtual boost::optional<FT> is_too_long(const vertex_descriptor& va,
const vertex_descriptor& vb) const = 0;
virtual boost::optional<FT> 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
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CGAL/license/Polygon_mesh_processing/meshing_hole_filling.h>

Expand Down Expand Up @@ -54,23 +54,32 @@ class Uniform_sizing_field : public CGAL::Sizing_field<PolygonMesh>
}

public:
bool is_too_long(const halfedge_descriptor& h, FT& sqlen) const
boost::optional<FT> 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<FT> 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<FT> 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
Expand All @@ -89,4 +98,4 @@ class Uniform_sizing_field : public CGAL::Sizing_field<PolygonMesh>

}//end namespace CGAL

#endif //CGAL_UNIFORM_SIZING_FIELD_H
#endif //CGAL_PMP_REMESHING_UNIFORM_SIZING_FIELD_H
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ namespace internal {
{
if (!is_split_allowed(e))
continue;
double sqlen;
if(sizing.is_too_long(halfedge(e, mesh_), sqlen))
long_edges.insert(long_edge(halfedge(e, mesh_), sqlen));
boost::optional<double> sqlen = sizing.is_too_long(halfedge(e, mesh_));
if(sqlen != boost::none)
long_edges.insert(long_edge(halfedge(e, mesh_), sqlen.get()));
}

//split long edges
Expand Down Expand Up @@ -537,11 +537,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.insert(long_edge(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<double> sqlen_new = sizing.is_too_long(hnew);
if(sqlen_new != boost::none)
long_edges.insert(long_edge(hnew, sqlen_new.get()));

sqlen_new = sizing.is_too_long(next(hnew, mesh_));
if (sqlen_new != boost::none)
long_edges.insert(long_edge(next(hnew, mesh_), sqlen_new.get()));

//insert new edges to keep triangular faces, and update long_edges
if (!is_on_border(hnew))
Expand All @@ -560,9 +562,9 @@ namespace internal {

if (snew == PATCH)
{
double sql;
if(sizing.is_too_long(hnew2, sql))
long_edges.insert(long_edge(hnew2, sql));
boost::optional<double> sql = sizing.is_too_long(hnew2);
if(sql != boost::none)
long_edges.insert(long_edge(hnew2, sql.get()));
}
}

Expand All @@ -583,9 +585,9 @@ namespace internal {

if (snew == PATCH)
{
double sql;
if (sizing.is_too_long(hnew2, sql))
long_edges.insert(long_edge(hnew2, sql));
boost::optional<double> sql = sizing.is_too_long(hnew2);
if (sql != boost::none)
long_edges.insert(long_edge(hnew2, sql.get()));
}
}
}
Expand Down Expand Up @@ -628,10 +630,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<double> 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;
Expand Down Expand Up @@ -725,7 +727,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<double> sqha = sizing.is_too_long(vb, va_i);
if (sqha != boost::none)
{
collapse_ok = false;
break;
Expand Down Expand Up @@ -789,10 +792,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<double> 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)
Expand Down Expand Up @@ -1703,9 +1706,9 @@ namespace internal {
//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<double> 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_) &&
Expand Down

0 comments on commit 9f06bfc

Please sign in to comment.