Ocean
PixelBoundingBox.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_CV_PIXEL_BOUNDING_BOX_H
9 #define META_OCEAN_CV_PIXEL_BOUNDING_BOX_H
10 
11 #include "ocean/cv/CV.h"
12 #include "ocean/cv/PixelPosition.h"
13 
14 namespace Ocean
15 {
16 
17 namespace CV
18 {
19 
20 // Forward declaration.
21 template <typename T> class PixelBoundingBoxT;
22 
23 /**
24  * Definition of the default PixelBoundingBox object with data type allowing only positive coordinate values.
25  * @see PixelPositionT
26  * @ingroup cv
27  */
29 
30 /**
31  * Definition of a PixelBoundingBox object with data type allowing positive and negative coordinate values.
32  * @see PixelPositionT
33  * @ingroup cv
34  */
36 
37 /**
38  * Definition of a vector holding bounding box objects with only positive coordinate values.
39  * @see PixelBoundingBox
40  * @ingroup cv
41  */
42 typedef std::vector<PixelBoundingBox> PixelBoundingBoxes;
43 
44 /**
45  * Definition of a vector holding bounding box objects with positive and negative coordinate values.
46  * @see PixelBoundingBoxI
47  * @ingroup cv
48  */
49 typedef std::vector<PixelBoundingBoxI> PixelBoundingBoxesI;
50 
51 /**
52  * This class implements a 2D bounding box with pixel precision.
53  * @ingroup cv
54  */
55 template <typename T>
57 {
58  public:
59 
60  /**
61  * Creates a empty bounding box.
62  */
64 
65  /**
66  * Copy constructor.
67  * @param boundingBox The bounding box to copy
68  */
69  inline PixelBoundingBoxT(const PixelBoundingBoxT<T>& boundingBox);
70 
71  /**
72  * Creates a bounding box covering one point only.
73  * @param point The point the box will cover
74  */
75  inline explicit PixelBoundingBoxT(const PixelPositionT<T>& point);
76 
77  /**
78  * Creates a bounding box covering several points.
79  * @param points The points the box will cover
80  */
81  inline explicit PixelBoundingBoxT(const std::vector<PixelPositionT<T>>& points);
82 
83  /**
84  * Creates a bounding box with specified dimension.
85  * @param left Left (including) pixel position
86  * @param top Top (including) pixel position
87  * @param right Right (including) pixel position, with range [left, infinity) to create a valid bounding box
88  * @param bottom Bottom (including) pixel position, with range [top, infinity) to create a valid bounding box
89  */
90  inline PixelBoundingBoxT(const T left, const T top, const T right, const T bottom);
91 
92  /**
93  * Creates a bounding box by a given top left position and a width and height of the bounding box.
94  * @param topLeft Top left position of the box
95  * @param width The width of the bounding box in pixel with range [1, infinity)
96  * @param height The height of the bounding box in pixel, with range [1, infinity)
97  */
98  inline PixelBoundingBoxT(const PixelPositionT<T>& topLeft, const unsigned int width, const unsigned int height);
99 
100  /**
101  * Creates a bounding box covering two points.
102  * @param point0 The first point that will be converted by the bounding box
103  * @param point1 The second point that will be converted by the bounding box
104  */
105  inline PixelBoundingBoxT(const PixelPositionT<T>& point0, const PixelPositionT<T>& point1);
106 
107  /**
108  * Returns the left (including) pixel position of this bounding box.
109  * @return Left position
110  */
111  inline T left() const;
112 
113  /**
114  * Returns the top (including) pixel position of this bounding box.
115  * @return Top position
116  */
117  inline T top() const;
118 
119  /**
120  * Returns the right (including) pixel position of this bounding box.
121  * @return Right position
122  */
123  inline T right() const;
124 
125  /**
126  * Returns the right (excluding) pixel position of this bounding box.
127  * @return First pixel to the right of the bounding box
128  */
129  inline T rightEnd() const;
130 
131  /**
132  * Returns the bottom (including) position of this bounding box.
133  * @return Bottom position
134  */
135  inline T bottom() const;
136 
137  /**
138  * Returns the bottom (excluding) pixel position of this bounding box.
139  * @return First pixel below the bounding box
140  */
141  inline T bottomEnd() const;
142 
143  /**
144  * Returns the top left corner of this bounding box.
145  * @return Top left corner
146  */
147  inline PixelPositionT<T> topLeft() const;
148 
149  /**
150  * Returns the top right corner of this bounding box.
151  * @return Top right corner
152  */
153  inline PixelPositionT<T> topRight() const;
154 
155  /**
156  * Returns the bottom left corner of this bounding box.
157  * @return bottom left corner
158  */
160 
161  /**
162  * Returns the bottom right corner of this bounding box.
163  * @return Bottom right corner
164  */
166 
167  /**
168  * Returns the width (the number of horizontal including pixels) of this bounding box.
169  * @return Bounding box width
170  */
171  inline unsigned int width() const;
172 
173  /**
174  * Returns the height (the number of vertical including pixels) of this bounding box.
175  * @return Bounding box height
176  */
177  inline unsigned int height() const;
178 
179  /**
180  * Returns the area (the number of including pixels) this bounding box covers.
181  * If this bounding box is invalid, than zero is returned.
182  * @return Number of pixels or zero.
183  */
184  inline unsigned int size() const;
185 
186  /**
187  * Returns whether a given point lies inside this bounding box.
188  * @param point The point to be checked, must be valid
189  * @return True, if so
190  */
191  inline bool isInside(const PixelPositionT<T>& point) const;
192 
193  /**
194  * Returns whether a given bounding box lies entirely inside this bounding box.
195  * @param boundingBox The bounding box to be checked, must be valid
196  * @return True, if so
197  */
198  inline bool isInside(const PixelBoundingBoxT<T>& boundingBox) const;
199 
200  /**
201  * Returns whether a given bounding box has an intersection with this bounding box.
202  * @param boundingBox The bounding box to be checked, must be valid
203  * @return True, if so
204  */
205  inline bool hasIntersection(const PixelBoundingBoxT<T>& boundingBox) const;
206 
207  /**
208  * Returns whether a given bounding box is touching this bounding box.
209  * Two bounding boxes are touching if both boxes are intersecting or if both boxes have a touching edge.<br>
210  * When two bounding boxes are touching at the corners, the 'useNeighborhood4' property defines whether both boxes count as touching or not.
211  * @param boundingBox The bounding box to be checked, must be valid
212  * @param useNeighborhood8 True, to use a 8-neighborhood during the check; False, to use an 4-neighborhood during the check
213  * @return True, if so
214  */
215  inline bool isTouching(const PixelBoundingBoxT<T>& boundingBox, const bool useNeighborhood8) const;
216 
217  /**
218  * Returns a new bounding box by extending this bounding box with a given number of pixel in each direction.
219  * @param pixels Number of pixels to be added to each bounding box boundary
220  * @param minLeft Minimal (including) left boundary, with minLeft <= left()
221  * @param minTop Minimal (including) top boundary, with minTop <= top()
222  * @param maxRight Minimal (including) right boundary, with maxRight >= right()
223  * @param maxBottom Minimal (including) bottom boundary, with maxBottom >= bottom()
224  * @return Extended bounding box
225  */
226  inline PixelBoundingBoxT<T> extended(const unsigned int pixels, const T minLeft, const T minTop, const T maxRight, const T maxBottom) const;
227 
228  /**
229  * Returns whether this bounding box covers a valid pixel area.
230  * @return True, if so
231  */
232  inline bool isValid() const;
233 
234  /**
235  * Adds a new point to the bounding box.
236  * If the point lies inside the bounding box the box is unchanged, otherwise the box will be extended
237  * @param point The point extending the box
238  * @return Reference to this box
239  */
241 
242  /**
243  * Assignment operator override to match copy constructor
244  */
245  inline PixelBoundingBoxT<T>& operator=(const PixelBoundingBoxT<T>& other) = default;
246 
247  /**
248  * Returns whether two bounding boxes are equal.
249  * @param box Second bounding box
250  * @return True, if so
251  */
252  inline bool operator==(const PixelBoundingBoxT<T>& box) const;
253 
254  /**
255  * Returns whether two bounding boxes are not equal.
256  * @param box Second bounding box
257  * @return True, if so
258  */
259  inline bool operator!=(const PixelBoundingBoxT<T>& box) const;
260 
261  /**
262  * Multiplies this bounding box by a specified scalar (multiplies left, top, right, and bottom location by the scalar).
263  * @param factor The multiplication factor, with range (-infinity, infinity)
264  * @return The new (bigger/multiplied) bounding box
265  */
266  inline PixelBoundingBoxT<T> operator*(const T factor) const;
267 
268  /**
269  * Multiplies this bounding box by a specified scalar (multiplies left, top, right, and bottom location by the scalar).
270  * @param factor The multiplication factor, with range (-infinity, infinity)
271  * @return Reference to this modified bounding box
272  */
273  inline PixelBoundingBoxT<T>& operator*=(const T factor);
274 
275  /**
276  * Divides this bounding box by a specified scalar (divides left, top, right, and bottom location by the scalar).
277  * @param factor The division factor, with range (-infinity, infinity) \ {0}
278  * @return The new (smaller/divided) bounding box
279  */
280  inline PixelBoundingBoxT<T> operator/(const T factor) const;
281 
282  /**
283  * Divides this bounding box by a specified scalar (divides left, top, right, and bottom location by the scalar).
284  * @param factor The division factor, with range (-infinity, infinity) \ {0}
285  * @return Reference to this modified bounding box
286  */
287  inline PixelBoundingBoxT<T>& operator/=(const T factor);
288 
289  /**
290  * Returns the union of two bounding boxes.
291  * @param box Second bounding box
292  * @return New union bounding box
293  */
295 
296  /**
297  * Returns the intersection of two bounding boxes.
298  * Beware: The intersection between a valid and an invalid bounding box is an invalid bounding box.
299  * @param box Second bounding box
300  * @return New intersection bounding box
301  */
303 
304  /**
305  * Hash function.
306  * @param boundingBox The bounding box for which the hash value will be determined
307  * @return The resulting hash value
308  */
309  inline size_t operator()(const PixelBoundingBoxT<T>& boundingBox) const;
310 
311  /**
312  * Returns whether this bounding box covers a valid pixel area.
313  * @return True, if so
314  */
315  explicit inline operator bool() const;
316 
317  private:
318 
319  /// Left (including) pixel position of this bounding box.
320  T left_;
321 
322  /// Top (including) pixel position of this bounding box.
323  T top_;
324 
325  /// Right (including) pixel position of this bounding box.
327 
328  /// Bottom (including) pixel position of this bounding box.
330 };
331 
332 template <typename T>
334  left_(NumericT<T>::maxValue()),
335  top_(NumericT<T>::maxValue()),
336  right_(NumericT<T>::minValue()),
337  bottom_(NumericT<T>::minValue())
338 {
339  // nothing to do here
340 }
341 
342 template <typename T>
344  left_(boundingBox.left_),
345  top_(boundingBox.top_),
346  right_(boundingBox.right_),
347  bottom_(boundingBox.bottom_)
348 {
349  // nothing to do here
350 }
351 
352 template <typename T>
354  left_(point.x()),
355  top_(point.y()),
356  right_(point.x()),
357  bottom_(point.y())
358 {
359  // nothing to do here
360 }
361 
362 template <typename T>
363 inline PixelBoundingBoxT<T>::PixelBoundingBoxT(const std::vector<PixelPositionT<T>>& points) :
364  left_(NumericT<T>::maxValue()),
365  top_(NumericT<T>::maxValue()),
366  right_(NumericT<T>::minValue()),
367  bottom_(NumericT<T>::minValue())
368 {
369  for (typename std::vector<PixelPositionT<T>>::const_iterator i = points.begin(); i != points.end(); ++i)
370  {
371  *this += *i;
372  }
373 }
374 
375 template <typename T>
376 inline PixelBoundingBoxT<T>::PixelBoundingBoxT(const T left, const T top, const T right, const T bottom) :
377  left_(left),
378  top_(top),
379  right_(right),
380  bottom_(bottom)
381 {
382  // nothing to do here
383 }
384 
385 template <typename T>
386 inline PixelBoundingBoxT<T>::PixelBoundingBoxT(const PixelPositionT<T>& topLeft, const unsigned int width, const unsigned int height) :
387  left_(topLeft.x()),
388  top_(topLeft.y()),
389  right_(topLeft.x() + T(width - 1u)),
390  bottom_(topLeft.y() + T(height - 1u))
391 {
392  ocean_assert(width >= 1u);
393  ocean_assert(height >= 1u);
394 }
395 
396 template <typename T>
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()))
402 {
403  ocean_assert(width() >= 1u);
404  ocean_assert(height() >= 1u);
405 
406 #ifdef OCEAN_DEBUG
407  PixelBoundingBoxT<T> debugBoundingBox;
408  debugBoundingBox += point0;
409  debugBoundingBox += point1;
410 
411  ocean_assert(*this == debugBoundingBox);
412 #endif
413 }
414 
415 template <typename T>
417 {
418  ocean_assert(isValid());
419  return left_;
420 }
421 
422 template <typename T>
424 {
425  ocean_assert(isValid());
426  return top_;
427 }
428 
429 template <typename T>
431 {
432  ocean_assert(isValid());
433  return right_;
434 }
435 
436 template <typename T>
438 {
439  ocean_assert(isValid());
440  return right_ + T(1);
441 }
442 
443 template <typename T>
445 {
446  ocean_assert(isValid());
447  return bottom_;
448 }
449 
450 template <typename T>
452 {
453  ocean_assert(isValid());
454  return bottom_ + T(1);
455 }
456 
457 template <typename T>
459 {
460  return PixelPositionT<T>(left_, top_);
461 }
462 
463 template <typename T>
465 {
466  return PixelPositionT<T>(right_, top_);
467 }
468 
469 template <typename T>
471 {
472  return PixelPositionT<T>(left_, bottom_);
473 }
474 
475 template <typename T>
477 {
478  return PixelPositionT<T>(right_, bottom_);
479 }
480 
481 template <typename T>
482 inline unsigned int PixelBoundingBoxT<T>::width() const
483 {
484  ocean_assert(isValid());
485  return (unsigned int)(right_ - left_) + 1u;
486 }
487 
488 template <typename T>
489 inline unsigned int PixelBoundingBoxT<T>::height() const
490 {
491  ocean_assert(isValid());
492  return (unsigned int)(bottom_ - top_) + 1u;
493 }
494 
495 template <typename T>
496 inline unsigned int PixelBoundingBoxT<T>::size() const
497 {
498  if (!isValid())
499  {
500  return 0u;
501  }
502 
503  return width() * height();
504 }
505 
506 template <typename T>
507 inline bool PixelBoundingBoxT<T>::isInside(const PixelPositionT<T>& point) const
508 {
509  ocean_assert(isValid() && point.isValid());
510 
511  return point.x() >= left_ && point.y() >= top_ && point.x() <= right_ && point.y() <= bottom_;
512 }
513 
514 template <typename T>
515 inline bool PixelBoundingBoxT<T>::isInside(const PixelBoundingBoxT<T>& boundingBox) const
516 {
517  ocean_assert(isValid() && boundingBox.isValid());
518 
519  return boundingBox.left_ >= left_ && boundingBox.top_ >= top_ && boundingBox.right_ <= right_ && boundingBox.bottom_ <= bottom_;
520 }
521 
522 template <typename T>
523 inline bool PixelBoundingBoxT<T>::hasIntersection(const PixelBoundingBoxT<T>& boundingBox) const
524 {
525  ocean_assert(isValid() && boundingBox.isValid());
526 
527  // we have not an intersection if one box is entirely outside of the other box
528 
529  return !(left_ > boundingBox.right_ || boundingBox.left_ > right_
530  || top_ > boundingBox.bottom_ || boundingBox.top_ > bottom_);
531 }
532 
533 template <typename T>
534 inline bool PixelBoundingBoxT<T>::isTouching(const PixelBoundingBoxT<T>& boundingBox, const bool useNeighborhood8) const
535 {
536  ocean_assert(isValid() && boundingBox.isValid());
537 
538  if (left_ > boundingBox.right_ + T(1) || boundingBox.left_ > right_ + T(1)
539  || top_ > boundingBox.bottom_ + T(1) || boundingBox.top_ > bottom_ + T(1))
540  {
541  return false;
542  }
543 
544  if (!useNeighborhood8)
545  {
546  // we need to check the case that both boxes touch at a corner
547 
548  if ((left_ == boundingBox.right_ + T(1) || right_ + T(1) == boundingBox.left_) && (top_ == boundingBox.bottom_ + T(1) || bottom_ + T(1) == boundingBox.top_))
549  {
550  return false;
551  }
552  }
553 
554  return true;
555 }
556 
557 template <typename T>
558 inline PixelBoundingBoxT<T> PixelBoundingBoxT<T>::extended(const unsigned int pixels, const T minLeft, const T minTop, const T maxRight, const T maxBottom) const
559 {
560  static_assert(sizeof(T) <= sizeof(int), "Invalid template data type T");
561 
562  ocean_assert(isValid());
563 
564  ocean_assert(minLeft <= left() && minTop <= top());
565  ocean_assert(maxRight >= right() && maxBottom >= bottom());
566 
567  ocean_assert(minLeft <= maxRight);
568  ocean_assert(minTop <= maxBottom);
569 
570  return PixelBoundingBoxT<T>(max(int(minLeft), int(left_) - int(pixels)),
571  max(int(minTop), int(top_) - int(pixels)),
572  min(maxRight, right_ + T(pixels)),
573  min(maxBottom, bottom_ + T(pixels)));
574 }
575 
576 template <typename T>
577 inline bool PixelBoundingBoxT<T>::isValid() const
578 {
579  return right_ >= left_ && bottom_ >= top_;
580 }
581 
582 template <typename T>
584 {
585  ocean_assert(point.isValid());
586 
587  if (point.x() < left_)
588  {
589  left_ = point.x();
590  }
591 
592  if (point.x() > right_)
593  {
594  right_ = point.x();
595  }
596 
597  if (point.y() < top_)
598  {
599  top_ = point.y();
600  }
601 
602  if (point.y() > bottom_)
603  {
604  bottom_ = point.y();
605  }
606 
607  return *this;
608 }
609 
610 template <typename T>
612 {
613  return left_ == box.left_ && top_ == box.top_ && right_ == box.right_ && bottom_ == box.bottom_;
614 }
615 
616 template <typename T>
618 {
619  return !(*this == box);
620 }
621 
622 template <typename T>
624 {
625  ocean_assert(isValid());
626 
627  return PixelBoundingBoxT<T>(left_ * factor, top_ * factor, right_ * factor, bottom_ * factor);
628 }
629 
630 template <typename T>
632 {
633  ocean_assert(isValid());
634 
635  left_ *= factor;
636  top_ *= factor;
637  right_ *= factor;
638  bottom_ *= factor;
639 
640  return *this;
641 }
642 
643 template <typename T>
645 {
646  ocean_assert(isValid());
647  ocean_assert(factor != T(0));
648 
649  return PixelBoundingBoxT<T>(left_ / factor, top_ / factor, right_ / factor, bottom_ / factor);
650 }
651 
652 template <typename T>
654 {
655  ocean_assert(isValid());
656  ocean_assert(factor != T(0));
657 
658  left_ /= factor;
659  top_ /= factor;
660  right_ /= factor;
661  bottom_ /= factor;
662 
663  return *this;
664 }
665 
666 template <typename T>
668 {
669  if (isValid())
670  {
671  if (box.isValid())
672  {
673  return PixelBoundingBoxT<T>(min(left_, box.left_), min(top_, box.top_), max(right_, box.right_), max(bottom_, box.bottom_));
674  }
675 
676  return *this;
677  }
678 
679  return box;
680 }
681 
682 template <typename T>
684 {
685  if (isValid() && box.isValid())
686  {
687  return PixelBoundingBoxT<T>(max(left_, box.left_), max(top_, box.top_), min(right_, box.right_), min(bottom_, box.bottom_));
688  }
689 
690  return PixelBoundingBoxT<T>();
691 }
692 
693 template <typename T>
694 inline size_t PixelBoundingBoxT<T>::operator()(const PixelBoundingBoxT<T>& boundingBox) const
695 {
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);
700 
701  return seed;
702 }
703 
704 template <typename T>
706 {
707  return isValid();
708 }
709 
710 }
711 
712 }
713 
714 #endif // META_OCEAN_CV_PIXEL_BOUNDING_BOX_H
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
PixelBoundingBoxT(const std::vector< PixelPositionT< T >> &points)
Creates a bounding box covering several points.
Definition: PixelBoundingBox.h:363
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
T left_
Left (including) pixel position of this bounding box.
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
T left() const
Returns the left (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:416
PixelBoundingBoxT< T > & operator=(const PixelBoundingBoxT< T > &other)=default
Assignment operator override to match copy constructor.
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
T right() const
Returns the right (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:430
T bottom() const
Returns the bottom (including) position of this bounding box.
Definition: PixelBoundingBox.h:444
unsigned int width() const
Returns the width (the number of horizontal including pixels) of this bounding box.
Definition: PixelBoundingBox.h:482
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
T top_
Top (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:323
PixelBoundingBoxT< T > operator||(const PixelBoundingBoxT< T > &box) const
Returns the union of two bounding boxes.
Definition: PixelBoundingBox.h:667
PixelPositionT< T > topLeft() const
Returns the top left corner of this bounding box.
Definition: PixelBoundingBox.h:458
unsigned int size() const
Returns the area (the number of including pixels) this bounding box covers.
Definition: PixelBoundingBox.h:496
PixelPositionT< T > bottomLeft() const
Returns the bottom left corner of this bounding box.
Definition: PixelBoundingBox.h:470
T bottom_
Bottom (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:329
PixelBoundingBoxT(const PixelPositionT< T > &point0, const PixelPositionT< T > &point1)
Creates a bounding box covering two points.
Definition: PixelBoundingBox.h:397
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
T top() const
Returns the top (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:423
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
Returns the height (the number of vertical including pixels) of this bounding box.
Definition: PixelBoundingBox.h:489
T right_
Right (including) pixel position of this bounding box.
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:65
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:470
T x() const
Returns the horizontal coordinate position of this object.
Definition: PixelPosition.h:458
This class provides basic numeric functionalities.
Definition: Numeric.h:57
std::vector< PixelBoundingBoxI > PixelBoundingBoxesI
Definition of a vector holding bounding box objects with positive and negative coordinate values.
Definition: PixelBoundingBox.h:49
PixelBoundingBoxT< int > PixelBoundingBoxI
Definition of a PixelBoundingBox object with data type allowing positive and negative coordinate valu...
Definition: PixelBoundingBox.h:35
std::vector< PixelBoundingBox > PixelBoundingBoxes
Definition of a vector holding bounding box objects with only positive coordinate values.
Definition: PixelBoundingBox.h:42
PixelBoundingBoxT< unsigned int > PixelBoundingBox
Definition of the default PixelBoundingBox object with data type allowing only positive coordinate va...
Definition: PixelBoundingBox.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15