SuperSampleGenerator.cpp
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @file SuperSampleGenerator.cpp 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @date Fall 2008 00005 00006 @brief 00007 Brute force super sampling, where sub-bin (sub-pixel) sampling is done 00008 via an auxillary SampleGenerator 00009 <!-------------------------------------------------------------------->**/ 00010 00011 #include "SuperSampleGenerator.h" 00012 #include <PointSampleRenderer.h> 00013 #include <ResourceManager.h> 00014 #include <Random.h> 00015 #include <QtCore> 00016 using namespace std; 00017 00018 #define NO_SUB_GENERATORS (133) 00019 00020 template <class SG> 00021 void SuperSG<SG>::init() { 00022 SG::init(); 00023 00024 const unsigned noSuperSamples = 00025 boost::any_cast<unsigned>(SG::getValue("noSuperSamples", 4u)); 00026 Viewport subviewport(noSuperSamples); 00027 00028 cerr << "noSuperSamples: " << noSuperSamples << endl; 00029 SampleGenerator *sg = 00030 SampleGenerator::create(m_subGeneratorType); 00031 00032 sg->init(); 00033 for(unsigned i = NO_SUB_GENERATORS; i--;) { 00034 m_samples.push_back(PointSampleList()); 00035 sg->generate(m_samples.back(), subviewport); 00036 } 00037 00038 safeDelete(sg); 00039 } 00040 00041 template <class SG> 00042 void SuperSG<SG>::generate(PointSampleList &outSamples, 00043 const Viewport &viewport) 00044 { 00045 ASSERT(m_samples.size() == NO_SUB_GENERATORS); 00046 00047 const unsigned noSuperSamples = m_samples[0].size(); 00048 const unsigned width = viewport.getWidth(); 00049 const unsigned height = viewport.getHeight(); 00050 00051 const real_t binWidth = viewport.getInvWidth(); 00052 const real_t binHeight = viewport.getInvHeight(); 00053 00054 for(unsigned s = 0; s < noSuperSamples; ++s) { 00055 cerr << "progress: " << (unsigned)(100 * ((real_t)(s) / noSuperSamples)) 00056 << "% complete; " 00057 << SG::getRenderer()->getElapsedTime() << " elapsed" << endl; 00058 00059 unsigned index = (NO_SUB_GENERATORS - 1); 00060 for(unsigned i = 0; i < height; ++i) { 00061 for(unsigned j = 0; j < width; ++j) { 00062 const PointSample &p = m_samples[index][s]; 00063 const real_t x = j * binWidth + p.position[0] * binWidth; 00064 const real_t y = i * binHeight + p.position[1] * binHeight; 00065 00066 SG::_addSample(PointSample(x, y), outSamples); 00067 00068 if (index-- == 0) 00069 index = NO_SUB_GENERATORS - 1; 00070 } 00071 } 00072 } 00073 } 00074 00075 // force explicit template specialization of SuperSampleGeneratorThread 00076 #include <generators.h> 00077 00078 // Only declare threaded version of super sample generator 00079 typedef SuperSG<SampleGeneratorThread> SuperSampleGeneratorThread; 00080 template class SuperSG<SampleGeneratorThread>; 00081
Generated on 28 Feb 2009 for Milton by
1.5.6