Bayeux  3.4.1
Core Foundation library for SuperNEMO
i_shape_3d.h
Go to the documentation of this file.
1 // \file geomtools/i_shape_3d.h
2 /* Author(s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2008-05-23
4  * Last modified: 2017-02-22
5  *
6  * Description:
7  *
8  * Interface for all 3D shaped volumes
9  *
10  */
11 
12 #ifndef GEOMTOOLS_I_SHAPE_3D_H
13 #define GEOMTOOLS_I_SHAPE_3D_H 1
14 
15 // Standard library:
16 #include <string>
17 
18 // Third party:
19 // - Boost:
20 #include <boost/utility.hpp>
21 #include <boost/optional.hpp>
22 // - Bayeux/datatools:
23 #include <datatools/handle.h>
24 #include <datatools/ocd_macros.h>
25 
26 // This project:
27 #include <geomtools/utils.h>
28 #include <geomtools/i_object_3d.h>
29 #include <geomtools/i_stackable.h>
32 #include <geomtools/face_info.h>
34 
35 namespace datatools {
36  // Forward class declaration:
37  class properties;
38 }
39 
40 namespace geomtools {
41 
42  // Forward class declaration:
43  class i_shape_2d;
44 
46  class i_shape_3d
47  : public i_object_3d
48  , public i_wires_3d_rendering
49  , public i_find_intercept
50  {
51  public:
52 
53  static const double DEFAULT_SKIN;
54  static const double ZERO_SKIN;
55  static const double USING_PROPER_SKIN;
56 
58  static double get_default_skin();
59 
61  static double get_zero_skin();
62 
64  static double get_proper_skin();
65 
66  // Return the property key for the volume property
67  static const std::string & volume_key();
68 
69  // Return the property key for the surface property
70  static const std::string & surface_key();
71 
72  /* Check if a 3D-shape can be stacked using some
73  * stacking algorithms. There are 2 checks:
74  * check #1: checks if the instance owns a valid
75  * embedded 'stackable_data' instance.
76  * check #2: if check #1 fails, check if the instance inherits
77  * the 'i_stackable' interface.
78  */
79  // static bool is_stackable(const i_shape_3d &);
80 
81  // Check if the shape is natively stackable (i.e. inherits the 'geomtools::i_stackable' interface)
82  bool is_native_stackable() const;
83 
85  static bool pickup_stackable(const i_shape_3d &, stackable_data &);
86 
89 
91  const stackable_data & get_stackable_data() const;
92 
94  bool has_stackable_data() const;
95 
97  bool owns_stackable_data() const;
98 
100  void set_stackable_data(const stackable_data & a_stackable_data);
101 
103  void set_stackable_data(const stackable_data * a_stackable_data);
104 
106  void reset_stackable_data();
107 
109  int get_dimensional() const;
110 
112  double get_skin(double a_skin) const;
113 
115  double get_skin() const;
116 
118  void set_skin(double a_skin);
119 
121  i_shape_3d();
122 
124  i_shape_3d(double a_skin);
125 
127  i_shape_3d(double a_skin_, double angular_tolerance_);
128 
130  i_shape_3d(const i_shape_3d &);
131 
133  i_shape_3d & operator=(const i_shape_3d &);
134 
136  virtual ~i_shape_3d();
137 
139  virtual bool is_composite() const;
140 
142  virtual bool using_face_id_bits() const;
143 
145  virtual bool using_face_id_index() const;
146 
148  virtual bool using_face_id_part_index() const;
149 
151  virtual void make_any_face(face_identifier &) const;
152 
154  virtual bool has_number_of_faces() const;
155 
157  virtual unsigned int get_number_of_faces() const;
158 
160  virtual bool volume_can_be_forced() const;
161 
163  virtual bool has_forced_volume() const;
164 
166  void set_forced_volume(double volume_);
167 
169  double get_forced_volume() const;
170 
172  virtual bool has_volume(uint32_t flags_ = 0) const;
173 
175  virtual double get_volume(uint32_t flags_ = 0) const;
176 
178  double get_effective_volume() const;
179 
181  virtual bool has_surface(uint32_t flags_ = face_identifier::FACE_BITS_ANY) const;
182 
184  virtual double get_surface(uint32_t flags_ = face_identifier::FACE_BITS_ANY) const;
185 
187  bool check_inside(const vector_3d & position_,
188  double a_skin = GEOMTOOLS_PROPER_TOLERANCE) const;
189 
191  bool check_outside(const vector_3d & position_,
192  double a_skin = GEOMTOOLS_PROPER_TOLERANCE) const;
193 
195  face_identifier check_surface(const vector_3d & position_,
196  const face_identifier & a_surface_mask = face_identifier::FACE_BITS_ANY,
197  double a_skin = GEOMTOOLS_PROPER_TOLERANCE) const;
198 
200  bool check_surface(const vector_3d & position_,
201  double a_skin = GEOMTOOLS_PROPER_TOLERANCE) const;
202 
204  virtual bool is_inside(const vector_3d & position_,
205  double a_skin = GEOMTOOLS_PROPER_TOLERANCE) const = 0;
206 
208  virtual bool is_outside(const vector_3d &,
209  double a_skin = GEOMTOOLS_PROPER_TOLERANCE) const = 0;
210 
212  virtual face_identifier on_surface(const vector_3d & position_,
213  const face_identifier & a_surface_mask = face_identifier::FACE_BITS_ANY,
214  double a_skin = GEOMTOOLS_PROPER_TOLERANCE) const = 0;
215 
217  virtual vector_3d get_normal_on_surface(const vector_3d & a_position,
218  const face_identifier & a_surface_bit) const = 0;
219 
221  bool is_on_surface(const vector_3d & position_,
222  const face_identifier & a_surface_mask = face_identifier::FACE_BITS_ANY,
223  double a_skin = GEOMTOOLS_PROPER_TOLERANCE) const;
224 
226  virtual shape_domain_flags_type where_is(const vector_3d & position_, double a_skin) const;
227 
229  virtual unsigned int compute_faces(face_info_collection_type & faces_) const;
230 
232  bool has_computed_faces() const;
233 
236 
238  void reset_computed_faces();
239 
241  bool has_bounding_data() const;
242 
244  const bounding_data & get_bounding_data() const;
245 
247  void reset_bounding_data();
248 
250  void set_bounding_data(const bounding_data &);
251 
254 
256  virtual void tree_dump(std::ostream & a_out = std::clog,
257  const std::string & a_title = "",
258  const std::string & a_indent = "",
259  bool a_inherit = false) const;
260 
263 
265  bool is_locked() const;
266 
268  void lock();
269 
271  void unlock();
272 
273  protected:
274 
276  void _set_defaults();
277 
279  virtual void _at_lock();
280 
282  virtual void _at_unlock();
283 
285  void _initialize(const datatools::properties &, const handle_dict_type * = 0);
286 
288  void _reset();
289 
291  virtual void _build_bounding_data();
292 
294 
317  void _initialize_bounding_data(const datatools::properties & config_);
318 
320 
334 
336  void _reset_bounding_data();
337 
340 
341  private:
342 
343  // Work data:
344  bool _locked_;
345  bool _owns_stackable_data_;
346  const stackable_data * _stackable_data_;
347  bounding_data _bounding_data_;
348  boost::optional<double> _forced_volume_;
350 
351  // Serialization interface
353 
354  };
355 
356 } // end of namespace geomtools
357 
358 /*
359 // Class version:
360 #include <boost/serialization/version.hpp>
361 BOOST_CLASS_VERSION(geomtools::i_shape_3d, 0)
362 */
363 
364 #endif // GEOMTOOLS_I_SHAPE_3D_H
365 
366 // Local Variables: --
367 // mode: c++ --
368 // c-file-style: "gnu" --
369 // tab-width: 2 --
370 // End: --
void _initialize(const datatools::properties &, const handle_dict_type *=0)
Initialize from properties.
virtual unsigned int compute_faces(face_info_collection_type &faces_) const
Return a collection of face info objects.
virtual void _at_lock()
Executed at lock stage.
virtual face_identifier on_surface(const vector_3d &position_, const face_identifier &a_surface_mask=face_identifier::FACE_BITS_ANY, double a_skin=GEOMTOOLS_PROPER_TOLERANCE) const =0
Primitive check is a point is located on a given surface.
Mother abstract class for all 3D object classes.
Definition: i_object_3d.h:49
void set_bounding_data(const bounding_data &)
Set the bounding data.
Abstract interface for all objects for which we can compute the intercept with a ray emitted from a p...
Definition: i_find_intercept.h:32
static void init_ocd(datatools::object_configuration_description &)
OCD support.
static const double ZERO_SKIN
Definition: i_shape_3d.h:54
Mother abstract class for all 3D solid shapes.
Definition: i_shape_3d.h:46
double get_forced_volume() const
Return the forced volume.
i_shape_3d & operator=(const i_shape_3d &)
Assignment operator.
virtual bool using_face_id_part_index() const
Check if the face identification scheme uses part index.
virtual bool is_outside(const vector_3d &, double a_skin=GEOMTOOLS_PROPER_TOLERANCE) const =0
Primitive check is a point is outside the solid.
bool owns_stackable_data() const
Check if some enforced stackable data are available and owned by the shape itself.
Identifier of a face attached to a solid shape.
Definition: face_identifier.h:32
static const std::string & volume_key()
static const double USING_PROPER_SKIN
Definition: i_shape_3d.h:55
static double get_proper_skin()
Return the special skin value that tells to use the intrinsic skin of the shape itself (< 0)
void _set_defaults()
Set default values for attributes.
virtual bool using_face_id_index() const
Check if the face identification scheme is based on face index.
static const std::string & surface_key()
double get_skin() const
Return the intrinsic skin tolerance.
void set_forced_volume(double volume_)
Force the volume.
void set_stackable_data(const stackable_data &a_stackable_data)
Set external enforced stackable data.
void set_skin(double a_skin)
Set the intrinsic skin tolerance.
An object that describes the way an object of a given class can be configured through properties.
Definition: object_configuration_description.h:234
virtual bool has_forced_volume() const
Check is a forced volume is set.
void reset_bounding_data()
Reset the bounding data.
#define DATATOOLS_SERIALIZATION_DECLARATION()
Definition: i_serializable.h:266
static double get_default_skin()
Return the default skin value.
void build_default_bounding_data()
Build default bounding data.
shape_domain_flags_type
Flags determining the position of a point with respect to a 3D shape.
Definition: utils.h:199
#define GEOMTOOLS_PROPER_TOLERANCE
Definition: geomtools_config.h:26
bool is_native_stackable() const
virtual void make_any_face(face_identifier &) const
Build a face identifier any mask.
bool is_locked() const
Check the lock flag.
virtual bool using_face_id_bits() const
Check if the face identification scheme is based on face bits.
virtual double get_volume(uint32_t flags_=0) const
Return the volume.
virtual void _at_unlock()
Executed at unlock stage.
static double get_zero_skin()
Return the zero skin value (0 == no thickness)
std::map< std::string, object_entry > handle_dict_type
Dictionary of handle of 3D object entries.
Definition: i_object_3d.h:124
int get_dimensional() const
Return the dimension (3)
virtual double get_surface(uint32_t flags_=face_identifier::FACE_BITS_ANY) const
Return the surface cumulated by faces.
static bool pickup_stackable(const i_shape_3d &, stackable_data &)
Initialize a 'stackable_data' instance from stackable data attached to the 3D-shape.
virtual void tree_dump(std::ostream &a_out=std::clog, const std::string &a_title="", const std::string &a_indent="", bool a_inherit=false) const
Smart print.
bounding_data & _grab_bounding_data()
Return the bounding data.
virtual bool has_surface(uint32_t flags_=face_identifier::FACE_BITS_ANY) const
Check is the surface is known.
void _initialize_stackable_data(const datatools::properties &config_)
Parse stackable data from a properties container.
virtual void _build_bounding_data()
Build the bounding data.
bool has_stackable_data() const
Check if some enforced stackable data are available.
virtual shape_domain_flags_type where_is(const vector_3d &position_, double a_skin) const
Localize a point with respect to the solid.
static const double DEFAULT_SKIN
Definition: i_shape_3d.h:53
brief Abstract interface for objects that can describe themselves as a collection of polylines for 3D...
Definition: i_wires_3d_rendering.h:39
bool has_bounding_data() const
Check the bounding data.
stackability_mode
Definition: i_stackable.h:69
CLHEP::Hep3Vector vector_3d
Alias for the CLHEP 3D-vector class.
Definition: clhep.h:63
i_shape_3d()
Constructor.
Bounding volume data for i_shape_3d derived solid shapes.
Definition: bounding_data.h:41
virtual bool volume_can_be_forced() const
Check if a forced volume can be set.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
virtual vector_3d get_normal_on_surface(const vector_3d &a_position, const face_identifier &a_surface_bit) const =0
Return the normal at a point of the surface given its surface identifier.
virtual bool is_composite() const
Check if the solid is composite.
virtual ~i_shape_3d()
Destructor.
virtual bool is_inside(const vector_3d &position_, double a_skin=GEOMTOOLS_PROPER_TOLERANCE) const =0
Primitive check is a point is inside the solid.
Data for stacking along X, Y and/or Z axis.
Definition: i_stackable.h:161
void lock()
Lock the shape, performing some internal calculations.
bool check_inside(const vector_3d &position_, double a_skin=GEOMTOOLS_PROPER_TOLERANCE) const
Check if a point is inside the solid.
void reset_computed_faces()
Reset the computed faces.
bool check_outside(const vector_3d &position_, double a_skin=GEOMTOOLS_PROPER_TOLERANCE) const
Check if a point is outside the solid.
virtual unsigned int get_number_of_faces() const
Return the number of faces.
static const uint32_t FACE_BITS_ANY
All faces are selected.
Definition: face_identifier.h:46
const bounding_data & get_bounding_data() const
Return the bounding data.
face_identifier check_surface(const vector_3d &position_, const face_identifier &a_surface_mask=face_identifier::FACE_BITS_ANY, double a_skin=GEOMTOOLS_PROPER_TOLERANCE) const
Check is a point is located on a given surface.
void unlock()
Unlock the shape.
void _initialize_bounding_data(const datatools::properties &config_)
Parse bounding data from a properties container.
virtual bool has_volume(uint32_t flags_=0) const
Check is the volume is known.
void reset_stackable_data()
Reset enforced stackable data.
const stackable_data & get_stackable_data() const
Return the enforced stackable data associated to the shape.
bool is_on_surface(const vector_3d &position_, const face_identifier &a_surface_mask=face_identifier::FACE_BITS_ANY, double a_skin=GEOMTOOLS_PROPER_TOLERANCE) const
Check is a point is on a surface of the solid.
static bool check_stackability(const i_shape_3d &, const stackable::stackability_mode)
Check the stackability of the shape (from native or enforced stackable infos)
std::vector< face_info > face_info_collection_type
Type alias for a collection of face information objects.
Definition: face_info.h:168
const face_info_collection_type & get_computed_faces() const
Return the collection of faces.
double get_effective_volume() const
Return the total effective volume.
virtual bool has_number_of_faces() const
Check if the number of faces is known.
void _reset_bounding_data()
Reset the bounding data.
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39
A dictionary of arbitrary properties.
Definition: properties.h:125
bool has_computed_faces() const
Check if the embedded collection of faces has been computed.