diff --git a/Triangulation_2/include/CGAL/Constrained_triangulation_2.h b/Triangulation_2/include/CGAL/Constrained_triangulation_2.h index 72e14052d61..c1ec747d702 100644 --- a/Triangulation_2/include/CGAL/Constrained_triangulation_2.h +++ b/Triangulation_2/include/CGAL/Constrained_triangulation_2.h @@ -1115,7 +1115,7 @@ operator<<(std::ostream& os, //Helping functions to compute intersections of constrained edges template bool -intersection(Gt , +intersection(const Gt& , const typename Gt::Point_2& , const typename Gt::Point_2& , const typename Gt::Point_2& , @@ -1128,7 +1128,7 @@ intersection(Gt , template bool -intersection(Gt gt, +intersection(const Gt& gt, const typename Gt::Point_2& pa, const typename Gt::Point_2& pb, const typename Gt::Point_2& pc, @@ -1142,7 +1142,7 @@ intersection(Gt gt, template inline bool -intersection(Gt gt, +intersection(const Gt& gt, const typename Gt::Point_2& pa, const typename Gt::Point_2& pb, const typename Gt::Point_2& pc, @@ -1155,7 +1155,7 @@ intersection(Gt gt, template bool -compute_intersection(Gt gt, +compute_intersection(const Gt& gt, const typename Gt::Point_2& pa, const typename Gt::Point_2& pb, const typename Gt::Point_2& pc, @@ -1173,7 +1173,7 @@ compute_intersection(Gt gt, template int -limit_intersection(Gt , +limit_intersection(const Gt& , const typename Gt::Point_2& , const typename Gt::Point_2& , const typename Gt::Point_2& , @@ -1185,7 +1185,7 @@ limit_intersection(Gt , template int -limit_intersection(Gt , +limit_intersection(const Gt& , const typename Gt::Point_2& , const typename Gt::Point_2& , const typename Gt::Point_2& , @@ -1197,7 +1197,7 @@ limit_intersection(Gt , template int -limit_intersection(Gt gt, +limit_intersection(const Gt& gt, const typename Gt::Point_2& pa, const typename Gt::Point_2& pb, const typename Gt::Point_2& pc, diff --git a/Triangulation_2/include/CGAL/Triangulation_2_filtered_projection_traits_3.h b/Triangulation_2/include/CGAL/Triangulation_2_filtered_projection_traits_3.h index a9260d5922b..63ac5d4e14d 100644 --- a/Triangulation_2/include/CGAL/Triangulation_2_filtered_projection_traits_3.h +++ b/Triangulation_2/include/CGAL/Triangulation_2_filtered_projection_traits_3.h @@ -43,86 +43,39 @@ public: typedef Triangulation_2_projection_traits_3 Exact_traits; typedef Triangulation_2_projection_traits_3 Filtering_traits; -private: - // private data - Exact_traits exact_traits_; - Filtering_traits filtering_traits_; - // NOTE: The traits are precomputed, here. My small bench showed that it - // is at least twice slower if the predicates are constructed from a - // vector, instead of from a traits reference (with a precomputed - // normal), because the Filtered_predicate converts the object that is - // passed as argument its constructor. public: Triangulation_2_filtered_projection_traits_3(const typename K::Vector_3& n) - : Base(n), - exact_traits_(C2E()(n)), - filtering_traits_(C2F()(n)) + : Base(n) { } + Triangulation_2_filtered_projection_traits_3(const Self& other) + : Base(other) + { + CGAL_PROFILER("Copy of the filtered traits") + CGAL_TIME_PROFILER("Copy of the filtered traits") +// std::cerr << "Copy of the filtered traits.\n"; + } + Self& operator=(const Self& other) { + std::cerr << "Assignement of the filtered traits.\n"; if(this != &other) { Base::operator=(other); - exact_traits_ = other.exact_traits_; - filtering_traits_ = other.filtering_traits_; } return *this; } - const Exact_traits& exact_traits() const { return exact_traits_; } - const Filtering_traits& filtering_traits() const { return filtering_traits_; } - - struct MyC2E : public C2E { -#ifndef CGAL_CFG_MATCHING_BUG_6 - using C2E::operator(); -#else - typedef typename C2E Converter; - typedef typename Converter::Source_kernel Source_kernel; - typedef typename Converter::Target_kernel Target_kernel; - - CGAL::Point_3 - operator()(const CGAL::Point_3 & p) const - { - return Converter::operator()(p); - } -#endif - - Exact_traits operator()(const Self& traits) const - { - return traits.exact_traits(); - } - }; - - struct MyC2F : public C2F { -#ifndef CGAL_CFG_MATCHING_BUG_6 - using C2F::operator(); -#else - typedef typename C2F Converter; - typedef typename Converter::Source_kernel Source_kernel; - typedef typename Converter::Target_kernel Target_kernel; - - CGAL::Point_3 - operator()(const CGAL::Point_3 & p) const - { - return Converter::operator()(p); - } -#endif - - Filtering_traits operator()(const Self& traits) const - { - return traits.filtering_traits(); - } - }; // end class MyC2F - #define CGAL_TRIANGULATION_2_PROJ_TRAITS_FILTER_PRED(P, Pf, obj) \ typedef Filtered_predicate< \ typename Exact_traits::P, \ typename Filtering_traits::P, \ - MyC2E, \ - MyC2F > P; \ - const P& Pf() const { return P(*this); } - + C2E, \ + C2F > P; \ + P Pf() const { \ + return P(this->normal()); \ + } + // std::cerr << #P << "_object()\n"; CGAL_TRIANGULATION_2_PROJ_TRAITS_FILTER_PRED(Orientation_2, orientation_2_object, orientation) diff --git a/Triangulation_2/include/CGAL/Triangulation_2_projection_traits_3.h b/Triangulation_2/include/CGAL/Triangulation_2_projection_traits_3.h index 03c35887ba4..61a20cd00e3 100644 --- a/Triangulation_2/include/CGAL/Triangulation_2_projection_traits_3.h +++ b/Triangulation_2/include/CGAL/Triangulation_2_projection_traits_3.h @@ -1,4 +1,4 @@ - // Copyright (c) 2009 GeometryFactory (France) +// Copyright (c) 2009 GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org); you may redistribute it under @@ -32,26 +32,30 @@ template class Projected_orientation_with_normal_3 { // private members - const Traits& traits; + const typename Traits::Vector_3 normal; // private type aliases typedef typename Traits::K K; typedef typename Traits::Point_2 Point; + typedef typename Traits::Vector_3 Vector_3; public: typedef typename K::Orientation Orientation; typedef Orientation result_type; - Projected_orientation_with_normal_3(const Traits& traits_) - : traits(traits_) + Projected_orientation_with_normal_3(const Vector_3& normal_) + : normal(normal_) { + CGAL_PROFILER("Construct Projected_orientation_with_normal_3.") + CGAL_TIME_PROFILER("Construct Projected_orientation_with_normal_3") } Orientation operator()(const Point& p, const Point& q, const Point& r) const { - CGAL_TIME_PROFILER("Projected_orientation_with_normal_3"); - return orientation(q-p, r-p, traits.normal()); + CGAL_PROFILER("Projected_orientation_with_normal_3::operator()"); + CGAL_TIME_PROFILER("Projected_orientation_with_normal_3::operator()"); + return orientation(q-p, r-p, normal); } }; // end class Projected_orientation_with_normal_3 @@ -59,7 +63,7 @@ template class Projected_side_of_oriented_circle_with_normal_3 { // private members - const Traits& traits; + const typename Traits::Vector_3 normal; // private types aliases typedef typename Traits::K K; @@ -67,13 +71,25 @@ class Projected_side_of_oriented_circle_with_normal_3 typedef typename Traits::Vector_3 Vector_3; typedef typename Traits::FT FT; + typedef Projected_side_of_oriented_circle_with_normal_3 Self; + public: typedef typename K::Oriented_side Oriented_side; typedef Oriented_side result_type; - Projected_side_of_oriented_circle_with_normal_3(const Traits& traits_) - : traits(traits_) + Projected_side_of_oriented_circle_with_normal_3(const Vector_3& normal_) + : normal(normal_) { + CGAL_PROFILER("Construct Projected_side_of_oriented_circle_with_normal_3.") + CGAL_TIME_PROFILER("Construct Projected_side_of_oriented_circle_with_normal_3.") +// std::cerr << "Projected_side_of_oriented_circle_with_normal_3(" << normal_ << ")\n"; + } + + Projected_side_of_oriented_circle_with_normal_3(const Self& other) + : normal(other.normal) + { + CGAL_PROFILER("Copy Projected_side_of_oriented_circle_with_normal_3::operator()") + CGAL_TIME_PROFILER("Copy Projected_side_of_oriented_circle_with_normal_3::operator()") } Oriented_side operator()(const Point& p, @@ -81,8 +97,10 @@ public: const Point& r, const Point& t) const { - CGAL_TIME_PROFILER("Projected_side_of_oriented_circle_with_normal_3") - const Vector_3& u = traits.normal(); + CGAL_PROFILER("Projected_side_of_oriented_circle_with_normal_3::operator()") + CGAL_TIME_PROFILER("Projected_side_of_oriented_circle_with_normal_3::operator()") + const Vector_3& u = normal; +// std::cerr << "Projected_side_of_oriented_circle_with_normal_3::operator(). Normal=" << normal << ")\n"; const Vector_3 tp = p - t; const Vector_3 tq = q - t; @@ -111,7 +129,7 @@ template class Projected_square_distance_to_line_with_normal_3 { // private members - const Traits& traits; + const typename Traits::Vector_3 normal; // private types aliases typedef typename Traits::K K; @@ -121,15 +139,20 @@ class Projected_square_distance_to_line_with_normal_3 typedef typename Traits::FT FT; public: - Projected_square_distance_to_line_with_normal_3(const Traits& traits_) - : traits(traits_) - {} + Projected_square_distance_to_line_with_normal_3(const Vector_3& normal_) + : normal(normal_) + { + CGAL_PROFILER("Construct Projected_square_distance_to_line_with_normal_3.") + CGAL_TIME_PROFILER("Construct Projected_square_distance_to_line_with_normal_3") + } FT operator()(const Line& line, const Point& p) { + CGAL_PROFILER("Projected_square_distance_to_line_with_normal_3::operator()") + CGAL_TIME_PROFILER("Projected_square_distance_to_line_with_normal_3::operator()") const Vector_3& vl = line.to_vector(); const Point& pl = line.point(); - const Vector_3 v = cross_product(traits.normal(), + const Vector_3 v = cross_product(normal, vl); if(v == NULL_VECTOR) { // den == 0 if the line is vertical @@ -139,7 +162,7 @@ public: return (w * w) / (vl * vl); } else { - const FT det = determinant(traits.normal(), + const FT det = determinant(normal, vl, pl - p); return (det * det) / ( v * v ); @@ -151,7 +174,7 @@ template class Projected_intersect_3 { // private members - const Traits& traits; + const typename Traits::Vector_3 normal; // private types aliases typedef typename Traits::K K; @@ -162,18 +185,22 @@ class Projected_intersect_3 typedef typename Traits::Vector_3 Vector_3; typedef typename Traits::FT FT; public: - Projected_intersect_3(const Traits& traits_) - : traits(traits_) - {} + Projected_intersect_3(const Vector_3& normal_) + : normal(normal_) + { + CGAL_PROFILER("Construct Projected_intersect_3") + CGAL_TIME_PROFILER("Construct Projected_intersect_3") + } Object operator()(const Segment& s1, const Segment& s2) { - CGAL_TIME_PROFILER("Projected_intersect_3") - const Vector_3 u1 = cross_product(s1.to_vector(), traits.normal()); + CGAL_PROFILER("Projected_intersect_3::operator()") + CGAL_TIME_PROFILER("Projected_intersect_3::operator()") + const Vector_3 u1 = cross_product(s1.to_vector(), normal); if(u1 == NULL_VECTOR) return K().intersect_3_object()(s1.supporting_line(), s2); - const Vector_3 u2 = cross_product(s2.to_vector(), traits.normal()); + const Vector_3 u2 = cross_product(s2.to_vector(), normal); if(u2 == NULL_VECTOR) return K().intersect_3_object()(s1, s2.supporting_line()); @@ -188,11 +215,11 @@ public: if(const Line* line = object_cast(&planes_intersection)) { const Point& pi = line->point(0); - if(cross_product(traits.normal(), pi - s1.source()) - * cross_product(traits.normal(), pi - s1.target()) > FT(0) + if(cross_product(normal, pi - s1.source()) + * cross_product(normal, pi - s1.target()) > FT(0) || - cross_product(traits.normal(), pi - s2.source()) - * cross_product(traits.normal(), pi - s2.target()) > FT(0) ) + cross_product(normal, pi - s2.source()) + * cross_product(normal, pi - s2.target()) > FT(0) ) { // the intersection of the lines is not inside the segments std::cerr << "intersection not inside\n"; @@ -236,20 +263,28 @@ public: : n(n_) {} + Triangulation_2_projection_traits_3(const Self& other) + : n(other.n) + { +// std::cerr << "Copy of a traits. Type=" +// << typeid(*this).name() << std::endl +// << "normal=" << normal() << std::endl; + } + const Vector_3& normal() const { +// std::cerr << "normal=" << n << std::endl; return n; } - Triangulation_2_projection_traits_3(const Self& other) - : n(other.n) - {} - Self& operator=(const Self& other) { + std::cerr << "Assign of a non-filtrered projected traits. Type=" + << typeid(*this).name() << std::endl; if(this != &other) { n = other.n; } + std::cerr << "Normal="<< this->normal() << std::endl; return *this; } @@ -306,25 +341,25 @@ public: Orientation_2 orientation_2_object() const { - return Orientation_2(*this); + return Orientation_2(this->normal()); } Side_of_oriented_circle_2 side_of_oriented_circle_2_object() const { - return Side_of_oriented_circle_2(*this); + return Side_of_oriented_circle_2(this->normal()); } Compute_squared_distance_2 compute_squared_distance_2_object() const { - return Compute_squared_distance_2(*this); + return Compute_squared_distance_2(this->normal()); } Intersect_2 intersect_2_object () const { - return Intersect_2(*this); + return Intersect_2(this->normal()); } Construct_segment_2 construct_segment_2_object() const @@ -336,6 +371,32 @@ public: Construct_triangle_2 construct_triangle_2_object() const {return Construct_triangle_2();} + + // Special functor, not in the Kernel concept + class Projection_to_plan { + // Remeber: Point_2 is K::Point_3 + const Point_2& plane_point; + const Vector_3& normal; + public: + // Return the projection of a point to a plane passing through + // the point 'plane_point' and with orthogonal vector normal(). + Projection_to_plan(const Point_2& plane_point_, const Self& self) + : plane_point(plane_point_), + normal(self.normal()) + {} + + Point_2 operator()(const Point_2& point) const + { + return point + + ( ( (plane_point - point) * normal ) / (normal * normal) ) * normal; + } + }; // end Projection_to_plan + + Projection_to_plan projection_to_plan_object(const Point_2& plane_point) const + { + return Projection_to_plan(plane_point, *this); + } + }; // end class Triangulation_2_projection_traits_3