Line data Source code
1 : #include "BoundingBox.h" 2 : 3 : #include <stdexcept> 4 : 5 : #include "Error.h" 6 : 7 : namespace elsa 8 : { 9 : BoundingBox::BoundingBox(const IndexVector_t& volDims) 10 : : _dim(volDims.size()), 11 : _min(RealVector_t::Zero(_dim)), 12 : _max(volDims.template cast<real_t>()) 13 8665 : { 14 8665 : } 15 : 16 : BoundingBox::BoundingBox(const RealVector_t& min, const RealVector_t& max) 17 : : _dim(min.size()), _min(min), _max(max) 18 0 : { 19 0 : } 20 : 21 : index_t BoundingBox::dim() const 22 382 : { 23 382 : return _dim; 24 382 : } 25 : 26 : RealVector_t BoundingBox::center() const 27 14 : { 28 14 : return (_max - _min).array() / 2; 29 14 : } 30 : 31 : RealVector_t& BoundingBox::min() 32 18482 : { 33 18482 : return _min; 34 18482 : } 35 : 36 : const RealVector_t& BoundingBox::min() const 37 1185248 : { 38 1185248 : return _min; 39 1185248 : } 40 : 41 : RealVector_t& BoundingBox::max() 42 19752 : { 43 19752 : return _max; 44 19752 : } 45 : 46 : const RealVector_t& BoundingBox::max() const 47 705563 : { 48 705563 : return _max; 49 705563 : } 50 : 51 : void BoundingBox::translateMin(const real_t& t) 52 0 : { 53 0 : this->min().array() += t; 54 0 : } 55 : 56 : void BoundingBox::translateMin(const RealVector_t& t) 57 0 : { 58 0 : this->min() += t; 59 0 : } 60 : 61 : void BoundingBox::translateMax(const real_t& t) 62 0 : { 63 0 : this->max().array() += t; 64 0 : } 65 : 66 : void BoundingBox::translateMax(const RealVector_t& t) 67 0 : { 68 0 : this->max() += t; 69 0 : } 70 : 71 : void BoundingBox::recomputeBounds() 72 1683 : { 73 1683 : RealVector_t min = _min.cwiseMin(_max); 74 1683 : RealVector_t max = _min.cwiseMax(_max); 75 : 76 1683 : _min = min; 77 1683 : _max = max; 78 1683 : } 79 : 80 : bool operator==(const BoundingBox& box1, const BoundingBox& box2) 81 0 : { 82 0 : return box1._min == box2._min && box1._max == box2._max; 83 0 : } 84 : 85 : bool operator!=(const BoundingBox& box1, const BoundingBox& box2) 86 0 : { 87 0 : return !(box1 == box2); 88 0 : } 89 : 90 : std::ostream& operator<<(std::ostream& stream, const BoundingBox& aabb) 91 0 : { 92 0 : Eigen::IOFormat fmt(4, 0, ", ", ", ", "", "", "[", "]"); 93 0 : stream << "AABB { min = " << aabb._min.format(fmt) << ", max = " << aabb._max.format(fmt) 94 0 : << " }"; 95 : 96 0 : return stream; 97 0 : } 98 : 99 : } // namespace elsa