PhotonMapping.h

Go to the documentation of this file.
00001 /* $Id:$ */
00002 
00003 #ifndef __PHOTON_MAPPING_H
00004 #define __PHOTON_MAPPING_H
00005 
00006 #include <gra/reflection/PathTracing.h>
00007 #include <esg/energy/PhotonMap.h>
00008 #include <esg/energy/IrradianceCache.h>
00009 #include <gra/scene/Scene.h>
00010 
00011 /*
00012  * Estimates emergy from photon map stored in scene.
00013  * Includes irradiance caching.
00014  */
00015 
00016 using namespace esg;
00017 
00018 namespace gra {
00019 
00020 class GRA_EXPORT PhotonMapping : public PathTracing {
00021     public:
00022         static const int DIRECT_ILLUMINATION;
00023         static const int SPECULAR_REFLECTION;
00024         static const int CAUSTICS;
00025         static const int INDIRECT_ILLUMINATION;
00026         
00027         static const int GLOBAL_ILLUMINATION;
00028         
00029         static const unsigned PARTITIONING;
00030         static const unsigned PARTITIONING_2;
00031         static const double   ANTIBIAS_FRACTION;
00032         
00033     protected:
00034         unsigned   _photonsPerSpecularSurface;
00035         unsigned   _numPhotonsToEst;
00036         float      _maxDistToEst;
00037         unsigned   _preciseIllumRefl;
00038         double     _preciseIllumDist;
00039         int        _illumStage;
00040         bool       _incomingLighting;
00041         unsigned   _maxError;
00042         bool       _cacheIrradiance;
00043         double     _sceneDistance;
00044     
00045         unsigned   _specReflections;
00046         bool       _diffReflection;
00047         
00048         const PhotonMap* _pGlobalMap;
00049         const PhotonMap* _pCausticsMap;
00050 
00051         IrradianceCache* _pIrradCache;
00052     
00053     protected:
00054         bool _interpolate_irradiance(const vector<IrradianceCache::Value*>&,
00055                                      Color3f&);
00056 
00057         double* _power_square(const vector<Photon*>&,
00058                               const Vector3&,
00059                               BRDF&,
00060                               const MatVisitor&,
00061                               double&);
00062 
00063         double _importance_sampling(const Vector3&,
00064                                     BRDF&,
00065                                     const MatVisitor&,
00066                                     double*,
00067                                     double,
00068                                     Vector3&);
00069         
00070         //precise diffuse refl. computed by Monte Carlo with irradiance caching
00071         virtual void _sample_diffuse(PointEnv&,
00072                                      unsigned,
00073                                      bool,
00074                                      Color3f&,
00075                                      MatVisitor&);
00076         
00077         //precise specular&glossy reflection computed by Monte Carlo algorihm
00078         virtual void _sample_specular(PointEnv&,
00079                                       unsigned,
00080                                       bool,
00081                                       Color3f&,
00082                                       MatVisitor&);
00083         
00084         //diffuse and specular&glossy reflections are treated separately,
00085         //see above
00086         virtual void _cast_secondary_rays(PointEnv&,
00087                                           unsigned,
00088                                           bool,
00089                                           Color3f&,
00090                                           MatVisitor&) {}
00091         
00092         virtual void _illuminate(PointEnv&, unsigned, bool, Color3f&);
00093     
00094     public:
00118         PhotonMapping (AutoPtr<LocalReflection> * r  = NULL,
00119                        const Color3f            & bg = Color3f(0,0,0),
00120                        Intersector              * i  = NULL,
00121                        unsigned                   d  = 1,
00122                        float                      w  = .001,
00123                        float                      f  = REFR_AIR,
00124                        unsigned                   p  = 1,
00125                        unsigned                   ps = 1,
00126                        unsigned                   e  = 20,
00127                        float                      m  = sqrt(FLT_MAX-1),
00128                        unsigned                   pr = 2,
00129                        double                     pd = .05,
00130                        int                        st = GLOBAL_ILLUMINATION,
00131                        bool                       il = true,
00132                        unsigned                   er = 10,
00133                        bool                       ci = true)
00134             : PathTracing(r,bg,i,d,w,f,p),
00135               _photonsPerSpecularSurface(ps),
00136               _numPhotonsToEst(e),
00137               _maxDistToEst(m),
00138               _preciseIllumRefl(pr),
00139               _preciseIllumDist(pd),
00140               _illumStage(st),
00141               _incomingLighting(il),
00142               _maxError(er+1),
00143               _cacheIrradiance(ci) {}
00144         
00145         /*
00146          * Required input parametters:
00147          *   PointEnv.intersection  = point of interest (PoI)
00148          *   PointEnv.pVisitableObj = object of interest
00149          *   PointEnv.normal        = surface normal at PoI
00150          *   PointEnv.viewerDir     = normalized direction from PoI to viewer
00151          *   PointEnv.distance      = distance between PoI and viewer 
00152          * [ PointEnv.trMat         = possible transformation ]
00153          * [ PointEnv.energy        = initial ray energy, default = (1,1,1) ]
00154          */
00155         virtual Color3f* illuminatePoint(PointEnv & /* point of interest */);
00156 
00161         virtual void setScene(Scene * s);
00162 };
00163 
00164 } // namespace
00165 
00166 #endif // __PHOTON_MAPPING_H

Generated on Tue Nov 21 15:11:42 2006 for gra by  doxygen 1.4.6