MEPP2 Project
Geometry_traits_cgal_common.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 #include "FEVV/Wrappings/Geometry_traits.h" // For forward convenience
15 #include <CGAL/Kernel/global_functions.h> // for CGAL::unit_normal, CGAL::scalar_product, CGAL::cross_product
16 
17 namespace FEVV {
18 
43 template< typename MeshT, typename KernelT >
44 class Geometry_traits_for_cgal : public KernelT
45 {
46 public:
48  typedef MeshT Mesh;
49  typedef KernelT Kernel;
50  typedef typename Kernel::Point_3 Point;
51  typedef typename Kernel::Vector_3 Vector;
52  typedef typename Kernel::FT Scalar;
53 
54  Geometry_traits_for_cgal(const Mesh &m) : m_mesh(const_cast< Mesh & >(m)) {}
55 
56  static Scalar get_x(const Point &p) { return p.x(); }
57 
58  static Scalar get_y(const Point &p) { return p.y(); }
59 
60  static Scalar get_z(const Point &p) { return p.z(); }
61 
62  static Vector unit_normal(const Point &p1, const Point &p2, const Point &p3)
63  {
64  return CGAL::unit_normal(p1, p2, p3);
65  }
66 
67  static Vector normal(const Point &p1, const Point &p2, const Point &p3)
68  {
69  return typename Kernel::Construct_normal_3()(p1, p2, p3);
70  }
71 
72  static Scalar dot_product(const Vector &v1, const Vector &v2)
73  {
74  return CGAL::scalar_product(v1, v2);
75  }
76 
77  static Vector cross_product(const Vector &v1, const Vector &v2)
78  {
79  return CGAL::cross_product(v1, v2);
80  }
81 
82  static Scalar length2(const Vector &v) { return v.squared_length(); }
83 
84  static Scalar length(const Vector &v) { return sqrt(length2(v)); }
85 
86  static Scalar length(const Point &p1, const Point &p2)
87  {
88  Vector v = p1 - p2;
89  return length(v);
90  }
91 
92  static Vector normalize(const Vector &v)
93  {
94  Scalar dist = length(v);
95  Vector res;
96  if(dist > 2e-7)
97  {
98  res = v * 1. / dist;
99  }
100  else
101  res = v;
102  return res;
103  }
104 
105  static Vector add_v(const Vector &v1, const Vector &v2) { return v1 + v2; }
106 
107  static Point add_pv(
108  const Point &p,
109  const Vector &v) // we need addP and add functions to have function names
110  // consistent with those of OpenMesh geometry trait
111  {
112  /*Point result(p1[0] + v[0],
113  p1[1] + v[1],
114  p1[2] + v[2] );
115  return result;*/
116  return p +
117  v; // defined in
118  // http://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Point__3.html
119  }
120 
121  static Point sub_pv(const Point &p,
122  const Vector &v) // subP to be consistent with addP
123  {
124  /*Point result(p[0] - v[0],
125  p[1] - v[1],
126  p[2] - v[2] );
127  return result;*/
128  return p -
129  v; // defined in
130  // http://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Point__3.html
131  };
132 
133  static Vector sub_p(const Point &p1, const Point &p2) { return p1 - p2; }
134 
135  static Vector sub_v(const Vector &v1, const Vector &v2) { return v1 - v2; }
136 
137  static Vector scalar_mult(const Vector &v, Scalar s) { return v * s; }
138 
139  static const Vector NULL_VECTOR;
140  static const Point ORIGIN;
141 
142 protected:
144 };
145 
151 template< typename MeshT, typename KernelT >
154 
160 template< typename MeshT, typename KernelT >
163 
164 } // namespace FEVV
165 
FEVV::Geometry_traits_for_cgal::get_z
static Scalar get_z(const Point &p)
Definition: Geometry_traits_cgal_common.h:60
FEVV::Geometry_traits_for_cgal::length
static Scalar length(const Vector &v)
Definition: Geometry_traits_cgal_common.h:84
FEVV::Geometry_traits_for_cgal::get_x
static Scalar get_x(const Point &p)
Definition: Geometry_traits_cgal_common.h:56
FEVV::Geometry_traits_for_cgal::ORIGIN
static const Point ORIGIN
Initialisation of static member ORIGIN of Geometry_traits_for_cgal class.
Definition: Geometry_traits_cgal_common.h:140
FEVV::Geometry_traits_for_cgal::dot_product
static Scalar dot_product(const Vector &v1, const Vector &v2)
Definition: Geometry_traits_cgal_common.h:72
FEVV::Geometry_traits_for_cgal::get_y
static Scalar get_y(const Point &p)
Definition: Geometry_traits_cgal_common.h:58
FEVV::Geometry_traits_for_cgal::m_mesh
MeshT & m_mesh
Definition: Geometry_traits_cgal_common.h:143
FEVV::Geometry_traits_for_cgal::sub_p
static Vector sub_p(const Point &p1, const Point &p2)
Definition: Geometry_traits_cgal_common.h:133
FEVV::Geometry_traits_for_cgal::Scalar
Kernel::FT Scalar
Definition: Geometry_traits_cgal_common.h:52
FEVV::Geometry_traits_for_cgal::unit_normal
static Vector unit_normal(const Point &p1, const Point &p2, const Point &p3)
Definition: Geometry_traits_cgal_common.h:62
FEVV::Math::Vector::cross_product
static std::vector< ElementType > cross_product(const ElementType v1[DIM], const ElementType v2[DIM])
Definition: MatrixOperations.hpp:460
FEVV::Geometry_traits_for_cgal::sub_pv
static Point sub_pv(const Point &p, const Vector &v)
Definition: Geometry_traits_cgal_common.h:121
FEVV::Geometry_traits_for_cgal::add_pv
static Point add_pv(const Point &p, const Vector &v)
Definition: Geometry_traits_cgal_common.h:107
FEVV::Geometry_traits_for_cgal::scalar_mult
static Vector scalar_mult(const Vector &v, Scalar s)
Definition: Geometry_traits_cgal_common.h:137
FEVV::Geometry_traits_for_cgal::normal
static Vector normal(const Point &p1, const Point &p2, const Point &p3)
Definition: Geometry_traits_cgal_common.h:67
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Geometry_traits_for_cgal::add_v
static Vector add_v(const Vector &v1, const Vector &v2)
Definition: Geometry_traits_cgal_common.h:105
FEVV::Geometry_traits_for_cgal::Mesh
MeshT Mesh
Definition: Geometry_traits_cgal_common.h:48
FEVV::Geometry_traits_for_cgal::cross_product
static Vector cross_product(const Vector &v1, const Vector &v2)
Definition: Geometry_traits_cgal_common.h:77
FEVV::Geometry_traits_for_cgal::Geometry_traits_for_cgal
Geometry_traits_for_cgal(const Mesh &m)
Definition: Geometry_traits_cgal_common.h:54
Geometry_traits.h
FEVV::Geometry_traits_for_cgal::Kernel
KernelT Kernel
Definition: Geometry_traits_cgal_common.h:49
FEVV::Geometry_traits_for_cgal::normalize
static Vector normalize(const Vector &v)
Definition: Geometry_traits_cgal_common.h:92
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::Geometry_traits_for_cgal::length2
static Scalar length2(const Vector &v)
Definition: Geometry_traits_cgal_common.h:82
FEVV::Geometry_traits_for_cgal::Vector
Kernel::Vector_3 Vector
Definition: Geometry_traits_cgal_common.h:51
FEVV::Geometry_traits_for_cgal::Self
Geometry_traits_for_cgal Self
Definition: Geometry_traits_cgal_common.h:47
FEVV::Geometry_traits_for_cgal
Many mesh representations of CGLA, e.g. CGAL::Exact_predicate_inexact_construction_kernel and CGAL::C...
Definition: Geometry_traits_cgal_common.h:45
FEVV::Geometry_traits_for_cgal::Point
Kernel::Point_3 Point
Definition: Geometry_traits_cgal_common.h:50
FEVV::Geometry_traits_for_cgal::length
static Scalar length(const Point &p1, const Point &p2)
Definition: Geometry_traits_cgal_common.h:86
FEVV::Geometry_traits_for_cgal::NULL_VECTOR
static const Vector NULL_VECTOR
Initialisation of static member NULL_VECTOR of Geometry_traits_for_cgal class.
Definition: Geometry_traits_cgal_common.h:139
FEVV::Geometry_traits_for_cgal::sub_v
static Vector sub_v(const Vector &v1, const Vector &v2)
Definition: Geometry_traits_cgal_common.h:135
Geometry_traits_operators.h