Bayeux  3.4.1
Core Foundation library for SuperNEMO
simple_polygon.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2015-07-09
4  * Last modified: 2015-07-09
5  *
6  * License:
7  *
8  * Description:
9  *
10  * A simple polygon in 2D space
11  *
12  * History:
13  *
14  */
15 
16 #ifndef GEOMTOOLS_SIMPLE_POLYGON_H
17 #define GEOMTOOLS_SIMPLE_POLYGON_H
18 
19 // Standard library:
20 #include <vector>
21 #include <string>
22 
23 // Third party:
24 // - Bayeux/mygsl:
25 #include <mygsl/min_max.h>
26 
27 // This project:
28 #include <geomtools/utils.h>
29 #include <geomtools/i_shape_2d.h>
30 #include <geomtools/i_polygon.h>
31 
32 namespace geomtools {
33 
34  // Forward declaration:
35  class triangle;
36 
38  class simple_polygon : public i_shape_2d,
39  public i_polygon
40  {
41 
42  public:
43 
49  };
50 
52  static build_mode_type build_mode_from_label(const std::string &);
53 
55  static std::string label_from_build_mode(build_mode_type);
56 
58  static const std::string & simple_polygon_label();
59 
61  bool is_valid() const;
62 
64  virtual std::string get_shape_name() const;
65 
73  double start_angle;
74  double stop_angle;
75  };
76 
78  typedef std::vector<wall_segment_type> wall_segment_col_type;
79 
82 
85 
87  virtual double get_perimeter(uint32_t flags_ = ALL_PIECES) const;
88 
90  virtual double get_surface(uint32_t flags_ = ALL_PIECES) const;
91 
93  unsigned int get_number_of_vertices() const;
94 
96  const vector_2d & get_vertex(int) const;
97 
99  bool is_convex() const;
100 
102  void add_vertex(double x_, double y_);
103 
105  void add_vertex(const vector_2d &);
106 
108  void add_wall_segment(const vector_2d & start_,
109  const vector_2d & stop_,
110  double left_thickness_,
111  double right_thickness_,
112  double start_angle_ = 0.0,
113  double stop_angle_ = std::numeric_limits<double>::quiet_NaN());
114 
116  void add_wall_segment(const vector_2d & stop_,
117  double left_thickness_,
118  double right_thickness_,
119  double stop_angle_ = std::numeric_limits<double>::quiet_NaN());
120 
122  bool walls_are_terminated() const;
123 
125  simple_polygon();
126 
128  virtual ~simple_polygon();
129 
131  virtual bool is_on_surface(const vector_3d &,
132  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
133 
135  virtual vector_3d get_normal_on_surface(const vector_3d & position_,
136  bool check_ = false,
137  double skin_ = GEOMTOOLS_PROPER_TOLERANCE) const;
138 
140  bool is_clockwise() const;
141 
143  bool is_anticlockwise() const;
144 
146  virtual bool find_intercept(const vector_3d & from_,
147  const vector_3d & direction_,
148  face_intercept_info & intercept_,
149  double tolerance_ = GEOMTOOLS_PROPER_TOLERANCE) const;
150 
152  virtual void tree_dump(std::ostream & out_ = std::clog,
153  const std::string & title_ = "",
154  const std::string & indent_ = "",
155  bool inherit_= false) const;
156 
162  )
163  };
164 
166  virtual void generate_wires_self(wires_type & wires_,
167  uint32_t options_ = 0) const;
168 
170  virtual unsigned int compute_vertexes(vertex_col_type & vertexes_) const;
171 
173  unsigned int number_of_triangles() const;
174 
176  const triangle & get_triangle(int index_) const;
177 
179  const mygsl::min_max & get_xrange() const;
180 
182  const mygsl::min_max & get_yrange() const;
183 
185  bool is_initialized() const;
186 
188  void initialize(const datatools::properties &, const handle_dict_type * objects_ = 0);
189 
191  void reset();
192 
194  static bool find_segment_2d_intersection(const vector_2d & a_,
195  const vector_2d & b_,
196  const vector_2d & c_,
197  const vector_2d & d_,
198  vector_2d & intersection_);
199 
201  static void triangulation(const std::vector<const vector_2d *> & vertices_,
202  const vector_3d & normal_,
203  std::vector<triangle> & triangles_);
204 
205 
206  protected:
207 
209  void _set_defaults();
210 
212  void _build_by_vertices();
213 
215  void _build_by_segments();
216 
218  bool _check_vertex(const vector_2d & vtx_, bool no_first_check_ = false) const;
219 
221  void _compute_normal();
222 
224  void _add_vertex(const vector_2d & vtx_);
225 
227  void _add_wall_segment(const vector_2d & start_,
228  const vector_2d & stop_,
229  double left_thickness_,
230  double right_thickness_,
231  double start_angle_,
232  double stop_angle_);
233 
235  void _at_initialize();
236 
237  private:
238 
239  build_mode_type _build_mode_;
240  std::vector<vector_2d> _vertices_;
241  wall_segment_col_type _wall_segments_;
242 
243  // Working data:
244  bool _convex_;
245  mygsl::min_max _xrange_;
246  mygsl::min_max _yrange_;
247  vector_3d _normal_;
248  std::vector<triangle> _triangles_;
249 
250  // Registration interface :
252 
253  };
254 
255 } // end of namespace geomtools
256 
257 #endif // GEOMTOOLS_SIMPLE_POLYGON_H
258 
259 /*
260 ** Local Variables: --
261 ** mode: c++ --
262 ** c-file-style: "gnu" --
263 ** tab-width: 2 --
264 ** End: --
265 */
virtual bool find_intercept(const vector_3d &from_, const vector_3d &direction_, face_intercept_info &intercept_, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
Find the intercept of a ray with the 2D shape's surfaces.
vector_2d start
Definition: simple_polygon.h:69
virtual void generate_wires_self(wires_type &wires_, uint32_t options_=0) const
Generate a sequence of polylines for wires 3D rendering.
static build_mode_type build_mode_from_label(const std::string &)
Return the build mode from a label.
virtual unsigned int compute_vertexes(vertex_col_type &vertexes_) const
Build an ordered collection of vertexes.
double start_angle
Definition: simple_polygon.h:73
virtual double get_perimeter(uint32_t flags_=ALL_PIECES) const
Return the perimeter.
Do render the internal triangle edges.
Definition: simple_polygon.h:159
void _build_by_segments()
Build by walls.
CLHEP::Hep2Vector vector_2d
Alias for the CLHEP 2D-vector class.
Definition: clhep.h:60
void _at_initialize()
Special init operations.
virtual ~simple_polygon()
Destructor.
virtual std::string get_shape_name() const
Return the identifier/name of the shape.
std::vector< wall_segment_type > wall_segment_col_type
Type alias for a collection of wall segment data.
Definition: simple_polygon.h:78
static const std::string & simple_polygon_label()
Return the class label.
Rendering options bit mask.
Definition: simple_polygon.h:161
const triangle & get_triangle(int index_) const
Return a non mutable reference to one of the inner triangles.
static bool find_segment_2d_intersection(const vector_2d &a_, const vector_2d &b_, const vector_2d &c_, const vector_2d &d_, vector_2d &intersection_)
Find the intersection between two 2D segments.
void set_build_mode(build_mode_type)
Set the build mode.
double stop_angle
Definition: simple_polygon.h:74
A simple polygon in the XY plane.
Definition: simple_polygon.h:38
double left_thickness
Definition: simple_polygon.h:71
Record the min and max values from a set of values.
Definition: min_max.h:24
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
virtual vector_3d get_normal_on_surface(const vector_3d &position_, bool check_=false, double skin_=GEOMTOOLS_PROPER_TOLERANCE) const
Return the normal direction at some position on the 2D shape's path.
simple_polygon()
Default constructor.
bool is_convex() const
Check if the simple polygon is convex.
The face_intercept_info class hosts the parameters of.
Definition: face_intercept_info.h:31
void add_wall_segment(const vector_2d &start_, const vector_2d &stop_, double left_thickness_, double right_thickness_, double start_angle_=0.0, double stop_angle_=std::numeric_limits< double >::quiet_NaN())
Add wall segment.
#define GEOMTOOLS_PROPER_TOLERANCE
Definition: geomtools_config.h:26
bool is_valid() const
Check the validity of the simple polygon.
Invalid build mode.
Definition: simple_polygon.h:46
Build mode by segments.
Definition: simple_polygon.h:48
bool is_initialized() const
Check initialization.
virtual bool is_on_surface(const vector_3d &, double tolerance_=GEOMTOOLS_PROPER_TOLERANCE) const
Check is a given point belongs to the surface of the 2D shape.
void _add_vertex(const vector_2d &vtx_)
Add a new vertex.
static const uint32_t ALL_PIECES
Special flag representing all pieces composing a 2D shape.
Definition: i_shape_2d.h:53
bool _check_vertex(const vector_2d &vtx_, bool no_first_check_=false) const
Check if a vertex can be added.
bool is_anticlockwise() const
Check if the polygon is anticlockwise.
std::map< std::string, object_entry > handle_dict_type
Dictionary of handle of 3D object entries.
Definition: i_object_3d.h:124
unsigned int get_number_of_vertices() const
Return the number of vertices.
A triangle.
Definition: triangle.h:29
bool walls_are_terminated() const
Check if walls are terminated.
#define GEOMTOOLS_OBJECT_3D_REGISTRATION_INTERFACE(ModelClassName)
Definition: i_object_3d.h:260
The abstract base class for all 2D shapes/surfaces.
Definition: i_shape_2d.h:37
static void triangulation(const std::vector< const vector_2d * > &vertices_, const vector_3d &normal_, std::vector< triangle > &triangles_)
Triangulation of a simple polygon.
static std::string label_from_build_mode(build_mode_type)
Return the label associated to a build mode.
bool is_clockwise() const
Check if the polygon is clockwise.
CLHEP::Hep3Vector vector_3d
Alias for the CLHEP 3D-vector class.
Definition: clhep.h:63
build_mode_type get_build_mode() const
Return the build mode.
const mygsl::min_max & get_xrange() const
Return the bounding interval on the X axis.
void _compute_normal()
Compute normal.
vector_2d stop
Definition: simple_polygon.h:70
void initialize(const datatools::properties &, const handle_dict_type *objects_=0)
Initialization.
Last defined bit.
Definition: i_wires_3d_rendering.h:62
double right_thickness
Definition: simple_polygon.h:72
const vector_2d & get_vertex(int) const
Return the vertex by index.
Polygon 2D shape.
Definition: i_polygon.h:28
void add_vertex(double x_, double y_)
Append a vertex to the list of vertexes.
void _build_by_vertices()
Build by vertices.
Last defined bit.
Definition: simple_polygon.h:160
void _set_defaults()
Set defaults attributes.
std::vector< vector_3d > vertex_col_type
Aliases for an ordered collection of 3D vertice.
Definition: utils.h:58
std::list< polyline_type > wires_type
Alias for a list of 3D-polylines.
Definition: utils.h:61
unsigned int number_of_triangles() const
Return the number of triangles.
void _add_wall_segment(const vector_2d &start_, const vector_2d &stop_, double left_thickness_, double right_thickness_, double start_angle_, double stop_angle_)
Add wall segment.
Build mode by vertices.
Definition: simple_polygon.h:47
virtual double get_surface(uint32_t flags_=ALL_PIECES) const
Return the surface.
build_mode_type
Build mode.
Definition: simple_polygon.h:45
simple_polygon_wires_rendering_option_type
3D rendering options
Definition: simple_polygon.h:158
const mygsl::min_max & get_yrange() const
Return the bounding interval on the Y axis.
Data for a wall segment.
Definition: simple_polygon.h:67
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39
A dictionary of arbitrary properties.
Definition: properties.h:125