From c58582b5ec81a640f347528c185b32e18a5993a7 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 27 Sep 2016 14:05:10 +0200 Subject: [PATCH] Add global function dihedral_angle() --- .../Kernel_23/CGAL/Kernel/global_functions.h | 9 +++++ .../include/CGAL/Kernel/function_objects.h | 37 +++++++++++++++++++ .../include/CGAL/Kernel/global_functions_3.h | 11 ++++++ .../CGAL/Kernel/global_functions_internal_3.h | 11 ++++++ .../include/CGAL/Kernel/interface_macros.h | 2 + .../include/CGAL/Mesh_3/min_dihedral_angle.h | 1 - .../Hole_filling/Triangulate_hole_polyline.h | 5 +-- ...cale_space_surface_reconstruction_3_impl.h | 9 ++--- .../Surface_mesh_segmentation.h | 4 +- 9 files changed, 77 insertions(+), 12 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 451ea6f1cf5..af5e70f0558 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -1690,6 +1690,15 @@ const CGAL::Vector_3& v, const CGAL::Vector_3& w); /// @} +/*! +returns the dihedral angle of .... between `-180` and `180` degree. +*/ +template +Kernel::FT dihedral_angle(const CGAL::Point_3& p, + const CGAL::Point_3& q, + const CGAL::Point_3& r, + const CGAL::Point_3& s); + // This is there to keep the global functions in alphabetical order // instead of processing order. diff --git a/Kernel_23/include/CGAL/Kernel/function_objects.h b/Kernel_23/include/CGAL/Kernel/function_objects.h index 64c60433476..36f9936703d 100644 --- a/Kernel_23/include/CGAL/Kernel/function_objects.h +++ b/Kernel_23/include/CGAL/Kernel/function_objects.h @@ -35,6 +35,8 @@ #include #include +#include // for Compute_dihedral_angle + namespace CGAL { namespace CommonKernelFunctors { @@ -361,6 +363,41 @@ namespace CommonKernelFunctors { } }; + template + class Compute_dihedral_angle_3 + { + typedef typename K::Point_3 Point_3; + public: + typedef typename K::FT result_type; + + result_type + operator()(const Point_3& a, const Point_3& b, const Point_3& c, const Point_3& d) const + { + K k; + 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(); + typename K::Compute_squared_distance_3 sq_distance = + k.compute_squared_distance_3_object(); + typename K::Compute_scalar_product_3 scalar_product = + k.compute_scalar_product_3_object(); + + typedef typename K::Vector_3 Vector_3; + typedef typename K::FT FT; + + const Vector_3 ab = vector(a,b); + const Vector_3 ac = vector(a,c); + const Vector_3 ad = vector(a,d); + + const Vector_3 abad = cross_product(ab,ad); + const double x = CGAL::to_double(scalar_product(cross_product(ab,ac), abad)); + const double l_ab = CGAL::sqrt(CGAL::to_double(sq_distance(a,b))); + const double y = l_ab * CGAL::to_double(scalar_product(ac,abad)); + + return FT(std::atan2(y, x) * 180 / CGAL_PI ); + } + }; + template class Compute_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 0a68e07d313..7fde519b63f 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_3.h @@ -516,6 +516,17 @@ determinant(const Vector_3 &v0, const Vector_3 &v1, return internal::determinant(v0, v1, v2, K()); } +template < class K > +inline +typename K::FT +dihedral_angle(const Point_3 &p, + const Point_3 &q, + const Point_3 &r, + const Point_3 &s) +{ + return internal::dihedral_angle(p, q, r, s, K()); +} + template < class K > inline typename K::Line_3 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 280dc072730..0e5b013430a 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h @@ -591,6 +591,17 @@ determinant(const typename K::Vector_3 &v0, return k.compute_determinant_3_object()(v0, v1, v2); } +template < class K > +inline +typename K::FT +dihedral_angle(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.compute_dihedral_angle_3_object()(p, q, r, s); +} + template < class K > inline typename K::Line_3 diff --git a/Kernel_23/include/CGAL/Kernel/interface_macros.h b/Kernel_23/include/CGAL/Kernel/interface_macros.h index e4769ba252c..164a4ee3e82 100644 --- a/Kernel_23/include/CGAL/Kernel/interface_macros.h +++ b/Kernel_23/include/CGAL/Kernel/interface_macros.h @@ -176,6 +176,8 @@ CGAL_Kernel_cons(Compute_determinant_2, compute_determinant_2_object) CGAL_Kernel_cons(Compute_determinant_3, compute_determinant_3_object) +CGAL_Kernel_cons(Compute_dihedral_angle_3, + compute_dihedral_angle_3_object) CGAL_Kernel_cons(Compute_scalar_product_2, compute_scalar_product_2_object) CGAL_Kernel_cons(Compute_scalar_product_3, diff --git a/Mesh_3/include/CGAL/Mesh_3/min_dihedral_angle.h b/Mesh_3/include/CGAL/Mesh_3/min_dihedral_angle.h index 827429ca4e1..8770bd2ba8c 100644 --- a/Mesh_3/include/CGAL/Mesh_3/min_dihedral_angle.h +++ b/Mesh_3/include/CGAL/Mesh_3/min_dihedral_angle.h @@ -21,7 +21,6 @@ #ifndef CGAL_MESH_3_MIN_DIHEDRAL_ANGLE_H #define CGAL_MESH_3_MIN_DIHEDRAL_ANGLE_H -#include #include namespace CGAL { diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Hole_filling/Triangulate_hole_polyline.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Hole_filling/Triangulate_hole_polyline.h index f19ff5a72a3..6cd8dfb5ff9 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Hole_filling/Triangulate_hole_polyline.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Hole_filling/Triangulate_hole_polyline.h @@ -21,7 +21,6 @@ #ifndef CGAL_HOLE_FILLING_TRIANGULATE_HOLE_POLYLINE_H #define CGAL_HOLE_FILLING_TRIANGULATE_HOLE_POLYLINE_H -#include #include #include #include @@ -249,14 +248,14 @@ private: // check whether the edge is border if( (v0 + 1 == v1 || (v0 == n-1 && v1 == 0) ) && !Q.empty() ) { angle = 180 - CGAL::abs( - to_double(CGAL::Mesh_3::dihedral_angle(P[v0],P[v1],P[v_other],Q[v0])) ); + to_double(CGAL::dihedral_angle(P[v0],P[v1],P[v_other],Q[v0])) ); } else { if(e == 2) { continue; } if(lambda.get(v0, v1) != -1){ const Point_3& p01 = P[lambda.get(v0, v1)]; angle = 180 - CGAL::abs( - to_double(CGAL::Mesh_3::dihedral_angle(P[v0],P[v1],P[v_other],p01)) ); + to_double(CGAL::dihedral_angle(P[v0],P[v1],P[v_other],p01)) ); } } ang_max = (std::max)(ang_max, angle); diff --git a/Scale_space_reconstruction_3/include/CGAL/Scale_space_reconstruction_3/Scale_space_surface_reconstruction_3_impl.h b/Scale_space_reconstruction_3/include/CGAL/Scale_space_reconstruction_3/Scale_space_surface_reconstruction_3_impl.h index 8d9c7aaf14c..c9294946c15 100644 --- a/Scale_space_reconstruction_3/include/CGAL/Scale_space_reconstruction_3/Scale_space_surface_reconstruction_3_impl.h +++ b/Scale_space_reconstruction_3/include/CGAL/Scale_space_reconstruction_3/Scale_space_surface_reconstruction_3_impl.h @@ -31,7 +31,6 @@ #include #include -#include namespace CGAL { @@ -753,10 +752,10 @@ detect_bubbles(FT border_angle) { || _shape->classify (f1) != Shape::REGULAR) continue; - double angle = CGAL::Mesh_3::dihedral_angle (vedge.first->point (), - vedge.second->point (), - c->vertex (i)->point (), - c->vertex ((i + (j+2)%3 + 1)%4)->point ()); + double angle = CGAL::dihedral_angle (vedge.first->point (), + vedge.second->point (), + c->vertex (i)->point (), + c->vertex ((i + (j+2)%3 + 1)%4)->point ()); if (-border_angle < angle && angle < border_angle) { diff --git a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Surface_mesh_segmentation.h b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Surface_mesh_segmentation.h index b6273d49922..4faee3c8936 100644 --- a/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Surface_mesh_segmentation.h +++ b/Surface_mesh_segmentation/include/CGAL/internal/Surface_mesh_segmentation/Surface_mesh_segmentation.h @@ -21,8 +21,6 @@ #include #include -#include - #include #include @@ -326,7 +324,7 @@ private: // As far as I check: if, say, dihedral angle is 5, this returns 175, // if dihedral angle is -5, this returns -175. // Another words this function returns angle between planes. - double n_angle = to_double( ::CGAL::Mesh_3::dihedral_angle(a, b, c, d) ); + double n_angle = to_double( ::CGAL::dihedral_angle(a, b, c, d) ); n_angle /= 180.0; bool concave = n_angle > 0; double angle = 1 + ((concave ? -1 : +1) * n_angle);