GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Frame.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_FRAME_hpp_
31 #define _GranOO_libGeom_FRAME_hpp_
32 
33 #include <iostream>
34 
35 #ifndef SERVER
36  #if defined OSX
37  #include <OpenGL/gl.h>
38  #else
39  #include <GL/gl.h>
40  #endif
41 #endif
42 
43 #include <boost/archive/text_oarchive.hpp>
44 #include <boost/archive/text_iarchive.hpp>
45 
46 #include "GranOO3/Geom/Vector.hpp"
47 
48 class TiXmlElement;
49 
50 namespace GranOO3
51 {
52  namespace Geom
53  {
54 
55  class Point;
56  class Quaternion;
57  class Frame;
58  struct global;
59  struct null;
60 
61  // Extern operators
62  std::ostream& operator<< (std::ostream& o, const Frame& f);
63  bool operator==(const Frame& f1, const Frame& f2);
64  bool operator!=(const Frame& f1, const Frame& f2);
65 
66 
67  class Frame
68  {
69 
70  public:
71  // Usefull for internal use only, NOT DOCUMENTED !
72  static Frame& glob(const std::string& id);
73  static std::string class_ID() {return "Frame";}
74  static Frame* new_object(const TiXmlElement* el);
75 
76  static const Frame& global;
77  static const Frame& null;
78 
79  friend class global;
80  friend class null;
81 
82  public:
83  // Constructors and destructor
84  Frame(const Point &center, const Quaternion &quaternion, const Frame& reference);
85  ~Frame();
86 
87  // Accessors
88  GRANOO_ACCESS_GET(center, Point, center);
89  GRANOO_ACCESS_GET(quaternion, Quaternion, quaternion);
90  GRANOO_ACCESS_GET(rank, unsigned int, rank);
91  const Vector& get_position() const;
92 
93  bool is_global() const;
94 
95  // Reference frame
96  const Frame& get_reference() const;
97 
98  void update_glMatrix();
99  void update_glMatrix() const;
100  std::string info() const;
101 
102 
103 #ifndef SERVER
104  const GLdouble* get_glMatrix() const {
105  return &_m[0][0];
106  }
107 
108 #endif
109 
110  void add_glob(const std::string& id);
111 
112  private:
114  Frame() = delete;
115  Frame(const Frame& frame) = delete;
116  Frame & operator=(const Frame &) = delete;
117 
118  public:
119  const Point& center;
121  const unsigned int rank;
122  const Frame& ref;
123 
124 
125 #ifndef SERVER
126  GLdouble _m[4][4];
127 #endif
128 
129  };
130 
131 #ifndef DOXYGEN_SHOULD_SKIP_THIS
132 
133  inline
134  Frame::Frame(const Point& center, const Quaternion& quaternion, const Frame& reference):
135  center(center),
136  quaternion(quaternion),
137  rank( (this == &global::frame) ? 0 : reference.rank+1),
138  ref(reference){
139  }
140 
141  inline
142  Frame::Frame(const Point& center, const Quaternion& quaternion):
143  center(center),
144  quaternion(quaternion),
145  rank(0),
146  ref(*this){
147  }
148 
149  inline bool
150  Frame::is_global() const {
151  return this == &global;
152  }
153 
154  inline const Frame&
155  Frame::get_reference() const {
156  return ref;
157  }
158 
159  inline
160  Frame::~Frame() {
161  }
162 
163  inline const Vector&
164  Frame::get_position() const {
165  return reinterpret_cast<const Vector&>(center);
166  };
167 
168 
169  inline bool
170  operator==(const Frame& f1, const Frame& f2) {
171  return &f1 == &f2;
172  }
173 
174  inline bool
175  operator!=(const Frame& f1, const Frame& f2) {
176  return !(f1 == f2);
177  }
178 
179 
180 #endif
181  }
182 }
183 
184 
185 #endif
Definition: Frame.hpp:68
const GLdouble * get_glMatrix() const
Definition: Frame.hpp:104
Frame(const Point &center, const Quaternion &quaternion, const Frame &reference)
static Frame * new_object(const TiXmlElement *el)
Definition: Frame.cpp:64
static std::string class_ID()
Definition: Frame.hpp:73
GLdouble _m[4][4]
Definition: Frame.hpp:126
std::string info() const
Definition: Frame.cpp:85
Frame(const Point &center, const Quaternion &quaternion)
Frame(const Frame &frame)=delete
void update_glMatrix()
Definition: Frame.cpp:94
const Frame & ref
Definition: Frame.hpp:122
Frame & operator=(const Frame &)=delete
const Point & center
Definition: Frame.hpp:119
static const Frame & global
Definition: Frame.hpp:76
const unsigned int rank
Definition: Frame.hpp:121
const Quaternion & quaternion
Definition: Frame.hpp:120
const Frame & get_reference() const
static Frame & glob(const std::string &id)
Definition: Frame.cpp:53
const Vector & get_position() const
bool is_global() const
void add_glob(const std::string &id)
Definition: Frame.cpp:162
Definition: Point.hpp:62
Definition: Quaternion.hpp:54
Definition: Vector.hpp:75
bool operator!=(const EulerAngle &, const EulerAngle &)
std::ostream & operator<<(std::ostream &, const EulerAngle &)
bool operator==(const EulerAngle &, const EulerAngle &)
Definition: Common.hpp:198
Definition: Constant.hpp:66
Definition: Constant.hpp:74