template struct mrpt::math::TBoundingBox_

A bounding box defined by the 3D points at each minimum-maximum corner.

#include <mrpt/math/TBoundingBox.h>

template <typename T>
struct TBoundingBox_
{
    // enums

    enum CTOR_FLAGS;

    //
fields

    mrpt::math::TPoint3D_<T> min;
    mrpt::math::TPoint3D_<T> max;

    // construction

    TBoundingBox_();
    TBoundingBox_(const mrpt::math::TPoint3D_<T>& Min, const mrpt::math::TPoint3D_<T>& Max, const CTOR_FLAGS f = CTOR_FLAGS::None);

    //
methods

    T volume() const;

    std::optional<TBoundingBox_<T>> intersection(
        const TBoundingBox_<T>& b,
        const T epsilon = static_cast<T>(1e-4)
        ) const;

    TBoundingBox_<T> unionWith(const TBoundingBox_<T>& b) const;
    void updateWithPoint(const mrpt::math::TPoint3D_<T>& p);
    bool containsPoint(const mrpt::math::TPoint3D_<T>& p) const;

    template <typename POSE_T>
    TBoundingBox_<T> compose(const POSE_T& pose) const;

    template <typename POSE_T>
    TBoundingBox_<T> inverseCompose(const POSE_T& pose) const;

    std::string asString() const;
    static TBoundingBox_<T> PlusMinusInfinity();
};

Fields

mrpt::math::TPoint3D_<T> min

The corners of the bounding box.

Construction

TBoundingBox_(const mrpt::math::TPoint3D_<T>& Min, const mrpt::math::TPoint3D_<T>& Max, const CTOR_FLAGS f = CTOR_FLAGS::None)

Ctor from min-max corners.

A bounding box may have a zero volume if max==min. It is ilegal for a coordinate of the max vector to be smaller than its min counterpart, in which case an exception will be thrown, except if the flag CTOR_FLAGS::AllowUnordered is passed.

Methods

T volume() const

Returns the volume of the box.

std::optional<TBoundingBox_<T>> intersection(
    const TBoundingBox_<T>& b,
    const T epsilon = static_cast<T>(1e-4)
    ) const

Returns the intersection of this bounding box with “b”, or std::nullopt if no intersection exists.

Note that borders are enlarged by “epsilon” before to testing for intersection to handle numerical innacuracies, for example on planar bounding boxes with a fixed “z”.

TBoundingBox_<T> unionWith(const TBoundingBox_<T>& b) const

Returns the union of this bounding box with “b”, i.e.

a new bounding box comprising both this and b

void updateWithPoint(const mrpt::math::TPoint3D_<T>& p)

Expands the box limits to include the given point.

bool containsPoint(const mrpt::math::TPoint3D_<T>& p) const

Returns true if the point lies within the bounding box (including the exact border)

(New in MRPT 2.3.3)

template <typename POSE_T>
TBoundingBox_<T> compose(const POSE_T& pose) const

Returns a new bounding box, transforming this from local coordinates to global coordinates, as if this was given with respect to pose, ie:

return.min = pose \oplus this->min
return.max = pose \oplus this->max

If a rotation exists, the output bounding box will no longer be an accurate representation of the actual 3D box.

Parameters:

POSE_T

Can be mrpt::poses::CPose3D, or mrpt::math::TPose3D

template <typename POSE_T>
TBoundingBox_<T> inverseCompose(const POSE_T& pose) const

Returns a new bounding box, transforming this from global coordinates to local coordinates with respect to pose, ie:

return.min = this->min \ominus pose
return.max = this->max \ominus pose

If a rotation exists, the output bounding box will no longer be an accurate representation of the actual 3D box.

Parameters:

POSE_T

Can be mrpt::poses::CPose3D, or mrpt::math::TPose3D

std::string asString() const

Print bounding box as a string with format “(minx,miny,minz)-(maxx,maxy,maxz)”.

Do not inherit from mrpt::Stringifyable to avoid virtual class table and keeping the class trivially-copiable.

static TBoundingBox_<T> PlusMinusInfinity()

Initialize with min=+Infinity, max=-Infinity.

This is useful as an initial value before processing a list of points to keep their minimum/maximum.