8#ifndef META_OCEAN_CV_PIXEL_BOUNDING_BOX_H
9#define META_OCEAN_CV_PIXEL_BOUNDING_BOX_H
184 inline unsigned int size()
const;
315 explicit inline operator bool()
const;
369 for (
typename std::vector<
PixelPositionT<T>>::const_iterator i = points.begin(); i != points.end(); ++i)
392 ocean_assert(
width >= 1u);
393 ocean_assert(
height >= 1u);
398 left_(std::min(point0.x(), point1.x())),
399 top_(std::min(point0.y(), point1.y())),
400 right_(std::max(point0.x(), point1.x())),
401 bottom_(std::max(point0.y(), point1.y()))
403 ocean_assert(
width() >= 1u);
404 ocean_assert(
height() >= 1u);
408 debugBoundingBox += point0;
409 debugBoundingBox += point1;
411 ocean_assert(*
this == debugBoundingBox);
544 if (!useNeighborhood8)
560 static_assert(
sizeof(T) <=
sizeof(int),
"Invalid template data type T");
564 ocean_assert(minLeft <=
left() && minTop <=
top());
565 ocean_assert(maxRight >=
right() && maxBottom >=
bottom());
567 ocean_assert(minLeft <= maxRight);
568 ocean_assert(minTop <= maxBottom);
571 max(
int(minTop),
int(
top_) -
int(pixels)),
572 min(maxRight,
right_ + T(pixels)),
573 min(maxBottom,
bottom_ + T(pixels)));
597 if (point.
y() <
top_)
619 return !(*
this == box);
647 ocean_assert(factor != T(0));
656 ocean_assert(factor != T(0));
696 size_t seed = std::hash<T>{}(boundingBox.
left());
697 seed ^= std::hash<T>{}(boundingBox.
top()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
698 seed ^= std::hash<T>{}(boundingBox.
right()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
699 seed ^= std::hash<T>{}(boundingBox.
bottom()) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
This class implements a 2D bounding box with pixel precision.
Definition PixelBoundingBox.h:57
PixelBoundingBoxT< T > & operator/=(const T factor)
Divides this bounding box by a specified scalar (divides left, top, right, and bottom location by the...
Definition PixelBoundingBox.h:653
PixelBoundingBoxT(const PixelPositionT< T > &point)
Creates a bounding box covering one point only.
Definition PixelBoundingBox.h:353
PixelBoundingBoxT< T > & operator*=(const T factor)
Multiplies this bounding box by a specified scalar (multiplies left, top, right, and bottom location ...
Definition PixelBoundingBox.h:631
bool operator==(const PixelBoundingBoxT< T > &box) const
Returns whether two bounding boxes are equal.
Definition PixelBoundingBox.h:611
PixelBoundingBoxT(const PixelPositionT< T > &topLeft, const unsigned int width, const unsigned int height)
Creates a bounding box by a given top left position and a width and height of the bounding box.
Definition PixelBoundingBox.h:386
bool operator!=(const PixelBoundingBoxT< T > &box) const
Returns whether two bounding boxes are not equal.
Definition PixelBoundingBox.h:617
unsigned int left_
Definition PixelBoundingBox.h:320
PixelBoundingBoxT< T > operator/(const T factor) const
Divides this bounding box by a specified scalar (divides left, top, right, and bottom location by the...
Definition PixelBoundingBox.h:644
unsigned int left() const
bool hasIntersection(const PixelBoundingBoxT< T > &boundingBox) const
Returns whether a given bounding box has an intersection with this bounding box.
Definition PixelBoundingBox.h:523
PixelBoundingBoxT(const T left, const T top, const T right, const T bottom)
Creates a bounding box with specified dimension.
Definition PixelBoundingBox.h:376
PixelBoundingBoxT< T > operator&&(const PixelBoundingBoxT< T > &box) const
Returns the intersection of two bounding boxes.
Definition PixelBoundingBox.h:683
unsigned int right() const
unsigned int bottom() const
unsigned int width() const
PixelBoundingBoxT(const PixelBoundingBoxT< T > &boundingBox)
Copy constructor.
Definition PixelBoundingBox.h:343
PixelPositionT< T > bottomRight() const
Returns the bottom right corner of this bounding box.
Definition PixelBoundingBox.h:476
T rightEnd() const
Returns the right (excluding) pixel position of this bounding box.
Definition PixelBoundingBox.h:437
bool isValid() const
Returns whether this bounding box covers a valid pixel area.
Definition PixelBoundingBox.h:577
bool isInside(const PixelBoundingBoxT< T > &boundingBox) const
Returns whether a given bounding box lies entirely inside this bounding box.
Definition PixelBoundingBox.h:515
bool isInside(const PixelPositionT< T > &point) const
Returns whether a given point lies inside this bounding box.
Definition PixelBoundingBox.h:507
PixelBoundingBoxT()
Creates a empty bounding box.
Definition PixelBoundingBox.h:333
T bottomEnd() const
Returns the bottom (excluding) pixel position of this bounding box.
Definition PixelBoundingBox.h:451
PixelBoundingBoxT< T > extended(const unsigned int pixels, const T minLeft, const T minTop, const T maxRight, const T maxBottom) const
Returns a new bounding box by extending this bounding box with a given number of pixel in each direct...
Definition PixelBoundingBox.h:558
unsigned int top_
Definition PixelBoundingBox.h:323
PixelBoundingBoxT< T > operator||(const PixelBoundingBoxT< T > &box) const
Returns the union of two bounding boxes.
Definition PixelBoundingBox.h:667
PixelPositionT< unsigned int > topLeft() const
unsigned int size() const
Returns the area (the number of including pixels) this bounding box covers.
Definition PixelBoundingBox.h:496
PixelBoundingBoxT(const std::vector< PixelPositionT< T > > &points)
Creates a bounding box covering several points.
Definition PixelBoundingBox.h:363
PixelPositionT< T > bottomLeft() const
Returns the bottom left corner of this bounding box.
Definition PixelBoundingBox.h:470
unsigned int bottom_
Definition PixelBoundingBox.h:329
PixelBoundingBoxT(const PixelPositionT< T > &point0, const PixelPositionT< T > &point1)
Creates a bounding box covering two points.
Definition PixelBoundingBox.h:397
PixelBoundingBoxT< T > & operator=(const PixelBoundingBoxT< T > &other)=default
Assignment operator override to match copy constructor.
PixelPositionT< T > topRight() const
Returns the top right corner of this bounding box.
Definition PixelBoundingBox.h:464
size_t operator()(const PixelBoundingBoxT< T > &boundingBox) const
Hash function.
Definition PixelBoundingBox.h:694
PixelBoundingBoxT< T > & operator+=(const PixelPositionT< T > &point)
Adds a new point to the bounding box.
Definition PixelBoundingBox.h:583
PixelBoundingBoxT< T > operator*(const T factor) const
Multiplies this bounding box by a specified scalar (multiplies left, top, right, and bottom location ...
Definition PixelBoundingBox.h:623
unsigned int height() const
unsigned int right_
Definition PixelBoundingBox.h:326
bool isTouching(const PixelBoundingBoxT< T > &boundingBox, const bool useNeighborhood8) const
Returns whether a given bounding box is touching this bounding box.
Definition PixelBoundingBox.h:534
This class implements a 2D pixel position with pixel precision.
Definition PixelPosition.h:63
bool isValid() const
Returns whether this pixel position object holds two valid parameters.
T y() const
Returns the vertical coordinate position of this object.
Definition PixelPosition.h:468
T x() const
Returns the horizontal coordinate position of this object.
Definition PixelPosition.h:456
This class provides basic numeric functionalities.
Definition Numeric.h:57
std::vector< PixelBoundingBox > PixelBoundingBoxes
Definition of a vector holding bounding box objects with only positive coordinate values.
Definition PixelBoundingBox.h:42
PixelBoundingBoxT< int > PixelBoundingBoxI
Definition of a PixelBoundingBox object with data type allowing positive and negative coordinate valu...
Definition PixelBoundingBox.h:35
std::vector< PixelBoundingBoxI > PixelBoundingBoxesI
Definition of a vector holding bounding box objects with positive and negative coordinate values.
Definition PixelBoundingBox.h:49
PixelBoundingBoxT< unsigned int > PixelBoundingBox
Definition of the default PixelBoundingBox object with data type allowing only positive coordinate va...
Definition PixelBoundingBox.h:28
Namespace of the CV library.
Definition Advanced.h:17
The namespace covering the entire Ocean framework.
Definition Accessor.h:15