Bayeux  3.4.1
Core Foundation library for SuperNEMO
polyhedra.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2010-10-08
4  * Last modified: 2015-03-19
5  *
6  * License:
7  *
8  * Description:
9  * Polyhedra 3D shape with regular polygon sections
10  * See also: http://en.wikipedia.org/wiki/Frustum
11  *
12  * History:
13  *
14  */
15 
16 #ifndef GEOMTOOLS_POLYHEDRA_H
17 #define GEOMTOOLS_POLYHEDRA_H 1
18 
19 // Standard library:
20 #include <iostream>
21 #include <string>
22 #include <map>
23 
24 // This project:
25 #include <geomtools/i_shape_3d.h>
26 #include <geomtools/i_stackable.h>
27 
28 namespace geomtools {
29 
30  // Forward class declaration:
31  class composite_surface;
32  class right_polygonal_frustrum;
33 
35  class polyhedra : public i_shape_3d,
36  public i_stackable
37  {
38  public:
39 
41  static const std::string & polyhedra_label();
42 
44  static const size_t MIN_NUMBER_OF_SIDES = 3;
45 
55  | FACE_BOTTOM
56  | FACE_TOP)
57  };
58 
61  RMIN_RMAX = 0,
64  };
65 
66  /*
67  * The polyhedra is defined by a list of (z, rmin, rmax) triplets
68  * the radius are the distance from center to corners (OA, OB...).
69  * Caution: the Geant4 and GDML use the tangential radius (radius of the inscribed
70  * circles == apothem == OT) and not the distance from Z-axis to the corners.
71  *
72  * Example with a 'n_sides==6' polyhedra:
73  *
74  * C B
75  * +_________+
76  * / \
77  * / .+ T
78  * / . \
79  * D + + + A
80  * \ O /
81  * \ /
82  * \___________/
83  * + +
84  * E F
85  *
86  */
87  struct r_min_max
88  {
89  double rmin, rmax;
90  };
91 
92  // Type alias
93  typedef std::map<double, r_min_max> rz_col_type;
94 
96  struct frustrum_data {
97  // Bottom parameters:
98  double z1, a1, b1;
99  // Top parameters:
100  double z2, a2, b2;
101  };
102 
104  bool is_extruded () const;
105 
107  double get_xmin () const;
108 
110  double get_xmax () const;
111 
113  double get_ymin () const;
114 
116  double get_ymax () const;
117 
119  double get_zmin () const;
120 
122  double get_zmax () const;
123 
125  double get_r_max () const;
126 
128  vector_3d get_corner (int zplane_index_,
129  int corner_index_,
130  bool inner_ = false) const;
131 
133  void set_n_sides (size_t n_sides_);
134 
136  size_t get_n_sides () const;
137 
139  unsigned int number_of_frustra() const;
140 
142  void get_frustrum_data(size_t i_, frustrum_data &) const;
143 
145  const rz_col_type & points () const;
146 
148  polyhedra ();
149 
151  virtual ~polyhedra ();
152 
154  virtual std::string get_shape_name () const;
155 
157  bool is_valid () const;
158 
160  void add (double z_, double rmax_, bool compute_ = true);
161 
163  void add (double z_, double rmin_, double rmax_, bool compute_ = true);
164 
166  virtual void initialize (const datatools::properties & setup_, const handle_dict_type * = 0);
167 
169  virtual void reset ();
170 
172  void initialize (const std::string & filename_, int mode_ = RMIN_RMAX);
173 
175  bool has_top_face() const;
176 
178  bool has_bottom_face() const;
179 
181  bool has_inner_face() const;
182 
184  bool has_angle_faces() const;
185 
187  void compute_top_face(composite_surface & top_, placement &) const;
188 
190  void compute_bottom_face(composite_surface & bottom_, placement &) const;
191 
193  void compute_frustrum(right_polygonal_frustrum & f_, placement &, int index_) const;
194 
196  void compute_inner_face(composite_surface & in_, placement &, int index_) const;
197 
199  void compute_outer_face(composite_surface & on_, placement &, int index_) const;
200 
202  void compute_inner_face(composite_surface & in_, placement &) const;
203 
205  void compute_outer_face(composite_surface & in_, placement &) const;
206 
208  virtual unsigned int compute_faces(face_info_collection_type &) const;
209 
211  void compute_inner_polyhedra (polyhedra & ip_);
212 
214  void compute_outer_polyhedra (polyhedra & op_);
215 
217  virtual double get_volume (uint32_t flags_ = 0) const;
218 
220  virtual double get_surface (uint32_t mask_ = FACE_ALL) const;
221 
223  double get_z_min () const;
224 
226  double get_z_max () const;
227 
229  double get_xy_max () const;
230 
232  double get_parameter ( const std::string & flag_ ) const;
233 
235  virtual bool is_inside (const vector_3d &,
236  double skin_ = GEOMTOOLS_PROPER_TOLERANCE) const;
237 
239  virtual bool is_outside (const vector_3d &,
240  double skin_ = GEOMTOOLS_PROPER_TOLERANCE) const;
241 
243  virtual face_identifier on_surface(const vector_3d &,
244  const face_identifier & a_surface_mask = face_identifier::face_bits_any(),
245  double a_skin = GEOMTOOLS_PROPER_TOLERANCE) const;
246 
248  virtual vector_3d get_normal_on_surface (const vector_3d & position_,
249  const face_identifier & ) const;
250 
252  virtual bool find_intercept(const vector_3d & from_,
253  const vector_3d & direction_,
254  face_intercept_info & intercept_,
255  double skin_ = GEOMTOOLS_PROPER_TOLERANCE) const;
256 
258  virtual void tree_dump(std::ostream & out_ = std::clog,
259  const std::string & title_ = "",
260  const std::string & indent_ = "",
261  bool inherit_ = false) const;
262 
269  // WR_POLYHEDRA_NO_START_ANGLE_FACE = (WR_BASE_LAST << 5), //!< Do not render the start angle face
270  // WR_POLYHEDRA_NO_STOP_ANGLE_FACE = (WR_BASE_LAST << 6), //!< Do not render the stop angle face
276  // | WR_POLYHEDRA_NO_START_ANGLE_FACE
277  // | WR_POLYHEDRA_NO_STOP_ANGLE_FACE
278  )
279  };
280 
282  virtual void generate_wires_self(wires_type & wires_,
283  uint32_t options_ = 0) const;
284 
285  friend std::ostream & operator<< (std::ostream &, const polyhedra &);
286 
287  friend std::istream & operator>> (std::istream &, polyhedra &);
288 
289  protected:
290 
292  virtual void _build_bounding_data();
293 
295  void _set_defaults();
296 
298  virtual void _at_lock();
299 
300  private:
301 
302  void _compute_surfaces_();
303 
304  void _compute_volume_();
305 
306  void _compute_limits_();
307 
308  void _compute_misc_();
309 
310  void _compute_all_();
311 
312  private:
313 
314  // Parameters:
315  size_t _n_sides_;
316  rz_col_type _points_;
317 
318  // Working data:
319  bool _computed_;
320  boost::logic::tribool _has_top_face_;
321  boost::logic::tribool _has_bottom_face_;
322  boost::logic::tribool _has_inner_face_;
323  double _top_surface_;
324  double _bottom_surface_;
325  double _outer_side_surface_;
326  double _inner_side_surface_;
327  double _outer_volume_;
328  double _inner_volume_;
329  double _volume_;
330  double _z_min_;
331  double _z_max_;
332  double _r_max_;
333  double _xy_max_;
334  bool _extruded_;
335 
336  // Registration interface :
338 
339  };
340 
341 } // end of namespace geomtools
342 
343 #endif // GEOMTOOLS_POLYHEDRA_H
344 
345 /*
346 ** Local Variables: --
347 ** mode: c++ --
348 ** c-file-style: "gnu" --
349 ** tab-width: 2 --
350 ** End: --
351 */
double get_xy_max() const
Return the max X or Y.
Do not render the inner face.
Definition: polyhedra.h:267
void compute_frustrum(right_polygonal_frustrum &f_, placement &, int index_) const
Compute frustrum at given index.
bool is_extruded() const
Check if the polycone has a hole (Rmin != 0)
virtual ~polyhedra()
Destructor.
virtual std::string get_shape_name() const
Return the identifier/name of the shape.
Mother abstract class for all 3D solid shapes.
Definition: i_shape_3d.h:46
double b2
Definition: polyhedra.h:100
Right polygonal frustrum (3D shape)
Definition: right_polygonal_frustrum.h:27
virtual vector_3d get_normal_on_surface(const vector_3d &position_, const face_identifier &) const
Compute the normal to the surface of the furstrum.
The abstract base class for all 2D shapes/surfaces.
Definition: composite_surface.h:26
double get_parameter(const std::string &flag_) const
Return a parameter by name.
static const uint32_t bit01
Definition: bit_mask.h:28
double rmax
Definition: polyhedra.h:89
double z1
Definition: polyhedra.h:98
Definition: polyhedra.h:50
static const uint32_t bit03
Definition: bit_mask.h:30
Data describing one frustrum.
Definition: polyhedra.h:96
virtual unsigned int compute_faces(face_info_collection_type &) const
Compute informations about the faces of this solid shape.
Identifier of a face attached to a solid shape.
Definition: face_identifier.h:32
void compute_outer_face(composite_surface &on_, placement &, int index_) const
Compute the outer face at given frustrum index.
void compute_bottom_face(composite_surface &bottom_, placement &) const
Compute the bottom face.
void compute_top_face(composite_surface &top_, placement &) const
Compute the top face.
faces_mask_type
Face flags.
Definition: polyhedra.h:47
std::map< double, r_min_max > rz_col_type
Definition: polyhedra.h:93
virtual face_identifier on_surface(const vector_3d &, const face_identifier &a_surface_mask=face_identifier::face_bits_any(), double a_skin=GEOMTOOLS_PROPER_TOLERANCE) const
Return the surface bit a point belongs to.
const rz_col_type & points() const
Return the dictionary of points.
Ignore first column as Rmin and use only second one for Rmax.
Definition: polyhedra.h:62
polyhedra_wires_rendering_option_type
3D rendering options
Definition: polyhedra.h:264
The face_intercept_info class hosts the parameters of.
Definition: face_intercept_info.h:31
#define GEOMTOOLS_PROPER_TOLERANCE
Definition: geomtools_config.h:26
void set_n_sides(size_t n_sides_)
Set the number of sides.
virtual double get_surface(uint32_t mask_=FACE_ALL) const
Compute the surface.
bool has_angle_faces() const
Check for angle faces.
void add(double z_, double rmax_, bool compute_=true)
Add a new point with only Rmax.
void get_frustrum_data(size_t i_, frustrum_data &) const
Compute frustrum data at given index.
Abstract base stackable object.
Definition: i_stackable.h:32
double get_z_max() const
Return the max Z.
double get_zmax() const
Return the Z max.
void compute_inner_face(composite_surface &in_, placement &, int index_) const
Compute the inner face at given frustrum index.
double get_z_min() const
Return the min Z.
virtual void _build_bounding_data()
Build bounding data.
double get_xmin() const
Return the X min.
Do not render the top face.
Definition: polyhedra.h:266
virtual void generate_wires_self(wires_type &wires_, uint32_t options_=0) const
Generate a list of polylines representing the contour of the shape (for display clients)
Definition: polyhedra.h:48
double a1
Definition: polyhedra.h:98
polyhedra()
Default constructor.
static const face_identifier & face_bits_any()
Return a singleton face identifier with any bit.
Polyhedra 3D solid shape.
Definition: polyhedra.h:35
Definition: polyhedra.h:51
std::map< std::string, object_entry > handle_dict_type
Dictionary of handle of 3D object entries.
Definition: i_object_3d.h:124
Do not render the outer face.
Definition: polyhedra.h:268
unsigned int number_of_frustra() const
Return the number of frustra.
static const uint32_t bit02
Definition: bit_mask.h:29
bool has_top_face() const
Check for a top face.
static const uint32_t FACE_BITS_NONE
No valid or known face bit.
Definition: face_identifier.h:45
Do not render the bottom face.
Definition: polyhedra.h:265
void compute_inner_polyhedra(polyhedra &ip_)
Compute the inner polyhedra.
Definition: polyhedra.h:49
Definition: polyhedra.h:52
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
Definition: polyhedra.h:87
#define GEOMTOOLS_OBJECT_3D_REGISTRATION_INTERFACE(ModelClassName)
Definition: i_object_3d.h:260
virtual void _at_lock()
Executed at lock stage.
double get_zmin() const
Return the Z min.
friend std::ostream & operator<<(std::ostream &, const polyhedra &)
virtual void initialize(const datatools::properties &setup_, const handle_dict_type *=0)
Main initialization method from a container of configuration parameters.
double get_ymax() const
Return the Y max.
CLHEP::Hep3Vector vector_3d
Alias for the CLHEP 3D-vector class.
Definition: clhep.h:63
bool has_inner_face() const
Check for an inner face.
Last defined bit.
Definition: i_wires_3d_rendering.h:62
Use one first column as Rmax.
Definition: polyhedra.h:63
void compute_outer_polyhedra(polyhedra &op_)
Compute the outer polyhedra.
virtual bool is_outside(const vector_3d &, double skin_=GEOMTOOLS_PROPER_TOLERANCE) const
Check if a point is outside the frustrum.
The placement for a geometry volume with its translation and rotation with respect to some mother ref...
Definition: placement.h:34
Rendering options bit mask.
Definition: polyhedra.h:272
size_t get_n_sides() const
Return the number of sides.
void _set_defaults()
Set default attributes.
virtual void reset()
Reset/invalidate the solid.
static const std::string & polyhedra_label()
Return the identifier label for the class.
double a2
Definition: polyhedra.h:100
double get_ymin() const
Return the Y min.
friend std::istream & operator>>(std::istream &, polyhedra &)
Last defined bit.
Definition: polyhedra.h:271
double b1
Definition: polyhedra.h:98
std::list< polyline_type > wires_type
Alias for a list of 3D-polylines.
Definition: utils.h:61
double z2
Definition: polyhedra.h:100
static const uint32_t bit00
Definition: bit_mask.h:27
virtual bool is_inside(const vector_3d &, double skin_=GEOMTOOLS_PROPER_TOLERANCE) const
Check if a point is inside the frustrum.
virtual double get_volume(uint32_t flags_=0) const
Compute the volume.
bool is_valid() const
Check if the solid is valid.
double rmin
Definition: polyhedra.h:89
Definition: polyhedra.h:53
virtual bool find_intercept(const vector_3d &from_, const vector_3d &direction_, face_intercept_info &intercept_, double skin_=GEOMTOOLS_PROPER_TOLERANCE) const
Find the intercept point with a face of the frustrum.
Use one first column for Rmin and second one for Rmax.
Definition: polyhedra.h:61
datafile_column_mode
Format of the datafile for reading Z/Rmin/Rmax data.
Definition: polyhedra.h:60
std::vector< face_info > face_info_collection_type
Type alias for a collection of face information objects.
Definition: face_info.h:168
vector_3d get_corner(int zplane_index_, int corner_index_, bool inner_=false) const
Return the coordinates of a vertex on one of the polyhedra edge.
double get_xmax() const
Return the X max.
bool has_bottom_face() const
Check for a bottom face.
static const size_t MIN_NUMBER_OF_SIDES
Minimum number of sides.
Definition: polyhedra.h:44
double get_r_max() const
Return the R max.
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39
A dictionary of arbitrary properties.
Definition: properties.h:125