Skip to content

Commit 2b47b04

Browse files
committed
add inside the visitor a function to allow or forbid some triangles
compiles but still some warnings and runtime issue in some test
1 parent 70f1f26 commit 2b47b04

File tree

7 files changed

+413
-99
lines changed

7 files changed

+413
-99
lines changed

PMP_Mesh_repair/include/CGAL/Polygon_mesh_processing/internal/Hole_filling/Triangulate_hole_polygon_mesh.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,22 +178,24 @@ triangulate_hole_polygon_mesh(PolygonMesh& pmesh,
178178
} while(++circ_vertex != done_vertex);
179179
}
180180

181+
using Is_valid_base = CGAL::internal::Is_valid_existing_edges_and_degenerate_triangle;
182+
Is_valid_base is_valid_base(existing_edges);
183+
CGAL::internal::Is_valid_compose is_valid(is_valid_base, visitor);
184+
181185
//#define CGAL_USE_WEIGHT_INCOMPLETE
182186
#ifdef CGAL_USE_WEIGHT_INCOMPLETE
183187
typedef CGAL::internal::Weight_calculator<CGAL::internal::Weight_incomplete<CGAL::internal::Weight_min_max_dihedral_and_area>,
184-
CGAL::internal::Is_valid_existing_edges_and_degenerate_triangle> WC;
188+
decltype(is_valid)> WC;
185189
#else
186190
typedef CGAL::internal::Weight_calculator<CGAL::internal::Weight_min_max_dihedral_and_area,
187-
CGAL::internal::Is_valid_existing_edges_and_degenerate_triangle> WC;
191+
decltype(is_valid)> WC;
188192
#endif
189193

190-
CGAL::internal::Is_valid_existing_edges_and_degenerate_triangle is_valid(existing_edges);
191-
192194
// fill hole using polyline function, with custom tracer for PolygonMesh
193195
Tracer_polyhedron<PolygonMesh, OutputIterator> tracer(out, pmesh, P_edges);
194196

195197
#ifndef CGAL_HOLE_FILLING_DO_NOT_USE_CDT2
196-
if(use_cdt && triangulate_hole_polyline_with_cdt(P, tracer, visitor, is_valid, k, max_squared_distance))
198+
if(use_cdt && triangulate_hole_polyline_with_cdt(P, tracer, visitor, k, max_squared_distance))
197199
return std::make_pair(tracer.out, CGAL::internal::Weight_min_max_dihedral_and_area(0,0));
198200
#endif
199201
CGAL::internal::Weight_min_max_dihedral_and_area weight =

