Struct AABB

Synopsis

#include <Source/Falcor/Utils/Math/AABB.h>

struct AABB

Description

Axis-aligned bounding box (AABB) stored by its min/max points.

The user is responsible for checking the validity of returned AABBs. There is an equivalent GPU-side implementation in the AABB.slang module.

Mentioned in

  • Usage / Scripting / AABB
  • Usage / Scripting / Scene

Methods

AABB overloadConstruct bounding box initialized to +/-inf.
AABB overloadConstruct bounding box initialized to single point.
AABB overloadConstruct bounding box initialized to min/max point.
areaReturns the surface area of the box.
centerReturns the box center.
extentReturns the box extent.
include overloadGrows the box to include the point p.
include overloadGrows the box to include another box.
intersectionMake the box be the intersection between this and another box.
invalidateInvalidates the box.
operator!=Checks whether two bounding boxes are not equal.
operator&Intersection of two boxes.
operator&=Intersection of two boxes.
operator==Checks whether two bounding boxes are equal.
operator|Union of two boxes.
operator|=Union of two boxes.
radiusReturns the radius of the minimal sphere that encloses the box.
set overloadSet box to single point.
set overloadSet the box corners explicitly.
transformCalculates the bounding box transformed by a matrix.
validReturns true if bounding box is valid (all dimensions zero or larger).
volumeReturn the volume of the box.

Source

Lines 39-222 in Source/Falcor/Utils/Math/AABB.h.

struct AABB
{
    float3 minPoint = float3(std::numeric_limits<float>::infinity());   ///< Minimum point.
    float3 maxPoint = float3(-std::numeric_limits<float>::infinity());  ///< Maximum point. If any minPoint > maxPoint the box is invalid.
    /** Construct bounding box initialized to +/-inf.
    */
    AABB() = default;
    /** Construct bounding box initialized to single point.
    */
    AABB(const float3& p) : minPoint(p), maxPoint(p) {}
    /** Construct bounding box initialized to min/max point.
    */
    AABB(const float3& pmin, const float3& pmax) : minPoint(pmin), maxPoint(pmax) {}
    /** Set box to single point.
    */
    void set(const float3& p) { minPoint = maxPoint = p; }
    /** Set the box corners explicitly.
    */
    void set(const float3& pmin, const float3& pmax)
    {
        minPoint = pmin;
        maxPoint = pmax;
    }
    /** Invalidates the box.
    */
    void invalidate()
    {
        minPoint = float3(std::numeric_limits<float>::infinity());
        maxPoint = float3(-std::numeric_limits<float>::infinity());
    }
    /** Returns true if bounding box is valid (all dimensions zero or larger).
    */
    bool valid() const
    {
        return maxPoint.x >= minPoint.x && maxPoint.y >= minPoint.y && maxPoint.z >= minPoint.z;
    }
    /** Grows the box to include the point p.
    */
    AABB& include(const float3& p)
    {
        minPoint = min(minPoint, p);
        maxPoint = max(maxPoint, p);
        return *this;
    }
    /** Grows the box to include another box.
    */
    AABB& include(const AABB& b)
    {
        minPoint = min(minPoint, b.minPoint);
        maxPoint = max(maxPoint, b.maxPoint);
        return *this;
    }
    /** Make the box be the intersection between this and another box.
    */
    AABB& intersection(const AABB& b)
    {
        minPoint = glm::max(minPoint, b.minPoint);
        maxPoint = glm::min(maxPoint, b.maxPoint);
        return *this;
    }
    /** Returns the box center.
        \return Center of the box if valid, undefined otherwise.
    */
    float3 center() const
    {
        return (minPoint + maxPoint) * 0.5f;
    }
    /** Returns the box extent.
        \return Size of the box if valid, undefined otherwise.
    */
    float3 extent() const
    {
        return maxPoint - minPoint;
    }
    /** Returns the surface area of the box.
        \return Surface area if box is valid, undefined otherwise.
    */
    float area() const
    {
        float3 e = extent();
        return (e.x * e.y + e.x * e.z + e.y * e.z) * 2.f;
    }
    /** Return the volume of the box.
        \return Volume if the box is valid, undefined otherwise.
    */
    float volume() const
    {
        float3 e = extent();
        return e.x * e.y * e.z;
    }
    /** Returns the radius of the minimal sphere that encloses the box.
        \return Radius of minimal bounding sphere, or undefined if box is invalid.
    */
    float radius() const
    {
        return 0.5f * glm::length(extent());
    }
    /** Calculates the bounding box transformed by a matrix.
        \param[in] mat Transform matrix
        \return Bounding box after transformation.
    */
    AABB transform(const glm::mat4& mat) const
    {
        float3 xa = float3(mat[0] * minPoint.x);
        float3 xb = float3(mat[0] * maxPoint.x);
        float3 xMin = glm::min(xa, xb);
        float3 xMax = glm::max(xa, xb);
        float3 ya = float3(mat[1] * minPoint.y);
        float3 yb = float3(mat[1] * maxPoint.y);
        float3 yMin = glm::min(ya, yb);
        float3 yMax = glm::max(ya, yb);
        float3 za = float3(mat[2] * minPoint.z);
        float3 zb = float3(mat[2] * maxPoint.z);
        float3 zMin = glm::min(za, zb);
        float3 zMax = glm::max(za, zb);
        float3 newMin = xMin + yMin + zMin + float3(mat[3]);
        float3 newMax = xMax + yMax + zMax + float3(mat[3]);
        return AABB(newMin, newMax);
    }
    /** Checks whether two bounding boxes are equal.
    */
    bool operator== (const AABB& rhs) const
    {
        return minPoint == rhs.minPoint && maxPoint == rhs.maxPoint;
    }
    /** Checks whether two bounding boxes are not equal.
    */
    bool operator!= (const AABB& rhs) const
    {
        return minPoint != rhs.minPoint || maxPoint != rhs.maxPoint;
    }
    /** Union of two boxes.
    */
    AABB& operator|= (const AABB& rhs)
    {
        return include(rhs);
    }
    /** Union of two boxes.
    */
    AABB operator| (const AABB& rhs) const
    {
        AABB bb = *this;
        return bb |= rhs;
    }
    /** Intersection of two boxes.
    */
    AABB& operator&= (const AABB& rhs)
    {
        return intersection(rhs);
    }
    /** Intersection of two boxes.
    */
    AABB operator& (const AABB& rhs) const
    {
        AABB bb = *this;
        return bb &= rhs;
    }
};





Add Discussion as Guest

Log in