MSDM
 All Classes Namespaces Files Functions Variables Typedefs Pages
Header.h
Go to the documentation of this file.
1 
9 #ifndef MY_HEADER_H
10 #define MY_HEADER_H
11 
12 #include <omp.h>
13 #include <boost/math/constants/constants.hpp>
14 #include "mex.h"
15 #include <CGAL/Simple_cartesian.h>
16 #include <CGAL/Polyhedron_3.h>
17 #include <CGAL/Bbox_3.h>
18 #include <CGAL/Timer.h>
19 
21 typedef CGAL::Simple_cartesian<double> K;
23 typedef K::Point_3 Point;
25 typedef K::Triangle_3 Triangle;
29 typedef K::Plane_3 Plane;
30 
32 const static double pi = boost::math::constants::pi<double>();
33 
37 inline bool sphere_clip_vector(const Point &O, double r,const Point &P, Vector_3 &V)
38 {
39  Vector_3 W = P - O ;
40  double a = V.squared_length();
41  if (a == 0)
42  return true;
43  double b = V * W ;
44  double c = W.squared_length() - r * r ;
45  double delta = b * b - a * c;
46  if (delta < 0)
47  return true; //numerical precision
48  double t = (- b + 2 * std::sqrt(delta)) / (2 * a) ;
49  if (t < 0)
50  return true; //numerical precision
51  if (t >= 1)
52  return false ; //inside sphere
53  if (t == 0)
54  t = 0.01;
55  V = V * t;
56  return true;
57 }
58 
65 {
71  bool display;
73  bool isGeodesic;
75  double radius;
77  double alpha;
79  double beta;
81  double gamma;
83  double Mpower;
85  bool isRelative;
86 };
87 
99 template<typename T>
100 inline void getMatlabFieldScalar(const mxArray* MATLAB_struct, mwIndex index, const char* fieldname, T* out)
101 {
102  mxArray* field = mxGetField(MATLAB_struct, index, fieldname);
103 #pragma warning (push)
104 #pragma warning (disable: 4800)
105  if (field != NULL)
106  *out = static_cast<T>(mxGetScalar(field));
107 #pragma warning (pop)
108 }
109 
114 inline Vector_3 normalize(const Vector_3& v)
115 {
116  double l = v.squared_length();
117  return (l != 0.0) ? (v / std::sqrt(l)) : v;
118 }
119 
121 inline double asinT(double sine)
122 {
123  if (sine >= 1)
124  return pi/2;
125  else
126  {
127  if (sine <= -1)
128  return -pi/2;
129  else
130  return std::asin(sine);
131  }
132 }
133 
134 
135 #include "enriched_polyhedron.h"
138 
139 #endif
K::Vector_3 Vector_3
Definition: Header.h:27
CGAL::Simple_cartesian< double > K
Definition: Header.h:21
double beta
Definition: Header.h:79
K::Plane_3 Plane
Definition: Header.h:29
int nb_threads
Definition: Header.h:69
bool isRelative
Definition: Header.h:85
double Mpower
Definition: Header.h:83
bool isGeodesic
Definition: Header.h:73
double gamma
Definition: Header.h:81
Vector_3 normalize(const Vector_3 &v)
Normalize a CGAL vector using according to its Euclidean norm.
Definition: Header.h:114
Enriched CGAL Polyhedron for the MSDM estimation.
Enriched_polyhedron< K, Enriched_items > Polyhedron
Definition: Header.h:137
K::Triangle_3 Triangle
Definition: Header.h:25
double alpha
Definition: Header.h:77
static const double pi
Constant pi from boost library.
Definition: Header.h:32
void getMatlabFieldScalar(const mxArray *MATLAB_struct, mwIndex index, const char *fieldname, T *out)
Extract a scalar value associated with a field in a MATLAB structure.
Definition: Header.h:100
bool multithreading
Definition: Header.h:67
Structure that contains all the parameters of the MSDM estimation.
Definition: Header.h:64
K::Point_3 Point
Definition: Header.h:23
bool display
Definition: Header.h:71
double radius
Definition: Header.h:75
Polyhedron class for the MSDM computation.
Definition: enriched_polyhedron.h:189
bool sphere_clip_vector(const Point &O, double r, const Point &P, Vector_3 &V)
Clip a 3D vector within a sphere.
Definition: Header.h:37
double asinT(double sine)
Returns asin or if outside the range.
Definition: Header.h:121