Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

iphotontracer.cpp

Go to the documentation of this file.
00001 /*
00002     toxic - A Global Illumination Renderer
00003     Copyright (C) 2003-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of toxic.
00007 
00008     toxic is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     toxic is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with toxic; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #include "iphotontracer.h"  // include first
00024 #include "common/math/real.h"
00025 #include "ilight.h"
00026 #include "photonmap.h"
00027 #include "scene.h"
00028 
00029 #include <cassert>
00030 
00031 using namespace sheep;
00032 using namespace toxic;
00033 
00034 void IPhotonTracer::BuildPhotonMap(const Context &context,
00035                                    PhotonMap *photonmap,
00036                                    const Scene *scene,
00037                                    int photon_count,
00038                                    ProgressMonitor *progmon /*= 0*/) const
00039 {
00040     assert(photonmap);
00041     assert(scene);
00042     assert(photon_count > 0);
00043 
00044     const Real inv_photon_count = 1.0 / photon_count;
00045     const int light_count = scene->GetLightCount();
00046 
00047     if(light_count > 0) {
00048         photon_count /= light_count;    //!\todo Repare, this is a quick hack!
00049 
00050         const Real inv_light_count = 1.0 / light_count;
00051 
00052         for(int i = 0; i < light_count; ++i) {
00053             if(progmon)
00054                 progmon->StartJob(0.0, photon_count, inv_light_count);
00055 
00056             emit_photons(
00057                 context,
00058                 photonmap,
00059                 scene,
00060                 scene->GetLight(i),
00061                 photon_count,
00062                 progmon
00063             );
00064 
00065             if(progmon)
00066                 progmon->EndJob();
00067 
00068             //!\todo Repare, scaling is not accurate (some photons may have been lost).
00069             photonmap->ScalePhotonPower(inv_photon_count);
00070         }
00071     }
00072 
00073     if(progmon)
00074         progmon->Done();
00075 }
00076 
00077 void IPhotonTracer::emit_photons(const Context &context,
00078                                  PhotonMap *photonmap,
00079                                  const Scene *scene,
00080                                  const ILight *light,
00081                                  int photon_count,
00082                                  ProgressMonitor *progmon /*= 0*/) const
00083 {
00084     assert(photonmap);
00085     assert(scene);
00086     assert(light);
00087     assert(photon_count > 0);
00088 
00089     for(int i = 0; i < photon_count; ++i) {
00090         if(progmon)
00091             progmon->SetJobProgress(i);
00092 
00093         trace_photon(
00094             context,
00095             photonmap,
00096             scene,
00097             light->GeneratePhotonRay(context),
00098             light->GetPower()
00099         );
00100     }
00101 }

Generated on Tue May 11 01:31:50 2004 for toxic by doxygen 1.3.6