Sphere.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  Sphere
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006    
00007    @brief
00008       Representation of a 3D sphere with radius .5, enclosed in the unit box 
00009    (-.5,-.5,-.5) to (.5,.5,.5)
00010    <!-------------------------------------------------------------------->**/
00011 
00012 #ifndef SPHERE_H_
00013 #define SPHERE_H_
00014 
00015 #include <shapes/Implicit.h>
00016 #include <stats/samplers/UniformOnSphereSampler.h>
00017 
00018 class Sphere : public Implicit {
00019    public:
00020       inline Sphere(Material *material = NULL) 
00021          : Implicit(material), 
00022            m_quadric(NULL), m_surfaceSampler(NULL)
00023       { }
00024       
00025       virtual ~Sphere() {
00026          if (m_quadric) {
00027             gluDeleteQuadric(m_quadric);
00028             m_quadric = NULL;
00029          }
00030          
00031          safeDelete(m_surfaceSampler);
00032       }
00033       
00034       
00035       ///@name Intersection routines
00036       //@{-----------------------------------------------------------------
00037       
00038       virtual real_t getIntersection(const Ray &ray, SurfacePoint &pt);
00039       
00040       virtual bool intersects(const Ray &ray, 
00041                               real_t tMax = INFINITY);
00042       
00043       
00044       //@}-----------------------------------------------------------------
00045       ///@name Core functionality
00046       //@{-----------------------------------------------------------------
00047       
00048       virtual void preview();
00049       
00050       
00051       //@}-----------------------------------------------------------------
00052       ///@name Sampling functionality
00053       //@{-----------------------------------------------------------------
00054       
00055       /**
00056        * @returns a point chosen uniformly random over the surface of this 
00057        *    shape
00058        * @note the probability density of selecting this point is assumed to 
00059        *    be (1.0 / getSurfaceArea())
00060        */
00061       virtual void getRandomPoint(SurfacePoint &pt);
00062       
00063       /**
00064        * @returns the point on the surface of this shape corresponding to the 
00065        *    given UV coordinates
00066        */
00067       virtual Point3 getPosition(const UV &uv);
00068       
00069       
00070       //@}-----------------------------------------------------------------
00071       
00072    protected:
00073       virtual void _getUV(SurfacePoint &pt) const;
00074       virtual void _getGeometricNormal(SurfacePoint &pt) const;
00075       
00076       /**
00077        * @returns the total surface area of this shape
00078        * 
00079        * @TODO return surface area in world-space!!!
00080        */
00081       virtual real_t _getSurfaceArea();
00082       
00083    protected:
00084       GLUquadric             *m_quadric;
00085       UniformOnSphereSampler *m_surfaceSampler;
00086 };
00087 
00088 #endif // SPHERE_H_
00089 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6