diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_intersection.h index 99dcd24ff45..68166f18c6e 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_intersection.h @@ -34,28 +34,6 @@ namespace CGAL { namespace Intersections { namespace internal{ -//TODO: move into a functor -template -typename K::FT -coplanar_segment_segment_alpha_intersection(const typename K::Point_3& p1, const typename K::Point_3& p2, // segment 1 - const typename K::Point_3& p3, const typename K::Point_3& p4, // segment 2 - const K& k) -{ - const typename K::Vector_3 v1 = p2-p1; - const typename K::Vector_3 v2 = p4-p3; - - CGAL_assertion(k.coplanar_3_object()(p1,p2,p3,p4)); - - const typename K::Vector_3 v3 = p3 - p1; - const typename K::Vector_3 v3v2 = cross_product(v3,v2); - const typename K::Vector_3 v1v2 = cross_product(v1,v2); - const typename K::FT sl = v1v2.squared_length(); - CGAL_assertion(!certainly(is_zero(sl))); - - const typename K::FT t = ((v3v2.x()*v1v2.x()) + (v3v2.y()*v1v2.y()) + (v3v2.z()*v1v2.z())) / sl; - return t; // p1 + (p2-p1) * t -} - template struct Point_on_triangle { @@ -179,6 +157,8 @@ intersection(const Point_on_triangle& p, std::cout << " (" << p.id1() << "," << p.id2() << ",[" << p.alpha << "]) -"; std::cout << " (" << q.id1() << "," << q.id2() << ",[" << q.alpha << "]) || e" << edge_id_t1; #endif + typename Kernel::Compute_alpha_for_coplanar_triangle_intersection_3 compute_alpha + = k.compute_alpha_for_coplanar_triangle_intersection_3_object(); typedef Point_on_triangle Pot; switch(p.id1()) { @@ -193,10 +173,9 @@ intersection(const Point_on_triangle& p, #ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION std::cout << " -- case 1\n"; #endif - typename Kernel::FT alpha = - coplanar_segment_segment_alpha_intersection(p1, q1, - Pot::point_from_id(p2, q2, r2, p.id2()), - Pot::point_from_id(p2, q2, r2, q.id2()), k); + typename Kernel::FT alpha = compute_alpha(p1, q1, + Pot::point_from_id(p2, q2, r2, p.id2()), + Pot::point_from_id(p2, q2, r2, q.id2())); int id2 = (p.id2()+1)%3 == q.id2() ? p.id2() : q.id2(); return Point_on_triangle(edge_id_t1, id2, alpha); // intersection with an original edge of t2 } @@ -209,10 +188,9 @@ intersection(const Point_on_triangle& p, std::cout << " -- case 2\n"; #endif // points are on the same edge of t2 --> we shorten an already cut edge - typename Kernel::FT alpha = - coplanar_segment_segment_alpha_intersection(p1, q1, - Pot::point_from_id(p2, q2, r2, q.id2()), - Pot::point_from_id(p2, q2, r2, (q.id2()+1)%3), k); + typename Kernel::FT alpha = compute_alpha(p1, q1, + Pot::point_from_id(p2, q2, r2, q.id2()), + Pot::point_from_id(p2, q2, r2, (q.id2()+1)%3)); return Point_on_triangle(edge_id_t1, q.id2(), alpha); } @@ -278,10 +256,9 @@ intersection(const Point_on_triangle& p, std::cout << " -- case 7\n"; #endif // points are on the same edge of t2 --> we shorten an already cut edge - typename Kernel::FT alpha = - coplanar_segment_segment_alpha_intersection(p1, q1, - Pot::point_from_id(p2, q2, r2, p.id2()), - Pot::point_from_id(p2, q2, r2, (p.id2()+1)%3), k); + typename Kernel::FT alpha = compute_alpha(p1, q1, + Pot::point_from_id(p2, q2, r2, p.id2()), + Pot::point_from_id(p2, q2, r2, (p.id2()+1)%3)); return Point_on_triangle(edge_id_t1, p.id2(), alpha); } @@ -314,10 +291,9 @@ intersection(const Point_on_triangle& p, #ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION std::cout << " -- case 10\n"; #endif - typename Kernel::FT alpha = - coplanar_segment_segment_alpha_intersection(p1, q1, - Pot::point_from_id(p2, q2, r2, q.id2()), - Pot::point_from_id(p2, q2, r2, (q.id2()+1)%3), k); + typename Kernel::FT alpha = compute_alpha(p1, q1, + Pot::point_from_id(p2, q2, r2, q.id2()), + Pot::point_from_id(p2, q2, r2, (q.id2()+1)%3)); return Point_on_triangle(edge_id_t1, q.id2(), alpha); } // we are intersecting an edge of t1 diff --git a/Kernel_23/include/CGAL/Kernel/function_objects.h b/Kernel_23/include/CGAL/Kernel/function_objects.h index 71aa268e6d3..780c0b2d4e5 100644 --- a/Kernel_23/include/CGAL/Kernel/function_objects.h +++ b/Kernel_23/include/CGAL/Kernel/function_objects.h @@ -2149,6 +2149,37 @@ namespace CommonKernelFunctors { } }; + template + class Compute_alpha_for_coplanar_triangle_intersection_3 + { + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + public: + typedef typename K::FT result_type; + result_type + operator()(const Point_3& p1, const Point_3& p2, // segment 1 + const Point_3& p3, const Point_3& p4) const // segment 2 + { + typename K::Construct_vector_3 vector = K().construct_vector_3_object(); + typename K::Construct_cross_product_vector_3 cross_product = + K().construct_cross_product_vector_3_object(); + + const Vector_3 v1 = vector(p1, p2); + const Vector_3 v2 = vector(p3, p4); + + CGAL_assertion(K().coplanar_3_object()(p1,p2,p3,p4)); + + const Vector_3 v3 = vector(p1, p3); + const Vector_3 v3v2 = cross_product(v3,v2); + const Vector_3 v1v2 = cross_product(v1,v2); + const typename K::FT sl = K().compute_squared_length_3_object()(v1v2); + CGAL_assertion(!certainly(is_zero(sl))); + + const typename K::FT t = ((v3v2.x()*v1v2.x()) + (v3v2.y()*v1v2.y()) + (v3v2.z()*v1v2.z())) / sl; + return t; // p1 + (p2-p1) * t + } + }; + template class Construct_point_on_2 { diff --git a/Kernel_23/include/CGAL/Kernel/interface_macros.h b/Kernel_23/include/CGAL/Kernel/interface_macros.h index 9c85643a977..e5a2ebf8121 100644 --- a/Kernel_23/include/CGAL/Kernel/interface_macros.h +++ b/Kernel_23/include/CGAL/Kernel/interface_macros.h @@ -396,6 +396,8 @@ CGAL_Kernel_cons(Construct_plane_3, construct_plane_3_object) CGAL_Kernel_cons(Construct_plane_line_intersection_point_3, construct_plane_line_intersection_point_3_object) +CGAL_Kernel_cons(Compute_alpha_for_coplanar_triangle_intersection_3, + compute_alpha_for_coplanar_triangle_intersection_3_object) CGAL_Kernel_cons(Construct_point_on_2, construct_point_on_2_object) CGAL_Kernel_cons(Construct_point_on_3, diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/autorefinement.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/autorefinement.h index 6b664ec360b..6c8ba3f8cd2 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/autorefinement.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/autorefinement.h @@ -386,7 +386,7 @@ void coplanar_intersections(const std::array& t1, //intersect t2 with the three half planes which intersection defines t1 K k; - intersection_coplanar_triangles_cutoff(p1,q1,r1,0,p2,q2,r2,k,l_inter_pts); //line p1q1 + Intersections::internal::intersection_coplanar_triangles_cutoff(p1,q1,r1,0,p2,q2,r2,k,l_inter_pts); //line p1q1 #ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION std::cout << " ipts size: " << l_inter_pts.size() << "\n"; print_points(); @@ -401,7 +401,7 @@ void coplanar_intersections(const std::array& t1, } } #endif - intersection_coplanar_triangles_cutoff(q1,r1,p1,1,p2,q2,r2,k,l_inter_pts); //line q1r1 + Intersections::internal::intersection_coplanar_triangles_cutoff(q1,r1,p1,1,p2,q2,r2,k,l_inter_pts); //line q1r1 #ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION std::cout << " ipts size: " << l_inter_pts.size() << "\n"; print_points(); @@ -416,7 +416,7 @@ void coplanar_intersections(const std::array& t1, } } #endif - intersection_coplanar_triangles_cutoff(r1,p1,q1,2,p2,q2,r2,k,l_inter_pts); //line r1p1 + Intersections::internal::intersection_coplanar_triangles_cutoff(r1,p1,q1,2,p2,q2,r2,k,l_inter_pts); //line r1p1 #ifdef CGAL_DEBUG_COPLANAR_T3_T3_INTERSECTION std::cout << " ipts size: " << l_inter_pts.size() << "\n"; print_points();