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:
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 
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
datatypes::Box2D::getBoundingAngles
std::pair< value_type, value_type > getBoundingAngles() const
Returns boundary angles for this box.
Definition: Box2D.cpp:138
datatypes::Point2D
Definition: Point2D.hpp:27
Point2D.hpp
datatypes::Box2D::Box2D
Box2D()
Constructor for an all-zero Box2D.
Definition: Box2D.cpp:23
datatypes::Box2D::getSize
const Point2D & getSize() const
Returns the size of this Box.
Definition: Box2D.hpp:101
datatypes::Box2D::toBoundingBox
Box2D toBoundingBox() const
Returns a Box in parallel to the coordinate system that bounds this box.
Definition: Box2D.cpp:115
datatypes::Box2D
A rotated 2-dimensional box in the plane.
Definition: Box2D.hpp:34
datatypes::Box2D::setRotation
void setRotation(value_type r)
Sets the rotation angle of this Box in [radians], counter clock wise.
Definition: Box2D.cpp:71
datatypes::Box2D::setCenter
void setCenter(value_type x, value_type y)
Sets the center point of this Box2D.
Definition: Box2D.hpp:151
datatypes::BasicData
Definition: BasicDatatypes.hpp:95
datatypes::operator==
bool operator==(const Box2D &b1, const Box2D &b2)
Definition: Box2D.hpp:269
datatypes::Box2D::m_size
Point2D m_size
Definition: Box2D.hpp:41
datatypes::Point2D::setXY
void setXY(value_type x, value_type y)
Definition: Point2D.hpp:147
datatypes::Box2D::movedBy
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
datatypes::Box2D::containsPoint
bool containsPoint(const Point2D &point) const
Returns true if the given Point2D is inside this box or on its outline.
Definition: Box2D.cpp:173
datatypes::Box2D::orientatedBox
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
datatypes::Box2D::getCenter
const Point2D & getCenter() const
Returns the center point of this Box.
Definition: Box2D.hpp:92
datatypes::Box2D::m_rotation
value_type m_rotation
Definition: Box2D.hpp:42
datatypes::Box2D::verifyNumericRanges
void verifyNumericRanges()
Definition: Box2D.cpp:418
datatypes::Box2D::getUsedMemory
virtual const UINT32 getUsedMemory() const
Definition: Box2D.hpp:85
datatypes::Box2D::moveBy
void moveBy(const Point2D &centerMovement)
Move the center point of this box by the given point values.
Definition: Box2D.cpp:79
datatypes::Point2D::value_type
double value_type
The type of the stored x and y coordinates.
Definition: Point2D.hpp:31
datatypes::Box2D::m_center
Point2D m_center
Definition: Box2D.hpp:40
datatypes::Box2D::operator==
friend bool operator==(const Box2D &, const Box2D &)
Definition: Box2D.hpp:269
datatypes::Box2D::operator!=
friend bool operator!=(const Box2D &, const Box2D &)
Definition: Box2D.hpp:277
fuzzyCompare
bool fuzzyCompare(double a, double b)
Tests if two double values are nearly equal.
Definition: MathToolbox.hpp:29
datatypes::Box2D::setSize
void setSize(const Point2D &p)
Sets the size of this Box. Must be non-negative.
Definition: Box2D.cpp:58
datatypes::Box2D::toString
std::string toString() const
Definition: Box2D.cpp:471
datatypes::Box2D::getRotation
value_type getRotation() const
Definition: Box2D.hpp:108
datatypes::Polygon2D
A polygon of 2D-points.
Definition: Polygon2D.hpp:43
isNaN
bool isNaN(floatT x)
Checks if a floating point value is Not-a-Number (NaN)
Definition: MathToolbox.hpp:64
datatypes::Box2D::value_type
Point2D::value_type value_type
The type of the stored x, y coordinates, and the rotation.
Definition: Box2D.hpp:38
UINT32
uint32_t UINT32
Definition: BasicDatatypes.hpp:26
datatypes::Box2D::toPolygon
Polygon2D toPolygon() const
Converts this Box2D to a closed polygon.
Definition: Box2D.cpp:89
datatypes::operator!=
bool operator!=(const Box2D &b1, const Box2D &b2)
Definition: Box2D.hpp:277
datatypes::Box2D::distanceFromOutline
Point2D::value_type distanceFromOutline(const Point2D &point) const
Returns the distance from the outline of this Box2D to the given point.
datatypes
Definition: BasicDatatypes.hpp:91
datatypes::Box2D::setCenter
void setCenter(const Point2D &p)
Sets the center point of this Box2D.
Definition: Box2D.hpp:148


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Wed Oct 26 2022 02:11:57