2 #ifndef vbl_bounding_box_h_ 3 #define vbl_bounding_box_h_ 20 # include <vcl_msvc_warnings.h> 23 #include <type_traits> 25 #ifndef DOXYGEN_SHOULD_SKIP_THIS 28 struct vbl_bounding_box_DIM {
enum { value = DIM }; };
29 #endif // DOXYGEN_SHOULD_SKIP_THIS 31 template <
class T,
class DIM_>
40 assert(DIM_::value == 1);
45 inline void update(T
const& x, T
const& y) {
46 assert(DIM_::value == 2);
52 inline void update(T
const& x, T
const& y, T
const& z) {
53 assert(DIM_::value == 3);
59 inline int dimension()
const {
return DIM_::value; }
69 if (point[i] <
min_[i])
min_[i] = point[i];
70 if (point[i] >
max_[i])
max_[i] = point[i];
82 inline bool inside(
const T& x,
const T& y)
const {
83 assert (DIM_::value == 2);
84 constexpr
unsigned int xdim = 0;
85 constexpr
unsigned int ydim = (DIM_::value == 2) ? 1 : 0;
88 min_[xdim] <= x && x <=
max_[xdim] &&
93 inline bool inside(
const T& x,
const T& y,
const T& z)
const {
94 assert (DIM_::value == 3);
95 constexpr
unsigned int xdim = 0;
96 constexpr
unsigned int ydim = (DIM_::value == 3) ? 1 : 0;
97 constexpr
unsigned int zdim = (DIM_::value == 3) ? 2 : 0;
99 min_[xdim] <= x && x <=
max_[xdim] &&
100 min_[ydim] <= y && y <=
max_[ydim] &&
105 inline bool inside(T
const* point)
const {
108 if ( point[i] <
min_[i] ||
max_[i] < point[i] )
122 std::ostream&
print(std::ostream& s)
const;
132 inline T
const&
ymin()
const { assert(DIM_::value >= 2);
return (DIM_::value >= 2) ?
min_[1] :
min_[0]; }
133 inline T
const&
ymax()
const { assert(DIM_::value >= 2);
return (DIM_::value >= 2) ?
max_[1] :
max_[0]; }
134 inline T
const&
zmin()
const { assert(DIM_::value >= 3);
return (DIM_::value >= 3) ?
min_[2] :
min_[0]; }
135 inline T
const&
zmax()
const { assert(DIM_::value >= 3);
return (DIM_::value >= 3) ?
max_[2] :
max_[0]; }
172 template <
class T,
int DIM>
181 template <
class T,
class DIM_>
185 for (
int i=0; i<DIM_::value; ++i)
192 template <
class T,
class DIM_>
197 for (
int i=0; i<DIM_::value; ++i)
204 template <
class T,
class DIM_>
210 template <
class T,
class DIM_>
213 #endif // vbl_bounding_box_h_ T volume() const
return "volume".
void update(T const &x, T const &y)
Incorporate 2d point x, y.
void reset()
Reset to empty.
bool disjoint(vbl_bounding_box_base< T, DIM_ > const &a, vbl_bounding_box_base< T, DIM_ > const &b)
is the intersection empty?.
void update(T const *point)
Incorporate DIM-d point.
bool inside(const T &x, const T &y) const
is a 2D point inside the bounding box.
vbl_bounding_box_base()
Construct an empty bounding box.
std::ostream & print(std::ostream &s) const
A class to hold and update a bounding box.
std::ostream & operator<<(std::ostream &s, const vbl_bounding_box_base< T, DIM_ > &bbox)
int dimension() const
return dimension.
void update(T const &x, T const &y, T const &z)
Incorporate 3d point x, y, z.
bool inside(T const *point) const
inside test for arbitrary dimension.
bool meet(vbl_bounding_box_base< T, DIM_ > const &a, vbl_bounding_box_base< T, DIM_ > const &b)
is the intersection nonempty?.
bool inside(const T &x, const T &y, const T &z) const
is a 3D point inside the bounding box.
bool empty() const
Return initialisation status.
bool nested(vbl_bounding_box_base< T, DIM_ > const &a, vbl_bounding_box_base< T, DIM_ > const &b)
this is "operator \subseteq".
void update(T const &x)
Incorporate 1d point x.