PointSampleRenderer.h
Go to the documentation of this file.00001 /**<!--------------------------------------------------------------------> 00002 @class PointSampleRenderer 00003 @author Travis Fischer (fisch0920@gmail.com) 00004 @author Matthew Jacobs (jacobs.mh@gmail.com) 00005 @date Fall 2008 00006 00007 @brief 00008 Abstraction of renderers which construct their output by point sampling 00009 a 2D domain (the film plane). The steps of generating point 00010 samples across this domain (SampleGenerator), evaluating the samples 00011 (PointSampleRenderer/SampleConsumer), and storing/using the evaluated 00012 samples (RenderOutput) have been abstracted from each other. 00013 <!-------------------------------------------------------------------->**/ 00014 00015 #ifndef POINT_SAMPLE_RENDERER_H_ 00016 #define POINT_SAMPLE_RENDERER_H_ 00017 00018 #include <renderers/Renderer.h> 00019 #include <renderers/PointSample.h> 00020 00021 #include <QWaitCondition> 00022 #include <QMutexLocker> 00023 #include <QThread> 00024 #include <QMutex> 00025 00026 #define MAX_SHARED_SAMPLES_SIZE (512) 00027 00028 struct PointSample; 00029 class RenderOutput; 00030 00031 class SampleGeneratorThread; 00032 class SampleConsumer; 00033 00034 DECLARE_STL_TYPEDEF(std::vector<SampleConsumer *>, SampleConsumerList); 00035 00036 class PointSampleRenderer : public Renderer { 00037 00038 public: 00039 ///@name Constructors 00040 //@{----------------------------------------------------------------- 00041 00042 inline PointSampleRenderer(RenderOutput *output = NULL, 00043 Camera *camera = NULL, 00044 Scene *scene = NULL) 00045 : Renderer(camera, scene), m_noProducers(0), m_output(output) 00046 { } 00047 00048 virtual ~PointSampleRenderer() 00049 { } 00050 00051 00052 //@}----------------------------------------------------------------- 00053 ///@name Main usage interface 00054 //@{----------------------------------------------------------------- 00055 00056 /** 00057 * @brief 00058 * Renders the underlying scene synchronously 00059 */ 00060 virtual void render(); 00061 00062 /** 00063 * @brief 00064 * Renders a single point sample (incident radiance evaluation) at 00065 * the point specified on the film plane 00066 */ 00067 virtual void sample(PointSample &outSample) = 0; 00068 00069 /** 00070 * @brief 00071 * Called upon finishing a call to render 00072 * 00073 * @note 00074 * Default implementation is blank 00075 */ 00076 virtual void finalize(); 00077 00078 00079 //@}----------------------------------------------------------------- 00080 ///@name Accessors / Mutators 00081 //@{----------------------------------------------------------------- 00082 00083 virtual RenderOutput *getOutput() { 00084 return m_output; 00085 } 00086 00087 virtual void setOutput(RenderOutput *output) { 00088 QMutexLocker lock(&m_renderMutex); 00089 00090 m_output = output; 00091 } 00092 00093 //@}----------------------------------------------------------------- 00094 00095 public: 00096 virtual void addSharedSample (const PointSample &s); 00097 virtual void addSharedSamples(const PointSampleList &s); 00098 virtual bool getSharedSample(PointSample &outSample); 00099 00100 virtual void addProducer(); 00101 virtual void removeProducer(); 00102 00103 protected: 00104 /** 00105 * @brief 00106 * Factory method for creating new SampleGeneratorThreads 00107 */ 00108 virtual SampleGeneratorThread *_getGenerator(); 00109 00110 /** 00111 * @brief 00112 * Factory method for creating new SampleConsumers 00113 */ 00114 virtual SampleConsumer *_getConsumer(); 00115 00116 protected: 00117 /// Provides mutual exclusion to 'render' method 00118 QMutex m_renderMutex; 00119 00120 /// Provides mutual exclusion to shared sample list betweeen 00121 /// SampleGeneratorThreads and SampleConsumers 00122 QMutex m_mutex; 00123 00124 /// Wait condition variables used to implement producer/consumer 00125 /// with respect to shared PointSampleQueue 00126 QWaitCondition m_producer; 00127 QWaitCondition m_consumer; 00128 00129 PointSampleQueue m_sharedShamples; 00130 unsigned m_noProducers; 00131 00132 /// Abstract class which aggregates point samples (eg, an Image wrapper) 00133 RenderOutput *m_output; 00134 }; 00135 00136 #endif // POINT_SAMPLE_RENDERER_H_ 00137
Generated on 28 Feb 2009 for Milton by
1.5.6