Volume Cartographer 2.27.0
BoundingBox.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <type_traits>
6
7#include <opencv2/core.hpp>
8
9namespace volcart
10{
11
23template <
24 typename T,
25 int Dim,
26 typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
28{
29public:
31 using Point = cv::Vec<T, Dim>;
32
34 BoundingBox() = default;
35
37 BoundingBox(Point lower, Point upper) : p0_{lower}, p1_{upper} {}
38
40 Point getLowerBound() const { return p0_; }
41
43 Point getUpperBound() const { return p1_; }
44
47 {
48 if (i >= Dim) {
49 throw std::domain_error("Invalid dimension index");
50 }
51 return p0_[i];
52 }
53
56 {
57 if (i >= Dim) {
58 throw std::domain_error("Invalid dimension index");
59 }
60 return p1_[i];
61 }
62
64 void setLowerBound(Point p) { p0_ = std::move(p); }
65
67 void setUpperBound(Point p) { p1_ = std::move(p); }
68
70 void setLowerBoundByIndex(int i, T val)
71 {
72 if (i >= Dim) {
73 throw std::domain_error("Invalid dimension index");
74 }
75 p0_[i] = val;
76 }
77
79 void setUpperBoundByIndex(int i, T val)
80 {
81 if (i >= Dim) {
82 throw std::domain_error("Invalid dimension index");
83 }
84 p1_[i] = val;
85 }
86
88 bool isInBounds(const Point& p) const
89 {
90 for (int d = 0; d < Dim; d++) {
91 if (p[d] < p0_[d] || p[d] >= p1_[d]) {
92 return false;
93 }
94 }
95 return true;
96 }
97
98private:
100 Point p0_{0, 0, 0};
102 Point p1_{0, 0, 0};
103};
104} // namespace volcart
Generic axis-aligned bounding box class for operations in N-dimensions.
Definition: BoundingBox.hpp:28
bool isInBounds(const Point &p) const
Check if a Point is within the bounds of the box.
Definition: BoundingBox.hpp:88
cv::Vec< T, Dim > Point
Definition: BoundingBox.hpp:31
void setUpperBound(Point p)
Set the upper boundary for each axis.
Definition: BoundingBox.hpp:67
BoundingBox()=default
Default constructor.
void setLowerBound(Point p)
Set the lower boundary for each axis.
Definition: BoundingBox.hpp:64
Point getUpperBound() const
Get the upper boundary for each axis.
Definition: BoundingBox.hpp:43
void setLowerBoundByIndex(int i, T val)
Set the lower boundary for a specific axis by axis index.
Definition: BoundingBox.hpp:70
T getUpperBoundByIndex(int i)
Get the upper boundary for a specific axis by axis index.
Definition: BoundingBox.hpp:55
void setUpperBoundByIndex(int i, T val)
Set the upper boundary for a specific axis by axis index.
Definition: BoundingBox.hpp:79
Point getLowerBound() const
Get the lower boundary for each axis.
Definition: BoundingBox.hpp:40
T getLowerBoundByIndex(int i)
Get the lower boundary for a specific axis by axis index.
Definition: BoundingBox.hpp:46
BoundingBox(Point lower, Point upper)
Constructor with lower and upper bounds initialization.
Definition: BoundingBox.hpp:37
Volume Cartographer library