GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
EulerAngle.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 #ifndef _GranOO_libGeom_EulerAngle_hpp_
31 #define _GranOO_libGeom_EulerAngle_hpp_
32 
33 #include <iostream>
34 #include <string>
35 #include <vector>
36 #include <cmath>
37 #include "GranOO3/3rdParty/Eigen/Dense"
38 
39 #include <boost/archive/text_oarchive.hpp>
40 #include <boost/archive/text_iarchive.hpp>
41 
43 #include "GranOO3/Geom/Axis.hpp"
44 #include "GranOO3/Core/Macro.hpp"
45 
46 class TiXmlElement;
47 
48 namespace GranOO3
49 {
50  namespace Geom
51  {
52  class EulerAngle;
53  class Quaternion;
54 
55  bool operator==(const EulerAngle &, const EulerAngle &);
56  bool operator!=(const EulerAngle &, const EulerAngle &);
57  std::ostream& operator<<(std::ostream &, const EulerAngle &);
58 
59 
60  class EulerAngle
61  {
62 
63  public:
64  static const int N = 3;
65 
66  public:
69  explicit EulerAngle(double, double, double);
71 
72  // Internal operators
74 
75  // Quaternion conversion
76  void to_quaternion(Quaternion&) const;
77  Quaternion to_quaternion() const;
78  EulerAngle & operator=(const Quaternion &);
79 
80 
81  // Component
82  double & x();
83  const double & x() const;
84  double & y();
85  const double & y() const;
86  double & z();
87  const double & z() const;
88 
89  // Component (for python wrapper)
90  void set_x(const double&);
91  void set_y(const double&);
92  void set_z(const double&);
93 
94  // Component (for python wrapper)
95  double get_x() const;
96  double get_y() const;
97  double get_z() const;
98 
99  template <typename Axis> double& val();
100  template <typename Axis> const double& val() const;
101  const double & operator() (unsigned int i) const;
102  double& operator() (unsigned int i);
103 
104  // Misc
105  bool is_nan() const;
106  std::string info() const;
107  void add_glob(const std::string& id);
108 
109  private:
110  // - BOOST SERIALIZATION - //
112  template<class Archive> void serialize(Archive&, const unsigned int );
113 
114  public:
115  Eigen::Matrix<double, 3, 1> coord;
116  };
117 #ifndef DOXYGEN_SHOULD_SKIP_THIS
118 
119 
120 
121  // - BOOST SERIALIZATION - //
122  template<class Archive>
123  void
124  EulerAngle::serialize(Archive & ar, const unsigned int ) {
125  ar & x(); ar & y(); ar & z();
126  }
127 
128  // Constructors ...
129  inline
131  : coord() {
132  }
133 
134  inline
135  EulerAngle::EulerAngle(const EulerAngle &p)
136  : coord(p.coord) {
137  }
138 
139  inline
140  EulerAngle::EulerAngle(double x, double y, double z)
141  : coord(x, y, z){
142  }
143 
144 
145  inline
147  }
148 
149 
150  // External Operators ...
151  inline
152  bool operator==(const EulerAngle & pt1, const EulerAngle & pt2) {
153  return (pt1.x() == pt2.x() && pt1.y() == pt2.y() && pt1.z() == pt2.z());
154  }
155 
156  inline
157  bool operator!=(const EulerAngle & pt1, const EulerAngle & pt2) {
158  return !(pt1==pt2);
159  }
160 
161  inline double&
162  EulerAngle::x() {
163  return coord(0);
164  }
165 
166  inline const double&
167  EulerAngle::x() const {
168  return coord(0);
169  }
170 
171  inline double&
172  EulerAngle::y() {
173  return coord(1);
174  }
175 
176  inline const double&
177  EulerAngle::y() const {
178  return coord(1);
179  }
180 
181  inline double&
182  EulerAngle::z() {
183  return coord(2);
184  }
185 
186  inline const double&
187  EulerAngle::z() const {
188  return coord(2);
189  }
190 
191  inline void
192  EulerAngle::set_x(const double& val) {
193  x() = val;
194  }
195 
196  inline void
197  EulerAngle::set_y(const double& val) {
198  y() = val;
199  }
200 
201  inline void
202  EulerAngle::set_z(const double& val) {
203  z() = val;
204  }
205 
206  inline double
207  EulerAngle::get_x() const {
208  return x();
209  }
210 
211  inline double
212  EulerAngle::get_y() const {
213  return y();
214  }
215 
216  inline double
217  EulerAngle::get_z() const {
218  return z();
219  }
220 
221  template<typename Axis> inline
222  double& EulerAngle::val() {
223  SafeModeAssert(0, "Non specilized method is forbidden");
224  return x();
225  }
226 
227  template<typename Axis> inline
228  const double& EulerAngle::val() const {
229  SafeModeAssert(0, "Non specilized method is forbidden");
230  return x();
231  }
232 
233  template<> inline
234  double& EulerAngle::val<X>() {
235  return x();
236  }
237 
238  template<> inline
239  const double& EulerAngle::val<X>() const {
240  return x();
241  }
242 
243  template<> inline
244  double& EulerAngle::val<Y>() {
245  return y();
246  }
247 
248  template<> inline
249  const double& EulerAngle::val<Y>() const {
250  return y();
251  }
252 
253  template<> inline
254  double& EulerAngle::val<Z>() {
255  return z();
256  }
257 
258  template<> inline
259  const double& EulerAngle::val<Z>() const {
260  return z();
261  }
262 
263  inline const double&
264  EulerAngle::operator() (unsigned int i) const {
265  SafeModeAssert(i < 3, "The component must be in [0, 2] range");
266  return coord(i);
267  }
268 
269  inline double&
270  EulerAngle::operator() (unsigned int i) {
271  SafeModeAssert(i < 3, "The component must be in [0, 2] range");
272  return coord(i);
273  }
274 
275  inline std::ostream &
276  operator<<(std::ostream& out, const EulerAngle& pt) {
277  return out << pt.x() << "\t" << pt.y() << "\t" << pt.z() <<"\t";
278  }
279 
280  inline EulerAngle &
281  EulerAngle::operator=(const EulerAngle & p) {
282  if (this == &p)
283  return *this;
284  coord = p.coord;
285  return *this;
286  }
287 
288  inline bool
289  EulerAngle::is_nan() const {
290  if (x()!=x())
291  return true;
292  if (y()!=y())
293  return true;
294  if (z()!=z())
295  return true;
296  return false;
297  }
298 
299 
300 #endif
301  } // namespace Geom
302 }
303 
304 #endif
#define SafeModeAssert(condition, message)
Definition: Macro.hpp:47
Definition: EulerAngle.hpp:61
void set_x(const double &)
EulerAngle(double, double, double)
const double & z() const
const double & operator()(unsigned int i) const
EulerAngle & operator=(const EulerAngle &)
const double & val() const
void add_glob(const std::string &id)
void set_y(const double &)
EulerAngle(const EulerAngle &)
Eigen::Matrix< double, 3, 1 > coord
Definition: EulerAngle.hpp:115
void serialize(Archive &, const unsigned int)
const double & x() const
const double & y() const
void set_z(const double &)
static const int N
Definition: EulerAngle.hpp:64
Quaternion to_quaternion() const
Definition: EulerAngle.cpp:59
friend class boost::serialization::access
Definition: EulerAngle.hpp:111
std::string info() const
Definition: EulerAngle.cpp:88
Definition: Quaternion.hpp:54
bool operator!=(const EulerAngle &, const EulerAngle &)
std::ostream & operator<<(std::ostream &, const EulerAngle &)
bool operator==(const EulerAngle &, const EulerAngle &)
Definition: Common.hpp:198
x y * z
Definition: Exprtk.hpp:11139
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)