Struct BBox

Synopsis

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

struct BBox

Description

An axis-aligned bounding box stored by its min/max points. The user is responsible for checking the validity of returned bounding-boxes before using them. Note: Falcor already has an AABB class that works differently, hence the name.

Methods

BBox
centroidReturns the centroid of the bounding box.
dimensionsReturns the dimensions of the bounding box.
operator&
operator&=Intersection of two boxes.
operator|
operator|=Union of two boxes.
surfaceAreaReturns the surface area of the bounding box.
validReturns true if bounding box is valid (all dimensions zero or larger).
volumeReturns the volume of the bounding box.

Source

Lines 38-96 in Source/Falcor/Utils/Math/BBox.h.

struct BBox
{
    float3 minPoint = float3(std::numeric_limits<float>::infinity());     // +inf
    float3 maxPoint = float3(-std::numeric_limits<float>::infinity());    // -inf
    BBox() {}
    BBox(const glm::float3& p) : minPoint(p), maxPoint(p) {}
    /** 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; }
    /** Returns the dimensions of the bounding box. */
    float3 dimensions() const { return maxPoint - minPoint; }
    /** Returns the centroid of the bounding box. */
    float3 centroid() const { return (minPoint + maxPoint) * 0.5f; }
    /** Returns the surface area of the bounding box. */
    float surfaceArea() const
    {
        const float3 dims = dimensions();
        return 2.0f * (dims.x * dims.y + dims.y * dims.z + dims.x * dims.z);
    }
    /** Returns the volume of the bounding box.
        \param[in] epsilon Replace dimensions that are zero by this value.
        \return the volume of the bounding box if it is valid, -inf otherwise.
    */
    float volume(float epsilon = 0.0f) const
    {
        if (valid() == false)
        {
            return -std::numeric_limits<float>::infinity();
        }
        const float3 dims = glm::max(float3(epsilon), dimensions());
        return dims.x * dims.y * dims.z;
    }
    /** Union of two boxes. */
    BBox& operator|= (const BBox& rhs)
    {
        minPoint = glm::min(minPoint, rhs.minPoint);
        maxPoint = glm::max(maxPoint, rhs.maxPoint);
        return *this;
    }
    BBox operator| (const BBox& rhs) const { BBox bb = *this; bb |= rhs; return bb; }
    /** Intersection of two boxes. */
    BBox& operator&= (const BBox& rhs)
    {
        minPoint = glm::max(minPoint, rhs.minPoint);
        maxPoint = glm::min(maxPoint, rhs.maxPoint);
        return *this;
    }
    BBox operator& (const BBox& rhs) const { BBox bb = *this; bb &= rhs; return bb; }
};





Add Discussion as Guest

Log in to DocsForge