GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
ConeTruncated.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_ConeTruncated_hh_
31 #define _GranOO_LibShape_ConeTruncated_hh_
32 
33 #include <iostream>
34 #include <string>
35 
36 #include <vtkUnstructuredGrid.h>
37 
38 #include "GranOO3/Geom/Point.hpp"
39 #include "GranOO3/Shape/Volume.hpp"
40 #include "GranOO3/Core/String.hpp"
41 
42 namespace GranOO3 {
43 
44 namespace Shape {
45 
46  class Sphere;
47  class ConeTruncated : public Volume, public Core::ObjectFactoryInterface<Base, ConeTruncated> {
48 
49  GRANOO_OBJECT_FACTORY(ConeTruncated);
50 
51  private:
53  XMIN = 1 << 0,
54  RADIUS = 1 << 1,
55  XMAX = 1 << 2,
56  };
57 
58  public:
59  static std::string class_ID() {return std::string("ConeTruncated");}
60  static std::string desc();
61 
62  public:
63  //CONSTRUCTORS & DESTRUCTORS
64  ConeTruncated();
65  ConeTruncated(double radius1, double radius2, double length, const Geom::Frame& frame);
67  ConeTruncated(const ConeTruncated &, const Geom::Frame&);
68  ConeTruncated(const Geom::Frame& frame);
69  virtual ~ConeTruncated();
70 
71  //IO
72  void read_xml_element(const TiXmlElement* el);
73  virtual std::ostream& write_ascii (std::ostream& out) const;
74  virtual std::istream& read_ascii (std::istream& in);
75  virtual void to_vtk(vtkUnstructuredGrid* data);
76  std::string info() const;
77 
78  //CLONING
80 
81  //BOUNDING SHAPE
84  double get_greatest_dimension() const;
85  AABB aabb() const;
86 
87  //CONTACT DETECTION
89  Interference locate(const Geom::Point&, double radius) const;
90  void set_contact_regions(const std::string &regions);
91 
92  //CONTACT DETECTION v2
93  GRANOO_DECLARE_SHAPE_COLLISION();
94  bool collide_inside(const Geom::Point& p1, double radius, Collision::Data& info) const;
95  bool collide_outside(const Geom::Point& p1, double radius, Collision::Data& info) const;
97 
98  //USEFULL
99  double get_volume() const;
100  void compute_inertia_tensor(double density, Geom::Tensor &) const;
101  double get_half_angle() const {
102  return atan((_radius1-_radius2)/_length);
103  }
104 
105  void draw_gl() const;
106  void scale(double);
107 
108  //ACCESSORS
109  GRANOO_ACCESS_SHAPE_DIM(radius1, double, _radius1);
110  GRANOO_ACCESS_SHAPE_DIM(radius2, double, _radius2);
111  GRANOO_ACCESS_SHAPE_DIM(length, double, _length);
112  double get_radius_at(double) const;
113  double get_centre_of_mass() const;
114 
115  std::ostream& to_povray (std::ostream& out, const Core::Color& ) const;
116 
117  private:
118  ConeTruncated & operator=(const ConeTruncated &); //Not allowed
119 
120  //SERIALIZATION
122  template<class Archive> void serialize(Archive&, const unsigned int);
123 
124  private:
125  double _radius1;
126  double _radius2;
127  double _length;
131  };
132 
133  inline
134  ConeTruncated::ConeTruncated(double radius1, double radius2, double length, const Geom::Frame& frame)
135  : Volume(frame),
136  _radius1(radius1),
137  _radius2(radius2),
138  _length(length),
139  _bounding_box(0),
140  _bounding_sphere(0),
141  _cRegion(ContactRegion(XMIN | RADIUS | XMAX)) {
142 
143  set_face_ID("xMin", "radius", "vertex");
144  SafeModeAssert(_radius1>=0, "bad input value");
145  SafeModeAssert(_radius2>=0, "bad input value");
146  SafeModeAssert(_radius1>=_radius2, "bad input value");
147  SafeModeAssert(_length>=0, "bad input value");
148  }
149 
150  inline
151  ConeTruncated::ConeTruncated() : ConeTruncated(0., 0., 0., Geom::Frame::global) {
152 
153  }
154 
155  inline
156  ConeTruncated::ConeTruncated(const ConeTruncated &s, const Geom::Frame& frame) : ConeTruncated(s._radius1, s._radius2, s._length, frame) {
157 
158  }
159 
160  inline
161  ConeTruncated::ConeTruncated(const ConeTruncated &s) : ConeTruncated(s._radius1, s._radius2, s._length, s._frame ) {
162 
163  }
164 
165  inline
166  ConeTruncated::ConeTruncated(const Geom::Frame& frame) : ConeTruncated(0., 0., 0., frame) {
167 
168  }
169 
170  inline double
172 
173  return _length*M_PI*(pow(_radius1, 2)+pow(_radius2, 2)+_radius1*_radius2)/3.;
174  }
175 
176  inline double
178 
179  double max = get_radius1()*2.;
180  if (get_length() > max)
181  max = get_length();
182 
183  return max;
184  }
185 
186  inline
188 
189  double xMin = farthest_point_along(Geom::Vector(-1, 0, 0)).x();
190  double xMax = farthest_point_along(Geom::Vector( 1, 0, 0)).x();
191  double yMin = farthest_point_along(Geom::Vector( 0, -1, 0)).y();
192  double yMax = farthest_point_along(Geom::Vector( 0, 1, 0)).y();
193  double zMin = farthest_point_along(Geom::Vector( 0, 0, -1)).z();
194  double zMax = farthest_point_along(Geom::Vector( 0, 0, 1)).z();
195 
196  double minPoint[] = { xMin, yMin, zMin };
197  double maxPoint[] = { xMax, yMax, zMax };
198 
199  return StaticAABBTree::new_lonely_aabb(minPoint, maxPoint);
200  }
201 
202  inline double
204 
205  x += get_centre_of_mass();
206  return _radius1 - ((_radius1-_radius2)/_length)*x;
207  }
208 
209  template<class Archive>
210  inline void
211  ConeTruncated::serialize(Archive& ar, const unsigned int) {
212 
213  ar & boost::serialization::base_object<Volume>(*this);
214  ar & _radius1;
215  ar & _radius2;
216  ar & _length;
217  ar & _cRegion;
218  }
219  }
220 }
221 
222 //Don't forget to export for dynamic serialization of child class
223 #include <boost/serialization/export.hpp>
225 
226 #include <boost/serialization/version.hpp>
228 GRANOO_SERIALIZE_SHAPE(ConeTruncated)
229 
230 namespace GranOO3 {
231 
232  extern template class Core::ObjectFactoryInterface<Shape::Base, Shape::ConeTruncated>;
233 }
234 
235 #endif
BOOST_CLASS_EXPORT_KEY(GranOO3::Shape::Box) namespace GranOO3
Definition: Box.hpp:319
BOOST_CLASS_VERSION(GranOO3::Core::Base, 1) namespace GranOO3
Definition: Base.hpp:277
#define SafeModeAssert(condition, message)
Definition: Macro.hpp:47
Definition: Color.hpp:44
Definition: ObjectFactory.hpp:235
Definition: Frame.hpp:68
Definition: Point.hpp:62
Definition: Tensor.hpp:62
Definition: Vector.hpp:75
Definition: Box.hpp:57
Definition: ConeTruncated.hpp:47
static std::string class_ID()
Definition: ConeTruncated.hpp:59
double get_centre_of_mass() const
std::ostream & to_povray(std::ostream &out, const Core::Color &) const
bool collide_inside(const Geom::Point &p1, double radius, Collision::Data &info) const
double get_radius_at(double) const
Definition: ConeTruncated.hpp:203
void make_equal_to(const ConeTruncated &)
double _radius1
Definition: ConeTruncated.hpp:125
void set_contact_regions(const std::string &regions)
double get_volume() const
Definition: ConeTruncated.hpp:171
Interference locate(const Geom::Point &) const
AABB aabb() const
Definition: ConeTruncated.hpp:187
void read_xml_element(const TiXmlElement *el)
ContactRegion _cRegion
Definition: ConeTruncated.hpp:130
Box * _bounding_box
Definition: ConeTruncated.hpp:128
ConeTruncated()
Definition: ConeTruncated.hpp:151
bool collide_outside(const Geom::Point &p1, double radius, Collision::Data &info) const
ConeTruncated & operator=(const ConeTruncated &)
Interference locate(const Geom::Point &, double radius) const
Geom::Point farthest_point_along(const Geom::Vector &) const
double get_greatest_dimension() const
Definition: ConeTruncated.hpp:177
double _radius2
Definition: ConeTruncated.hpp:126
double get_half_angle() const
Definition: ConeTruncated.hpp:101
static std::string desc()
virtual std::istream & read_ascii(std::istream &in)
friend class boost::serialization::access
Definition: ConeTruncated.hpp:121
double _length
Definition: ConeTruncated.hpp:127
virtual void to_vtk(vtkUnstructuredGrid *data)
std::string info() const
void serialize(Archive &, const unsigned int)
Definition: ConeTruncated.hpp:211
Sphere * _bounding_sphere
Definition: ConeTruncated.hpp:129
virtual std::ostream & write_ascii(std::ostream &out) const
void compute_inertia_tensor(double density, Geom::Tensor &) const
ContactRegion
Definition: ConeTruncated.hpp:52
@ RADIUS
Definition: ConeTruncated.hpp:54
@ XMAX
Definition: ConeTruncated.hpp:55
@ XMIN
Definition: ConeTruncated.hpp:53
Definition: Sphere.hpp:50
Definition: Volume.hpp:103
void set_face_ID(const T &, Args... args)
Definition: Volume.hpp:185
static AABB new_lonely_aabb(double minPoint[3], double maxPoint[3], unsigned int primtiveIndex=-1)
Creates a new 'lonely' AABB with given extreme points.
Definition: StaticAABBTree.cpp:415
Interference
Definition: Volume.hpp:100
Definition: Common.hpp:198
T pow(const T v0, const T v1)
Definition: Exprtk.hpp:1491
T max(const T v0, const T v1)
Definition: Exprtk.hpp:1463
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)
static std::string data()
Definition: Exprtk.hpp:44228
Definition: StaticAABBTree.hpp:38
Definition: Data.hpp:43