Skip to content

Commit fb64e68

Browse files
committed
Merge pull request #7552 from MaelRL/Mesh_3-PMD_init_bug_fixes-GF
Fix initialisation issues in Mesh_3
2 parents a10d75d + 1f258bc commit fb64e68

File tree

4 files changed

+75
-46
lines changed

4 files changed

+75
-46
lines changed

Mesh_3/include/CGAL/Mesh_3/Protect_edges_sizing_field.h

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ insert_corners()
578578
Index p_index = domain_.index_from_corner_index(cit->first);
579579

580580
#if CGAL_MESH_3_PROTECTION_DEBUG & 1
581-
std::cerr << "** treat corner #" << CGAL::IO::oformat(p_index) << std::endl;
581+
std::cerr << "\n** treat corner #" << CGAL::IO::oformat(p_index) << std::endl;
582582
#endif
583583

584584
// Get weight (the ball radius is given by the 'query_size' function)
@@ -633,6 +633,13 @@ insert_point(const Bare_point& p, const Weight& w, int dim, const Index& index,
633633
{
634634
using CGAL::Mesh_3::internal::weight_modifier;
635635

636+
#if CGAL_MESH_3_PROTECTION_DEBUG & 1
637+
std::cerr << "insert_point( (" << p
638+
<< "), w=" << w
639+
<< ", dim=" << dim
640+
<< ", index=" << CGAL::IO::oformat(index) << ")\n";
641+
#endif
642+
636643
// Convert the dimension if it was set to a negative value (marker for special balls).
637644
if(dim < 0)
638645
dim = -1 - dim;
@@ -709,6 +716,7 @@ smart_insert_point(const Bare_point& p, Weight w, int dim, const Index& index,
709716
<< "), w=" << w
710717
<< ", dim=" << dim
711718
<< ", index=" << CGAL::IO::oformat(index) << ")\n";
719+
std::cerr << "triangulation dimension is " << c3t3_.triangulation().dimension() << std::endl;
712720
#endif
713721
const Tr& tr = c3t3_.triangulation();
714722

@@ -743,8 +751,8 @@ smart_insert_point(const Bare_point& p, Weight w, int dim, const Index& index,
743751
#endif
744752

745753
// if sq_d < nearest_vh's weight
746-
while ( cwsr(c3t3_.triangulation().point(nearest_vh), - sq_d) == CGAL::SMALLER &&
747-
! is_special(nearest_vh) )
754+
while ( ! is_special(nearest_vh) &&
755+
cwsr(c3t3_.triangulation().point(nearest_vh), - sq_d) == CGAL::SMALLER )
748756
{
749757
CGAL_assertion( minimal_size_ > 0 || sq_d > 0 );
750758

@@ -833,7 +841,7 @@ smart_insert_point(const Bare_point& p, Weight w, int dim, const Index& index,
833841
#if CGAL_MESH_3_PROTECTION_DEBUG & 1
834842
std::cerr << "smart_insert_point: weight " << w
835843
<< " reduced to " << min_sq_d
836-
<< "\n (near existing point: " << nearest_point << " )\n";
844+
<< " (near existing point: " << nearest_point << " )\n";
837845
#endif
838846
w = min_sq_d;
839847
add_handle_to_unchecked = true;
@@ -854,46 +862,45 @@ smart_insert_point(const Bare_point& p, Weight w, int dim, const Index& index,
854862
else // tr.dimension() <= 2
855863
{
856864
// change size of existing balls which include p
857-
bool restart = true;
858-
while ( restart )
865+
for ( typename Tr::Finite_vertices_iterator it = tr.finite_vertices_begin(),
866+
end = tr.finite_vertices_end() ; it != end ; ++it )
859867
{
860-
restart = false;
861-
for ( typename Tr::Finite_vertices_iterator it = tr.finite_vertices_begin(),
862-
end = tr.finite_vertices_end() ; it != end ; ++it )
868+
const Weighted_point& it_wp = tr.point(it);
869+
FT sq_d = tr.min_squared_distance(p, cp(it_wp));
870+
if ( cwsr(it_wp, - sq_d) == CGAL::SMALLER )
863871
{
864-
const Weighted_point& it_wp = tr.point(it);
865-
FT sq_d = tr.min_squared_distance(p, cp(it_wp));
866-
if ( cwsr(it_wp, - sq_d) == CGAL::SMALLER )
872+
bool special_ball = false;
873+
if(minimal_weight_ != Weight() && sq_d < minimal_weight_)
867874
{
868-
bool special_ball = false;
869-
if(minimal_weight_ != Weight() && sq_d > minimal_weight_) {
870-
sq_d = minimal_weight_;
871-
w = minimal_weight_;
872-
special_ball = true;
873-
insert_a_special_ball = true;
874-
}
875-
if( ! is_special(it) ) {
876-
*out++ = it;
877-
change_ball_size(it, sq_d, special_ball);
878-
restart = true;
879-
}
880-
break;
875+
sq_d = minimal_weight_;
876+
w = minimal_weight_;
877+
special_ball = true;
878+
insert_a_special_ball = true;
879+
}
880+
881+
if( ! is_special(it) ) {
882+
*out++ = it;
883+
change_ball_size(it, sq_d, special_ball);
881884
}
882885
}
883886
}
884887

888+
// Change w in order to be sure that no existing point will be included in (p,w)
885889
FT min_sq_d = w;
890+
#if CGAL_MESH_3_PROTECTION_DEBUG & 1
886891
typename Tr::Point nearest_point;
887-
// Change w in order to be sure that no existing point will be included
888-
// in (p,w)
892+
#endif
893+
889894
for ( typename Tr::Finite_vertices_iterator it = tr.finite_vertices_begin(),
890895
end = tr.finite_vertices_end() ; it != end ; ++it )
891896
{
892897
const Weighted_point& it_wp = tr.point(it);
893898
FT sq_d = tr.min_squared_distance(p, cp(it_wp));
894899
if(sq_d < min_sq_d) {
895900
min_sq_d = sq_d;
901+
#if CGAL_MESH_3_PROTECTION_DEBUG & 1
896902
nearest_point = c3t3_.triangulation().point(it);
903+
#endif
897904
}
898905
}
899906

@@ -902,7 +909,7 @@ smart_insert_point(const Bare_point& p, Weight w, int dim, const Index& index,
902909
#if CGAL_MESH_3_PROTECTION_DEBUG & 1
903910
std::cerr << "smart_insert_point: weight " << w
904911
<< " reduced to " << min_sq_d
905-
<< "\n (near existing point: " << nearest_point << " )\n";
912+
<< " (near existing point: " << nearest_point << " )\n";
906913
#endif
907914
w = min_sq_d;
908915
add_handle_to_unchecked = true;
@@ -921,6 +928,11 @@ smart_insert_point(const Bare_point& p, Weight w, int dim, const Index& index,
921928
}
922929

923930
if( w < minimal_weight_) {
931+
#if CGAL_MESH_3_PROTECTION_DEBUG & 1
932+
std::cerr << "smart_insert_point: weight " << w
933+
<< " was smaller than minimal weight (" << minimal_weight_ << ")\n";
934+
#endif
935+
924936
w = minimal_weight_;
925937
insert_a_special_ball = true;
926938
}
@@ -956,7 +968,7 @@ insert_balls_on_edges()
956968
if ( ! is_treated(curve_index) )
957969
{
958970
#if CGAL_MESH_3_PROTECTION_DEBUG & 1
959-
std::cerr << "** treat curve #" << curve_index << std::endl;
971+
std::cerr << "\n** treat curve #" << curve_index << std::endl;
960972
#endif
961973
const Bare_point& p = std::get<1>(*fit).first;
962974
const Bare_point& q = std::get<2>(*fit).first;

Mesh_3/include/CGAL/Mesh_3/Robust_intersection_traits_3.h

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,14 @@ tr_intersection(const typename K::Triangle_3 &t,
418418

419419
typedef typename K::Point_3 Point_3;
420420

421-
typename K::Construct_vertex_3 vertex_on =
422-
k.construct_vertex_3_object();
423-
421+
typename K::Do_intersect_3 do_intersect =
422+
k.do_intersect_3_object();
424423
typename K::Orientation_3 orientation =
425424
k.orientation_3_object();
426-
427425
typename K::Construct_point_on_3 point_on =
428426
k.construct_point_on_3_object();
427+
typename K::Construct_vertex_3 vertex_on =
428+
k.construct_vertex_3_object();
429429

430430
typename Mesh_3::Vector_plane_orientation_3_static_filter<K> vector_plane_orient;
431431

@@ -439,17 +439,24 @@ tr_intersection(const typename K::Triangle_3 &t,
439439
const Point_3& q = point_on(r,1);
440440

441441
const Orientation ray_direction = vector_plane_orient(p, q, a, b, c);
442-
443-
if(ray_direction == COPLANAR) return result_type();
442+
if(ray_direction == COPLANAR)
443+
return result_type();
444444

445445
const Orientation abcp = orientation(a,b,c,p);
446+
if(abcp == COPLANAR) // p belongs to the triangle's supporting plane
447+
{
448+
if(do_intersect(t, p))
449+
return result_type(p);
450+
else
451+
return result_type();
452+
}
446453

447-
if(abcp == COPLANAR) return result_type(); // p belongs to the triangle's
448-
// supporting plane
449-
450-
if(ray_direction == abcp) return result_type();
451-
// The ray lies entirely in one of the two open halfspaces defined by the
452-
// triangle's supporting plane.
454+
if(ray_direction == abcp)
455+
{
456+
// The ray lies entirely in one of the two open halfspaces defined by the
457+
// triangle's supporting plane.
458+
return result_type();
459+
}
453460

454461
// Here we know that the ray crosses the plane (abc)
455462

Mesh_3/include/CGAL/Polyhedral_mesh_domain_3.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,13 +692,14 @@ Construct_initial_points::operator()(OutputIterator pts,
692692
typename IGT::Construct_vector_3 vector = IGT().construct_vector_3_object();
693693

694694
const Bounding_box bbox = r_domain_.tree_.bbox();
695-
const Point_3 center( FT( (bbox.xmin() + bbox.xmax()) / 2),
696-
FT( (bbox.ymin() + bbox.ymax()) / 2),
697-
FT( (bbox.zmin() + bbox.zmax()) / 2) );
695+
Point_3 center( FT( (bbox.xmin() + bbox.xmax()) / 2),
696+
FT( (bbox.ymin() + bbox.ymax()) / 2),
697+
FT( (bbox.zmin() + bbox.zmax()) / 2) );
698698

699699
CGAL::Random& rng = *(r_domain_.p_rng_ != 0 ?
700700
r_domain_.p_rng_ :
701701
new Random(0));
702+
702703
Random_points_on_sphere_3<Point_3> random_point(1., rng);
703704

704705
int i = n;
@@ -728,6 +729,15 @@ Construct_initial_points::operator()(OutputIterator pts,
728729
% (n - i)
729730
% n;
730731
# endif
732+
733+
// If the source of the ray is on the surface, every ray will return its source
734+
// so change the source to a random point in the bounding box
735+
if(std::get<0>(intersection) == ray_shot.source())
736+
{
737+
center = Point_3(rng.get_double(bbox.xmin(), bbox.xmax()),
738+
rng.get_double(bbox.ymin(), bbox.ymax()),
739+
rng.get_double(bbox.zmin(), bbox.zmax()));
740+
}
731741
}
732742
++random_point;
733743
}

Periodic_3_mesh_3/include/CGAL/Periodic_3_mesh_3/Protect_edges_sizing_field.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,8 +1683,8 @@ smart_insert_point(const Bare_point& p, Weight w, int dim, const Index& index,
16831683
#endif
16841684

16851685
// This will never happen for a dummy point
1686-
while(cwsr(c3t3_.triangulation().point(nearest_vh), - sq_d) == CGAL::SMALLER &&
1687-
! is_special(nearest_vh))
1686+
while(! is_special(nearest_vh) &&
1687+
cwsr(c3t3_.triangulation().point(nearest_vh), - sq_d) == CGAL::SMALLER)
16881688
{
16891689
CGAL_assertion(minimal_size_ > 0 || sq_d > 0);
16901690

0 commit comments

Comments
 (0)