IrradianceCache.h

Go to the documentation of this file.
00001 /* $Id:$ */
00002 
00003 #ifndef __IRRADIANCE_CACHE_H
00004 #define __IRRADIANCE_CACHE_H
00005 
00006 #include <esg/Definitions.h>
00007 #include <vector>
00008 #include <stdexcept>
00009 
00010 namespace esg {
00011 
00021     class OGSCENE_EXPORT IrradianceCache {
00022         public:
00023             class Value; 
00024         protected:
00025             class Node;  
00026             
00027         protected:
00031             const float maxError; 
00032 
00036             IrradianceCache::Node* root; 
00037 
00038             vector< vector<IrradianceCache::Value*>* > treeValuesBuffer;
00039 
00040 
00041         protected:
00042 
00049             bool isInside(const Vector3& position) const;
00050 
00051 
00052         public:
00062             IrradianceCache(float mError, float rootSize) throw (out_of_range);
00063 
00064 
00068             virtual ~IrradianceCache();
00069 
00070 
00082             void addValue(const Vector3& pos,
00083                           const Vector3& normal,
00084                           const Color3f& irrad,
00085                           float meanDistance) throw (out_of_range);
00086 
00087 
00098             void getValue(const Vector3&                   pos,
00099                           const Vector3&                   normal,
00100                           vector<IrradianceCache::Value*>& buffer)
00101                 const throw (out_of_range);
00102 
00103 
00107             unsigned int getNumStoredValues() const;
00108 
00109 
00113             unsigned int getNumNodes() const;
00114 
00115 
00122             const IrradianceCache::Value* getNextValuePointer();
00123 
00124 
00129             inline void resetValuePointer() {
00130                 treeValuesBuffer.clear();
00131             }
00132 
00133     }; // class
00134 
00135 
00136 
00137 
00138     /*******************************************************************
00139      * Irradiance value stored in the octree
00140      */
00141 
00142     class IrradianceCache::Value {
00143         private:
00144             Vector3 position;     
00145             Vector3 normal;       
00146             Color3f irradiance;   
00147             float   meanDistance; 
00148             float   weight;       
00149 
00150         public:
00154             Value();
00155 
00164             Value(const Vector3& pos,
00165                   const Vector3& normal,
00166                   const Color3f& irrad,
00167                   float          meanDistance);
00168             
00172             ~Value() {};
00173 
00174 
00189             bool checkDomain(const Vector3& position,
00190                              const Vector3& normal,
00191                              float          maxError);
00192 
00208             friend ostream& operator << (ostream&     out,
00209                                          const Value& irradValue) {
00210                 out << "location: " << irradValue.position
00211                     << ", normal: " << irradValue.normal
00212                     << ", harmonic mean distance: " << irradValue.meanDistance
00213                     << ", irradiance: " << irradValue.irradiance
00214                     << ", weighta: " << irradValue.weight;
00215                 return out;
00216             }
00217 
00221             inline float getWeight() const { return weight; }
00222 
00226             inline const Color3f& getIrradiance() const { return irradiance; }
00227 
00231             inline const Vector3& getPosition() const { return position; }
00232 
00236             inline const Vector3& getNormal() const { return normal; }
00237 
00241             inline const float getMeanDistance() const { return meanDistance; }     
00242     }; // class
00243 
00244 
00245 
00246     
00247         
00248     /*******************************************************************
00249      * Node of the irradiance cache octree
00250      */
00251 
00252     class IrradianceCache::Node {
00253         protected:
00254             vector<IrradianceCache::Value*> irradianceValues; 
00255             Node*         subnodes[8];   
00256             const Vector3 center;        
00257             const float   size;          
00258 
00259         protected:
00265             void allocate(unsigned int nodeIndex);
00266 
00267 
00274             inline bool isAllocated(unsigned int nodeIndex) const {
00275                 return (subnodes[nodeIndex]);
00276             }
00277 
00278 
00286             unsigned int selectSubnode(const Vector3& position) const;
00287 
00288 
00298             bool necessaryToSearch(const Vector3& position) const;
00299 
00300 
00301         public:
00308             Node(float s, float cX, float cY, float cZ);
00309 
00310 
00314             virtual ~Node();
00315 
00327             void addValue(const Vector3& position,
00328                           const Vector3& normal,
00329                           const Vector3& color,
00330                           float          meanDistance,
00331                           float          minSize,
00332                           float          maxSize);
00333 
00334 
00351             void getValue(const Vector3&                   position,
00352                           const Vector3&                   normal,
00353                           vector<IrradianceCache::Value*>& buffer,
00354                           float                            maxError);
00355 
00356 
00361             unsigned int getNumStoredValues() const;
00362 
00363 
00367             unsigned int getNumNodes() const;
00368 
00369             
00373             inline float getSize() const  { return size; }
00374 
00375 
00383             void getNodeValues(vector<vector<IrradianceCache::Value*>*>& irValues);
00384     }; // class
00385 
00386 };
00387 
00388 #endif // __IRRADIANCE_CACHE_H

Generated on Wed Jun 28 12:24:28 2006 for esg by  doxygen 1.4.6