00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_SCENE_H
00024 #define LUX_SCENE_H
00025
00026 #include "lux.h"
00027 #include "primitive.h"
00028 #include "sampling.h"
00029 #include "timer.h"
00030
00031 #include <boost/thread/thread.hpp>
00032 #include <boost/noncopyable.hpp>
00033 #include <boost/thread/mutex.hpp>
00034
00035 namespace lux {
00036
00037 class RenderThread : public boost::noncopyable {
00038 public:
00039 RenderThread( int _n, int _signal, SurfaceIntegrator* _Si, VolumeIntegrator* _Vi,
00040 Sampler* _Splr, Camera* _Cam, Scene* _Scn)
00041 : n(_n), signal(_signal), surfaceIntegrator(_Si), volumeIntegrator(_Vi),
00042 sample(NULL), sampler(_Splr), camera(_Cam), scene(_Scn), thread(NULL) {
00043 stat_Samples=0;
00044 stat_blackSamples=0;
00045 sample = new Sample(surfaceIntegrator, volumeIntegrator, scene);
00046 }
00047
00048 ~RenderThread() {
00049 delete sample;
00050 delete thread;
00051 }
00052
00053 static void render(RenderThread *r);
00054
00055 int n, signal;
00056 double stat_Samples, stat_blackSamples;
00057 SurfaceIntegrator *surfaceIntegrator;
00058 VolumeIntegrator *volumeIntegrator;
00059 Sample *sample;
00060 Sampler *sampler;
00061 Camera *camera;
00062 Scene *scene;
00063 boost::thread *thread;
00064
00065 static const int SIG_RUN=1, SIG_PAUSE=2, SIG_EXIT=3;
00066 };
00067
00068
00069 class Scene {
00070 public:
00071
00072 void Render();
00073 Scene(Camera *c, SurfaceIntegrator *in,
00074 VolumeIntegrator *vi, Sampler *s,
00075 Primitive *accel, const vector<Light *> <s,
00076 VolumeRegion *vr);
00077 ~Scene();
00078 bool Intersect(const Ray &ray, Intersection *isect) const {
00079 return aggregate->Intersect(ray, isect);
00080 }
00081 bool IntersectP(const Ray &ray) const {
00082 return aggregate->IntersectP(ray);
00083 }
00084 const BBox &WorldBound() const;
00085 SWCSpectrum Li(const RayDifferential &ray, const Sample *sample,
00086 float *alpha = NULL) const;
00087 SWCSpectrum Transmittance(const Ray &ray) const;
00088
00089
00090 void Start();
00091 void Pause();
00092 void Exit();
00093
00094 int AddThread();
00095 void RemoveThread();
00096 double GetNumberOfSamples();
00097 double Statistics_SamplesPSec();
00098 double Statistics_SamplesPTotSec();
00099 double Statistics_Efficiency();
00100 double Statistics_SamplesPPx();
00101
00102 void UpdateFramebuffer();
00103 unsigned char* GetFramebuffer();
00104 int DisplayInterval();
00105 int FilmXres();
00106 int FilmYres();
00107 Timer s_Timer;
00108 double lastSamples, lastTime;
00109
00110 double Statistics(const string &statName);
00111
00112 int CreateRenderThread();
00113 void RemoveRenderThread();
00114 void SignalThreads(int signal);
00115
00116
00117 Primitive *aggregate;
00118 vector<Light *> lights;
00119 Camera *camera;
00120 VolumeRegion *volumeRegion;
00121 SurfaceIntegrator *surfaceIntegrator;
00122 VolumeIntegrator *volumeIntegrator;
00123 Sampler *sampler;
00124 BBox bound;
00125 int seedBase;
00126
00127
00128 double numberOfSamplesFromNetwork;
00129
00130
00131 bool preprocessDone;
00132
00133 private:
00134
00135
00136 boost::mutex renderThreadsMutex;
00137 std::vector<RenderThread*> renderThreads;
00138
00139 int CurThreadSignal;
00140 };
00141
00142 }
00143
00144 #endif // LUX_SCENE_H