GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Cone.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_Cone_hh_
31 #define _GranOO_LibShape_Cone_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 Cone : public Volume,
47  public Core::ObjectFactoryInterface<Base, Cone>
48  {
49 
50  GRANOO_OBJECT_FACTORY(Cone);
51 
52  public:
53  static std::string class_ID() {return std::string("Cone");}
54  static std::string desc();
55 
56  public:
57  //CONSTRUCTORS & DESTRUCTORS
58  Cone();
59  Cone(double radius, double length, const Geom::Frame& frame);
60  Cone(const Cone &);
61  Cone(const Cone &, const Geom::Frame&);
62  Cone(const Geom::Frame& frame);
63  virtual ~Cone();
64 
65  //IO
66  void read_xml_element(const TiXmlElement* el);
67  virtual std::ostream& write_ascii (std::ostream& out) const;
68  virtual std::istream& read_ascii (std::istream& in);
69  virtual void to_vtk(vtkUnstructuredGrid* data);
70  std::string info() const;
71 
72  //CLONING
73  void make_equal_to(const Cone&);
74 
75  //BOUNDING SHAPE
78  double get_greatest_dimension() const;
79  AABB aabb() const;
80 
81  //CONTACT DETECTION
83  Interference locate(const Geom::Point&, double radius) const;
84 
85  //CONTACT DETECTION v2
86  GRANOO_DECLARE_SHAPE_COLLISION();
87  bool collide_inside(const Geom::Point& p1, double radius, Collision::Data& info) const;
88  bool collide_outside(const Geom::Point& p1, double radius, Collision::Data& info) const;
90 
91  //USEFULL
92  double get_volume() const;
93  void compute_inertia_tensor(double density, Geom::Tensor &) const;
94  double get_half_angle() const {
95  return atan(_radius/_length);
96  }
97 
98  void draw_gl() const;
99  void scale(double);
100 
101 
102 
103  //ACCESSORS
104  GRANOO_ACCESS_SHAPE_DIM(radius, double, _radius);
105  GRANOO_ACCESS_SHAPE_DIM(length, double, _length);
106  double get_radius_at(double) const;
107 
108  std::ostream& to_povray (std::ostream& out, const Core::Color& ) const;
109 
110  private:
111  Cone & operator=(const Cone &); //Not allowed
112 
113  //SERIALIZATION
115  template<class Archive> void serialize(Archive&, const unsigned int);
116 
117  private:
118  double _radius;
119  double _length;
122  };
123 
124 
125 
126 
127 
128  inline
129  Cone::Cone(double radius, double length, const Geom::Frame& frame)
130  : Volume(frame),
131  _radius(radius),
132  _length(length),
133  _bounding_box(0),
134  _bounding_sphere(0) {
135  set_face_ID("xMin", "radius", "vertex");
136  SafeModeAssert(_radius>=0, "bad input value");
137  SafeModeAssert(_length>=0, "bad input value");
138  }
139 
140  inline
142  : Cone(0., 0., Geom::Frame::global) {
143  }
144 
145  inline
146  Cone::Cone(const Cone &s, const Geom::Frame& frame)
147  : Cone(s._radius, s._length, frame) {
148  }
149 
150  inline
151  Cone::Cone(const Cone &s)
152  : Cone(s._radius, s._length, s._frame ) {
153  }
154 
155  inline
156  Cone::Cone(const Geom::Frame& frame)
157  : Cone(0., 0., frame) {
158  }
159 
160  inline double
162  return _length*M_PI*pow(_radius,2)/3.;
163  }
164 
165  inline double
167  double max = get_radius()*2.;
168  if (get_length() > max)
169  max = get_length();
170 
171  return max;
172  }
173 
174  inline
175  AABB Cone::aabb() const {
176 
177  double xMin = farthest_point_along(Geom::Vector(-1, 0, 0)).x();
178  double xMax = farthest_point_along(Geom::Vector( 1, 0, 0)).x();
179  double yMin = farthest_point_along(Geom::Vector( 0, -1, 0)).y();
180  double yMax = farthest_point_along(Geom::Vector( 0, 1, 0)).y();
181  double zMin = farthest_point_along(Geom::Vector( 0, 0, -1)).z();
182  double zMax = farthest_point_along(Geom::Vector( 0, 0, 1)).z();
183 
184  double minPoint[] = { xMin, yMin, zMin };
185  double maxPoint[] = { xMax, yMax, zMax };
186 
187  return StaticAABBTree::new_lonely_aabb(minPoint, maxPoint);
188  }
189 
190  inline void
191  Cone::compute_inertia_tensor(double density, Geom::Tensor &m) const {
192  const double mass = get_volume()*density;
193 
194  m.clear();
195  const double Ixx = (3./10.)*mass*pow(_radius,2);
196  const double Iyy = (3./20.)*mass*pow(_radius,2) + (1./10.)*mass*pow(_length,2);
197  m.xx() = Ixx;
198  m.yy() = m.zz() = Iyy;
199  }
200 
201  inline double
202  Cone::get_radius_at(double x) const {
203  x += _length/4.;
204  return _radius - (_radius/_length)*x;
205  }
206 
207  template<class Archive>
208  inline void
209  Cone::serialize(Archive& ar, const unsigned int) {
210  ar & boost::serialization::base_object<Volume>(*this);
211  ar & _radius;
212  ar & _length;
213  }
214 
215  }
216 }
217 
218 //Don't forget to export for dynamic serialization of child class
219 #include <boost/serialization/export.hpp>
221 
222 #include <boost/serialization/version.hpp>
224 GRANOO_SERIALIZE_SHAPE(Cone)
225 
226 namespace GranOO3
227 {
228  extern template class Core::ObjectFactoryInterface<Shape::Base, Shape::Cone>;
229 }
230 
231 
232 
233 #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: Cone.hpp:48
Interference locate(const Geom::Point &, double radius) const
bool collide_outside(const Geom::Point &p1, double radius, Collision::Data &info) const
virtual void to_vtk(vtkUnstructuredGrid *data)
virtual std::istream & read_ascii(std::istream &in)
std::string info() const
Cone & operator=(const Cone &)
std::ostream & to_povray(std::ostream &out, const Core::Color &) const
static std::string desc()
void read_xml_element(const TiXmlElement *el)
double _length
Definition: Cone.hpp:119
void make_equal_to(const Cone &)
double get_greatest_dimension() const
Definition: Cone.hpp:166
AABB aabb() const
Definition: Cone.hpp:175
void serialize(Archive &, const unsigned int)
Definition: Cone.hpp:209
Box * _bounding_box
Definition: Cone.hpp:120
Interference locate(const Geom::Point &) const
double get_volume() const
Definition: Cone.hpp:161
void compute_inertia_tensor(double density, Geom::Tensor &) const
Definition: Cone.hpp:191
double get_radius_at(double) const
Definition: Cone.hpp:202
Geom::Point farthest_point_along(const Geom::Vector &) const
Sphere * _bounding_sphere
Definition: Cone.hpp:121
double _radius
Definition: Cone.hpp:118
virtual std::ostream & write_ascii(std::ostream &out) const
void scale(double)
friend class boost::serialization::access
Definition: Cone.hpp:114
void draw_gl() const
double get_half_angle() const
Definition: Cone.hpp:94
Cone()
Definition: Cone.hpp:141
bool collide_inside(const Geom::Point &p1, double radius, Collision::Data &info) const
static std::string class_ID()
Definition: Cone.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