From 061a9b1ecd006cc483cd1b0890a0bedab82afd04 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 5 Jan 2017 12:23:09 +0100 Subject: [PATCH 01/23] Kernel:23 Add Compare_slope_3 --- .../Kernel_23/CGAL/Kernel/global_functions.h | 9 +++++ .../Concepts/FunctionObjectConcepts.h | 34 +++++++++++++++++++ Kernel_23/doc/Kernel_23/Concepts/Kernel.h | 5 +++ .../doc/Kernel_23/PackageDescription.txt | 1 + .../include/CGAL/Kernel/function_objects.h | 21 ++++++++++++ .../include/CGAL/Kernel/global_functions_3.h | 11 ++++++ .../CGAL/Kernel/global_functions_internal_3.h | 12 +++++++ .../include/CGAL/Kernel/interface_macros.h | 2 ++ .../include/CGAL/_test_fct_point_3.h | 7 ++++ 9 files changed, 102 insertions(+) diff --git a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h index b8083e59cfb..cb2c3223511 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -803,6 +803,15 @@ template Comparison_result compare_slopes(const CGAL::Segment_2 &s1, const CGAL::Segment_2 &s2); +/*! +compares the slopes of the segments `(p,q)` and `(r,s)`, +with `p.z() >= q.z()` and `r.z() >= s.z()`. +*/ +template +Comparison_result compare_slopes(const CGAL::Point_3 &p, + const CGAL::Point_3 &q, + const CGAL::Point_3 &r, + const CGAL::Point_3 &s); /// @} /// \defgroup compare_squared_distance_grp CGAL::compare_squared_distance() diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index a7c6a47ba91..1dc0d82158d 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -1000,6 +1000,40 @@ public: }; /* end Kernel::CompareSlope_2 */ + +/*! + \ingroup PkgKernel23ConceptsFunctionObjects + \cgalConcept + + \cgalRefines `AdaptableFunctor` (with two arguments) + + \sa `compare_slopes_grp` + +*/ +class CompareSlope_3 { +public: + + /// \name Operations + /// A model of this concept must provide: + /// @{ + + + /*! + compares the slopes of the segments `(p,q)` and `(r,s)` + with `p.z() >= q.z()` and `r.z() >= s.z()`. + */ + Comparison_result operator()(const Kernel::Point_3& p, + const Kernel::Point_3& q, + const Kernel::Point_3& r, + const Kernel::Point_3& s); + + + /// @} + +}; /* end Kernel::CompareSlope_2 */ + + + /*! \ingroup PkgKernel23ConceptsFunctionObjects \cgalConcept diff --git a/Kernel_23/doc/Kernel_23/Concepts/Kernel.h b/Kernel_23/doc/Kernel_23/Concepts/Kernel.h index fe5dcf86dfd..52ff08feba3 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/Kernel.h +++ b/Kernel_23/doc/Kernel_23/Concepts/Kernel.h @@ -1433,6 +1433,11 @@ public: */ typedef unspecified_type Compare_xyz_3; + /*! + a model of `Kernel::CompareSlope_3` + */ + typedef unspecified_type Compare_slope_3; + /*! a model of `Kernel::CompareSquaredDistance_3` */ diff --git a/Kernel_23/doc/Kernel_23/PackageDescription.txt b/Kernel_23/doc/Kernel_23/PackageDescription.txt index 878c8a27db1..aa5e95fc237 100644 --- a/Kernel_23/doc/Kernel_23/PackageDescription.txt +++ b/Kernel_23/doc/Kernel_23/PackageDescription.txt @@ -276,6 +276,7 @@ - `Kernel::CompareDistance_2` - `Kernel::CompareDistance_3` - `Kernel::CompareSlope_2` +- `Kernel::CompareSlope_3` - `Kernel::ComparePowerDistance_2` - `Kernel::ComparePowerDistance_3` - `Kernel::CompareSquaredDistance_2` diff --git a/Kernel_23/include/CGAL/Kernel/function_objects.h b/Kernel_23/include/CGAL/Kernel/function_objects.h index 29c766aaa5e..dea8402e3d1 100644 --- a/Kernel_23/include/CGAL/Kernel/function_objects.h +++ b/Kernel_23/include/CGAL/Kernel/function_objects.h @@ -752,6 +752,27 @@ namespace CommonKernelFunctors { } }; + template + class Compare_slope_3 + { + typedef typename K::FT FT; + typedef typename K::Point_3 Point_3; + public: + typedef typename K::Comparison_result result_type; + + result_type operator()(const Point_3& p, const Point_3& q, const Point_3& r, const Point_3& s) const + { + CGAL_assertion((p.z() >= q.z()) && (r.z() >= s.z())); + + if(p.z() == q.z() || r.z() == s.z()){ + return CGAL::compare(p.z() - q.z(), r.z() - s.z()); + } + + return CGAL::compare(squared_distance(p,q) / (p.z() - q.z()) , + squared_distance(r,s) / (r.z() - s.z())); + } + }; + template class Compare_squared_distance_2 { diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_3.h index 30605491fb6..5a561b9094f 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_3.h @@ -354,6 +354,17 @@ compare_power_distance(const Point_3 &r, return internal::compare_power_distance(r, p, q, K()); } +template < class K > +inline +typename K::Comparison_result +compare_slopes(const Point_3 &p, + const Point_3 &q, + const Point_3 &r, + const Point_3 &s) +{ + return internal::compare_slopes(p, q, r, s, K()); +} + template < class K > inline typename K::Comparison_result diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h index 7c603de5ccd..ee77794fbc4 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h @@ -413,6 +413,18 @@ compare_power_distance(const typename K::Point_3 &r, return k.compare_power_distance_3_object()(r, p, q); } +template < class K > +inline +typename K::Comparison_result +compare_slopes(const typename K::Point_3 &p, + const typename K::Point_3 &q, + const typename K::Point_3 &r, + const typename K::Point_3 &s, + const K& k) +{ + return k.compare_slope_3_object()(p, q, r, s); +} + template < class K > inline typename K::Comparison_result diff --git a/Kernel_23/include/CGAL/Kernel/interface_macros.h b/Kernel_23/include/CGAL/Kernel/interface_macros.h index dc8206caa67..329573d08f7 100644 --- a/Kernel_23/include/CGAL/Kernel/interface_macros.h +++ b/Kernel_23/include/CGAL/Kernel/interface_macros.h @@ -126,6 +126,8 @@ CGAL_Kernel_pred_RT(Compare_power_distance_3, compare_power_distance_3_object) CGAL_Kernel_pred(Compare_slope_2, compare_slope_2_object) +CGAL_Kernel_pred(Compare_slope_3, + compare_slope_3_object) CGAL_Kernel_pred(Compare_squared_distance_2, compare_squared_distance_2_object) CGAL_Kernel_pred(Compare_squared_distance_3, diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_point_3.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_point_3.h index b052ae6bf87..a930f5fe456 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_point_3.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_point_3.h @@ -233,6 +233,13 @@ _test_fct_point_3(const R& ) assert( CGAL::compare_squared_radius(p0, p1, p2, p3, four) == CGAL::EQUAL ); } + { + CGAL::Point_3 p0(0,0,1), p1(0,0,2), p2(1,0,0), p3(1,0,1); + assert( CGAL::compare_slopes(p0,p2, p1, p2) == CGAL::SMALLER ); + assert( CGAL::compare_slopes(p0,p2, p1, p3) == CGAL::EQUAL ); + } + + assert(CGAL::l_infinity_distance(p1,p2) == FT(11)); assert(CGAL::l_infinity_distance(p1,p5) == FT(6)); // More tests, that require sqrt(). From 5f8bc52082ca65cc2c38d2e2d72d0804fd14097f Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 5 Jan 2017 16:03:06 +0100 Subject: [PATCH 02/23] Add angle(Point_3, Point_3,Point_3,Vector_3) --- .../include/CGAL/Cartesian/function_objects.h | 7 +++++++ .../include/CGAL/Homogeneous/function_objects.h | 6 ++++++ .../doc/Kernel_23/CGAL/Kernel/global_functions.h | 12 ++++++++++++ .../doc/Kernel_23/Concepts/FunctionObjectConcepts.h | 11 ++++++++++- Kernel_23/include/CGAL/Kernel/global_functions_3.h | 9 +++++++++ .../CGAL/Kernel/global_functions_internal_3.h | 12 ++++++++++++ Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h | 7 +++++++ 7 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index c23d442fa63..a7ccc4e66bb 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -96,6 +96,13 @@ namespace CartesianKernelFunctors { r.x(), r.y(), r.z(), s.x(), s.y(), s.z()); } + + result_type + operator()(const Point_3& p, const Point_3& q, + const Point_3& r, const Vector_3& n) const + { + return enum_cast(orientation(p,q,r,r+n)); + } }; template diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index b3dc18a7bb4..5a213bfd0dc 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -112,6 +112,12 @@ namespace HomogeneousKernelFunctors { const Point_3& r, const Point_3& s) const { return enum_cast(CGAL_NTS sign(c(q,p) * c(s,r))); } // FIXME: scalar product + + result_type + operator()(const Point_3& p, const Point_3& q, + const Point_3& r, const Vector_3& n) const + { + return enum_cast(orientation(p,q,r,r+n)); }; diff --git a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h index cb2c3223511..bd5215b1858 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -37,6 +37,7 @@ const CGAL::Point_2& q, const CGAL::Point_2& r, const CGAL::Point_2& s); + /*! returns `CGAL::OBTUSE`, `CGAL::RIGHT` or `CGAL::ACUTE` depending @@ -61,6 +62,17 @@ Kernel::FT approximate_dihedral_angle(const CGAL::Point_3& p, const CGAL::Point_3& r, const CGAL::Point_3& s); +/*! + +returns `CGAL::OBTUSE`, `CGAL::RIGHT` or `CGAL::ACUTE` depending +on the angle formed by the normal vector of the plane `pqr` and `v`. +*/ +template +Angle angle(const CGAL::Point_3& p, +const CGAL::Point_3& q, +const CGAL::Point_3& r, +const CGAL::Vector_3& v); + /// @} diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index 1dc0d82158d..848d3eb6a2d 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -85,7 +85,16 @@ public: Angle operator()(const Kernel::Point_3&p, const Kernel::Point_3&q, const Kernel::Point_3&r, - const Kernel::Point_3&s); + const Kernel::Point_3&s); + + /*! + returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending + on the angle formed by the twonormal vector of the plane `pqr` and `v`. + */ + Angle operator()(const Kernel::Point_3&p, + const Kernel::Point_3&q, + const Kernel::Point_3&r, + const Kernel::Vector_3&s); /// @} }; /* end Kernel::Angle_3 */ diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_3.h index 5a561b9094f..83530bb8c4d 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_3.h @@ -59,6 +59,15 @@ angle(const Point_3 &p, const Point_3 &q, return internal::angle(p, q, r, s, K()); } +template +inline +Angle +angle(const Point_3 &p, const Point_3 &q, + const Point_3 &r, const Vector_3 &v) +{ + return internal::angle(p, q, r, v, K()); +} + template < class K > inline typename K::FT diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h index ee77794fbc4..eb4887b7724 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h @@ -70,6 +70,18 @@ angle(const typename K::Point_3 &p, return k.angle_3_object()(p, q, r, s); } +template +inline +typename K::Angle +angle(const typename K::Point_3 &p, + const typename K::Point_3 &q, + const typename K::Point_3 &r, + const typename K::Vector_3 &v, + const K &k) +{ + return k.angle_3_object()(p, q, r, v); +} + template < class K > inline typename K::FT diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h index eb11c1e3f2f..17b2bbbf889 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_angle.h @@ -33,6 +33,7 @@ _test_angle(const R&) typedef CGAL::Point_3 Point_3; typedef CGAL::Vector_2 Vector_2; + typedef CGAL::Vector_3 Vector_3; Point_2 p(RT(2),RT(1)); Point_2 q(RT(5),RT(4)); @@ -67,6 +68,12 @@ _test_angle(const R&) assert( CGAL::angle( org3 - sz, sz - sy) == CGAL::OBTUSE ); assert( CGAL::angle( org3 - sx, sy - sx) == CGAL::ACUTE ); + Vector_3 vz(RT0, RT0, RT1); + Vector_3 vcoplanar(RT1, RT1, RT0); + Vector_3 vmz(RT0, RT0, -RT1); + assert( CGAL::angle( org3, sx, sy, vz) == CGAL::ACUTE ); + assert( CGAL::angle( org3, sx, sy, vcoplanar) == CGAL::RIGHT ); + assert( CGAL::angle( org3, sx, sy, vmz) == CGAL::OBTUSE ); return true; } From 399d63754bd5159feb6ee476d34bc690c06729ec Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 5 Jan 2017 16:22:32 +0100 Subject: [PATCH 03/23] add missing } --- Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index 5a213bfd0dc..878d361e3ef 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -118,6 +118,7 @@ namespace HomogeneousKernelFunctors { const Point_3& r, const Vector_3& n) const { return enum_cast(orientation(p,q,r,r+n)); + } }; From 9ccc9c1178930032b6b3773238e03b3aef96320c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 6 Jan 2017 14:42:16 +0100 Subject: [PATCH 04/23] Fix compare_slope() --- .../Kernel_23/CGAL/Kernel/global_functions.h | 19 ++++--- .../Concepts/FunctionObjectConcepts.h | 9 ++-- .../include/CGAL/Kernel/function_objects.h | 23 +++++--- .../include/CGAL/Kernel/global_functions_2.h | 24 +++++++-- .../include/CGAL/Kernel/global_functions_3.h | 4 +- .../CGAL/Kernel/global_functions_internal_2.h | 8 +-- .../CGAL/Kernel/global_functions_internal_3.h | 10 ++-- .../Kernel_23/include/CGAL/_test_fct_line_2.h | 50 +++++++++--------- .../include/CGAL/_test_fct_point_3.h | 14 +++-- .../include/CGAL/_test_fct_segment_2.h | 52 +++++++++---------- 10 files changed, 127 insertions(+), 86 deletions(-) diff --git a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h index bd5215b1858..f4089869b74 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -805,25 +805,28 @@ const CGAL::Point_3& t); compares the slopes of the lines `l1` and `l2` */ template -Comparison_result compare_slopes(const CGAL::Line_2 &l1, +Comparison_result compare_slope(const CGAL::Line_2 &l1, const CGAL::Line_2 &l2); /*! -compares the slopes of the segments `s1` and `s2` +compares the slopes of the segments `s1` and `s2`, +where the slope is the variation of the `y`-coordinate +from the left to the right endpoint of the segments. */ template -Comparison_result compare_slopes(const CGAL::Segment_2 &s1, +Comparison_result compare_slope(const CGAL::Segment_2 &s1, const CGAL::Segment_2 &s2); /*! compares the slopes of the segments `(p,q)` and `(r,s)`, -with `p.z() >= q.z()` and `r.z() >= s.z()`. +where the slope is the variation of the `z`-coordinate from the first +to the second point of the segment. */ template -Comparison_result compare_slopes(const CGAL::Point_3 &p, - const CGAL::Point_3 &q, - const CGAL::Point_3 &r, - const CGAL::Point_3 &s); +Comparison_result compare_slope(const CGAL::Point_3 &p, + const CGAL::Point_3 &q, + const CGAL::Point_3 &r, + const CGAL::Point_3 &s); /// @} /// \defgroup compare_squared_distance_grp CGAL::compare_squared_distance() diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index 848d3eb6a2d..de8a8d2b3bf 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -1000,7 +1000,9 @@ public: const Kernel::Line_2& l2); /*! - compares the slopes of the segments `s1` and `s2` + compares the slopes of the segments `s1` and `s2`, + where the slope is the variation of the `y`-coordinate + from the left to the right endpoint of the segments. */ Comparison_result operator()(const Kernel::Segment_2& s1, const Kernel::Segment_2& s2); @@ -1028,8 +1030,9 @@ public: /*! - compares the slopes of the segments `(p,q)` and `(r,s)` - with `p.z() >= q.z()` and `r.z() >= s.z()`. + compares the slopes of the segments `(p,q)` and `(r,s)`, + where the slope is the variation of the `z`-coordinate + from the first to the second point of the segment. */ Comparison_result operator()(const Kernel::Point_3& p, const Kernel::Point_3& q, diff --git a/Kernel_23/include/CGAL/Kernel/function_objects.h b/Kernel_23/include/CGAL/Kernel/function_objects.h index dea8402e3d1..a0221cf51a4 100644 --- a/Kernel_23/include/CGAL/Kernel/function_objects.h +++ b/Kernel_23/include/CGAL/Kernel/function_objects.h @@ -762,15 +762,24 @@ namespace CommonKernelFunctors { result_type operator()(const Point_3& p, const Point_3& q, const Point_3& r, const Point_3& s) const { - CGAL_assertion((p.z() >= q.z()) && (r.z() >= s.z())); - - if(p.z() == q.z() || r.z() == s.z()){ - return CGAL::compare(p.z() - q.z(), r.z() - s.z()); + Comparison_result sign_pq = compare(q.z(),p.z()); + Comparison_result sign_rs = compare(s.z(),r.z()); + + if(sign_pq != sign_rs){ + return compare(static_cast(sign_pq), static_cast(sign_rs)); } - - return CGAL::compare(squared_distance(p,q) / (p.z() - q.z()) , - squared_distance(r,s) / (r.z() - s.z())); + + if((sign_pq == EQUAL) && (sign_rs == EQUAL)){ + return EQUAL; + } + + CGAL_assertion( (sign_pq == sign_rs) && (sign_pq != EQUAL) ); + + Comparison_result res = CGAL::compare(square(p.z() - q.z()) * squared_distance(r,s), + square(r.z() - s.z()) * squared_distance(p,q)); + return (sign_pq == SMALLER) ? opposite(res) : res; } + }; template diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_2.h index c892b4280b7..da5a45adde6 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -342,17 +342,35 @@ compare_lexicographically_xy(const Point_2 &p, template < class K > inline typename K::Comparison_result -compare_slopes(const Line_2 &l1, const Line_2 &l2) +compare_slope(const Line_2 &l1, const Line_2 &l2) { - return internal::compare_slopes(l1, l2, K()); + return internal::compare_slope(l1, l2, K()); } +template < class K > +inline +typename K::Comparison_result +compare_slope(const Segment_2 &s1, const Segment_2 &s2) +{ + return internal::compare_slope(s1, s2, K()); +} + +// kept for backward compatibility +template < class K > +inline +typename K::Comparison_result +compare_slopes(const Line_2 &l1, const Line_2 &l2) +{ + return internal::compare_slope(l1, l2, K()); +} + +// kept for backward compatibility template < class K > inline typename K::Comparison_result compare_slopes(const Segment_2 &s1, const Segment_2 &s2) { - return internal::compare_slopes(s1, s2, K()); + return internal::compare_slope(s1, s2, K()); } template < class K > diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_3.h index 83530bb8c4d..5471df92d42 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_3.h @@ -366,12 +366,12 @@ compare_power_distance(const Point_3 &r, template < class K > inline typename K::Comparison_result -compare_slopes(const Point_3 &p, +compare_slope(const Point_3 &p, const Point_3 &q, const Point_3 &r, const Point_3 &s) { - return internal::compare_slopes(p, q, r, s, K()); + return internal::compare_slope(p, q, r, s, K()); } template < class K > diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h index b5367d6b14f..a7ee11a7604 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h @@ -370,8 +370,8 @@ compare_signed_distance_to_line(const typename K::Line_2& l, template < class K > inline typename K::Comparison_result -compare_slopes(const typename K::Line_2 &l1, - const typename K::Line_2 &l2, const K& k) +compare_slope(const typename K::Line_2 &l1, + const typename K::Line_2 &l2, const K& k) { return k.compare_slope_2_object()(l1, l2); } @@ -379,8 +379,8 @@ compare_slopes(const typename K::Line_2 &l1, template < class K > inline typename K::Comparison_result -compare_slopes(const typename K::Segment_2 &s1, - const typename K::Segment_2 &s2, const K& k) +compare_slope(const typename K::Segment_2 &s1, + const typename K::Segment_2 &s2, const K& k) { return k.compare_slope_2_object()(s1, s2); } diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h index eb4887b7724..7d36aa83359 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h @@ -428,11 +428,11 @@ compare_power_distance(const typename K::Point_3 &r, template < class K > inline typename K::Comparison_result -compare_slopes(const typename K::Point_3 &p, - const typename K::Point_3 &q, - const typename K::Point_3 &r, - const typename K::Point_3 &s, - const K& k) +compare_slope(const typename K::Point_3 &p, + const typename K::Point_3 &q, + const typename K::Point_3 &r, + const typename K::Point_3 &s, + const K& k) { return k.compare_slope_3_object()(p, q, r, s); } diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_line_2.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_line_2.h index 49b2e1f57b9..9f4a61e81d2 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_line_2.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_line_2.h @@ -93,36 +93,36 @@ _test_fct_line_2(const R& ) Line_2 l2(p3, p2); Line_2 l3(p4, p6); - assert( CGAL::compare_slopes(l1,l2) == CGAL::EQUAL ); - assert( CGAL::compare_slopes(l1,l3) == CGAL::EQUAL ); - assert( CGAL::compare_slopes(l3,l1) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l1,l2) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l1,l3) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l3,l1) == CGAL::EQUAL ); std::cout <<'.'; // horizontal lines Line_2 l4(p3, p8); Line_2 l5(p4, p9); - assert( CGAL::compare_slopes(l4, l5) == CGAL::EQUAL ); - assert( CGAL::compare_slopes(l3, l4) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l4, l3) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l4, l5) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l3, l4) == CGAL::LARGER ); + assert( CGAL::compare_slope(l4, l3) == CGAL::SMALLER ); std::cout <<'.'; // parallel lines Line_2 l5a(p6, p7); Line_2 l5b(p11, p1); - assert( CGAL::compare_slopes(l5a, l5b) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l5a, l5b) == CGAL::EQUAL ); assert( CGAL::parallel(l5a, l5b) ); // two positive slopes Line_2 l6(p2, p4); Line_2 l7(p2, p6); Line_2 l8(p7, p10); - assert( CGAL::compare_slopes(l6, l6) == CGAL::EQUAL ); - assert( CGAL::compare_slopes(l6, l7) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l7, l6) == CGAL::SMALLER ); - assert( CGAL::compare_slopes(l6, l8) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l8, l6) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l6, l6) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l6, l7) == CGAL::LARGER ); + assert( CGAL::compare_slope(l7, l6) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l6, l8) == CGAL::LARGER ); + assert( CGAL::compare_slope(l8, l6) == CGAL::SMALLER ); assert( CGAL::parallel(l6, l6) ); assert( ! CGAL::parallel(l6, l7) ); assert( ! CGAL::parallel(l7, l6) ); @@ -130,14 +130,14 @@ _test_fct_line_2(const R& ) assert( ! CGAL::parallel(l8, l6) ); // vertical and positive slope - assert( CGAL::compare_slopes(l1, l6) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l6, l1) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l1, l6) == CGAL::LARGER ); + assert( CGAL::compare_slope(l6, l1) == CGAL::SMALLER ); assert( ! CGAL::parallel(l1, l6) ); assert( ! CGAL::parallel(l6, l1) ); // horizontal and positive slope - assert( CGAL::compare_slopes(l5, l6) == CGAL::SMALLER ); - assert( CGAL::compare_slopes(l6, l5) == CGAL::LARGER ); + assert( CGAL::compare_slope(l5, l6) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l6, l5) == CGAL::LARGER ); assert( ! CGAL::parallel(l5, l6) ); assert( ! CGAL::parallel(l6, l5) ); @@ -148,28 +148,28 @@ _test_fct_line_2(const R& ) Line_2 l10(p9, p8); Line_2 l11(p5, p3); - assert( CGAL::compare_slopes(l9, l10) == CGAL::SMALLER ); - assert( CGAL::compare_slopes(l10, l9) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l11, l10) == CGAL::LARGER ); + assert( CGAL::compare_slope(l9, l10) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l10, l9) == CGAL::LARGER ); + assert( CGAL::compare_slope(l11, l10) == CGAL::LARGER ); assert( ! CGAL::parallel(l9, l10) ); assert( ! CGAL::parallel(l10, l9) ); assert( ! CGAL::parallel(l11, l10) ); // vertical and negative slope - assert( CGAL::compare_slopes(l2, l9) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l9, l2) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l2, l9) == CGAL::LARGER ); + assert( CGAL::compare_slope(l9, l2) == CGAL::SMALLER ); assert( ! CGAL::parallel(l2, l9) ); assert( ! CGAL::parallel(l9, l2) ); // horizontal and negative slope - assert( CGAL::compare_slopes(l5, l9) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l9, l5) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l5, l9) == CGAL::LARGER ); + assert( CGAL::compare_slope(l9, l5) == CGAL::SMALLER ); std::cout <<'.'; // positive and negative slope - assert( CGAL::compare_slopes(l6, l9) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l9, l7) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l6, l9) == CGAL::LARGER ); + assert( CGAL::compare_slope(l9, l7) == CGAL::SMALLER ); assert( ! CGAL::parallel(l6, l9) ); assert( ! CGAL::parallel(l9, l7) ); diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_point_3.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_point_3.h index a930f5fe456..6ec40703966 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_point_3.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_point_3.h @@ -234,9 +234,17 @@ _test_fct_point_3(const R& ) } { - CGAL::Point_3 p0(0,0,1), p1(0,0,2), p2(1,0,0), p3(1,0,1); - assert( CGAL::compare_slopes(p0,p2, p1, p2) == CGAL::SMALLER ); - assert( CGAL::compare_slopes(p0,p2, p1, p3) == CGAL::EQUAL ); + CGAL::Point_3 p0(0,0,1), p1(0,0,2), p2(1,0,1), p3(1,0,2), p4(1,0,3); + assert( CGAL::compare_slope(p0, p2, p1, p3) == CGAL::EQUAL ); + assert( CGAL::compare_slope(p0, p2, p0, p3) == CGAL::SMALLER ); + assert( CGAL::compare_slope(p0, p2, p1, p2) == CGAL::LARGER ); + assert( CGAL::compare_slope(p0, p3, p0, p2) == CGAL::LARGER ); + assert( CGAL::compare_slope(p0, p3, p0, p4) == CGAL::SMALLER ); + assert( CGAL::compare_slope(p0, p3, p1, p2) == CGAL::LARGER ); + assert( CGAL::compare_slope(p1, p2, p0, p2) == CGAL::SMALLER ); + assert( CGAL::compare_slope(p1, p2, p0, p3) == CGAL::SMALLER ); + assert( CGAL::compare_slope(p1, p2, p4, p0) == CGAL::LARGER ); + } diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_2.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_2.h index a4f09851609..7293374b83c 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_2.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_2.h @@ -51,43 +51,43 @@ _test_fct_segment_2(const R& ) Segment_2 l2(p3, p2); Segment_2 l3(p4, p6); - assert( CGAL::compare_slopes(l1,l2) == CGAL::EQUAL ); - assert( CGAL::compare_slopes(l1,l3) == CGAL::EQUAL ); - assert( CGAL::compare_slopes(l3,l1) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l1,l2) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l1,l3) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l3,l1) == CGAL::EQUAL ); std::cout <<'.'; // horizontal segments Segment_2 l4(p3, p8); Segment_2 l5(p4, p9); - assert( CGAL::compare_slopes(l4, l5) == CGAL::EQUAL ); - assert( CGAL::compare_slopes(l3, l4) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l4, l3) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l4, l5) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l3, l4) == CGAL::LARGER ); + assert( CGAL::compare_slope(l4, l3) == CGAL::SMALLER ); std::cout <<'.'; // parallel segments Segment_2 l5a(p6, p7); Segment_2 l5b(p11, p1); - assert( CGAL::compare_slopes(l5a, l5b) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l5a, l5b) == CGAL::EQUAL ); - // two positive slopes + // two positive slope Segment_2 l6(p2, p4); Segment_2 l7(p2, p6); Segment_2 l8(p7, p10); - assert( CGAL::compare_slopes(l6, l6) == CGAL::EQUAL ); - assert( CGAL::compare_slopes(l6, l7) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l7, l6) == CGAL::SMALLER ); - assert( CGAL::compare_slopes(l6, l8) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l8, l6) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l6, l6) == CGAL::EQUAL ); + assert( CGAL::compare_slope(l6, l7) == CGAL::LARGER ); + assert( CGAL::compare_slope(l7, l6) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l6, l8) == CGAL::LARGER ); + assert( CGAL::compare_slope(l8, l6) == CGAL::SMALLER ); // vertical and positive slope - assert( CGAL::compare_slopes(l1, l6) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l6, l1) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l1, l6) == CGAL::LARGER ); + assert( CGAL::compare_slope(l6, l1) == CGAL::SMALLER ); // horizontal and positive slope - assert( CGAL::compare_slopes(l5, l6) == CGAL::SMALLER ); - assert( CGAL::compare_slopes(l6, l5) == CGAL::LARGER ); + assert( CGAL::compare_slope(l5, l6) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l6, l5) == CGAL::LARGER ); @@ -98,23 +98,23 @@ _test_fct_segment_2(const R& ) Segment_2 l10(p9, p8); Segment_2 l11(p5, p3); - assert( CGAL::compare_slopes(l9, l10) == CGAL::SMALLER ); - assert( CGAL::compare_slopes(l10, l9) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l11, l10) == CGAL::LARGER ); + assert( CGAL::compare_slope(l9, l10) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l10, l9) == CGAL::LARGER ); + assert( CGAL::compare_slope(l11, l10) == CGAL::LARGER ); // vertical and negative slope - assert( CGAL::compare_slopes(l2, l9) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l9, l2) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l2, l9) == CGAL::LARGER ); + assert( CGAL::compare_slope(l9, l2) == CGAL::SMALLER ); // horizontal and negative slope - assert( CGAL::compare_slopes(l5, l9) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l9, l5) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l5, l9) == CGAL::LARGER ); + assert( CGAL::compare_slope(l9, l5) == CGAL::SMALLER ); std::cout <<'.'; // positive and negative slope - assert( CGAL::compare_slopes(l6, l9) == CGAL::LARGER ); - assert( CGAL::compare_slopes(l9, l7) == CGAL::SMALLER ); + assert( CGAL::compare_slope(l6, l9) == CGAL::LARGER ); + assert( CGAL::compare_slope(l9, l7) == CGAL::SMALLER ); std::cout << "done" << std::endl; return true; From a53cd1091925556ebb661988771aacf9cf26daca Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Fri, 6 Jan 2017 15:18:59 +0100 Subject: [PATCH 05/23] typo --- Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index de8a8d2b3bf..d05d00104f1 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -1042,7 +1042,7 @@ public: /// @} -}; /* end Kernel::CompareSlope_2 */ +}; /* end Kernel::CompareSlope_3 */ From 2a05190ebc5d1fa7a4dafe88ef467a6787f2fcde Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 27 Apr 2017 10:50:45 +0200 Subject: [PATCH 06/23] Fix in the manual --- Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h | 2 +- Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h index f4089869b74..854c213a6ac 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -820,7 +820,7 @@ const CGAL::Segment_2 &s2); /*! compares the slopes of the segments `(p,q)` and `(r,s)`, where the slope is the variation of the `z`-coordinate from the first -to the second point of the segment. +to the second point of the segment divided by the length of the segment. */ template Comparison_result compare_slope(const CGAL::Point_3 &p, diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index d05d00104f1..25914e5ac03 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -1032,7 +1032,8 @@ public: /*! compares the slopes of the segments `(p,q)` and `(r,s)`, where the slope is the variation of the `z`-coordinate - from the first to the second point of the segment. + from the first to the second point of the segment divided + by the length of the segment. */ Comparison_result operator()(const Kernel::Point_3& p, const Kernel::Point_3& q, From 432a40df72e1b898676c55a340eafb81bee1c128 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 27 Apr 2017 11:25:09 +0200 Subject: [PATCH 07/23] improve implementation as suggested by @mglisse --- Kernel_23/include/CGAL/Kernel/function_objects.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel_23/include/CGAL/Kernel/function_objects.h b/Kernel_23/include/CGAL/Kernel/function_objects.h index a0221cf51a4..d1d300c52ae 100644 --- a/Kernel_23/include/CGAL/Kernel/function_objects.h +++ b/Kernel_23/include/CGAL/Kernel/function_objects.h @@ -775,8 +775,8 @@ namespace CommonKernelFunctors { CGAL_assertion( (sign_pq == sign_rs) && (sign_pq != EQUAL) ); - Comparison_result res = CGAL::compare(square(p.z() - q.z()) * squared_distance(r,s), - square(r.z() - s.z()) * squared_distance(p,q)); + Comparison_result res = CGAL::compare(square(p.z() - q.z()) * (square(r.x()-s.x())+square(r.y()-s.y())), + square(r.z() - s.z()) * (square(p.x()-q.x())+square(p.y()-q.y()))); return (sign_pq == SMALLER) ? opposite(res) : res; } From 7c8d709103bab21b7c0279074069276bf067d071 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 27 Apr 2017 11:31:15 +0200 Subject: [PATCH 08/23] Add to changes.html --- Installation/changes.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Installation/changes.html b/Installation/changes.html index c283b7dd5a8..0d4a15112f3 100644 --- a/Installation/changes.html +++ b/Installation/changes.html @@ -210,6 +210,10 @@ and src/ directories).
  • Add functions l_infinity_distance() for 2D and 3D.
  • +
  • Add a new functor in CGAL Kernel concept to compare the slope of two 3D segments. + All models of the Kernel concept now provide the functor Compare_slope_3, + and the free function compare_slope() is available. +
  • 3D Convex Hull

    From ce8a0be55eb8103c9f13353e9d7ce046ebd51203 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 27 Apr 2017 11:49:54 +0200 Subject: [PATCH 09/23] Update manual for Angle_3 and angle() --- Installation/changes.html | 3 ++ .../Kernel_23/CGAL/Kernel/global_functions.h | 42 ++++++++++++++----- .../Concepts/FunctionObjectConcepts.h | 26 ++++++------ 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/Installation/changes.html b/Installation/changes.html index 0d4a15112f3..8b4d20b7df4 100644 --- a/Installation/changes.html +++ b/Installation/changes.html @@ -214,6 +214,9 @@ and src/ directories). All models of the Kernel concept now provide the functor Compare_slope_3, and the free function compare_slope() is available. +
  • Add an operator in CGAL Kernel concept Angle_3 to qualify the angle + between the normal of the triangle given by three points, and a vector. +
  • 3D Convex Hull

    diff --git a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h index 854c213a6ac..c3370fd005c 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -37,9 +37,16 @@ const CGAL::Point_2& q, const CGAL::Point_2& r, const CGAL::Point_2& s); +/*! +returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending +on the angle formed by the two vectors `u` and `v`. +*/ +template +Angle angle(const CGAL::Vector_3& u, + const CGAL::Vector_3& v); + /*! - returns `CGAL::OBTUSE`, `CGAL::RIGHT` or `CGAL::ACUTE` depending on the angle formed by the three points `p`, `q`, `r` (`q` being the vertex of the angle). @@ -49,6 +56,29 @@ Angle angle(const CGAL::Point_3& p, const CGAL::Point_3& q, const CGAL::Point_3& r); +/*! +returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending +on the angle formed by the two vectors `pq`, `rs`. The returned value is +the same as `angle(q - p, s - r)`. +*/ +template +Angle angle(const CGAL::Point_3&p, + const CGAL::Point_3&q, + const CGAL::Point_3&r, + const CGAL::Point_3&s); + +/*! +returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending +on the angle formed by the normal of the triangle `pqr` and the vector `v`. +*/ + +template +Angle angle(const CGAL::Point_3&p, + const CGAL::Point_3&q, + const CGAL::Point_3&r, + const CGAL::Vector_3&v); + + /*! returns an approximation of the signed dihedral angle in the tetrahedron `pqrs` of edge `pq`. @@ -62,16 +92,6 @@ Kernel::FT approximate_dihedral_angle(const CGAL::Point_3& p, const CGAL::Point_3& r, const CGAL::Point_3& s); -/*! - -returns `CGAL::OBTUSE`, `CGAL::RIGHT` or `CGAL::ACUTE` depending -on the angle formed by the normal vector of the plane `pqr` and `v`. -*/ -template -Angle angle(const CGAL::Point_3& p, -const CGAL::Point_3& q, -const CGAL::Point_3& r, -const CGAL::Vector_3& v); /// @} diff --git a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h index 25914e5ac03..a3f2f3604a6 100644 --- a/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h +++ b/Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h @@ -62,20 +62,20 @@ public: /// @{ /*! - returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending - on the angle formed by the two vectors `u` and `v`. - */ - Angle operator()(const Kernel::Vector_3&u, - const Kernel::Vector_3&v); + returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending + on the angle formed by the two vectors `u` and `v`. + */ + Angle operator()(const Kernel::Vector_3&u, + const Kernel::Vector_3&v); /*! - returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending - on the angle formed by the three points `p`, `q`, `r` (`q` being the vertex of + returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending + on the angle formed by the three points `p`, `q`, `r` (`q` being the vertex of the angle). The returned value is the same as `operator()(p - q, r - q)`. - */ - Angle operator()(const Kernel::Point_3&p, - const Kernel::Point_3&q, - const Kernel::Point_3&r); + */ + Angle operator()(const Kernel::Point_3&p, + const Kernel::Point_3&q, + const Kernel::Point_3&r); /*! returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending @@ -89,12 +89,12 @@ public: /*! returns \ref CGAL::OBTUSE, \ref CGAL::RIGHT or \ref CGAL::ACUTE depending - on the angle formed by the twonormal vector of the plane `pqr` and `v`. + on the angle formed by the normal of the triangle `pqr` and the vector `v`. */ Angle operator()(const Kernel::Point_3&p, const Kernel::Point_3&q, const Kernel::Point_3&r, - const Kernel::Vector_3&s); + const Kernel::Vector_3&v); /// @} }; /* end Kernel::Angle_3 */ From 6c2ee8a35eaa8d9d0d58a5b9007ca46bb067827d Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 14 Apr 2017 17:42:06 +0200 Subject: [PATCH 10/23] fix the implementation of is_outward_oriented(polygon mesh) this implementation does not require the construction of the normal, and is based only on Kernel predicates --- .../Polygon_mesh_processing/orientation.h | 72 +++++++++++++++---- 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index 4c39e7684b0..75dae3dd8da 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -26,7 +26,6 @@ #include -#include #include #include #include @@ -40,23 +39,28 @@ namespace CGAL { namespace Polygon_mesh_processing { namespace internal{ - template - struct Compare_vertex_points_xyz_3{ - Less_xyz less; + + template + struct Compare_vertex_points_z_3 + { + typename GT::Compare_z_3 compare_z; VPmap vpmap; - Compare_vertex_points_xyz_3(VPmap const& vpmap) - : vpmap(vpmap){} + Compare_vertex_points_z_3(VPmap const& vpmap, const GT& gt) + : vpmap(vpmap) + { + compare_z = gt.compare_z_3_object(); + } typedef bool result_type; template bool operator()(vertex_descriptor v1, vertex_descriptor v2) const { - return less(get(vpmap, v1), get(vpmap, v2)); + return CGAL::SMALLER == compare_z(get(vpmap, v1), get(vpmap, v2)); } - }; + template bool is_outward_oriented(typename boost::graph_traits::vertex_descriptor vd, const PM& pmesh, @@ -117,17 +121,55 @@ bool is_outward_oriented(const PolygonMesh& pmesh, VPMap vpmap = choose_param(get_param(np, vertex_point), get_const_property_map(vertex_point, pmesh)); //Kernel - typedef typename GetGeomTraits::type Kernel; - - internal::Compare_vertex_points_xyz_3 - less_xyz(vpmap); + typedef typename GetGeomTraits::type GT; + GT gt = choose_param(get_param(np, geom_traits), GT()); + //find the vertex with maximal z coordinate typename boost::graph_traits::vertex_iterator vbegin, vend; cpp11::tie(vbegin, vend) = vertices(pmesh); - typename boost::graph_traits::vertex_iterator v_min - = std::min_element(vbegin, vend, less_xyz); - return internal::is_outward_oriented(*v_min, pmesh, np); + internal::Compare_vertex_points_z_3 less_z(vpmap, gt); + typename boost::graph_traits::vertex_iterator v_max_it + = std::max_element(vbegin, vend, less_z); + typename boost::graph_traits::vertex_descriptor v_max = *v_max_it; + + //among the incident edges to v_max, + // find one of the edges e with the minimal slope + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + halfedge_descriptor min_slope_he = halfedge(v_max, pmesh); + CGAL_assertion(v_max == target(min_slope_he, pmesh)); + + typename GT::Compare_slope_3 compare_slope = gt.compare_slope_3_object(); + BOOST_FOREACH(halfedge_descriptor he, halfedges_around_target(v_max, pmesh)) + { + CGAL_assertion(v_max == target(min_slope_he, pmesh)); + CGAL_assertion(v_max == target(he, pmesh)); + if(CGAL::SMALLER == compare_slope(get(vpmap, v_max), + get(vpmap, source(min_slope_he, pmesh)), + get(vpmap, v_max), + get(vpmap, source(he, pmesh)))) + { + min_slope_he = he; + } + } + + //around that edge, there are two faces(because the mesh is without borders), + //take the face f for which the other edge incident to f and v has the minimal slope + //Note we only keep the corresponding halfedge + if(CGAL::SMALLER != compare_slope(get(vpmap, v_max), + get(vpmap, source(min_slope_he, pmesh)), + get(vpmap, v_max), + get(vpmap, source(prev(opposite(min_slope_he, pmesh), pmesh), pmesh)))) + min_slope_he = opposite(min_slope_he, pmesh); + + //check that the normal to f has z > 0 + typename GT::Angle_3 angle_3 = gt.angle_3_object(); + typename GT::Vector_3 vertical(0, 0, 1); + + return CGAL::ACUTE == angle_3(get(vpmap, source(min_slope_he, pmesh)), + get(vpmap, target(min_slope_he, pmesh)), + get(vpmap, target(next(min_slope_he, pmesh), pmesh)), + vertical); } ///\cond SKIP_IN_MANUAL From 57b01e0b8fc2fb138495197ba2decd733e4dbb36 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 18 Apr 2017 10:18:09 +0200 Subject: [PATCH 11/23] make if work also if GT::Compare_z_3 does not have a default constructor (may happen with a geom traits with state) --- .../include/CGAL/Polygon_mesh_processing/orientation.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index 75dae3dd8da..d3af4c491b6 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -48,9 +48,8 @@ namespace internal{ Compare_vertex_points_z_3(VPmap const& vpmap, const GT& gt) : vpmap(vpmap) - { - compare_z = gt.compare_z_3_object(); - } + , compare_z(gt.compare_z_3_object()) + {} typedef bool result_type; template From 49818d56ce746b2b40900cd31b2c61c125a5d9ba Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 18 Apr 2017 10:26:23 +0200 Subject: [PATCH 12/23] add a runtime warning and return true for empty mesh --- .../include/CGAL/Polygon_mesh_processing/orientation.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index d3af4c491b6..676b4ab4359 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -112,6 +112,11 @@ bool is_outward_oriented(const PolygonMesh& pmesh, CGAL_warning(CGAL::is_closed(pmesh)); CGAL_precondition(CGAL::is_valid(pmesh)); + //check for empty pmesh + CGAL_warning(faces(pmesh).first != faces(pmesh).second); + if (faces(pmesh).first == faces(pmesh).second) + return true; + using boost::choose_param; using boost::get_param; From 766ff220b6afb69c6c2269495d8bcca0e86fae43 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 21 Apr 2017 14:59:07 +0200 Subject: [PATCH 13/23] and missing include and fix the use of namespaces --- .../include/CGAL/Polygon_mesh_processing/orientation.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index 676b4ab4359..b581b7fe2d1 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -26,6 +26,7 @@ #include +#include #include #include #include @@ -65,8 +66,8 @@ namespace internal{ const PM& pmesh, const NamedParameters& np) { - const typename Kernel::Vector_3& - normal_v_min = compute_vertex_normal(vd, pmesh, np); + const typename Kernel::Vector_3& normal_v_min + = CGAL::Polygon_mesh_processing::compute_vertex_normal(vd, pmesh, np); return normal_v_min[0] < 0 || ( normal_v_min[0] == 0 && ( From 686b418fe0ce23f6b773bd6f6456d08cf5be79da Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 21 Apr 2017 15:21:12 +0200 Subject: [PATCH 14/23] remove the use of internal::is_outward_oriented --- .../Polygon_mesh_processing/corefinement.h | 7 +++---- .../CGAL/Polygon_mesh_processing/orientation.h | 18 ------------------ 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h index b1e0f2322c2..180f5a3ba34 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h @@ -50,8 +50,8 @@ bool recursive_does_bound_a_volume(const TriangleMesh& tm, typedef Side_of_triangle_mesh Side_of_tm; // first check that the orientation of the current cc is consistant with its // parent cc containing it - bool new_is_parent_outward_oriented = internal::is_outward_oriented( - xtrm_vertices[xtrm_cc_id], tm, parameters::vertex_point_map(vpm)); + bool new_is_parent_outward_oriented = + is_outward_oriented(tm, parameters::vertex_point_map(vpm)); if (new_is_parent_outward_oriented==is_parent_outward_oriented) return false; cc_handled.set(xtrm_cc_id); @@ -200,8 +200,7 @@ bool does_bound_a_volume(const TriangleMesh& tm, const NamedParameters& np) if (get(vpm, xtrm_vertices[id])(xtrm_vertices[xtrm_cc_id], tm, np); + bool is_parent_outward_oriented = is_outward_oriented(tm, np); return internal::recursive_does_bound_a_volume(tm, vpm, fid_map, xtrm_vertices, diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index b581b7fe2d1..c6a30ada633 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -26,7 +26,6 @@ #include -#include #include #include #include @@ -59,23 +58,6 @@ namespace internal{ return CGAL::SMALLER == compare_z(get(vpmap, v1), get(vpmap, v2)); } }; - - - template - bool is_outward_oriented(typename boost::graph_traits::vertex_descriptor vd, - const PM& pmesh, - const NamedParameters& np) - { - const typename Kernel::Vector_3& normal_v_min - = CGAL::Polygon_mesh_processing::compute_vertex_normal(vd, pmesh, np); - - return normal_v_min[0] < 0 || ( - normal_v_min[0] == 0 && ( - normal_v_min[1] < 0 || - ( normal_v_min[1]==0 && normal_v_min[2] < 0 ) - ) - ); - } } // end of namespace internal /** From 1e22c09969396fd9cfa4d4a9819f6757c8dc348b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 24 Apr 2017 09:48:09 +0200 Subject: [PATCH 15/23] fix warning --- .../include/CGAL/Polygon_mesh_processing/orientation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index c6a30ada633..15acc22b358 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -43,8 +43,8 @@ namespace internal{ template struct Compare_vertex_points_z_3 { - typename GT::Compare_z_3 compare_z; VPmap vpmap; + typename GT::Compare_z_3 compare_z; Compare_vertex_points_z_3(VPmap const& vpmap, const GT& gt) : vpmap(vpmap) From 1a29f743254cf2f9d787f4e1cdbdedf41b009ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 24 Apr 2017 10:21:32 +0200 Subject: [PATCH 16/23] Revert "remove the use of internal::is_outward_oriented" This reverts commit 37c5b0bd4e6d550c86bf7f173eaa4bfc1fa5bf6f. --- .../Polygon_mesh_processing/corefinement.h | 7 ++++--- .../CGAL/Polygon_mesh_processing/orientation.h | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h index 180f5a3ba34..b1e0f2322c2 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h @@ -50,8 +50,8 @@ bool recursive_does_bound_a_volume(const TriangleMesh& tm, typedef Side_of_triangle_mesh Side_of_tm; // first check that the orientation of the current cc is consistant with its // parent cc containing it - bool new_is_parent_outward_oriented = - is_outward_oriented(tm, parameters::vertex_point_map(vpm)); + bool new_is_parent_outward_oriented = internal::is_outward_oriented( + xtrm_vertices[xtrm_cc_id], tm, parameters::vertex_point_map(vpm)); if (new_is_parent_outward_oriented==is_parent_outward_oriented) return false; cc_handled.set(xtrm_cc_id); @@ -200,7 +200,8 @@ bool does_bound_a_volume(const TriangleMesh& tm, const NamedParameters& np) if (get(vpm, xtrm_vertices[id])(xtrm_vertices[xtrm_cc_id], tm, np); return internal::recursive_does_bound_a_volume(tm, vpm, fid_map, xtrm_vertices, diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index 15acc22b358..b659b8b5226 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -26,6 +26,7 @@ #include +#include #include #include #include @@ -58,6 +59,23 @@ namespace internal{ return CGAL::SMALLER == compare_z(get(vpmap, v1), get(vpmap, v2)); } }; + + + template + bool is_outward_oriented(typename boost::graph_traits::vertex_descriptor vd, + const PM& pmesh, + const NamedParameters& np) + { + const typename Kernel::Vector_3& normal_v_min + = CGAL::Polygon_mesh_processing::compute_vertex_normal(vd, pmesh, np); + + return normal_v_min[0] < 0 || ( + normal_v_min[0] == 0 && ( + normal_v_min[1] < 0 || + ( normal_v_min[1]==0 && normal_v_min[2] < 0 ) + ) + ); + } } // end of namespace internal /** From 8af0216b54b4443999e86a4e0af664820db4fafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 24 Apr 2017 17:17:09 +0200 Subject: [PATCH 17/23] update internal use of is_outward_oriented() by does_bound_a_volume() --- .../Polygon_mesh_processing/corefinement.h | 22 ++--- .../Polygon_mesh_processing/orientation.h | 99 ++++++++++--------- 2 files changed, 62 insertions(+), 59 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h index b1e0f2322c2..87617cdca5e 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/corefinement.h @@ -50,7 +50,7 @@ bool recursive_does_bound_a_volume(const TriangleMesh& tm, typedef Side_of_triangle_mesh Side_of_tm; // first check that the orientation of the current cc is consistant with its // parent cc containing it - bool new_is_parent_outward_oriented = internal::is_outward_oriented( + bool new_is_parent_outward_oriented = internal::is_outward_oriented( xtrm_vertices[xtrm_cc_id], tm, parameters::vertex_point_map(vpm)); if (new_is_parent_outward_oriented==is_parent_outward_oriented) return false; @@ -91,8 +91,8 @@ bool recursive_does_bound_a_volume(const TriangleMesh& tm, for (std::size_t i=1;i + get(vpm,xtrm_vertices[new_xtrm_cc_id]).z()) new_xtrm_cc_id=candidate; new_cc_handled.reset(candidate); cc_handled.set(candidate); } @@ -111,7 +111,7 @@ bool recursive_does_bound_a_volume(const TriangleMesh& tm, candidate < cc_not_handled.npos; candidate = cc_not_handled.find_next(candidate)) { - if(get(vpm,xtrm_vertices[candidate]) < get(vpm,xtrm_vertices[new_xtrm_cc_id])) + if(get(vpm,xtrm_vertices[candidate]).z() > get(vpm,xtrm_vertices[new_xtrm_cc_id]).z()) new_xtrm_cc_id = candidate; } @@ -129,7 +129,7 @@ bool recursive_does_bound_a_volume(const TriangleMesh& tm, * * @tparam TriangleMesh a model of `MutableFaceGraph`, `HalfedgeListGraph` and `FaceListGraph`. * If `TriangleMesh` has an internal property map for `CGAL::face_index_t`, - * as a named parameter, then it must initialized. + * as a named parameter, then it must be initialized. * @tparam NamedParameters a sequence of \ref namedparameters * * @param tm a triangulated surface mesh @@ -182,7 +182,7 @@ bool does_bound_a_volume(const TriangleMesh& tm, const NamedParameters& np) boost::dynamic_bitset<> cc_handled(nb_cc, 0); - // extract the less-xyz vertex of each connected component + // extract a vertex with max z coordinate for each connected component std::vector xtrm_vertices(nb_cc, GT::null_vertex()); BOOST_FOREACH(vertex_descriptor vd, vertices(tm)) { @@ -190,18 +190,18 @@ bool does_bound_a_volume(const TriangleMesh& tm, const NamedParameters& np) if (xtrm_vertices[cc_id]==GT::null_vertex()) xtrm_vertices[cc_id]=vd; else - if (get(vpm, vd)get(vpm,xtrm_vertices[cc_id]).z()) xtrm_vertices[cc_id]=vd; } - //extract the less-xyz of all components + //extract a vertex with max z amongst all components std::size_t xtrm_cc_id=0; for(std::size_t id=1; idget(vpm,xtrm_vertices[xtrm_cc_id]).z()) xtrm_cc_id=id; bool is_parent_outward_oriented = - !internal::is_outward_oriented(xtrm_vertices[xtrm_cc_id], tm, np); + !internal::is_outward_oriented(xtrm_vertices[xtrm_cc_id], tm, np); return internal::recursive_does_bound_a_volume(tm, vpm, fid_map, xtrm_vertices, @@ -433,7 +433,7 @@ boolean_operation( TriangleMesh& tm1, * * @tparam TriangleMesh a model of `MutableFaceGraph`, `HalfedgeListGraph` and `FaceListGraph`. * If `TriangleMesh` has an internal property map for `CGAL::face_index_t`, - * as a named parameter, then it must initialized. + * as a named parameter, then it must be initialized. * * @tparam NamedParameters1 a sequence of \ref namedparameters * @tparam NamedParameters2 a sequence of \ref namedparameters diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index b659b8b5226..660e4d0e211 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -61,20 +61,59 @@ namespace internal{ }; - template - bool is_outward_oriented(typename boost::graph_traits::vertex_descriptor vd, - const PM& pmesh, + template + bool is_outward_oriented(typename boost::graph_traits::vertex_descriptor v_max, + const PolygonMesh& pmesh, const NamedParameters& np) { - const typename Kernel::Vector_3& normal_v_min - = CGAL::Polygon_mesh_processing::compute_vertex_normal(vd, pmesh, np); + using boost::choose_param; + using boost::get_param; - return normal_v_min[0] < 0 || ( - normal_v_min[0] == 0 && ( - normal_v_min[1] < 0 || - ( normal_v_min[1]==0 && normal_v_min[2] < 0 ) - ) - ); + //VertexPointMap + typedef typename GetVertexPointMap::const_type VPMap; + VPMap vpmap = choose_param(get_param(np, vertex_point), + get_const_property_map(vertex_point, pmesh)); + //Kernel + typedef typename GetGeomTraits::type GT; + GT gt = choose_param(get_param(np, geom_traits), GT()); + + //among the incident edges to v_max, + // find one of the edges e with the minimal slope + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + halfedge_descriptor min_slope_he = halfedge(v_max, pmesh); + CGAL_assertion(v_max == target(min_slope_he, pmesh)); + + typename GT::Compare_slope_3 compare_slope = gt.compare_slope_3_object(); + BOOST_FOREACH(halfedge_descriptor he, halfedges_around_target(v_max, pmesh)) + { + CGAL_assertion(v_max == target(min_slope_he, pmesh)); + CGAL_assertion(v_max == target(he, pmesh)); + if(CGAL::SMALLER == compare_slope(get(vpmap, v_max), + get(vpmap, source(min_slope_he, pmesh)), + get(vpmap, v_max), + get(vpmap, source(he, pmesh)))) + { + min_slope_he = he; + } + } + + //around that edge, there are two faces(because the mesh is without borders), + //take the face f for which the other edge incident to f and v has the minimal slope + //Note we only keep the corresponding halfedge + if(CGAL::SMALLER != compare_slope(get(vpmap, v_max), + get(vpmap, source(min_slope_he, pmesh)), + get(vpmap, v_max), + get(vpmap, source(prev(opposite(min_slope_he, pmesh), pmesh), pmesh)))) + min_slope_he = opposite(min_slope_he, pmesh); + + //check that the normal to f has z > 0 + typename GT::Angle_3 angle_3 = gt.angle_3_object(); + typename GT::Vector_3 vertical(0, 0, 1); + + return CGAL::ACUTE == angle_3(get(vpmap, source(min_slope_he, pmesh)), + get(vpmap, target(min_slope_he, pmesh)), + get(vpmap, target(next(min_slope_he, pmesh), pmesh)), + vertical); } } // end of namespace internal @@ -138,43 +177,7 @@ bool is_outward_oriented(const PolygonMesh& pmesh, = std::max_element(vbegin, vend, less_z); typename boost::graph_traits::vertex_descriptor v_max = *v_max_it; - //among the incident edges to v_max, - // find one of the edges e with the minimal slope - typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - halfedge_descriptor min_slope_he = halfedge(v_max, pmesh); - CGAL_assertion(v_max == target(min_slope_he, pmesh)); - - typename GT::Compare_slope_3 compare_slope = gt.compare_slope_3_object(); - BOOST_FOREACH(halfedge_descriptor he, halfedges_around_target(v_max, pmesh)) - { - CGAL_assertion(v_max == target(min_slope_he, pmesh)); - CGAL_assertion(v_max == target(he, pmesh)); - if(CGAL::SMALLER == compare_slope(get(vpmap, v_max), - get(vpmap, source(min_slope_he, pmesh)), - get(vpmap, v_max), - get(vpmap, source(he, pmesh)))) - { - min_slope_he = he; - } - } - - //around that edge, there are two faces(because the mesh is without borders), - //take the face f for which the other edge incident to f and v has the minimal slope - //Note we only keep the corresponding halfedge - if(CGAL::SMALLER != compare_slope(get(vpmap, v_max), - get(vpmap, source(min_slope_he, pmesh)), - get(vpmap, v_max), - get(vpmap, source(prev(opposite(min_slope_he, pmesh), pmesh), pmesh)))) - min_slope_he = opposite(min_slope_he, pmesh); - - //check that the normal to f has z > 0 - typename GT::Angle_3 angle_3 = gt.angle_3_object(); - typename GT::Vector_3 vertical(0, 0, 1); - - return CGAL::ACUTE == angle_3(get(vpmap, source(min_slope_he, pmesh)), - get(vpmap, target(min_slope_he, pmesh)), - get(vpmap, target(next(min_slope_he, pmesh), pmesh)), - vertical); + return internal::is_outward_oriented(v_max, pmesh, np); } ///\cond SKIP_IN_MANUAL From 976ba8b75a72e8250c030ded3abc659b10f4b0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 24 Apr 2017 18:32:40 +0200 Subject: [PATCH 18/23] fix the outward orientation test --- .../Polygon_mesh_processing/orientation.h | 29 +++++++++---------- .../orient_polygon_mesh_test.cpp | 1 + 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index 660e4d0e211..b045a59820b 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -77,8 +77,7 @@ namespace internal{ typedef typename GetGeomTraits::type GT; GT gt = choose_param(get_param(np, geom_traits), GT()); - //among the incident edges to v_max, - // find one of the edges e with the minimal slope + //among the incoming edges of `v_max`, find one edge `e` with the minimal slope typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; halfedge_descriptor min_slope_he = halfedge(v_max, pmesh); CGAL_assertion(v_max == target(min_slope_he, pmesh)); @@ -88,27 +87,27 @@ namespace internal{ { CGAL_assertion(v_max == target(min_slope_he, pmesh)); CGAL_assertion(v_max == target(he, pmesh)); - if(CGAL::SMALLER == compare_slope(get(vpmap, v_max), - get(vpmap, source(min_slope_he, pmesh)), - get(vpmap, v_max), - get(vpmap, source(he, pmesh)))) + if(CGAL::SMALLER == compare_slope(get(vpmap, source(he, pmesh)), + get(vpmap, v_max), + get(vpmap, source(min_slope_he, pmesh)), + get(vpmap, v_max))) { min_slope_he = he; } } - - //around that edge, there are two faces(because the mesh is without borders), - //take the face f for which the other edge incident to f and v has the minimal slope - //Note we only keep the corresponding halfedge - if(CGAL::SMALLER != compare_slope(get(vpmap, v_max), - get(vpmap, source(min_slope_he, pmesh)), - get(vpmap, v_max), - get(vpmap, source(prev(opposite(min_slope_he, pmesh), pmesh), pmesh)))) + // There are two faces around `e` (because the mesh is without borders). + // Select the halfedge of `e` contributing to the face `f`, such the another incoming edge of `v_max` + // that is incident to `f` has the minimal slope + if(CGAL::SMALLER != compare_slope(get(vpmap, target(next(min_slope_he, pmesh), pmesh)), + get(vpmap, v_max), + get(vpmap, source(prev(opposite(min_slope_he, pmesh), pmesh), pmesh)), + get(vpmap, v_max))) min_slope_he = opposite(min_slope_he, pmesh); //check that the normal to f has z > 0 typename GT::Angle_3 angle_3 = gt.angle_3_object(); - typename GT::Vector_3 vertical(0, 0, 1); + typename GT::Construct_vector_3 vector_3= gt.construct_vector_3_object(); + typename GT::Vector_3 vertical = vector_3(0, 0, 1); return CGAL::ACUTE == angle_3(get(vpmap, source(min_slope_he, pmesh)), get(vpmap, target(min_slope_he, pmesh)), diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp index a7718e6562d..6344e8bd114 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp @@ -61,6 +61,7 @@ int main() { test_orient("data/elephant.off"); + test_orient("data-coref/cube.off"); test_orient("data/elephant.off"); std::cerr << "All done." << std::endl; From 51dce78e78b11bcb8acb54e07b67a56785bd35d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 25 Apr 2017 11:28:52 +0200 Subject: [PATCH 19/23] fix the last step of the algorithm to pick the top face along the z-axis --- .../Polygon_mesh_processing/orientation.h | 49 +++++++++++++------ .../Polygon_mesh_processing/data/tetra1.off | 12 +++++ .../Polygon_mesh_processing/data/tetra2.off | 12 +++++ .../Polygon_mesh_processing/data/tetra3.off | 12 +++++ .../orient_polygon_mesh_test.cpp | 4 ++ 5 files changed, 73 insertions(+), 16 deletions(-) create mode 100644 Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra1.off create mode 100644 Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra2.off create mode 100644 Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra3.off diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index b045a59820b..7aef437007a 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -87,6 +88,7 @@ namespace internal{ { CGAL_assertion(v_max == target(min_slope_he, pmesh)); CGAL_assertion(v_max == target(he, pmesh)); + if(CGAL::SMALLER == compare_slope(get(vpmap, source(he, pmesh)), get(vpmap, v_max), get(vpmap, source(min_slope_he, pmesh)), @@ -95,24 +97,39 @@ namespace internal{ min_slope_he = he; } } - // There are two faces around `e` (because the mesh is without borders). - // Select the halfedge of `e` contributing to the face `f`, such the another incoming edge of `v_max` - // that is incident to `f` has the minimal slope - if(CGAL::SMALLER != compare_slope(get(vpmap, target(next(min_slope_he, pmesh), pmesh)), - get(vpmap, v_max), - get(vpmap, source(prev(opposite(min_slope_he, pmesh), pmesh), pmesh)), - get(vpmap, v_max))) - min_slope_he = opposite(min_slope_he, pmesh); - //check that the normal to f has z > 0 - typename GT::Angle_3 angle_3 = gt.angle_3_object(); - typename GT::Construct_vector_3 vector_3= gt.construct_vector_3_object(); - typename GT::Vector_3 vertical = vector_3(0, 0, 1); + // We compute the orientations of the two triangles incident to the edge + // of `min_slope_he` projected in the xy-plane. We can conclude using + // the 2D orientation of the 3D triangle that is the top one along the z-axis + // the neighborhood of `min_slope_he`. + Projection_traits_xy_3 p_gt; + typename Projection_traits_xy_3::Orientation_2 orientation_2 = p_gt.orientation_2_object(); - return CGAL::ACUTE == angle_3(get(vpmap, source(min_slope_he, pmesh)), - get(vpmap, target(min_slope_he, pmesh)), - get(vpmap, target(next(min_slope_he, pmesh), pmesh)), - vertical); + typename boost::property_traits::reference p1 = get(vpmap, source(min_slope_he, pmesh)); + typename boost::property_traits::reference p2 = get(vpmap, target(min_slope_he, pmesh)); + typename boost::property_traits::reference p3 = get(vpmap, target(next(min_slope_he, pmesh), pmesh)); + typename boost::property_traits::reference p4 = get(vpmap, target(next(opposite(min_slope_he, pmesh), pmesh), pmesh)); + + Orientation p1p2p3_2d = orientation_2(p1, p2, p3); + Orientation p2p1p4_2d = orientation_2(p2, p1, p4); + + CGAL_assertion( p1p2p3_2d!=COLLINEAR || p2p1p4_2d!=COLLINEAR ); // no self-intersection + + if ( p1p2p3_2d == COLLINEAR) + return p2p1p4_2d == LEFT_TURN; + if (p2p1p4_2d ==COLLINEAR) + return p1p2p3_2d == LEFT_TURN; + + // if the local dihedral angle is strictly larger that PI/2, we can conclude with any of two triangles + if (p1p2p3_2d==p2p1p4_2d) + return p1p2p3_2d == LEFT_TURN; + + typename GT::Orientation_3 orientation_3 = gt.orientation_3_object(); + Orientation p1p2p3p4 = orientation_3(p1, p2, p3, p4); + + CGAL_assertion( p1p2p3p4 != COPLANAR ); // same side of min_slope_he and no self-intersection + + return (p1p2p3_2d == LEFT_TURN) == (p1p2p3p4 == POSITIVE); } } // end of namespace internal diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra1.off b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra1.off new file mode 100644 index 00000000000..ebb37d3fd94 --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra1.off @@ -0,0 +1,12 @@ +OFF +4 4 0 + +0 0 0 +0.65000000000000002 -1.3 0.65000000000000002 +0.10000000000000001 -1 1 +2 -2 -0.5 +3 2 1 0 +3 1 3 0 +3 3 2 0 +3 3 1 2 + diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra2.off b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra2.off new file mode 100644 index 00000000000..0d18f67fd1d --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra2.off @@ -0,0 +1,12 @@ +OFF +4 4 0 + +0 0 0 +0.65000000000000002 -1.3 0.65000000000000002 +0.10000000000000001 -1 1 +-0.33420955685098419 -0.59067608503190883 0.55877066363146466 +3 2 1 0 +3 1 3 0 +3 3 2 0 +3 3 1 2 + diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra3.off b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra3.off new file mode 100644 index 00000000000..d83aa004308 --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra3.off @@ -0,0 +1,12 @@ +OFF +4 4 0 + +0 1 0 +1 0 0 +0 0 0 +0 0 1 +3 0 1 2 +3 2 3 0 +3 1 3 2 +3 0 3 1 + diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp index 6344e8bd114..3c036708045 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp @@ -62,6 +62,10 @@ int main() test_orient("data/elephant.off"); test_orient("data-coref/cube.off"); + test_orient("data/tetra1.off"); + test_orient("data/tetra2.off"); + test_orient("data/tetra3.off"); + test_orient("data-coref/cube.off"); test_orient("data/elephant.off"); std::cerr << "All done." << std::endl; From d4fa3c860ce9afba9b7575b85b247ba0816b2e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 4 May 2017 10:18:34 +0200 Subject: [PATCH 20/23] fix test incorrectly simplified test --- .../CGAL/Polygon_mesh_processing/orientation.h | 13 +++++++++---- .../test/Polygon_mesh_processing/data/tetra4.off | 12 ++++++++++++ .../orient_polygon_mesh_test.cpp | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra4.off diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h index 7aef437007a..f229d629972 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/orientation.h @@ -101,7 +101,7 @@ namespace internal{ // We compute the orientations of the two triangles incident to the edge // of `min_slope_he` projected in the xy-plane. We can conclude using // the 2D orientation of the 3D triangle that is the top one along the z-axis - // the neighborhood of `min_slope_he`. + // in the neighborhood of `min_slope_he`. Projection_traits_xy_3 p_gt; typename Projection_traits_xy_3::Orientation_2 orientation_2 = p_gt.orientation_2_object(); @@ -125,11 +125,16 @@ namespace internal{ return p1p2p3_2d == LEFT_TURN; typename GT::Orientation_3 orientation_3 = gt.orientation_3_object(); - Orientation p1p2p3p4 = orientation_3(p1, p2, p3, p4); - CGAL_assertion( p1p2p3p4 != COPLANAR ); // same side of min_slope_he and no self-intersection + CGAL_assertion( orientation_3(p1, p2, p3, p4) != COPLANAR ); // same side of min_slope_he and no self-intersection - return (p1p2p3_2d == LEFT_TURN) == (p1p2p3p4 == POSITIVE); + // if p1p2p3_2d is left turn, then it must be the top face so that the orientation is outward oriented + if (p1p2p3_2d == LEFT_TURN) + return orientation_3(p1, p2, p3, p4) == NEGATIVE; + + // same test with the other face + CGAL_assertion(p2p1p4_2d == LEFT_TURN); + return orientation_3(p2, p1, p4, p3) == NEGATIVE; } } // end of namespace internal diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra4.off b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra4.off new file mode 100644 index 00000000000..f0994dbb579 --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/data/tetra4.off @@ -0,0 +1,12 @@ +OFF +4 4 0 + +0 0 1 +0 1 0.8 +-1 1 0.9 +1 0 0.5 + +3 0 1 2 +3 0 2 3 +3 0 3 1 +3 1 3 2 diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp index 3c036708045..05638068954 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/orient_polygon_mesh_test.cpp @@ -65,6 +65,7 @@ int main() test_orient("data/tetra1.off"); test_orient("data/tetra2.off"); test_orient("data/tetra3.off"); + test_orient("data/tetra4.off"); test_orient("data-coref/cube.off"); test_orient("data/elephant.off"); From ed704ea0f3038f0fb747b193130245275f881148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 12 May 2017 10:02:08 +0200 Subject: [PATCH 21/23] protect deprecated code with deprecation macro --- Kernel_23/include/CGAL/Kernel/global_functions_2.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_2.h index da5a45adde6..cfd460bfc0a 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -355,6 +355,8 @@ compare_slope(const Segment_2 &s1, const Segment_2 &s2) return internal::compare_slope(s1, s2, K()); } + +#ifndef CGAL_NO_DEPRECATED_CODE // kept for backward compatibility template < class K > inline @@ -372,6 +374,7 @@ compare_slopes(const Segment_2 &s1, const Segment_2 &s2) { return internal::compare_slope(s1, s2, K()); } +#endif template < class K > inline From 9188647856b9282144a07c681353065424219ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 12 May 2017 10:07:36 +0200 Subject: [PATCH 22/23] mention the deprecation of compare_slopes --- Installation/changes.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Installation/changes.html b/Installation/changes.html index 8b4d20b7df4..1d423183635 100644 --- a/Installation/changes.html +++ b/Installation/changes.html @@ -205,6 +205,8 @@ and src/ directories).

    2D and 3D Linear Geometry Kernel

      +
    • Breaking change: The function compare_slopes() was renamed compare_slope. +
    • Added a 2D and 3D weighted point class and predicates and constructions.
    • From 05fcab830eda934cc7b73688b8b5925dd5ca8b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 15 May 2017 10:09:19 +0200 Subject: [PATCH 23/23] Add deprecation message --- Kernel_23/include/CGAL/Kernel/global_functions_2.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_2.h index cfd460bfc0a..acdd7f9cfa6 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -359,6 +359,7 @@ compare_slope(const Segment_2 &s1, const Segment_2 &s2) #ifndef CGAL_NO_DEPRECATED_CODE // kept for backward compatibility template < class K > +CGAL_DEPRECATED_MSG("This function is deprecated. CGAL::compare_slope() should be used instead") inline typename K::Comparison_result compare_slopes(const Line_2 &l1, const Line_2 &l2) @@ -368,6 +369,7 @@ compare_slopes(const Line_2 &l1, const Line_2 &l2) // kept for backward compatibility template < class K > +CGAL_DEPRECATED_MSG("This function is deprecated. CGAL::compare_slope() should be used instead") inline typename K::Comparison_result compare_slopes(const Segment_2 &s1, const Segment_2 &s2)