GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
GroundT.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for Physic simulation.
2 //
3 // Author(s) : - Jean-luc CHARLES I2M-DuMAS/ENSAM Talence France
4 // <jean-luc.charles@ensam.eu>
5 // - Damien ANDRE SPCTS/ENS Ceramique industrielle, Limoges France
6 // <damien.andre@unilim.fr>
7 // - Jeremie GIRARDOT I2M-DuMAS/ENSAM Talence France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UVHC Valenciennes France
10 // <cedric.hubert@univ-valenciennes.fr>
11 // - Ivan IORDANOFF I2M-DuMAS-MPI/ENSAM Talence France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2016 JL. CHARLES, D. ANDRE, I. IORDANOFF, J. GIRARDOT
15 //
16 //
17 //
18 //
19 //
20 // This program is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 // This program is distributed in the hope that it will be useful,
26 // but WITHOUT ANY WARRANTY; without even the implied warranty of
27 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 // GNU General Public License for more details.
29 //
30 // You should have received a copy of the GNU General Public License
31 // along with this program. If not, see <http://www.gnu.org/licenses/>.
32 
33 
34 #ifndef _LibPhysic_GroundT_H
35 #define _LibPhysic_GroundT_H
36 
37 #include <boost/serialization/version.hpp>
38 #include <boost/serialization/map.hpp>
39 
42 
43 // Volume shape
44 #include "GranOO3/Shape/Sphere.hpp"
45 #include "GranOO3/Shape/Box.hpp"
47 #include "GranOO3/Shape/Cone.hpp"
50 
51 // surface shape
52 #include "GranOO3/Shape/Plane.hpp"
54 #include "GranOO3/Shape/Disk.hpp"
55 
56 
57 namespace GranOO3
58 {
59  namespace Physic
60  {
61 
62  template<class shape>
63  class GroundT : public Ground,
64  public shape,
65  public Core::ObjectFactoryInterface<Ground, GroundT<shape> >,
66  public Core::Register<GroundT<shape> >
67  {
68 
69  GRANOO_CLASS_T(Physic::GroundT, shape, Ground);
70  GRANOO_OBJECT_FACTORY(GroundT);
71 
72  public:
73  static GroundT<shape>& get(const std::string&);
74  static bool exist(const std::string&);
75 
76  public:
77  //CONSTRUCTORS & DESTRUCTORS
78  GroundT(const std::string&, const Geom::Point & p, const Geom::Quaternion& q);
79 
81  virtual ~GroundT();
82 
83  //USEFULL
84  virtual std::string info() const;
85  void read_xml_element(const TiXmlElement* el);
86  virtual void draw();
87  virtual void draw_edge();
88  std::string shape_class_ID() const;
89 
90 
91  //ACCESSORS
92  const Geom::Frame& local_frame() const;
93 
94  //CASTING
96  virtual const Shape::Base& to_base_shape() const;
97 
98  // IO
99  virtual std::ostream& write_ascii (std::ostream& out) const;
100  virtual std::istream& read_ascii (std::istream& in);
101 
102  private:
103  GroundT(const GroundT&) = delete;
104  GroundT & operator=(const GroundT &) = delete;
105 
106  //BOOST SERIALIZATION
108  template<class Archive> void serialize(Archive&, const unsigned int);
109  };
110 
111 #ifndef DOXYGEN_SHOULD_SKIP_THIS
112 
113  template<typename shape>
114  inline GroundT<shape>&
115  GroundT<shape>::get(const std::string& id) {
116  Core::SetOf< GroundT<shape> >& set = Core::SetOf< GroundT<shape> >::get_global_set();
117  for (unsigned int i = 0; i<set.size(); ++i) {
118  if (set[i]->Ground::get_ID()==id)
119  return *set[i];
120  }
121  UserAssert(0, "can't find discrete shape " + id);
122  return set(0);
123  }
124 
125  template<typename shape>
126  inline bool
127  GroundT<shape>::exist(const std::string& id) {
128  Core::SetOf< GroundT<shape> >& set = Core::SetOf< GroundT<shape> >::get_global_set();
129  for (unsigned int i = 0; i<set.size(); ++i) {
130  if (set[i]->Ground::get_ID()==id)
131  return true;
132  }
133  return false;
134  }
135 
136  // Constructors
137  template<class shape>
138  inline
139  GroundT<shape>::GroundT(const std::string& id, const Geom::Point & p, const Geom::Quaternion& q)
140  : Ground(id, p, q),
141  shape(Ground::local_frame()) {
142  }
143 
144  template<class shape>
145  inline
147  : GroundT("", Geom::global::center, Geom::global::quaternion) {
148  }
149 
150  template<class shape>
151  inline
153  }
154 
155  template<class shape>
156  const Geom::Frame &
158  return Ground::local_frame();
159  }
160 
161  template<class shape>
162  inline const Shape::Base&
164  return *this;
165  }
166 
167  template<class shape>
168  inline Shape::Base&
170  return *this;
171  }
172 
173  template<class shape>
174  inline std::string
175  GroundT<shape>::info() const {
176  std::ostringstream os;
177  os << Ground::info() << '\n'
178  << shape::info();
179  return os.str();
180  }
181 
182  template<class shape>
183  inline void
184  GroundT<shape>::read_xml_element(const TiXmlElement* el) {
186  shape::read_xml_element(el);
187  }
188 
189  template<class shape>
190  inline std::string
192  return shape::class_ID();
193  }
194 
195  template<class shape>
196  std::ostream&
197  GroundT<shape>::write_ascii (std::ostream& out) const {
198  Ground::write_ascii(out);
199  shape::write_ascii(out);
200  return out;
201  }
202 
203  template<class shape>
204  std::istream&
205  GroundT<shape>::read_ascii (std::istream& in) {
206  Ground::read_ascii(in);
207  shape::read_ascii(in);
208  return in;
209  }
210 
211  template<class shape>
212  template<class Archive>
213  void
214  GroundT<shape>::serialize(Archive & ar, const unsigned int version) {
215  ar & boost::serialization::base_object<Ground>(*this);
216  ar & boost::serialization::base_object<shape>(*this);
217  }
218 
219  template<class shape>
220  inline void
222 #ifndef SERVER
223  Drawable::apply_color();
224  glPushMatrix();
225  glMultMatrixd(local_frame().get_glMatrix());
226  shape::draw_gl();
227  glPopMatrix();
228 #endif
229  }
230 
231 
232  template<class shape>
233  inline void
235 #ifndef SERVER
236  Drawable::apply_color();
237  glPushMatrix();
238  glMultMatrixd(local_frame().get_glMatrix());
239  shape::draw_gl_edge();
240  glPopMatrix();
241 #endif
242  }
243 
244 
245 #endif
246  }
247 }
248 
249 
250 
251 namespace GranOO3
252 {
253  GRANOO_CLASS_DECLARE_TPL(Physic::GroundT<Shape::Sphere>);
254  GRANOO_CLASS_DECLARE_TPL(Physic::GroundT<Shape::Box>);
255  GRANOO_CLASS_DECLARE_TPL(Physic::GroundT<Shape::Cylinder>);
256  GRANOO_CLASS_DECLARE_TPL(Physic::GroundT<Shape::Cone>);
257  GRANOO_CLASS_DECLARE_TPL(Physic::GroundT<Shape::ConeTruncated>);
258  GRANOO_CLASS_DECLARE_TPL(Physic::GroundT<Shape::Polyhedron>);
259 }
260 
261 
262 namespace GranOO3
263 {
264  namespace Core
265  {
266 
267  template<class shape>
268  struct Read<Physic::GroundT<shape> >
269  {
270  static Base* new_object(const std::string& classID, std::istream& in) {
272  pt->read_ascii(in);
273  return pt;
274  }
275 
276  };
277  }
278 }
279 
280 
281 #endif
282 
#define UserAssert(condition, message)
Definition: Macro.hpp:54
Definition: Base.hpp:61
virtual const std::string & get_ID() const
Definition: Base.hpp:144
Definition: ObjectFactory.hpp:235
Definition: SetOf.hpp:346
Definition: SetOf.hpp:236
Definition: Frame.hpp:68
Definition: Point.hpp:62
Definition: Quaternion.hpp:54
Definition: Ground.hpp:61
virtual std::ostream & write_ascii(std::ostream &out) const
Definition: Ground.cpp:120
virtual std::string info() const
Definition: Ground.hpp:206
virtual std::istream & read_ascii(std::istream &in)
Definition: Ground.cpp:128
virtual void read_xml_element(const TiXmlElement *el)
Definition: GroundT.hpp:67
const Geom::Frame & local_frame() const
void read_xml_element(const TiXmlElement *el)
virtual std::ostream & write_ascii(std::ostream &out) const
void serialize(Archive &, const unsigned int)
GroundT(const GroundT &)=delete
virtual std::istream & read_ascii(std::istream &in)
virtual const Shape::Base & to_base_shape() const
GroundT(const std::string &, const Geom::Point &p, const Geom::Quaternion &q)
static bool exist(const std::string &)
GroundT & operator=(const GroundT &)=delete
static GroundT< shape > & get(const std::string &)
std::string shape_class_ID() const
virtual std::string info() const
friend class boost::serialization::access
Definition: GroundT.hpp:107
virtual Shape::Base & to_base_shape()
virtual void draw_edge()
Definition: Base.hpp:97
Definition: Common.hpp:198
static char_cptr version
Definition: Exprtk.hpp:44221
static Base * new_object(const std::string &classID, std::istream &in)
Definition: GroundT.hpp:270
Definition: SetOfManager.hpp:63