Box2D.hpp
Go to the documentation of this file.
1 //
2 // Box2D.hpp
3 // A rotated 2-dimensional box.
4 //
5 
6 #ifndef BOX2D_H
7 #define BOX2D_H
8 
9 #include "Point2D.hpp"
10 #include "../BasicDatatypes.hpp"
11 #include <iosfwd> // for istream, ostream
12 #include <vector>
13 
14 namespace datatypes
15 {
16 
17 // Forward declarations
18 class Polygon2D;
19 
21 
34 class Box2D : public BasicData
35 {
36 public:
39 private:
42  value_type m_rotation;
43 public:
45  Box2D();
46 
48 
59  Box2D(const Point2D& center, const Point2D& size, value_type rotation = 0.0);
60 
62 
82  Box2D(value_type x_center, value_type y_center, value_type x_size, value_type y_size, value_type rotation = 0.0);
83 
84  // Estimate the memory usage of this object
85  virtual const UINT32 getUsedMemory() const { return sizeof(*this); };
86 
87 
89  //\{
90 
92  const Point2D& getCenter() const { return m_center; }
93 
95 
101  const Point2D& getSize() const { return m_size; }
102 
108  value_type getRotation() const { return m_rotation; }
109 
111 
115  Polygon2D toPolygon() const;
116 
118 
124  Box2D toBoundingBox() const;
125 
136  std::pair<value_type, value_type> getBoundingAngles() const;
137 
140  Box2D movedBy(const Point2D& centerMovement) const;
141  //\}
142 
143 
145  //\{
146 
148  void setCenter(const Point2D& p) { m_center = p; }
149 
151  void setCenter(value_type x, value_type y) { m_center.setXY(x, y); }
152 
154  void setSize(const Point2D& p);
155 
157  void setSize(value_type x_length, value_type y_width);
158 
166  void setRotation(value_type r);
167 
169  void moveBy(const Point2D& centerMovement);
170  //\}
171 
173  //\{
174 
176 
181  bool containsPoint(const Point2D& point) const;
182 
184 
194  Point2D::value_type distanceFromOutline(const Point2D& point) const;
195 
197 
207  Point2D::value_type distanceFromOutline(const std::vector<Point2D>& points) const;
208 
210 
220  Point2D::value_type distanceFromOutline(const std::vector<Point2D>::const_iterator& begin,
221  const std::vector<Point2D>::const_iterator& end) const;
222 
223 
225 
230  static Box2D orientatedBox(value_type orientation_rad, const Polygon2D& poly);
231 
233 
241  static Box2D orientatedBox(value_type orientation_rad, const std::vector<Point2D>& points);
242 
244 
252  static Box2D orientatedBox(value_type orientation_rad,
253  const std::vector<Point2D>::const_iterator& begin,
254  const std::vector<Point2D>::const_iterator& end);
255 
256 
257  std::string toString() const; // Konvertierung in String
258 
259 
260  friend inline bool operator==(const Box2D &, const Box2D &);
261  friend inline bool operator!=(const Box2D &, const Box2D &);
262 
263 private:
264  void verifyNumericRanges();
265 
266 };
267 
268 
269 inline bool operator==(const Box2D &b1, const Box2D &b2)
270 {
271  return (b1.m_center == b2.m_center)
272  && (b1.m_size == b2.m_size)
274  || (isNaN(b1.m_rotation) && isNaN(b2.m_rotation)));
275 }
276 
277 inline bool operator!=(const Box2D &b1, const Box2D &b2)
278 {
279  return ! operator==(b1, b2);
280 }
281 
282 
283 } // namespace datatypes
284 
285 #endif // BOX2D_H
value_type getRotation() const
Definition: Box2D.hpp:108
value_type m_rotation
Definition: Box2D.hpp:42
std::string toString() const
Definition: Box2D.cpp:471
const Point2D & getCenter() const
Returns the center point of this Box.
Definition: Box2D.hpp:92
friend bool operator!=(const Box2D &, const Box2D &)
Definition: Box2D.hpp:277
const Point2D & getSize() const
Returns the size of this Box.
Definition: Box2D.hpp:101
A rotated 2-dimensional box in the plane.
Definition: Box2D.hpp:34
void setSize(const Point2D &p)
Sets the size of this Box. Must be non-negative.
Definition: Box2D.cpp:58
uint32_t UINT32
A polygon of 2D-points.
Definition: Polygon2D.hpp:43
std::pair< value_type, value_type > getBoundingAngles() const
Returns boundary angles for this box.
Definition: Box2D.cpp:138
Box2D movedBy(const Point2D &centerMovement) const
Returns a Box that is copied from this one but with its center point moved.
Definition: Box2D.cpp:84
Polygon2D toPolygon() const
Converts this Box2D to a closed polygon.
Definition: Box2D.cpp:89
static Box2D orientatedBox(value_type orientation_rad, const Polygon2D &poly)
Returns an orientated bounding box for the given list of points.
Definition: Box2D.cpp:379
Point2D::value_type distanceFromOutline(const Point2D &point) const
Returns the distance from the outline of this Box2D to the given point.
Point2D::value_type value_type
The type of the stored x, y coordinates, and the rotation.
Definition: Box2D.hpp:38
friend bool operator==(const Box2D &, const Box2D &)
Definition: Box2D.hpp:269
void setRotation(value_type r)
Sets the rotation angle of this Box in [radians], counter clock wise.
Definition: Box2D.cpp:71
Point2D m_size
Definition: Box2D.hpp:41
void setCenter(value_type x, value_type y)
Sets the center point of this Box2D.
Definition: Box2D.hpp:151
void setCenter(const Point2D &p)
Sets the center point of this Box2D.
Definition: Box2D.hpp:148
void setXY(value_type x, value_type y)
Definition: Point2D.hpp:147
Box2D toBoundingBox() const
Returns a Box in parallel to the coordinate system that bounds this box.
Definition: Box2D.cpp:115
Box2D()
Constructor for an all-zero Box2D.
Definition: Box2D.cpp:23
double value_type
The type of the stored x and y coordinates.
Definition: Point2D.hpp:31
bool fuzzyCompare(double a, double b)
Tests if two double values are nearly equal.
Definition: MathToolbox.hpp:28
bool containsPoint(const Point2D &point) const
Returns true if the given Point2D is inside this box or on its outline.
Definition: Box2D.cpp:173
Point2D m_center
Definition: Box2D.hpp:40
virtual const UINT32 getUsedMemory() const
Definition: Box2D.hpp:85
bool isNaN(floatT x)
Checks if a floating point value is Not-a-Number (NaN)
Definition: MathToolbox.hpp:63
void moveBy(const Point2D &centerMovement)
Move the center point of this box by the given point values.
Definition: Box2D.cpp:79
void verifyNumericRanges()
Definition: Box2D.cpp:418


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Sat Jun 8 2019 17:57:33