GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Triangle.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_Triangle_hh_
31 #define _GranOO_LibShape_Triangle_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 Triangle : public Surface,
53  public Core::ObjectFactoryInterface< Base, Triangle>
54  {
55 
56  GRANOO_OBJECT_FACTORY(Triangle);
57 
58  public:
59  static std::string class_ID() {return std::string("Triangle");}
60  static std::string desc();
61 
62  public:
63  //CONSTRUCTORS & DESTRUCTORS
64  Triangle();
65  Triangle(double a, double b, double c, const Geom::Frame& frame);
66  Triangle(const Geom::Point& A, const Geom::Point& B, const Geom::Point& C, const Geom::Frame& frame,
67  Geom::Point& frameCenter, Geom::Quaternion& frameQuat);
68  Triangle(const Geom::Frame& frame);
69  Triangle(const Triangle &);
70  ~Triangle();
71 
72  //USEFULL
73  void read_xml_element(const TiXmlElement* el);
74  std::string description() const;
75  std::string get_str_type_key() const;
76  double area() const;
77 
78  //ACCESSORS
79  GRANOO_ACCESS_POS(la, double, _la );
80  GRANOO_ACCESS_POS(lb, double, _lb );
81  GRANOO_ACCESS_POS(angle, double, _angle );
82 
83  void draw_gl() const;
84  void scale(double);
85 
86  //CONTACT DETECTION v2
87  bool collide(const Volume&, Collision::Data&) const;
88  bool collide(const Geom::Point&, Collision::Data&) const;
89 
90  virtual void to_vtk(vtkUnstructuredGrid* data);
91  std::ostream& to_povray(std::ostream& out, const Core::Color& ) const;
92 
93  private:
94  bool is_point2D_in_triangle(const Geom::Point& p) const;
95 
96  private:
97  double _la;
98  double _lb;
99  double _angle;
100 
102  template<class Archive> void serialize(Archive & ar, const unsigned int);
103 
104  };
105 
106  inline
107  Triangle::Triangle(double a, double b, double c, const Geom::Frame& frame)
108  : Surface(frame),
109  _la(a),
110  _lb(b),
111  _angle(c) {
112  SafeModeAssert(_la>=0, "bad input value");
113  SafeModeAssert(_lb>=0, "bad input value");
114  SafeModeAssert(_angle>=0, "bad input value");
115  }
116 
117  inline
119  : Triangle(0.,0.,0., Geom::Frame::global) {
120  }
121 
122  inline
124  : Surface(frame),
125  _la(0.),
126  _lb(0.),
127  _angle(0.) {
128  SafeModeAssert(_la>=0, "bad input value");
129  SafeModeAssert(_lb>=0, "bad input value");
130  SafeModeAssert(_angle>=0, "bad input value");
131  }
132 
133  inline
135  : Surface(p.local_frame()),
136  _la(p.get_la()),
137  _lb(p.get_lb()),
138  _angle(p.get_angle()) {
139  SafeModeAssert(_la>=0, "bad input value");
140  SafeModeAssert(_lb>=0, "bad input value");
141  SafeModeAssert(_angle>=0, "bad input value");
142  }
143 
144  inline
146  }
147 
148 
149  inline std::string
151  return Triangle::class_ID();
152  }
153 
154  template<class Archive>
155  inline void
156  Triangle::serialize(Archive & ar, const unsigned int ) {
157  ar & boost::serialization::base_object<Surface>(*this);
158  ar & _la;
159  ar & _lb;
160  ar & _angle;
161  }
162 
163  }
164 }
165 
166 // Don't forget to export for dynamic serialization of child class
167 #include <boost/serialization/export.hpp>
169 
170 #include <boost/serialization/version.hpp>
172 GRANOO_SERIALIZE_SHAPE(Triangle)
173 
174 namespace GranOO3
175 {
176  extern template class Core::ObjectFactoryInterface<Shape::Base, Shape::Triangle>;
177 }
178 
179 
180 #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: Quaternion.hpp:54
Definition: Surface.hpp:55
Definition: Triangle.hpp:54
double _angle
Definition: Triangle.hpp:99
std::string description() const
bool collide(const Volume &, Collision::Data &) const
std::ostream & to_povray(std::ostream &out, const Core::Color &) const
std::string get_str_type_key() const
Definition: Triangle.hpp:150
Triangle()
Definition: Triangle.hpp:118
static std::string desc()
static std::string class_ID()
Definition: Triangle.hpp:59
bool collide(const Geom::Point &, Collision::Data &) const
Triangle(const Geom::Point &A, const Geom::Point &B, const Geom::Point &C, const Geom::Frame &frame, Geom::Point &frameCenter, Geom::Quaternion &frameQuat)
~Triangle()
Definition: Triangle.hpp:145
double _la
Definition: Triangle.hpp:97
void serialize(Archive &ar, const unsigned int)
Definition: Triangle.hpp:156
friend class boost::serialization::access
Definition: Triangle.hpp:101
bool is_point2D_in_triangle(const Geom::Point &p) const
double _lb
Definition: Triangle.hpp:98
void read_xml_element(const TiXmlElement *el)
virtual void to_vtk(vtkUnstructuredGrid *data)
Definition: Volume.hpp:103
Definition: Common.hpp:198
static std::string data()
Definition: Exprtk.hpp:44228
Definition: Data.hpp:43