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& volumeDimensions) : _dim(volumeDimensions.size()) 10 8092 : { 11 : // sanity check 12 8092 : if (volumeDimensions.size() < 2 || volumeDimensions.size() > 3) 13 0 : throw InvalidArgumentError("BoundingBox: can only deal with the 2d/3d cases"); 14 : 15 8092 : _min.setZero(); 16 8092 : _max = volumeDimensions.template cast<real_t>(); 17 : 18 8092 : _voxelCoordToIndexVector[0] = 1; 19 8092 : _voxelCoordToIndexVector[1] = volumeDimensions[1]; 20 8092 : if (_dim == 3) 21 5265 : _voxelCoordToIndexVector[2] = volumeDimensions[2] * volumeDimensions[2]; 22 8092 : } 23 : 24 14 : RealVector_t BoundingBox::center() const { return (_max - _min).array() / 2; } 25 : 26 : void BoundingBox::recomputeBounds() 27 1682 : { 28 1682 : RealVector_t min = _min.cwiseMin(_max); 29 1682 : RealVector_t max = _min.cwiseMax(_max); 30 : 31 1682 : _min = min; 32 1682 : _max = max; 33 1682 : } 34 : 35 : bool operator==(const BoundingBox& box1, const BoundingBox& box2) 36 0 : { 37 0 : return box1._min == box2._min && box1._max == box2._max; 38 0 : } 39 : 40 0 : bool operator!=(const BoundingBox& box1, const BoundingBox& box2) { return !(box1 == box2); } 41 : 42 : std::ostream& operator<<(std::ostream& stream, const BoundingBox& aabb) 43 0 : { 44 0 : Eigen::IOFormat fmt(4, 0, ", ", ", ", "", "", "[", "]"); 45 0 : stream << "AABB { min = " << aabb._min.format(fmt) << ", max = " << aabb._max.format(fmt) 46 0 : << " }"; 47 : 48 0 : return stream; 49 0 : } 50 : 51 : } // namespace elsa