GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Polyhedron.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 #ifndef _GranOO_LibShape__Polyhedron_Corehh_
30 #define _GranOO_LibShape__Polyhedron_Corehh_
31 
32 #include <iostream>
33 #include <fstream>
34 #include <string>
35 
36 #include <boost/serialization/string.hpp>
37 #include <boost/serialization/vector.hpp>
38 
39 #include <vtkUnstructuredGrid.h>
40 
41 
43 #include "GranOO3/Geom/Point.hpp"
44 #include "GranOO3/Shape/Sphere.hpp"
45 #include "GranOO3/Shape/Volume.hpp"
47 #include "GranOO3/Core/String.hpp"
48 
49 namespace GranOO3
50 {
51  namespace Shape
52  {
53  class Polyhedron : public Volume, public Core::ObjectFactoryInterface<Base, Polyhedron>
54  {
55  GRANOO_OBJECT_FACTORY(Polyhedron);
56 
57  public:
58  static std::string class_ID() {return std::string("Polyhedron");}
59  static std::string desc();
60 
61  public:
62  //CONSTRUCTORS & DESTRUCTORS
64  Polyhedron(std::string fileName, const Geom::Frame &frame);
65  Polyhedron(const Polyhedron &polyhedron, const Geom::Frame &frame);
66  Polyhedron(const Geom::Frame &frame);
68  virtual ~Polyhedron();
69 
70  //IO
71  void read_xml_element(const TiXmlElement *element);
72  virtual std::ostream &write_ascii(std::ostream &out) const;
73  virtual std::istream &read_ascii(std::istream &in);
74  virtual void to_vtk(vtkUnstructuredGrid *data);
75  std::string info() const;
76  void to_vtk(const unsigned int shift, unsigned int* conn, unsigned int* cell_type, double* point) const;
77  unsigned int vtk_conn_number() const;
78 
79  //CLONING
80  void make_equal_to(const Polyhedron&);
81 
82  //BOUNDING SHAPE
85  double get_greatest_dimension() const;
86  AABB aabb() const;
87 
88  //USEFULL
89  void set_input_file(std::stringstream &stringStream, bool update = true, bool translate_to_centroid = true);
90  void set_input_file(const std::string &offFile, bool update = true, bool translate_to_centroid = true);
91  void set_output_file(const std::string &offFile);
92  void set_input_offset_file(const std::string &offFile);
93  double get_volume() const;
94  void compute_inertia_tensor(double density, Geom::Tensor &) const;
96  bool basefacet_from_normal(const Geom::Vector &normal, unsigned int &basefacetIndex) const;
97  Geom::Point basefacet_center(const unsigned int basefacetIndex) const;
98 
99  double area_of_facet_crossed_by_vector(const Geom::Point &, const Geom::Vector &, unsigned int &, Geom::Vector &) const;
102  const PolyhedronCore& get_polyhedron_core() const;
103 
104  const std::map<std::string, std::vector<int>> &get_facet_map() const { return _map_facet; };
105 
106 
107  void draw_gl() const;
108  void draw_gl_edge() const;
109  void scale(double ratio);
110 
111  unsigned int get_number_of_vertex() const;
112  unsigned int get_number_of_facet() const;
113 
114  //CONTACT DETECTION
116  Interference locate(const Geom::Point &, double radius) const;
117  bool overlap(const Sphere &, double margin, std::vector<std::string> &facet) const;
118  double compute_distance(const Geom::Point &);
119 
120  //CONTACT DETECTION v2
121  GRANOO_DECLARE_SHAPE_COLLISION();
122  bool collide_inside(const Geom::Point& p1, double radius, Collision::Data& info) const;
123  bool collide_outside(const Geom::Point& p1, double radius, Collision::Data& info) const;
124 
125  std::ostream& to_povray(std::ostream& out, const Core::Color& ) const;
126 
127  private:
128  Polyhedron & operator = (const Polyhedron &); // copy constructor forbidden
129 
130  //SERIALIZATION
132  template<class Archive> void save(Archive& ar, const unsigned int version) const;
133  template<class Archive> void load(Archive& ar, const unsigned int version);
135 
136  private:
138  std::map<std::string, std::vector<int> > _map_facet;
139  };
140 
141 
142  inline PolyhedronCore&
144  return _polyhedron_core;
145  }
146 
147  inline const
150  return _polyhedron_core;
151  }
152 
153  template<class Archive>
154  inline void
155  Polyhedron::save(Archive& ar, const unsigned int version) const {
156  ar << boost::serialization::base_object<Volume>(*this);
157 
158  std::stringstream out;
160 
161  std::string str = out.str();
162  ar << str;
163  }
164 
165  template<class Archive>
166  inline void
167  Polyhedron::load(Archive& ar, const unsigned int version) {
168  ar >> boost::serialization::base_object<Volume>(*this);
169 
170  std::string str;
171  ar >> str;
172  std::stringstream stream(str);
175  }
176 
177  }
178 }
179 
180 //Don't forget to export for dynamic serialization of child class
181 #include <boost/serialization/export.hpp>
183 
184 #include <boost/serialization/version.hpp>
186 GRANOO_SERIALIZE_SHAPE(Polyhedron)
187 
188 
189 namespace GranOO3
190 {
191  extern template class Core::ObjectFactoryInterface<Shape::Base, Shape::Polyhedron>;
192 }
193 
194 
195 #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
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: Polyhedron.hpp:54
void read_xml_element(const TiXmlElement *element)
unsigned int get_number_of_vertex() const
void set_input_file(const std::string &offFile, bool update=true, bool translate_to_centroid=true)
bool collide_inside(const Geom::Point &p1, double radius, Collision::Data &info) const
double compute_distance(const Geom::Point &)
void set_input_file(std::stringstream &stringStream, bool update=true, bool translate_to_centroid=true)
void set_input_offset_file(const std::string &offFile)
void load(Archive &ar, const unsigned int version)
Definition: Polyhedron.hpp:167
virtual std::istream & read_ascii(std::istream &in)
std::ostream & to_povray(std::ostream &out, const Core::Color &) const
bool collide_outside(const Geom::Point &p1, double radius, Collision::Data &info) const
Geom::Point farthest_point_along(const Geom::Vector &) const
Geom::Point initial_centroid() const
void scale(double ratio)
Polyhedron(const Polyhedron &s)
PolyhedronCore _polyhedron_core
Definition: Polyhedron.hpp:137
virtual void to_vtk(vtkUnstructuredGrid *data)
Interference locate(const Geom::Point &, double radius) const
std::map< std::string, std::vector< int > > _map_facet
Definition: Polyhedron.hpp:138
Polyhedron(const Polyhedron &polyhedron, const Geom::Frame &frame)
Geom::Point basefacet_center(const unsigned int basefacetIndex) const
double area_of_facet_crossed_by_vector(const Geom::Point &, const Geom::Vector &, unsigned int &, Geom::Vector &) const
void to_vtk(const unsigned int shift, unsigned int *conn, unsigned int *cell_type, double *point) const
virtual std::ostream & write_ascii(std::ostream &out) const
void make_equal_to(const Polyhedron &)
void compute_inertia_tensor(double density, Geom::Tensor &) const
bool basefacet_from_normal(const Geom::Vector &normal, unsigned int &basefacetIndex) const
static std::string desc()
const std::map< std::string, std::vector< int > > & get_facet_map() const
Definition: Polyhedron.hpp:104
void set_output_file(const std::string &offFile)
Polyhedron(const Geom::Frame &frame)
friend class boost::serialization::access
Definition: Polyhedron.hpp:131
void save(Archive &ar, const unsigned int version) const
Definition: Polyhedron.hpp:155
unsigned int vtk_conn_number() const
Polyhedron(std::string fileName, const Geom::Frame &frame)
bool overlap(const Sphere &, double margin, std::vector< std::string > &facet) const
PolyhedronCore & get_polyhedron_core()
Definition: Polyhedron.hpp:143
double get_greatest_dimension() const
std::string info() const
Polyhedron & operator=(const Polyhedron &)
unsigned int get_number_of_facet() const
static std::string class_ID()
Definition: Polyhedron.hpp:58
Interference locate(const Geom::Point &) const
Definition: Sphere.hpp:50
Definition: Volume.hpp:103
void update_bounding_shape()
Definition: Volume.cpp:96
Definition: PolyhedronCore.hpp:38
void to_off_format(std::stringstream &offString, bool basefacet=true) const
Creates an std::stringstream with the polyhedron contents, in OFF file format.
Definition: PolyhedronCore.cpp:256
Interference
Definition: Volume.hpp:100
Definition: Common.hpp:198
static std::string data()
Definition: Exprtk.hpp:44228
static char_cptr version
Definition: Exprtk.hpp:44221
Definition: StaticAABBTree.hpp:38
Definition: Data.hpp:43