GranOO 3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Loading...
Searching...
No Matches
Ground.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_Ground_tpp_
35#define _libPhysic_Ground_tpp_
36
37#include <string>
38
41#include "GranOO3/Core/Base.hpp"
43
48
49
50namespace GranOO3
51{
52 namespace Physic
53 {
54 class Node;
55
56 // A ground is simply a shape inserted in a simulation.
57 // A ground is like a body without : force, torque, velocity or acceleration.
58 // This is a "passive" body. Each ground have a specific ID
59 // A ground may be a surface or a volume
60
61 class Ground : public Core::Base, public Core::Register<Ground> {
62
63 GRANOO_CLASS(Physic::Ground, Core::Base);
64 GRANOO_CLASS_DEFAULT_COLOR(.2, .8, .4, .2);
65
66 public:
67 static Ground& get(std::string);
68 static bool exist(std::string);
69 static Ground& glob(const std::string& id);
70 static Ground* new_object(const TiXmlElement* el);
71
72 public:
73 //CONSTRUCTORS & DESTRUCTORS
74 Ground(const std::string& id, const Geom::Point & p, const Geom::Quaternion& q);
75 virtual ~Ground();
76
77 //INTERNAL USE (Not documented)
78 virtual void read_xml_element(const TiXmlElement* el);
79 virtual void add_glob(const std::string&) = 0;
80
81 //USEFULL
82 virtual std::string info() const;
83 virtual std::string shape_class_ID() const = 0;
84
85 //ACCESSORS
86 GRANOO_ACCESS (ID , std::string , _ID );
87 GRANOO_ACCESS (center , Geom::Point , _center );
88 GRANOO_ACCESS (position , Geom::Vector , _position );
89 GRANOO_ACCESS (quaternion , Geom::Quaternion, _quat );
90 GRANOO_ACCESS (force , Geom::Vector , _force );
91 GRANOO_ACCESS (contact_force , Geom::Vector , _contact_force );
92 GRANOO_ACCESS (torque , Geom::Vector , _torque );
93 GRANOO_ACCESS (linear_velocity , Geom::Vector , _linear_velocity);
94 GRANOO_ACCESS (angular_velocity, Geom::Vector , _angular_vel );
95 GRANOO_ACCESS_REF_CONST (local_frame, Geom::Frame, _frame );
96
97 // IO
98 virtual std::ostream& write_ascii(std::ostream& out) const;
99 virtual std::istream& read_ascii(std::istream& in);
100 virtual std::ostream& export_to_povray(std::ostream& out) const;
101
102 // SHAPE MANAGEMENT
104 virtual const Shape::Base& to_base_shape() const = 0;
105
107 virtual const Shape::Volume& to_volume_shape() const;
108
110 virtual const Shape::Surface& to_surface_shape() const;
111
112 // FORCE COMPUTATION
113 void apply_force(const Geom::Vector&);
114 void apply_force_at(const Geom::Vector&, const Geom::Point&);
115 void clear_force();
116 void apply_torque(const Geom::Vector&);
117 void clear_torque();
118
119 // incremental_move() applies an incremental linear and angular displacement
120 // from the current velocity values (without any acceleration)
121 void incremental_move();
122
123
125
126 // For contact management, it always return false
127 bool is_interact_with(const Node &) const;
128
129 private:
130 Ground(const Ground &); //Not allowed
131 Ground & operator=(const Ground &); //Not allowed
132
133 //SERIALIZATION
135 template<class Archive> void save(Archive &, const unsigned int) const;
136 template<class Archive> void load(Archive &, const unsigned int);
138
139 protected:
140 Ground();
141
142 protected:
143 std::string _ID;
153 };
154
155 inline bool
157 return false;
158 }
159
160 inline Ground& Ground::get(std::string id) {
162 for (unsigned int i = 0; i<set.size(); ++i) {
163 if (set[i]->get_ID()==id)
164 return *set[i];
165 }
166 UserAssert(0, "can't find Ground named " + id);
167 return *set[0];
168 }
169
170 inline bool Ground::exist(std::string id) {
172 for (unsigned int i = 0; i<set.size(); ++i) {
173 if (set[i]->get_ID()==id)
174 return true;
175 }
176 return false;
177 }
178
179
180 inline Shape::Volume&
182 SafeModeAssert(to_base_shape().is_volume() == true, "Can't cast to Volume");
183 return static_cast<Shape::Volume&>(to_base_shape());
184 }
185
186 inline const Shape::Volume&
188 SafeModeAssert(to_base_shape().is_volume() == true, "Can't cast to Volume");
189 return static_cast<const Shape::Volume&>(to_base_shape());
190 }
191
192 inline Shape::Surface&
194 SafeModeAssert(to_base_shape().is_surface() == true, "Can't cast to surface");
195 return static_cast<Shape::Surface&>(to_base_shape());
196 }
197
198 inline const Shape::Surface&
200 SafeModeAssert(to_base_shape().is_surface() == true, "Can't cast to surface");
201 return static_cast<const Shape::Surface&>(to_base_shape());
202 }
203
204
205 inline std::string
206 Ground::info() const {
207 std::ostringstream os;
208
209 os << "**Ground**" << '\n'
210 << "id : " << _ID << '\n'
211 << "center : " << _center << '\n'
212 << "quaternion: " << _quat << '\n';
213 return os.str();
214 }
215
216 template<class Archive>
217 void
218 Ground::save(Archive& ar, const unsigned int v) const {
219 ar << boost::serialization::base_object<Core::Base>(*this);
220 ar << _ID;
221 ar << _center;
222 ar << _quat;
223 ar << _force;
224 ar << _torque;
225 ar << _linear_velocity;
226 ar << _angular_vel;
227 }
228
229 template<class Archive>
230 void
231 Ground::load(Archive& ar, const unsigned int v) {
232 ar >> boost::serialization::base_object<Core::Base>(*this);
233 std::string& id = const_cast<std::string&>(_ID);
234 ar >> id;
235 ar >> _center;
236 ar >> _quat;
237 ar >> _force;
238 ar >> _torque;
239 ar >> _linear_velocity;
240 ar >> _angular_vel;
241
242 local_frame().update_glMatrix();
245 }
246
247 }
248}
249
250#include <boost/serialization/version.hpp>
252
253namespace GranOO3
254{
255 GRANOO_CLASS_DECLARE_TPL(Physic::Ground);
256}
257
258
259
260#endif
BOOST_CLASS_VERSION(GranOO3::Physic::Ground, 0) namespace GranOO3
Definition Ground.hpp:251
#define SafeModeAssert(condition, message)
Definition Macro.hpp:47
#define UserAssert(condition, message)
Definition Macro.hpp:54
Definition Base.hpp:61
virtual const std::string & get_ID() const
Definition Base.hpp:144
Definition SetOf.hpp:346
static SetOf< type > & get_global_set()
const std::string & get_SerializationPrefix()
Definition SetOfManager.cpp:74
const std::string & get_SerializationSuffix()
Definition SetOfManager.cpp:89
static SetOfManager & get()
Definition Singleton.hpp:127
Definition Frame.hpp:68
Definition Point.hpp:62
Definition Quaternion.hpp:54
Definition Vector.hpp:75
Definition Ground.hpp:61
virtual std::ostream & write_ascii(std::ostream &out) const
Definition Ground.cpp:120
Geom::Vector get_linear_velocity_at(const Geom::Point &) const
Definition Ground.cpp:110
virtual std::string info() const
Definition Ground.hpp:206
static bool exist(std::string)
Definition Ground.hpp:170
void clear_torque()
Definition Ground.cpp:72
Geom::Vector _force
Definition Ground.hpp:148
static Ground & glob(const std::string &id)
Geom::Frame _frame
Definition Ground.hpp:147
Ground(const Ground &)
static Ground & get(std::string)
Definition Ground.hpp:160
virtual Shape::Base & to_base_shape()=0
virtual Shape::Surface & to_surface_shape()
Definition Ground.hpp:193
Geom::Vector & _position
Definition Ground.hpp:145
virtual ~Ground()
Definition Ground.cpp:63
virtual std::string shape_class_ID() const =0
Geom::Point _center
Definition Ground.hpp:144
Ground(const std::string &id, const Geom::Point &p, const Geom::Quaternion &q)
Definition Ground.cpp:47
virtual std::istream & read_ascii(std::istream &in)
Definition Ground.cpp:128
virtual Shape::Volume & to_volume_shape()
Definition Ground.hpp:181
virtual std::ostream & export_to_povray(std::ostream &out) const
Definition Ground.cpp:145
void apply_torque(const Geom::Vector &)
Definition Ground.cpp:88
void clear_force()
Definition Ground.cpp:67
void apply_force(const Geom::Vector &)
Definition Ground.cpp:77
bool is_interact_with(const Node &) const
Definition Ground.hpp:156
Ground()
Definition Ground.cpp:59
static Ground * new_object(const TiXmlElement *el)
virtual void read_xml_element(const TiXmlElement *el)
Ground & operator=(const Ground &)
Geom::Vector _contact_force
Definition Ground.hpp:149
Geom::Vector _torque
Definition Ground.hpp:150
std::string _ID
Definition Ground.hpp:143
virtual const Shape::Base & to_base_shape() const =0
Geom::Quaternion _quat
Definition Ground.hpp:146
friend class boost::serialization::access
Definition Ground.hpp:134
Geom::Vector _angular_vel
Definition Ground.hpp:152
void load(Archive &, const unsigned int)
Definition Ground.hpp:231
virtual void add_glob(const std::string &)=0
void incremental_move()
Definition Ground.cpp:93
Geom::Vector _linear_velocity
Definition Ground.hpp:151
void apply_force_at(const Geom::Vector &, const Geom::Point &)
Definition Ground.cpp:82
void save(Archive &, const unsigned int) const
Definition Ground.hpp:218
Definition Node.hpp:58
Definition Base.hpp:97
Definition Surface.hpp:55
Definition Volume.hpp:103
This namespace group the entire Physic library.
Definition Common.hpp:198