GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Rectangle.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_Rectangle_hh_
31 #define _GranOO_LibShape_Rectangle_hh_
32 
33 #include <iostream>
34 #include <string>
35 
36 #include <vtkUnstructuredGrid.h>
37 
39 #include "GranOO3/Geom/Point.hpp"
41 
42 #include "GranOO3/Core/String.hpp"
44 
45 
46 
47 namespace GranOO3
48 {
49  namespace Shape
50  {
51 
52  class Rectangle : public Surface,
53  public Core::ObjectFactoryInterface< Base, Rectangle>
54  {
55 
56  GRANOO_OBJECT_FACTORY(Rectangle);
57 
58  public:
59  static std::string class_ID() {
60  return std::string("Rectangle");
61  }
62 
63  static std::string desc();
64 
65  public:
66  //CONSTRUCTORS & DESTRUCTORS
67  Rectangle();
68  Rectangle(double dimY, double dimZ, const Geom::Frame& frame);
69  Rectangle(const Geom::Frame& frame);
70  Rectangle(const Rectangle &);
71  ~Rectangle();
72 
73  //USEFULL
74  void read_xml_element(const TiXmlElement* el);
75  std::string description() const;
76 
77  std::string get_str_type_key() const {
78  return Rectangle::class_ID();
79  }
80 
81  double area() const {
82  return _ly*_lz;
83  }
84 
85  //ACCESSORS
86  GRANOO_ACCESS_POS(ly, double, _ly);
87  GRANOO_ACCESS_POS(lz, double, _lz);
88 
89 
90  void draw_gl() const;
91  void scale(double);
92 
93  //CONTACT DETECTION v2
94  bool collide(const Volume&, Collision::Data&) const;
95  bool collide(const Geom::Point&, Collision::Data&) const;
96 
97  virtual void to_vtk(vtkUnstructuredGrid* data);
98  std::ostream& to_povray (std::ostream& out, const Core::Color& ) const;
99 
100  private:
101  double _ly;
102  double _lz;
103 
105  template<class Archive> void serialize(Archive & ar, const unsigned int);
106 
107  };
108 
109  inline
110  Rectangle::Rectangle(double dimY, double dimZ, const Geom::Frame& frame)
111  : Surface(frame),
112  _ly(dimY),
113  _lz(dimZ) {
114  SafeModeAssert(_ly>=0, "bad input value");
115  SafeModeAssert(_lz>=0, "bad input value");
116  }
117 
118  inline
120  : Rectangle(0.,0.,Geom::Frame::global) {
121  }
122 
123  inline
125  : Surface(frame),
126  _ly(0.),
127  _lz(0.) {
128  SafeModeAssert(_ly>=0, "bad input value");
129  SafeModeAssert(_lz>=0, "bad input value");
130  }
131 
132  inline
134  : Surface(p.local_frame()),
135  _ly(p.get_ly()),
136  _lz(p.get_lz()) {
137  SafeModeAssert(_ly>=0, "bad input value");
138  SafeModeAssert(_lz>=0, "bad input value");
139  }
140 
141  inline
143  }
144 
145  template<class Archive>
146  inline void
147  Rectangle::serialize(Archive & ar, const unsigned int ) {
148  ar & boost::serialization::base_object<Surface>(*this);
149  ar & _ly;
150  ar & _lz;
151  }
152 
153  }
154 }
155 
156 // Don't forget to export for dynamic serialization of child class
157 #include <boost/serialization/export.hpp>
159 
160 #include <boost/serialization/version.hpp>
162 GRANOO_SERIALIZE_SHAPE(Rectangle)
163 
164 namespace GranOO3
165 {
166  extern template class Core::ObjectFactoryInterface<Shape::Base, Shape::Rectangle>;
167 }
168 
169 
170 #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: Rectangle.hpp:54
std::string description() const
bool collide(const Geom::Point &, Collision::Data &) const
Rectangle()
Definition: Rectangle.hpp:119
static std::string class_ID()
Definition: Rectangle.hpp:59
void serialize(Archive &ar, const unsigned int)
Definition: Rectangle.hpp:147
double area() const
Definition: Rectangle.hpp:81
double _lz
Definition: Rectangle.hpp:102
bool collide(const Volume &, Collision::Data &) const
void read_xml_element(const TiXmlElement *el)
std::ostream & to_povray(std::ostream &out, const Core::Color &) const
std::string get_str_type_key() const
Definition: Rectangle.hpp:77
double _ly
Definition: Rectangle.hpp:101
friend class boost::serialization::access
Definition: Rectangle.hpp:104
static std::string desc()
~Rectangle()
Definition: Rectangle.hpp:142
virtual void to_vtk(vtkUnstructuredGrid *data)
Definition: Surface.hpp:55
Definition: Volume.hpp:103
Definition: Common.hpp:198
static std::string data()
Definition: Exprtk.hpp:44228
Definition: Data.hpp:43