Add global function dihedral_angle()

This commit is contained in:
Andreas Fabri 2016-09-27 14:05:10 +02:00 committed by Laurent Rineau
parent 367da380f1
commit c58582b5ec
9 changed files with 77 additions and 12 deletions

View File

@ -1690,6 +1690,15 @@ const CGAL::Vector_3<Kernel>& v,
const CGAL::Vector_3<Kernel>& w);
/// @}
/*!
returns the dihedral angle of .... between `-180` and `180` degree.
*/
template <typename Kernel>
Kernel::FT dihedral_angle(const CGAL::Point_3<Kernel>& p,
const CGAL::Point_3<Kernel>& q,
const CGAL::Point_3<Kernel>& r,
const CGAL::Point_3<Kernel>& s);
// This is there to keep the global functions in alphabetical order
// instead of processing order.

View File

@ -35,6 +35,8 @@
#include <CGAL/Kernel/Return_base_tag.h>
#include <CGAL/Kernel/global_functions_3.h>
#include <cmath> // for Compute_dihedral_angle
namespace CGAL {
namespace CommonKernelFunctors {
@ -361,6 +363,41 @@ namespace CommonKernelFunctors {
}
};
template <typename K>
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 <typename K>
class Compute_squared_distance_2
{

View File

@ -516,6 +516,17 @@ determinant(const Vector_3<K> &v0, const Vector_3<K> &v1,
return internal::determinant(v0, v1, v2, K());
}
template < class K >
inline
typename K::FT
dihedral_angle(const Point_3<K> &p,
const Point_3<K> &q,
const Point_3<K> &r,
const Point_3<K> &s)
{
return internal::dihedral_angle(p, q, r, s, K());
}
template < class K >
inline
typename K::Line_3

View File

@ -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

View File

@ -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,

View File

@ -21,7 +21,6 @@
#ifndef CGAL_MESH_3_MIN_DIHEDRAL_ANGLE_H
#define CGAL_MESH_3_MIN_DIHEDRAL_ANGLE_H
#include <CGAL/Mesh_3/dihedral_angle_3.h>
#include <cmath>
namespace CGAL {

View File

@ -21,7 +21,6 @@
#ifndef CGAL_HOLE_FILLING_TRIANGULATE_HOLE_POLYLINE_H
#define CGAL_HOLE_FILLING_TRIANGULATE_HOLE_POLYLINE_H
#include <CGAL/Mesh_3/dihedral_angle_3.h>
#include <CGAL/value_type_traits.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_3.h>
@ -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);

View File

@ -31,7 +31,6 @@
#include <boost/lexical_cast.hpp>
#include <string>
#include <CGAL/Mesh_3/dihedral_angle_3.h>
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)
{

View File

@ -21,8 +21,6 @@
#include <CGAL/internal/Surface_mesh_segmentation/Alpha_expansion_graph_cut.h>
#include <CGAL/internal/Surface_mesh_segmentation/SDF_calculation.h>
#include <CGAL/Mesh_3/dihedral_angle_3.h>
#include <CGAL/property_map.h>
#include <cmath>
@ -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);