MEPP2 Project
Geometry_traits_openmesh.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #if(_MSC_VER >= 1400)
14 #ifndef _SCL_SECURE_NO_WARNINGS
15 #define _SCL_SECURE_NO_WARNINGS
16 #endif
17 #endif
18 
19 #include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
20 #if !defined(CGAL_USE_OM_POINTS)
21 #include <CGAL/boost/graph/properties_PolyMesh_ArrayKernelT.h>
22 #endif
25 
26 namespace FEVV {
27 
34 template< typename T >
35 struct RetrieveKernel< OpenMesh::PolyMesh_ArrayKernelT< T > >
36 {
37  typedef T Kernel;
38 };
39 
50 template< typename T >
51 class Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >
52 {
53 public:
54  typedef OpenMesh::PolyMesh_ArrayKernelT< T > Mesh;
56  typedef typename Mesh::AttribKernel Kernel;
57  typedef typename Kernel::Normal Vector;
58  typedef typename Kernel::Scalar Scalar;
59 
60 // When CGAL_USE_OM_POINTS is defined then OpenMesh CGAL wrappers (refer to
61 // CGAL/boost/graph/properties_PolyMesh_ArrayKernelT.h) build on the fly
62 // of the put( vertex_point_t ) / get( vertex_point_t ) methods property
63 // maps that do not use OpenMesh kernel provided Point type. Instead the
64 // property maps use some hardwired CGAL Point type. In order for this
65 // Geometry_traits specialized for OpenMesh to be compatible with this
66 // CGAL choice for the boost/graph wrappers we adapt the Geometry Traits
67 // accordingly
68 #if defined(CGAL_USE_OM_POINTS)
69  typedef typename Kernel::Point Point;
70 #else
71  typedef CGAL::Exact_predicates_inexact_constructions_kernel CGALKernel;
72  typedef CGALKernel::Point_3 Point;
73  typedef CGALKernel::Vector_3 CGALVector;
74 #endif
75 
76  Geometry_traits(const Mesh &m) : m_mesh(const_cast< Mesh & >(m)) {}
77 
79  template< int D >
80  static Scalar get(const Point &p)
81  {
82  return static_cast< Scalar >(p[D]);
83  }
84 
85  static Scalar get_x(const Point &p) { return static_cast< Scalar >(p[0]); }
86 
87  static Scalar get_y(const Point &p) { return static_cast< Scalar >(p[1]); }
88 
89  static Scalar get_z(const Point &p) { return static_cast< Scalar >(p[2]); }
90 
91  Vector unit_normal(const Point &p1, const Point &p2, const Point &p3) const
92  {
93 #if defined(CGAL_USE_OM_POINTS)
94  return m_mesh.calc_face_normal(p1, p2, p3).normalize();
95 #else
96  CGALVector cga_lresult = CGAL::unit_normal(p1, p2, p3);
97  return Vector(cga_lresult[0], cga_lresult[1], cga_lresult[2]);
98 #endif
99  }
100 
101  Vector normal(const Point &p1, const Point &p2, const Point &p3) const
102  {
103 #if defined(CGAL_USE_OM_POINTS)
104  return m_mesh.calc_face_normal(p1, p2, p3);
105 #else
106  CGALVector cga_lresult = CGALKernel::Construct_normal_3()(p1, p2, p3);
107  return Vector(cga_lresult[0], cga_lresult[1], cga_lresult[2]);
108 #endif
109  }
110 
111  static Scalar dot_product(const Vector &v1, const Vector &v2)
112  {
113  return v1 | v2;
114  }
115 
116  static Vector cross_product(const Vector &v1, const Vector &v2)
117  {
118  return v1 % v2;
119  }
120 
121  static Scalar length2(const Vector &v) { return v.sqrnorm(); }
122 
123  static Scalar length(const Vector &v) { return v.length(); }
124 
125  static Scalar length(const Point &p1, const Point &p2)
126  {
127  // here, we have have native OpenMesh Points (VectorT) or native CGAL
128  // Vector_3
129  auto v = p1 - p2;
130 #if defined(CGAL_USE_OM_POINTS)
131  return length(v);
132 #else
133  Scalar dotprodloc = 0;
134  for(int i = 0; i < v.dimension(); ++i)
135  dotprodloc += v[i] * v[i];
136  return sqrt(dotprodloc);
137 #endif
138  }
139 
140  static Vector normalize(const Vector &v)
141  {
142  Scalar dist = length(v);
143  Vector res;
144  if(dist > 2e-7)
145  {
146  res = v * 1. / dist;
147  }
148  else
149  res = v;
150  return res;
151  }
152 
153  static Vector add_v(const Vector &v1, const Vector &v2) { return v1 + v2; }
154 
155  // we need add_pv and add_v functions, because in OpenMesh
156  // Point and Vector have the same type
157  static Point add_pv(const Point &p, const Vector &v)
158  {
159  // here, we have have native OpenMesh Points (VectorT) or native CGAL
160  // Vector_3
161 #if defined(CGAL_USE_OM_POINTS)
162  return p + v;
163 #else
164  return GeometryTraits::add_pv< Self >(p, v);
165 #endif
166  }
167 
168  static Point sub_pv(const Point &p,
169  const Vector &v) // sub_pv to be consistent with add_pv
170  {
171  // here, we have have native OpenMesh Points (VectorT) or native CGAL
172  // Vector_3
173 #if defined(CGAL_USE_OM_POINTS)
174  return p - v;
175 #else
176  return GeometryTraits::sub_pv< Self >(p, v);
177 #endif
178  }
179 
180  static Vector sub_p(const Point &p1, const Point &p2)
181  {
182  // here, we have have native OpenMesh Points (VectorT) or native CGAL
183  // Vector_3 (and there is not automatic convertion from Vector_3 to Vector
184 #if defined(CGAL_USE_OM_POINTS)
185  return p1 - p2;
186 #else
187  return GeometryTraits::sub_p< Self >(p1, p2);
188 #endif
189  }
190 
191  static Vector sub_v(const Vector &v1, const Vector &v2) { return v1 - v2; }
192 
193  static Vector scalar_mult(const Vector &v, Scalar s) { return v * s; }
194 
195  static const Vector NULL_VECTOR;
196  static const Point ORIGIN;
197 
198 protected:
200 };
201 
203 template< typename T >
205  T >::Vector
208  T >::Vector(0, 0, 0);
209 
211 template< typename T >
213  T >::Point
216  T >::Point(0, 0, 0);
217 
218 } // namespace FEVV
219 
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::sub_p
static Vector sub_p(const Point &p1, const Point &p2)
Definition: Geometry_traits_openmesh.h:180
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::Kernel
Mesh::AttribKernel Kernel
Definition: Geometry_traits_openmesh.h:56
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::scalar_mult
static Vector scalar_mult(const Vector &v, Scalar s)
Definition: Geometry_traits_openmesh.h:193
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::length
static Scalar length(const Vector &v)
Definition: Geometry_traits_openmesh.h:123
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::normalize
static Vector normalize(const Vector &v)
Definition: Geometry_traits_openmesh.h:140
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::sub_v
static Vector sub_v(const Vector &v1, const Vector &v2)
Definition: Geometry_traits_openmesh.h:191
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::Geometry_traits
Geometry_traits(const Mesh &m)
Definition: Geometry_traits_openmesh.h:76
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::unit_normal
Vector unit_normal(const Point &p1, const Point &p2, const Point &p3) const
Definition: Geometry_traits_openmesh.h:91
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::get_x
static Scalar get_x(const Point &p)
Definition: Geometry_traits_openmesh.h:85
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::CGALVector
CGALKernel::Vector_3 CGALVector
Definition: Geometry_traits_openmesh.h:73
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::add_v
static Vector add_v(const Vector &v1, const Vector &v2)
Definition: Geometry_traits_openmesh.h:153
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::Mesh
OpenMesh::PolyMesh_ArrayKernelT< T > Mesh
Definition: Geometry_traits_openmesh.h:54
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::NULL_VECTOR
static const Vector NULL_VECTOR
Initialisation of static member NULL_VECTOR of above OpenMesh specialisation.
Definition: Geometry_traits_openmesh.h:195
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::CGALKernel
CGAL::Exact_predicates_inexact_constructions_kernel CGALKernel
Definition: Geometry_traits_openmesh.h:71
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::Vector
Kernel::Normal Vector
Definition: Geometry_traits_openmesh.h:57
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::dot_product
static Scalar dot_product(const Vector &v1, const Vector &v2)
Definition: Geometry_traits_openmesh.h:111
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::sub_pv
static Point sub_pv(const Point &p, const Vector &v)
Definition: Geometry_traits_openmesh.h:168
FEVV::RetrieveKernel
A generic definition, that is template specialized for every supported native implementation,...
Definition: Geometry_traits.h:118
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::Point
CGALKernel::Point_3 Point
Definition: Geometry_traits_openmesh.h:72
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::cross_product
static Vector cross_product(const Vector &v1, const Vector &v2)
Definition: Geometry_traits_openmesh.h:116
Geometry_traits.h
FEVV::RetrieveKernel< OpenMesh::PolyMesh_ArrayKernelT< T > >::Kernel
T Kernel
Definition: Geometry_traits_openmesh.h:37
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::length2
static Scalar length2(const Vector &v)
Definition: Geometry_traits_openmesh.h:121
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::add_pv
static Point add_pv(const Point &p, const Vector &v)
Definition: Geometry_traits_openmesh.h:157
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::Self
Geometry_traits< Mesh, T > Self
Definition: Geometry_traits_openmesh.h:55
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::get
static Scalar get(const Point &p)
Deprecated syntax for coordinate access. Use the get_[x|y|z] versions.
Definition: Geometry_traits_openmesh.h:80
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::ORIGIN
static const Point ORIGIN
Initialisation of static member ORIGIN of above OpenMesh specialisation.
Definition: Geometry_traits_openmesh.h:196
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::normal
Vector normal(const Point &p1, const Point &p2, const Point &p3) const
Definition: Geometry_traits_openmesh.h:101
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::length
static Scalar length(const Point &p1, const Point &p2)
Definition: Geometry_traits_openmesh.h:125
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::get_z
static Scalar get_z(const Point &p)
Definition: Geometry_traits_openmesh.h:89
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::m_mesh
Mesh & m_mesh
Definition: Geometry_traits_openmesh.h:199
FEVV::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::Scalar
Kernel::Scalar Scalar
Definition: Geometry_traits_openmesh.h:58
Geometry_traits_operators.h
FEVV::Geometry_traits< OpenMesh::PolyMesh_ArrayKernelT< T >, T >::get_y
static Scalar get_y(const Point &p)
Definition: Geometry_traits_openmesh.h:87