template struct mrpt::math::TBoundingBox_

Overview

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::NoFlags);

    // 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;

    mrpt::math::TPoint3D_<T> corner(int i) const;
    std::string asString() const;
    bool operator == (const TBoundingBox_<T>& o) const;
    bool operator != (const TBoundingBox_<T>& o) const;
    static TBoundingBox_<T> PlusMinusInfinity();
    static TBoundingBox_<T> FromUnsortedPoints(const mrpt::math::TPoint3D_<T>& pt1, const mrpt::math::TPoint3D_<T>& pt2);
};

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::NoFlags)

Ctor from min-max corners.

A bounding box may have a zero volume if max==min. It is illegal 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 testing for intersection to handle numerical inaccuracies, for example on planar bounding boxes with a fixed “z”. If the boxes are separated by a gap smaller than “epsilon” along some axis, the result is flat along it (at the middle of the gap).

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. An empty box (see PlusMinusInfinity()) is the neutral element.

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 : the smallest axis-aligned box that contains the 8 corners of this transformed as pose \oplus corner.

Without rotation, this is just pose \oplus min and pose \oplus max.

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 : the smallest axis-aligned box that contains the 8 corners of this transformed as corner \ominus pose.

Parameters:

POSE_T

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

mrpt::math::TPoint3D_<T> corner(int i) const

Returns one of the 8 corners of the box: bits 0, 1 and 2 of i select the max (instead of the min) x, y and z coordinates, respectively.

New in MRPT 3.7.0

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.

static TBoundingBox_<T> FromUnsortedPoints(const mrpt::math::TPoint3D_<T>& pt1, const mrpt::math::TPoint3D_<T>& pt2)

Construct a bounding box from two points, by selecting their minimum and maximum (x,y,z) coordinates, so the point coordinates do not need to be already sorted by the user as one being the minimum and maximum corners.

(New in MRPT 2.5.6)