MEPP2 Project
GeometryConceptCheck.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 #undef NDEBUG // enable assert in release build
14 #include <cassert>
15 #include <boost/concept_check.hpp>
18 
19 namespace FEVV {
20 
27 template< typename Mesh >
29 {
31  typedef Geometry G; // Syntactic shortcut for operators
32  typedef typename Geometry::Point Point;
33  typedef typename Geometry::Vector Vector;
34  typedef typename Geometry::Scalar Scalar;
35 
37  {
38  Mesh mesh;
39  Geometry gt(mesh);
40  Vector v1;
41  Scalar s;
42 
44 
45  // Point constructor
46  Point p(1.1f, 2.2f, 3.3f);
47 
48  // Point copy construction
49  Point q(p);
50 
51  // Point assignement operator
52  q = p;
53 
54  // Point at origin
55  p = G::ORIGIN;
56  p = gt.ORIGIN;
57 
58  // Point coordinate component access
59 #ifdef __GNUC__
60 #pragma GCC diagnostic push
61 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
62 #endif
63  Scalar x = gt.get_x(p);
64  Scalar y = gt.get_y(p);
65  Scalar z = gt.get_z(p);
66 #ifdef __GNUC__
67 #pragma GCC diagnostic pop
68 #endif
69 
71 
72  // Vector constructor
73  Vector v(4.4f, 5.5f, 6.6f);
74 
75  // Vector copy construction
76  Vector v2(v1);
77 
78  // Vector assignement operator:
79  v2 = v1;
80 
81  // Null vector
82  v = G::NULL_VECTOR;
83  v = gt.NULL_VECTOR;
84 
85  // Vector/Scalar coordinate component access
86  x = v1[0];
87  y = v1[1];
88  z = v1[2];
89 
90  // One can NOT overwrite a single vector coordinate component e.g.
91  // v[0] = 1; will fail (refer below for the details).
92  // In order to alter one or many coordinate component of a Vector one must
93  // create a new Vector and reassign it:
94  v1 = Vector(v1[0], v1[1], 999.0f);
95 
96  // Misc vectors operations
97  v1 = gt.normalize(v);
98  s = gt.length2(v);
99  s = gt.length(v);
100  v = gt.add_v(v1, v2);
101  v = gt.sub_v(v1, v2);
102  gt.dot_product(v1, v2);
103  gt.cross_product(v1, v2);
104 
105  // Scalar/Vector:
106  v2 = gt.scalar_mult(v1, s);
107 
109 
110  s = gt.length(p, q);
111  v1 = gt.normal(p, p, p);
112  v1 = gt.unit_normal(p, p, p);
113  p = gt.add_pv(p, v1);
114  p = gt.sub_pv(p, v1);
115  v1 = gt.sub_p(p, p);
116 
117 #if 0
118 // The following is on debugging purposes, remains as traces
120 // of various trials, is deprecated or not recommendable.
121 // Do NOT use it in your generic code.
122 
123 // SurfaceMesh fail: operator[] returns a const value
124 #ifndef FEVV_USE_CGAL
125  v1[0] = 5;
126 #endif
127 
128  // Not recommendable because the notation is too heavy
129  v1 = GeometryTraits::sub_p< G >(p, p);
130  v1 = GeometryTraits::add_v< G >(v1, v2);
131  v1 = GeometryTraits::sub_v< G >(v1, v2);
132  p = GeometryTraits::add_pv< G >(p, v1);
133 
135 // Only working for some data structures and thus not generic
136 #ifndef FEVV_USE_CGAL
137 // Point r = p + q;
138 #endif
139 #endif
140  }
141 };
142 
143 
147 template< typename GeometryTraits >
149 {
150  typedef typename GeometryTraits::Point Point;
151  typedef typename GeometryTraits::Vector Vector;
152  typedef typename GeometryTraits::Scalar Scalar;
153 
154  // helper lambda function to test if two FP numbers are almost equal
155  auto almost_equal_s = [](Scalar s1, Scalar s2, Scalar epsilon) -> bool
156  {
157  return std::abs(s1 - s2) <= epsilon;
158  };
159 
160  // helper lambda function to test if two FP points are almost equal
161  auto almost_equal_p = [almost_equal_s](Point p1, Point p2, Scalar epsilon) -> bool
162  {
163  return almost_equal_s(GeometryTraits::get_x(p1),
164  GeometryTraits::get_x(p2),
165  epsilon) &&
166  almost_equal_s(GeometryTraits::get_y(p1),
167  GeometryTraits::get_y(p2),
168  epsilon) &&
169  almost_equal_s(GeometryTraits::get_z(p1),
170  GeometryTraits::get_z(p2),
171  epsilon);
172  };
173 
174  // helper lambda function to test if two FP vectors are almost equal
175  auto almost_equal_v = [almost_equal_s](Vector v1, Vector v2, Scalar epsilon) -> bool
176  {
177  return almost_equal_s(v1[0], v2[0], epsilon) &&
178  almost_equal_s(v1[1], v2[1], epsilon) &&
179  almost_equal_s(v1[2], v2[2], epsilon);
180  };
181 
182  Scalar eps = 1e-5f;
183  Vector u(8.3f, -3.2f, -3.8f);
184  Vector v(1.2f, 2.3f, 3.4f);
185  Point p(3.0f, 12.5f, -2.1f);
186  Point q(-1.4f, 4.6f, -1.9f);
187  Point r(-2.6f, 4.7f, 5.8f);
188 
189  {
190  Scalar l2 = GeometryTraits::length2(v);
191  assert(almost_equal_s(l2, 18.29f, eps));
192 
193  Scalar l = GeometryTraits::length(v);
194  assert(almost_equal_s(l, 4.276681f, eps));
195 
197  assert(almost_equal_v(n, Vector(0.280591f, 0.537800f, 0.795009f), eps));
198  }
199 
200  {
201  Vector w = GeometryTraits::sub_p(p, q);
202  assert(almost_equal_v(w, Vector(4.4f, 7.9f, -0.2f), eps));
203 
204  Scalar l = GeometryTraits::length(p, q);
205  assert(almost_equal_s(l, 9.044888f, eps));
206  }
207 
208  {
209  // these two function are not implemented with static method
210  // with OpenMesh, so we must create a mesh object and a geometry traits
211  // object
212  typename GeometryTraits::Mesh m;
213  GeometryTraits gt(m);
214 
215  Vector n = gt.normal(p, q, r);
216  assert(almost_equal_v(n, Vector(-60.85f, 33.64f, -9.92f), eps) ||
217  almost_equal_v(n, Vector(-0.866393f, 0.478972f, -0.141243f), eps) );
218  // OpenMesh returns a normalized normal
219 
220  n = gt.unit_normal(p, q, r);
221  assert(almost_equal_v(n, Vector(-0.866393f, 0.478972f, -0.141243f), eps));
222  }
223 
224  {
225  Vector w = GeometryTraits::add_v(u, v);
226  assert(almost_equal_v(w, Vector(9.5f, -0.9f, -0.4f), eps));
227 
228  Scalar d = GeometryTraits::dot_product(u, v);
229  assert(almost_equal_s(d, -10.32f, eps));
230 
232  assert(almost_equal_v(w, Vector(-2.14f, -32.78f, 22.93f), eps));
233  }
234 
235  {
236  Point a = GeometryTraits::add_pv(p, v);
237  assert(almost_equal_p(a, Point(4.2f, 14.8f, 1.3f), eps));
238 
239  a = GeometryTraits::sub_pv(p, v);
240  assert(almost_equal_p(a, Point(1.8f, 10.2f, -5.5f), eps));
241 
242  Vector w = GeometryTraits::scalar_mult(v, -2.345f);
243  assert(almost_equal_v(w, Vector(-2.814f, -5.3935f, -7.973f), eps));
244  }
245 }
246 
247 } // namespace FEVV
248 
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::GeometryTraits::sub_p
GeometryTraits::Vector sub_p(const typename GeometryTraits::Point &p1, const typename GeometryTraits::Point &p2)
Returns point P1 minus point P2.
Definition: Geometry_traits_operators.h:62
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::GeometryTraits::sub_pv
GeometryTraits::Point sub_pv(const typename GeometryTraits::Point &p, const typename GeometryTraits::Vector &v)
Returns point P minus vector V.
Definition: Geometry_traits_operators.h:49
FEVV::GeometryConcept::BOOST_CONCEPT_USAGE
BOOST_CONCEPT_USAGE(GeometryConcept)
Definition: GeometryConceptCheck.h:36
FEVV::Math::Vector::normalize
static GeometryTraits::Vector normalize(const typename GeometryTraits::Vector &v, const GeometryTraits &gt)
Definition: MatrixOperations.hpp:645
FEVV::Math::Vector::cross_product
static std::vector< ElementType > cross_product(const ElementType v1[DIM], const ElementType v2[DIM])
Definition: MatrixOperations.hpp:460
FEVV::GeometryTraits::dot_product
GeometryTraits::Scalar dot_product(const typename GeometryTraits::Vector &v1, const typename GeometryTraits::Vector &v2)
Returns the dot product of vectors V1 and V2.
Definition: Geometry_traits_operators.h:88
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::GeometryConcept
An elementary concept check Geometry_traits specializations Boost Concept Check Library (BCCL)
Definition: GeometryConceptCheck.h:29
Geometry_traits.h
FEVV::Math::Vector::scalar_mult
static std::vector< ElementType > scalar_mult(const std::vector< ElementType > &v1, ElementType coef)
Compute v1 * coef.
Definition: MatrixOperations.hpp:714
FEVV::check_operators_results
void check_operators_results(void)
Definition: GeometryConceptCheck.h:148
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
Mesh
FEVV::DataStructures::AIF::AIFMesh Mesh
Definition: test_complying_concepts_aif.cpp:18
FEVV::GeometryConcept::Scalar
Geometry::Scalar Scalar
Definition: GeometryConceptCheck.h:34
FEVV::GeometryConcept::G
Geometry G
Definition: GeometryConceptCheck.h:31
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
FEVV::GeometryConcept::Geometry
Geometry_traits< Mesh > Geometry
Definition: GeometryConceptCheck.h:30
FEVV::GeometryConcept::Vector
Geometry::Vector Vector
Definition: GeometryConceptCheck.h:33
FEVV::GeometryConcept::Point
Geometry::Point Point
Definition: GeometryConceptCheck.h:32
FEVV::GeometryTraits::add_pv
GeometryTraits::Point add_pv(const typename GeometryTraits::Point &p, const typename GeometryTraits::Vector &v)
Returns the sum of point P and vector V.
Definition: Geometry_traits_operators.h:36
epsilon
const float epsilon
Definition: core.h:51
FEVV::GeometryTraits::add_v
GeometryTraits::Vector add_v(const typename GeometryTraits::Vector &v1, const typename GeometryTraits::Vector &v2)
Returns the sum of vectors V1 and V2.
Definition: Geometry_traits_operators.h:23
FEVV::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31
Geometry_traits_operators.h