#pragma once #include #include #include namespace cgv { namespace media { /** * An axis aligned box, defined by to points: min and max */ template class axis_aligned_box { public: /// internally fixed sized points and vectors are used typedef cgv::math::fvec fpnt_type; typedef cgv::math::fvec fvec_type; /// the interface allows also to work with variable sized points typedef cgv::math::vec pnt_type; typedef cgv::math::vec vec_type; protected: fpnt_type minp; fpnt_type maxp; public: /// standard constructor does not initialize axis_aligned_box() { invalidate(); } /// type conversion copy constructor template axis_aligned_box(const axis_aligned_box& B) : minp(T(B.get_min_pnt()(0)), T(B.get_min_pnt()(1)), T(B.get_min_pnt()(2))), maxp(T(B.get_max_pnt()(0)), T(B.get_max_pnt()(1)), T(B.get_max_pnt()(2))) {} /// construct from min point and max point axis_aligned_box(const fpnt_type& _minp, const fpnt_type& _maxp) : minp(_minp), maxp(_maxp) {} /// construct from min point and max point axis_aligned_box(const pnt_type& _minp, const pnt_type& _maxp) { invalidate(); unsigned i; for (i=0; i<_minp.size(); ++i) { if (i == N) break; minp(i) = _minp(i); } for (i=0; i<_maxp.size(); ++i) { if (i == N) break; maxp(i) = _maxp(i); } } /// set to invalid min and max points void invalidate() { for (unsigned int c = 0; c= maxp(c)) return false; } return true; } /// extent box to include given point void add_point(const fpnt_type& p) { if (is_valid()) { for (unsigned int c = 0; c maxp(c)) maxp(c) = p(c); if (p(c) < minp(c)) minp(c) = p(c); } } else minp = maxp = p; } /// extent box to include given point void add_point(const pnt_type& p) { if (is_valid()) { for (unsigned int c = 0; p.size(); ++c) { if (c == N) break; if (p(c) > maxp(c)) maxp(c) = p(c); if (p(c) < minp(c)) minp(c) = p(c); } } else *this = axis_aligned_box(p,p); } /// extent box to include given axis alinged box void add_axis_aligned_box(const axis_aligned_box& aab) { if (!aab.is_valid()) return; add_point(aab.minp); add_point(aab.maxp); } /// scale the complete box with respect to the world coordinate origin void scale(const T& f) { for (unsigned int c = 0; c e(j)) j = i; return j; } }; } }