Shape.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @class Shape 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 Abstract representation of a shape in 3-space 00009 <!-------------------------------------------------------------------->**/ 00010 00011 #ifndef SHAPE_H_ 00012 #define SHAPE_H_ 00013 00014 #include <shapes/Intersectable.h> 00015 #include <common/math/algebra.h> 00016 #include <core/UV.h> 00017 00018 class InstancedShape; 00019 class Material; 00020 class Shape; 00021 00022 DECLARE_STL_TYPEDEF(std::vector<Shape*>, PrimitiveList); 00023 00024 class Shape : public Intersectable, public SSEAligned { 00025 public: 00026 ///@name Constructors 00027 //@{----------------------------------------------------------------- 00028 00029 inline Shape(Material *material = NULL) 00030 : Intersectable(), m_material(material), m_surfaceArea(0) 00031 { } 00032 00033 virtual ~Shape() 00034 { } 00035 00036 00037 //@}----------------------------------------------------------------- 00038 ///@name Initialization 00039 //@{----------------------------------------------------------------- 00040 00041 /** 00042 * @brief 00043 * Initializes this Shape for fast intersection testing 00044 * 00045 * @note default implementation ensures this shape has been given 00046 * a valid material 00047 * @note must be called before getIntersection or intersects 00048 */ 00049 virtual void init(); 00050 00051 00052 //@}----------------------------------------------------------------- 00053 ///@name Main usage interface 00054 //@{----------------------------------------------------------------- 00055 00056 /** 00057 * @returns whether or not this Shape supports the concept of a geometric 00058 * surface normal defined over its surface 00059 * 00060 * @note default implementation returns true 00061 */ 00062 virtual bool hasNormal() const; 00063 00064 /** 00065 * @brief 00066 * Displays a crude OpenGL preview of this shape 00067 * 00068 * @note default implementation calls preview on this shape's material 00069 */ 00070 virtual void preview(); 00071 00072 00073 //@}----------------------------------------------------------------- 00074 ///@name Sampling functionality 00075 //@{----------------------------------------------------------------- 00076 00077 /** 00078 * @returns a point chosen uniformly random over the surface of this 00079 * shape in 'pt' 00080 * @note the probability density of selecting this point is assumed to 00081 * be (1.0 / getSurfaceArea()) 00082 * 00083 * @note default implementation returns origin because not all shapes 00084 * support this functionality 00085 */ 00086 virtual void getRandomPoint(SurfacePoint &pt); 00087 00088 /** 00089 * @returns the point on the surface of this shape corresponding to the 00090 * given UV coordinates in 'pt' 00091 * 00092 * @note default implementation returns origin because not all shapes 00093 * support this functionality 00094 */ 00095 virtual void getPoint(SurfacePoint &pt, const UV &uv); 00096 00097 /** 00098 * @returns the point on the surface of this shape corresponding to the 00099 * given UV coordinates 00100 * 00101 * @note default implementation returns origin because not all shapes 00102 * support this functionality 00103 */ 00104 virtual Point3 getPosition(const UV &uv); 00105 00106 /** 00107 * @returns the total surface area of this shape 00108 * 00109 * @note default implementation returns m_surfaceArea, which is assumed 00110 * to be calculated at shape initialization 00111 */ 00112 virtual real_t getSurfaceArea(); 00113 00114 00115 //@}----------------------------------------------------------------- 00116 ///@name Accessors / Mutators 00117 //@{----------------------------------------------------------------- 00118 00119 virtual AABB getAABB() const { 00120 return m_aabb; 00121 } 00122 00123 inline void setMaterial(Material *material) { 00124 m_material = material; 00125 } 00126 00127 inline Material *getMaterial() { 00128 return m_material; 00129 } 00130 00131 /** 00132 * @returns true iff this Shape subclasses Transformable 00133 */ 00134 virtual bool isTransformable() const { 00135 return false; 00136 } 00137 00138 00139 //@}----------------------------------------------------------------- 00140 ///@name Lazy evaluation of SurfacePoint information 00141 //@{----------------------------------------------------------------- 00142 00143 /** 00144 * @brief 00145 * Initializes the given SurfacePoint which is assumed to lie on the 00146 * surface of this Shape; fills in the point's UV coords, normal, and 00147 * Material properties (@see Material::initSurfacePoint) 00148 */ 00149 virtual void initSurfacePoint(SurfacePoint &pt) const; 00150 00151 protected: 00152 virtual void _getUV(SurfacePoint &pt) const = 0; 00153 virtual void _getGeometricNormal(SurfacePoint &pt) const = 0; 00154 00155 /** 00156 * @returns the total surface area of this shape 00157 * 00158 * @note default implementation returns 0 because not all shapes support 00159 * this calculation (some are especially hard to compute in world 00160 * space) 00161 */ 00162 virtual real_t _getSurfaceArea(); 00163 00164 friend class InstancedShape; 00165 00166 //@}----------------------------------------------------------------- 00167 00168 protected: 00169 /// World-space AABB 00170 AABB m_aabb; 00171 00172 /// Material describing reflectance properties over this shape's surface 00173 Material *m_material; 00174 00175 /// World-space surface area of this shape 00176 real_t m_surfaceArea; 00177 }; 00178 00179 #endif // SHAPE_H_ 00180
Generated on 28 Feb 2009 for Milton by
1.5.6