Commit d2a9be89 authored by David Frank's avatar David Frank
Browse files

Enhance bounding box

parent 0facef56
......@@ -21,4 +21,31 @@ namespace elsa
_voxelCoordToIndexVector[2] = volumeDimensions[2] * volumeDimensions[2];
}
RealVector_t BoundingBox::center() const { return (_max - _min).array() / 2; }
void BoundingBox::recomputeBounds()
{
RealVector_t min = _min.cwiseMin(_max);
RealVector_t max = _min.cwiseMax(_max);
_min = min;
_max = max;
}
bool operator==(const BoundingBox& box1, const BoundingBox& box2)
{
return box1._min == box2._min && box1._max == box2._max;
}
bool operator!=(const BoundingBox& box1, const BoundingBox& box2) { return !(box1 == box2); }
std::ostream& operator<<(std::ostream& stream, const BoundingBox& aabb)
{
Eigen::IOFormat fmt(4, 0, ", ", ", ", "", "", "[", "]");
stream << "AABB { min = " << aabb._min.format(fmt) << ", max = " << aabb._max.format(fmt)
<< " }";
return stream;
}
} // namespace elsa
......@@ -19,6 +19,16 @@ namespace elsa
*/
BoundingBox(const IndexVector_t& volumeDimensions);
RealVector_t center() const;
void recomputeBounds();
friend bool operator==(const BoundingBox& box1, const BoundingBox& box2);
friend bool operator!=(const BoundingBox& box1, const BoundingBox& box2);
friend std::ostream& operator<<(std::ostream& stream, const BoundingBox& aabb);
/// the number of dimensions (2 or 3)
index_t _dim;
/// the front corner of the box
......@@ -28,4 +38,5 @@ namespace elsa
/// helper to convert coordinates to indices
IndexVector_t _voxelCoordToIndexVector{_dim};
};
} // namespace elsa
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment