GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Base.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_LibShape_Base_hh_
31 #define _GranOO_LibShape_Base_hh_
32 
33 #include <iostream>
34 #include <string>
35 #include <math.h>
36 
37 #include <vtkUnstructuredGrid.h>
38 
39 #include "GranOO3/Core/Macro.hpp"
40 #include "GranOO3/Core/String.hpp"
41 #include "GranOO3/Core/Color.hpp"
44 
45 #include "GranOO3/Geom/Tensor.hpp"
46 #include "GranOO3/Geom/Point.hpp"
48 #include "GranOO3/Geom/Frame.hpp"
49 
50 #ifndef SERVER
51  #if defined OSX
52  #include <OpenGL/gl.h>
53  #else
54  #include <GL/gl.h>
55  #endif
56 #endif
57 
58 
59 #define GRANOO_SERIALIZE_SHAPE(CLASS) \
60  namespace boost {namespace serialization { \
61  template<class Archive> \
62  inline void save_construct_data(Archive & ar, \
63  const GranOO3::Shape::CLASS * t, \
64  const unsigned int) { \
65  InternAssert(0); \
66  const GranOO3::Geom::Point* p = &t->get_center(); \
67  const GranOO3::Geom::Quaternion* q = &t->get_quaternion(); \
68  ar << p; ar << q;} \
69  template<class Archive> \
70  inline void load_construct_data(Archive & ar, \
71  GranOO3::Shape::CLASS * t, \
72  const unsigned int) { \
73  InternAssert(0); \
74  GranOO3::Geom::Point* p = nullptr; \
75  GranOO3::Geom::Quaternion* q = nullptr; \
76  ar >> p; ar >> q; \
77  GranOO3::Geom::Frame* f = new GranOO3::Geom::Frame(*p, *q, GranOO3::Geom::global::frame); \
78  ::new(t)GranOO3::Shape::CLASS(*f);}}}
79 
80 
81 namespace GranOO3
82 {
83  namespace Shape
84  {
85 
86  class Sphere;
87  class Box;
88  class Prolate;
89  class Base;
90  std::ostream& operator<< (std::ostream& os, const Base&);
91  std::istream& operator>> (std::istream& is, Base&);
92 
93  //
94  // Base class for all shapes !
95  //
96  class Base
97  {
98  public:
99  static Base& glob(const std::string& id);
100  static const Geom::Frame& frame_buffer();
101  static std::string class_ID() {
102  return std::string("ShapeBase");
103  }
104 
105  static Base* new_object(const TiXmlElement* el);
106 
107  private:
108  static const Geom::Frame* _frame_buffer;
109 
110  public:
111  //CONSTRUCTORS & DESTRUCTORS
112  explicit Base(const Geom::Frame &frame) : _frame(frame) {}
113  virtual ~Base() {}
114 
115  //USEFULL
116  virtual void draw_gl() const = 0;
117  virtual void draw_gl_edge() const;
118  virtual void scale(double) = 0;
119  void unscale(double);
120  virtual bool is_surface() const = 0;
121  virtual bool is_volume() const = 0;
122  virtual void add_glob(const std::string&) = 0;
123 
124  //IO
125  virtual void read_xml_element(const TiXmlElement* el);
126  virtual std::ostream& write_ascii (std::ostream& out) const;
127  virtual std::istream& read_ascii (std::istream& in);
128  virtual void to_vtk(vtkUnstructuredGrid* data);
129  virtual std::string info() const;
130  virtual std::ostream& to_povray (std::ostream& out, const Core::Color&) const;
131 
132  //ACCESSORS
133  const Geom::Frame& local_frame() const {return _frame;}
134  const Geom::Point& get_center() const {return _frame.get_center();}
135  const Geom::Quaternion& get_quaternion() const { return _frame.get_quaternion();}
136  const Geom::Vector& get_position() const {return _frame.get_position();}
137 
138  //MOVE
139  void translate(Geom::Vector &);
140  void rotate(const Geom::Vector & axis, const double angleRadian);
141 
142  protected:
144 
145  private:
146  Base(const Base &); // Copy constructor forbiden
147  Base & operator=(const Base &); // Assignement operator forbiden
148 
149  //SERIALIZATION
151  template<class Archive> void serialize(Archive & ar, const unsigned int version) {
152  }
153 
154  };
155 
156  inline std::ostream&
157  operator<< (std::ostream& os, const Base& b) {
158  return b.write_ascii(os);
159  }
160 
161  inline std::istream&
162  operator>> (std::istream& os, Base& b) {
163  return b.read_ascii(os);
164  }
165 
166  inline void
168  // do nothing
169  }
170 
171  inline void
173  Geom::Point & pt = const_cast<Geom::Point &>(_frame.get_center());
174  pt.translate(t);
175  }
176 
177  inline void
178  Base::rotate(const Geom::Vector & axis, const double angleRad) {
179  Geom::Quaternion & q = const_cast<Geom::Quaternion & >(_frame.get_quaternion());
180  q.set_axis_angle(axis, angleRad);
181  }
182 
183  inline std::string
184  Base::info() const {
185  std::ostringstream str;
186  str << "Frame center : " << local_frame().get_center() << '\n';
187  str << "Frame quaternion : " << local_frame().get_quaternion() << '\n';
188  return str.str();
189  }
190 
191  }
192 }
193 
194 
196 
197 namespace GranOO3
198 {
199  namespace Core
200  {
201 
202  template<class ChildClass>
203  struct ObjectFactoryConstructorWrapper<Shape::Base, ChildClass>
204  {
205  static ChildClass* build() {
206  return new ChildClass(Shape::Base::frame_buffer());
207  }
208 
209  };
210 
211  extern template class ObjectFactoryRegistered<Shape::Base>;
212  extern template class ObjectFactory<Shape::Base>;
213 
214  }
215 }
216 
217 
218 
219 
220 
221 
222 
223 #endif
Definition: Base.hpp:61
Definition: Color.hpp:44
Definition: Frame.hpp:68
const Vector & get_position() const
Definition: Point.hpp:62
void translate(const Vector &v)
Definition: Point.cpp:88
Definition: Quaternion.hpp:54
void set_axis_angle(const Vector &axis, double angle)
Definition: Vector.hpp:75
Definition: Base.hpp:97
virtual void scale(double)=0
static Base & glob(const std::string &id)
Definition: Base.cpp:44
virtual void draw_gl() const =0
virtual std::ostream & to_povray(std::ostream &out, const Core::Color &) const
Definition: Base.cpp:100
Base(const Base &)
virtual std::ostream & write_ascii(std::ostream &out) const
Definition: Base.cpp:79
void serialize(Archive &ar, const unsigned int version)
Definition: Base.hpp:151
Base(const Geom::Frame &frame)
Definition: Base.hpp:112
const Geom::Point & get_center() const
Definition: Base.hpp:134
virtual ~Base()
Definition: Base.hpp:113
const Geom::Quaternion & get_quaternion() const
Definition: Base.hpp:135
static Base * new_object(const TiXmlElement *el)
Definition: Base.cpp:60
void translate(Geom::Vector &)
Definition: Base.hpp:172
virtual void to_vtk(vtkUnstructuredGrid *data)
Definition: Base.cpp:90
Base & operator=(const Base &)
virtual std::string info() const
Definition: Base.hpp:184
void unscale(double)
Definition: Base.cpp:94
const Geom::Frame & _frame
Definition: Base.hpp:143
static std::string class_ID()
Definition: Base.hpp:101
static const Geom::Frame * _frame_buffer
Definition: Base.hpp:108
virtual void add_glob(const std::string &)=0
virtual std::istream & read_ascii(std::istream &in)
Definition: Base.cpp:85
virtual void read_xml_element(const TiXmlElement *el)
Definition: Base.cpp:55
friend class boost::serialization::access
Definition: Base.hpp:150
void rotate(const Geom::Vector &axis, const double angleRadian)
Definition: Base.hpp:178
virtual bool is_surface() const =0
virtual bool is_volume() const =0
const Geom::Frame & local_frame() const
Definition: Base.hpp:133
const Geom::Vector & get_position() const
Definition: Base.hpp:136
virtual void draw_gl_edge() const
Definition: Base.hpp:167
static const Geom::Frame & frame_buffer()
Definition: Base.cpp:49
std::ostream & operator<<(std::ostream &os, const Base &)
Definition: Base.hpp:157
std::istream & operator>>(std::istream &is, Base &)
Definition: Base.hpp:162
Definition: Common.hpp:198
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 t(t+t)") define_sfop3(16
static std::string data()
Definition: Exprtk.hpp:44228
static char_cptr version
Definition: Exprtk.hpp:44221
Definition: ObjectFactory.hpp:249