AABB.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  AABB
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @date   Fall 2008
00005    
00006    @brief
00007       3-Dimensional Axis-Aligned Bounding Box
00008    <!-------------------------------------------------------------------->**/
00009 
00010 #ifndef AABB_H_
00011 #define AABB_H_
00012 
00013 #include <common/math/algebra.h>
00014 #include <ostream>
00015 
00016 class Ray;
00017 
00018 struct AABB : public SSEAligned {
00019    Vector3 min;
00020    Vector3 max;
00021    
00022    ///@name Constructors
00023    //@{-----------------------------------------------------------------
00024 
00025    inline AABB()
00026       : min(Vector3::infinity()), max(Vector3::negativeInfinity())
00027    { }
00028    
00029    inline AABB(const Vector3 &min_, const Vector3 &max_)
00030       : min(min_), max(max_)
00031    { }
00032    
00033    
00034    //@}-----------------------------------------------------------------
00035    ///@name Main usage interface
00036    //@{-----------------------------------------------------------------
00037    
00038    inline bool intersects(const Ray &ray, real_t &tMin, real_t &tMax) const;
00039    
00040    /// unions this AABB with the given vector
00041    inline void add(const Vector3 &v);
00042    
00043    /// unions this AABB with the given Point
00044    inline void add(const Point3  &p);
00045    
00046    /// unions this AABB with the given AABB
00047    inline void add(const AABB &aabb);
00048    
00049    /// @returns whether or not this AABB intersects the given AABB
00050    /// @note inclusive with respect to boundaries
00051    inline bool intersects(const AABB &aabb) const;
00052    
00053    /// @returns whether or not this AABB contains the given point
00054    /// @note inclusive with respect to boundaries of AABB
00055    inline bool contains(const Point3 &p) const;
00056    
00057    void preview() const;
00058    
00059    //@}-----------------------------------------------------------------
00060    ///@name Accessors
00061    //@{-----------------------------------------------------------------
00062    
00063    /// @returns the diagonal of this AABB
00064    inline Vector3 getDiagonal() const;
00065    
00066    inline Point3  getCenter() const;
00067    
00068    /// @returns the dominant (longest) axis along this AABB
00069    inline unsigned getMaxExtent() const;
00070    /// @returns the shortest axis along this AABB
00071    inline unsigned getMinExtent() const;
00072    
00073    /// @returns the surface area of this AABB
00074    inline real_t   getSurfaceArea() const;
00075    
00076    /// @returns the surface area of the child AABBs split along the specified 
00077    ///    @axis at @pos
00078    /// @note this is used extensively by the SAH kd-Tree
00079    inline void     getMinMaxSurfaceArea(const unsigned axis, 
00080                                         const real_t pos, 
00081                                         real_t &leftArea, 
00082                                         real_t &rightArea) const;
00083    
00084    /// @returns the tightest-fitting AABB after undergoing a transformation
00085    inline AABB     getTransformed(const Matrix4x4 &trans) const;
00086    
00087    /// @returns true if this AABB has been initialized with a min <= max
00088    /// @note will be valid if 'min' is less than or equal to 'max'
00089    inline bool     isValid() const;
00090    
00091    /// @returns true if this AABB represents a single point (min == max)
00092    /// @note will be valid if 'min' is strictly less than 'max'
00093    inline bool     isPoint() const;
00094    
00095    //@}-----------------------------------------------------------------
00096 };
00097 
00098 /// Prints an AABB to an output stream
00099 inline std::ostream &operator<<(std::ostream &os, const AABB &aabb);
00100 
00101 /* Include inline implementations */
00102 #include "accel/AABB.inl"
00103 
00104 #endif // AABB_H_
00105 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6