Intersectable.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  Intersectable
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Interface for an intersectable object in 3-space, with some extra 
00009    functionality specific to accelerating spatial intersection queries
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #ifndef INTERSECTABLE_H_
00013 #define INTERSECTABLE_H_
00014 
00015 #include <accel/AABB.h>
00016 
00017 class  Ray;
00018 struct SurfacePoint;
00019 class  Intersectable;
00020 
00021 DECLARE_STL_TYPEDEF(std::vector<Intersectable*>, IntersectableList);
00022 
00023 class Intersectable {
00024    public:
00025       ///@name Fast-access public data
00026       //@{-----------------------------------------------------------------
00027       
00028       /// for 'mailboxing' intersection tests to speed up traversal of 
00029       /// kdTreeAccel by ensuring that large primitives which may lie in 
00030       /// more than one voxel are only tested for intersection once-per-ray
00031       /// for more info, search the raytracing literature for mailboxing
00032       unsigned int rayID;
00033       
00034       
00035       //@}-----------------------------------------------------------------
00036       ///@name Constructors
00037       //@{-----------------------------------------------------------------
00038       
00039       inline   Intersectable()
00040          : rayID((unsigned) -1)
00041       { }
00042       
00043       virtual ~Intersectable() 
00044       { }
00045       
00046       
00047       //@}-----------------------------------------------------------------
00048       ///@name Initialization
00049       //@{-----------------------------------------------------------------
00050       
00051       /**
00052        * @brief 
00053        *    Initializes this Intersectable for fast intersection testing
00054        * 
00055        * @note default implementation is empty
00056        * @note must be called before getIntersection or intersects
00057        */
00058       virtual void init();
00059       
00060       
00061       //@}-----------------------------------------------------------------
00062       ///@name Main usage interface
00063       //@{-----------------------------------------------------------------
00064       
00065       /**
00066        * @brief
00067        *    Tests the given ray with this object for intersection. If a valid 
00068        * intersection exists, its "t" value will be returned and the given 
00069        * SurfacePoint will be initialized with enough data for this object to 
00070        * later fill in all relevant information lazily (world space normal 
00071        * at intersection point, uv coordinates, etc.)
00072        * 
00073        * @note if you only care about whether or not an intersection exists 
00074        *    and don't actually need to know the exact intersection point, 
00075        *    see the intersects method instead.
00076        * @returns the smallest positive "t" value of any intersections 
00077        *    found, or INFINITY if no valid intersection exists
00078        */
00079       virtual real_t getIntersection(const Ray &ray, SurfacePoint &pt) = 0;
00080       
00081       /**
00082        * @brief
00083        *    Used for occlusion/visibility testing where you don't necessarily 
00084        * care about anything other than whether or not an intersection exists.
00085        * (generally faster than getIntersection)
00086        * 
00087        * @note default implementation defers to getIntersection
00088        * @returns whether or not the given ray intersects this object with a 
00089        *    positive "t" value greater than EPSILON and less than the given 
00090        *    @p tMax
00091        */
00092       virtual bool intersects(const Ray &ray, real_t tMax = INFINITY);
00093       
00094       
00095       //@}-----------------------------------------------------------------
00096       ///@name Accessors
00097       //@{-----------------------------------------------------------------
00098       
00099       virtual AABB getAABB() const = 0;
00100       
00101       inline real_t getMin(unsigned dim) const {
00102          return getAABB().min[dim];
00103       }
00104       
00105       inline real_t getMax(unsigned dim) const {
00106          return getAABB().max[dim];
00107       }
00108       
00109       
00110       //@}-----------------------------------------------------------------
00111 };
00112 
00113 #endif // INTERSECTABLE_H_
00114 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6