PMP_Mesh_repair/include/CGAL/Polygon_mesh_processing/internal/Hole_filling/Triangulate_hole_polyline.h

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,28 @@
5454
namespace CGAL {
5555
namespace internal {
5656

57+
template <class Base, class Visitor>
58+
struct Is_valid_compose
59+
{
60+
Is_valid_compose(const Base& base, const Visitor& visitor)
61+
: base(base)
62+
, visitor(visitor)
63+
{}
64+
65+
template<class Point_3>
66+
bool operator()(const std::vector<Point_3>& pts,
67+
int v0, int v1, int v2) const
68+
{
69+
if (visitor.accept_face(v0, v1, v2))
70+
return base(pts, v0, v1, v2);
71+
return false;
72+
}
73+
74+
const Base& base;
75+
const Visitor& visitor;
76+
};
77+
78+
5779
/************************************************************************
5880
* Lookup tables
5981
************************************************************************/
@@ -892,7 +914,7 @@ class Triangulate_hole_polyline_DT
892914
CGAL_assertion(v0 != -1); // edge can not be incident to infinite vertex
893915

894916
if( v0 + 1 == v1 || // border edge - should not check v0 = 0, v1 = n-1, because it is the initial edge where the algorithm starts
895-
W.get(v0, v1) != Weight::DEFAULT() ) // the range is previously processed
917+
W.get(v0, v1) != Weight::DEFAULT() ) // the range is previously processed // TODO: try to call accept_face() only here!
896918
{ return; }
897919

898920
visitor.quadratic_step();
@@ -1330,14 +1352,12 @@ template <
13301352
typename PointRange, // need size()
13311353
typename Tracer,
13321354
typename Visitor,
1333-
typename Validity_checker,
13341355
typename Traits
13351356
>
13361357
bool
13371358
triangulate_hole_polyline_with_cdt(const PointRange& points,
13381359
Tracer& tracer,
13391360
Visitor& visitor,
1340-
const Validity_checker& is_valid,
13411361
const Traits& traits,
13421362
const typename Traits::FT max_squared_distance)
13431363
{
@@ -1447,12 +1467,6 @@ triangulate_hole_polyline_with_cdt(const PointRange& points,
14471467
vertices[v->info()] = v;
14481468
}
14491469

1450-
if (vertices.size()!=cdt.number_of_vertices())
1451-
{
1452-
visitor.end_planar_phase(false);
1453-
return false;
1454-
}
1455-
14561470
try
14571471
{
14581472
for (std::size_t i = 0; i < size; ++i) {
@@ -1510,7 +1524,8 @@ triangulate_hole_polyline_with_cdt(const PointRange& points,
15101524

15111525
std::sort(is.begin(), is.end());
15121526
lambda.put(is[0], is[2], is[1]);
1513-
if (!is_valid(P, is[0], is[1], is[2])) {
1527+
if (!visitor.accept_face(is[0], is[1], is[2]))
1528+
{
15141529
// std::cerr << "WARNING: validity, cdt 2 falls back to the original solution!" << std::endl;
15151530
visitor.end_planar_phase(false);
15161531
return false;

PMP_Mesh_repair/include/CGAL/Polygon_mesh_processing/triangulate_hole.h

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,23 @@ namespace Polygon_mesh_processing {
5656
void end_refine_phase() const {}
5757
void start_fair_phase() const {}
5858
void end_fair_phase() const {}
59+
constexpr bool accept_face(int,int,int) const { return true; }
5960
#endif
6061
};
62+
63+
64+
#ifndef DOXYGEN_RUNNING
65+
// probably not needed if we're using c++17 constexpr
66+
struct Default_user_is_face_valid
67+
{
68+
constexpr
69+
bool accept_face( int /* v0 */, int /* v1 */, int /* v2 */) const
70+
{
71+
return true;
72+
}
73+
};
74+
#endif
75+
6176
} // namespace Hole_filling
6277

6378
/*!
@@ -652,9 +667,7 @@ namespace Polygon_mesh_processing {
652667
653668
@pre `third_points.size() == points.size()`
654669
655-
@tparam PointRange1 range of points, model of `Range`.
656-
Its iterator type is `InputIterator`.
657-
@tparam PointRange2 range of points, model of `Range`.
670+
@tparam PointRange range of points, model of `Range`.
658671
Its iterator type is `InputIterator`.
659672
@tparam OutputIterator model of `OutputIterator`, to collect patch faces.
660673
A specialization for `CGAL::value_type_traits<OutputIterator>` must be available,
@@ -741,9 +754,14 @@ bool use_dt3 =
741754
choose_parameter(get_parameter(np, internal_np::use_delaunay_triangulation), true);
742755
#endif
743756

757+
Hole_filling::Default_visitor default_visitor;
758+
auto visitor = choose_parameter(get_parameter_reference(np, internal_np::visitor), default_visitor);
759+
760+
CGAL::internal::Is_not_degenerate_triangle is_valid_base;
761+
CGAL::internal::Is_valid_compose is_valid(is_valid_base, visitor);
762+
744763
typedef CGAL::internal::Weight_min_max_dihedral_and_area Weight;
745-
typedef CGAL::internal::Weight_calculator<Weight,
746-
CGAL::internal::Is_not_degenerate_triangle> WC;
764+
typedef CGAL::internal::Weight_calculator<Weight, decltype(is_valid)> WC;
747765
typedef std::vector<std::pair<int, int> > Holes;
748766
typedef std::back_insert_iterator<Holes> Holes_out;
749767

@@ -757,17 +775,9 @@ bool use_dt3 =
757775
typedef typename std::iterator_traits<InIterator>::value_type Point;
758776
typedef typename CGAL::Kernel_traits<Point>::Kernel Kernel;
759777

760-
Hole_filling::Default_visitor default_visitor;
761-
762778
#ifndef CGAL_HOLE_FILLING_DO_NOT_USE_CDT2
763779
if (use_cdt)
764780
{
765-
struct Always_valid
766-
{
767-
bool operator()(const std::vector<Point>&, int,int,int) const { return true; }
768-
};
769-
Always_valid is_valid;
770-
771781
const typename Kernel::Iso_cuboid_3 bbox = CGAL::bounding_box(points.begin(), points.end());
772782
typename Kernel::FT default_squared_distance = CGAL::abs(CGAL::squared_distance(bbox.vertex(0), bbox.vertex(5)));
773783
default_squared_distance /= typename Kernel::FT(16); // one quarter of the bbox height
@@ -782,8 +792,7 @@ bool use_dt3 =
782792
if (triangulate_hole_polyline_with_cdt(
783793
points,
784794
tracer,
785-
choose_parameter(get_parameter_reference(np, internal_np::visitor), default_visitor),
786-
is_valid,
795+
visitor,
787796
choose_parameter<Kernel>(get_parameter(np, internal_np::geom_traits)),
788797
max_squared_distance))
789798
{
@@ -792,8 +801,8 @@ bool use_dt3 =
792801
}
793802
}
794803
#endif
795-
triangulate_hole_polyline(points, third_points, tracer, WC(),
796-
choose_parameter(get_parameter_reference(np, internal_np::visitor), default_visitor),
804+
triangulate_hole_polyline(points, third_points, tracer, WC(is_valid),
805+
visitor,
797806
use_dt3,
798807
choose_parameter(get_parameter(np, internal_np::do_not_use_cubic_algorithm), false),
799808
choose_parameter<Kernel>(get_parameter(np, internal_np::geom_traits)));

0 commit comments

Comments
 (0)