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 "api.h"
00028 #include "primitive.h"
00029 #include "sampling.h"
00030 #include "timer.h"
00031
00032 #include "fastmutex.h"
00033
00034 #include <boost/thread/thread.hpp>
00035 #include <boost/noncopyable.hpp>
00036 #include <boost/thread/mutex.hpp>
00037
00038 namespace lux {
00039
00040 class RenderThread : public boost::noncopyable {
00041 public:
00042 RenderThread( int _n, ThreadSignals _signal, SurfaceIntegrator* _Si, VolumeIntegrator* _Vi,
00043 Sampler* _Splr, Camera* _Cam, Scene* _Scn)
00044 : n(_n), signal(_signal), surfaceIntegrator(_Si), volumeIntegrator(_Vi),
00045 sample(NULL), sampler(_Splr->clone()), camera(_Cam), scene(_Scn),
00046 thread(NULL), samples(0.), blackSamples(0.) {
00047 sample = new Sample(surfaceIntegrator, volumeIntegrator, scene);
00048 }
00049
00050 ~RenderThread() {
00051
00052 delete sample;
00053 delete thread;
00054 }
00055
00056 static void render(RenderThread *r);
00057
00058 int n;
00059 ThreadSignals signal;
00060 SurfaceIntegrator *surfaceIntegrator;
00061 VolumeIntegrator *volumeIntegrator;
00062 Sample *sample;
00063 Sampler *sampler;
00064 Camera *camera;
00065 Scene *scene;
00066 TsPack *tspack;
00067 boost::thread *thread;
00068 double samples, blackSamples;
00069 fast_mutex statLock;
00070 };
00071
00072
00073 class Scene {
00074 public:
00075
00076 void Render();
00077 Scene(Camera *c, SurfaceIntegrator *in,
00078 VolumeIntegrator *vi, Sampler *s,
00079 boost::shared_ptr<Primitive> accel, const vector<Light *> <s,
00080 const vector<string> &lg, VolumeRegion *vr);
00081 Scene(Camera *c);
00082 ~Scene();
00083 bool Intersect(const Ray &ray, Intersection *isect) const {
00084 return aggregate->Intersect(ray, isect);
00085 }
00086 bool IntersectP(const Ray &ray) const {
00087 return aggregate->IntersectP(ray);
00088 }
00089 const BBox &WorldBound() const;
00090 SWCSpectrum Li(const RayDifferential &ray, const Sample *sample,
00091 float *alpha = NULL) const;
00092
00093 void Transmittance(const TsPack *tspack, const Ray &ray, const Sample *sample, SWCSpectrum *const L) const;
00094
00095
00096 void Start();
00097 void Pause();
00098 void Exit();
00099
00100 int AddThread();
00101 void RemoveThread();
00102 int getThreadsStatus(RenderingThreadInfo *info, int maxInfoCount);
00103
00104 void SaveFLM( const string& filename );
00105 bool IsFilmOnly() const { return filmOnly; }
00106
00107 double GetNumberOfSamples();
00108 double Statistics_SamplesPSec();
00109 double Statistics_SamplesPTotSec();
00110 double Statistics_Efficiency();
00111 double Statistics_SamplesPPx();
00112
00113 void UpdateFramebuffer();
00114 unsigned char* GetFramebuffer();
00115
00116
00117 void getHistogramImage(unsigned char *outPixels, int width, int height, int options);
00118
00119
00120 void SetParameterValue(luxComponent comp, luxComponentParameters param, double value, int index);
00121 double GetParameterValue(luxComponent comp, luxComponentParameters param, int index);
00122 double GetDefaultParameterValue(luxComponent comp, luxComponentParameters param, int index);
00123 void SetStringParameterValue(luxComponent comp, luxComponentParameters param, const string& value, int index);
00124 string GetStringParameterValue(luxComponent comp, luxComponentParameters param, int index);
00125 string GetDefaultStringParameterValue(luxComponent comp, luxComponentParameters param, int index);
00126
00127 int DisplayInterval();
00128 int FilmXres();
00129 int FilmYres();
00130 Timer s_Timer;
00131 double lastSamples, lastTime;
00132
00133 double Statistics(const string &statName);
00134
00135 int CreateRenderThread();
00136 void RemoveRenderThread();
00137 void SignalThreads(ThreadSignals signal);
00138
00139
00140 boost::shared_ptr<Primitive> aggregate;
00141 vector<Light *> lights;
00142 vector<string> lightGroups;
00143 Camera *camera;
00144 VolumeRegion *volumeRegion;
00145 SurfaceIntegrator *surfaceIntegrator;
00146 VolumeIntegrator *volumeIntegrator;
00147 Sampler *sampler;
00148 BBox bound;
00149 int seedBase;
00150
00151 ContributionPool *contribPool;
00152
00153
00154 double numberOfSamplesFromNetwork;
00155 double stat_Samples, stat_blackSamples;
00156
00157
00158 bool preprocessDone;
00159
00160
00161 bool suspendThreadsWhenDone;
00162
00163 private:
00164
00165
00166 boost::mutex renderThreadsMutex;
00167 std::vector<RenderThread*> renderThreads;
00168
00169 ThreadSignals CurThreadSignal;
00170 TsPack *tspack;
00171 bool filmOnly;
00172 };
00173
00174 }
00175
00176 #endif // LUX_SCENE_H