Path Tracer
Scene.h
Go to the documentation of this file.
1 #ifndef DEF_SCENE
2 #define DEF_SCENE
3 
4 #include <omp.h>
5 
6 #include "DoubleMatrix33.h"
7 #include "KDTreeNode.h"
8 #include "Object3DGroup.h"
9 #include "PerspectiveCamera.h"
10 #include "Picture.h"
11 
12 #include <fbxsdk.h>
13 #include <fbxsdk/fileio/fbxiosettings.h>
14 #include <fbxsdk/utils/fbxgeometryconverter.h>
15 
16 
291 class Scene {
292 private:
293  std::vector<Object3DGroup> objectGroups;
294  std::vector<Object3D*> objects;
295  std::vector<Object3D*> lamps;
296  KDTreeNode* kdTreeRoot = nullptr;
297 
298  PerspectiveCamera camera;
299  unsigned int samplesPerPixel;
300  unsigned int minBounces;
301 
302  bool russianRoulette = true;
303  double rrStopProbability = 0.1; // Linked to russianRoulette / stopProb=1 <=> russianRoulette=false
304  bool nextEventEstimation = true;
305  unsigned int numberThreads = omp_get_max_threads();
306  bool kdTree = true;
307  unsigned int kdMaxObjectNumber = 10;
308  unsigned int kdMaxDepth = 10;
309 
310  std::string backupFileName = "backup";
311  bool backupParameters = true;
312  bool backupObjectGroups = true;
313  bool backupPicture = true;
314  double leastRenderTime4PictureBackup = 180.0; // Three minutes
315 
316  KDTreeNode::Intersection bruteForceIntersection(const Ray& ray) const;
317  DoubleVec3D traceRay(const Ray& ray, double usedNextEventEstimation = false, const KDTreeNode* lastNode = nullptr, unsigned int bounces = 0) const;
318  std::string getCurrentIndex(int currentIndex, bool displayIndex) const;
319 
320 public:
321  Scene(PerspectiveCamera camera = PerspectiveCamera(), unsigned int samplesPerPixel = 8, unsigned int minBounces = 5);
322  Scene(const Scene& scene);
323 
324  std::vector<Object3DGroup> getObjectGroups() const;
325  std::vector<Object3DGroup>& getObjectGroupsReference(); // Reference -> can modify it -> != const
326  std::vector<Object3D*> getObjects();
327  std::vector<Object3D*> getLamps();
330  unsigned int getSamplesPerPixel() const;
331  unsigned int getMinBounces() const;
332  bool getRussianRoulette() const;
333  double getRrStopProbability() const;
334  bool getNextEventEstimation() const;
335  unsigned int getNumberThreads() const;
336  bool getKDTree() const;
337  unsigned int getKDMaxObjectNumber() const;
338  unsigned int getKDMaxDepth() const;
339  std::string getBackupFileName() const;
340  bool getBackupParameters() const;
341  bool getBackupObjectGroups() const;
342  bool getBackupPicture() const;
343  double getLeastRenderTime4PictureBackup() const;
344 
345  void setObjectGroups(std::vector<Object3DGroup> groups);
346  void setCamera(PerspectiveCamera camera);
347  void setSamplesPerPixel(unsigned int samplesPerPixel);
348  void setMinBounces(unsigned int minBounces);
349  void setRussianRoulette(bool russianRoulette);
350  void setRussianRoulette(bool russianRoulette, double rrStopProbability);
351  void setRrStopProbability(double rrStopProbability);
352  void setNextEventEstimation(bool nextEventEstimation);
353  void setNumberThreads(unsigned int numberThreads);
354  void setKDTree(bool kdTree);
355  void setKDMaxObjectNumber(unsigned int kdMaxObjectNumber);
356  void setKDMaxDepth(unsigned int kdMaxDepth);
357  void setBackupFileName(std::string backupFileName);
358  void setBackupParameters(bool backupParameters);
359  void setBackupObjectGroups(bool backupObjectGroups);
360  void setBackupPicture(bool backupPicture);
361  void setLeastRenderTime4PictureBackup(double leastRenderTime4PictureBackup);
362 
363  void addObjectGroup(const Object3DGroup& group);
365  void computeObjectsAndLamps();
366  void defaultScene();
367 
368  void saveParameters2File(std::string fileName) const;
369  void saveObjectGroups2File(std::string fileName) const;
370 
371  bool importFBXFile(const char* filePath, Material* material, std::string name);
372 
373  Picture* render();
374 
375  void displayParametersPage(bool displayIndexes = true) const;
376  void displayObjectsPage() const;
377 };
378 
379 bool importTrianglesFromFbxNode(FbxNode* node, Material* material, std::vector<Object3D*>& objects);
380 
381 void displayRenderingProgression(unsigned int numberPixelXAlreadyComputed, unsigned int pictureWidth, double loopBeginningTime);
382 
383 #endif
Defines the DoubleMatrix33 class and some functions around it.
static Scene scene
The scene that will be used by the interface.
Definition: Interface.h:59
Defines the KDTreeNode class and some functions around it.
Defines the Object3DGroup class and some functions around it.
Defines the PerspectiveCamera class.
Defines the Picture class and some functions around it.
void displayRenderingProgression(unsigned int numberPixelXAlreadyComputed, unsigned int pictureWidth, double loopBeginningTime)
Prints the progression information.
Definition: Scene.cpp:341
bool importTrianglesFromFbxNode(FbxNode *node, Material *material, std::vector< Object3D * > &objects)
Imports recursively all triangles present in a FBXNode.
Definition: Scene.cpp:169
A three-dimensional vector using double values.
Definition: DoubleVec3D.h:190
A node of a k-d tree.
Definition: KDTreeNode.h:140
Abstrat class that models a material.
Definition: Material.h:77
Group of objects.
Definition: Object3DGroup.h:122
Models a perspective camera.
Definition: PerspectiveCamera.h:76
Stores radiance for every pixel.
Definition: Picture.h:120
Combination of an origin and a direction.
Definition: Ray.h:44
Stores object groups and a camera for the render.
Definition: Scene.h:291
void defaultScene()
Sets this scene's objects to default ones.
Definition: Scene.cpp:90
void setRrStopProbability(double rrStopProbability)
Setter for the russian roulette stop probability.
Definition: Scene.cpp:56
void setLeastRenderTime4PictureBackup(double leastRenderTime4PictureBackup)
Setter for the least render time after which the picture is backed up.
Definition: Scene.cpp:66
void setKDMaxObjectNumber(unsigned int kdMaxObjectNumber)
Setter for the maximum number of objects in a k-d tree leaf.
Definition: Scene.cpp:60
void setBackupFileName(std::string backupFileName)
Setter for the new name of the file in which backups will be made.
Definition: Scene.cpp:62
double getRrStopProbability() const
Getter for the russian roulette stop probability.
Definition: Scene.cpp:33
PerspectiveCamera & getCameraReference()
Getter for a reference to the camera.
Definition: Scene.cpp:29
Scene(PerspectiveCamera camera=PerspectiveCamera(), unsigned int samplesPerPixel=8, unsigned int minBounces=5)
Main constructor.
Definition: Scene.cpp:4
std::vector< Object3D * > getLamps()
Getter for the lamps.
Definition: Scene.cpp:22
void setNextEventEstimation(bool nextEventEstimation)
Setter for the next event estimation.
Definition: Scene.cpp:57
void computeObjectsAndLamps()
Computes all the objects.
Definition: Scene.cpp:80
bool getKDTree() const
Getter for the k-d tree option.
Definition: Scene.cpp:36
unsigned int getSamplesPerPixel() const
Getter for the number of samples per pixel.
Definition: Scene.cpp:30
void setBackupObjectGroups(bool backupObjectGroups)
Setter for the option to backup the object groups.
Definition: Scene.cpp:64
unsigned int getMinBounces() const
Getter for the minimum number of bounces.
Definition: Scene.cpp:31
void resetAndDeleteObjectGroups()
Deletes all object groups and their objects.
Definition: Scene.cpp:74
void setKDMaxDepth(unsigned int kdMaxDepth)
Setter for the maximum depth recursion of the k-d tree.
Definition: Scene.cpp:61
void setKDTree(bool kdTree)
Setter for the k-d tree.
Definition: Scene.cpp:59
bool getBackupObjectGroups() const
Getter for the option to backup the object groups.
Definition: Scene.cpp:41
void displayParametersPage(bool displayIndexes=true) const
Prints the parameters page.
Definition: Scene.cpp:462
bool importFBXFile(const char *filePath, Material *material, std::string name)
Imports a fbx file as triangles.
Definition: Scene.cpp:128
void setBackupParameters(bool backupParameters)
Setter for the option to backup the parameters.
Definition: Scene.cpp:63
std::string getBackupFileName() const
Getter for the name of the file in which backups will be made.
Definition: Scene.cpp:39
void setCamera(PerspectiveCamera camera)
Setter for the camera.
Definition: Scene.cpp:48
double getLeastRenderTime4PictureBackup() const
Getter for the least render time after which the picture is backed up.
Definition: Scene.cpp:43
std::vector< Object3DGroup > getObjectGroups() const
Getter for the object groups.
Definition: Scene.cpp:12
unsigned int getKDMaxDepth() const
Getter for the maximum depth recursion of the k-d tree.
Definition: Scene.cpp:38
bool getBackupParameters() const
Getter for the option to backup the parameters.
Definition: Scene.cpp:40
std::vector< Object3DGroup > & getObjectGroupsReference()
Getter for a reference to the object groups.
Definition: Scene.cpp:13
void saveObjectGroups2File(std::string fileName) const
Saves object groups to a file.
Definition: Scene.cpp:248
void setBackupPicture(bool backupPicture)
Setter for the option to backup the picture.
Definition: Scene.cpp:65
PerspectiveCamera getCamera() const
Getter for the camera.
Definition: Scene.cpp:28
std::vector< Object3D * > getObjects()
Getter for the objects.
Definition: Scene.cpp:16
void saveParameters2File(std::string fileName) const
Saves parameters to a file.
Definition: Scene.cpp:208
void setNumberThreads(unsigned int numberThreads)
Setter for the number of CPU threads.
Definition: Scene.cpp:58
void setSamplesPerPixel(unsigned int samplesPerPixel)
Setter for the number of samples per pixel.
Definition: Scene.cpp:49
void displayObjectsPage() const
Prints the objects page.
Definition: Scene.cpp:500
unsigned int getNumberThreads() const
Getter for the number of CPU threads.
Definition: Scene.cpp:35
bool getBackupPicture() const
Getter for the option to backup the picture.
Definition: Scene.cpp:42
bool getNextEventEstimation() const
Getter for the next event estimation.
Definition: Scene.cpp:34
void setObjectGroups(std::vector< Object3DGroup > groups)
Setter for the object groups.
Definition: Scene.cpp:47
void setRussianRoulette(bool russianRoulette)
Setter for the russian roulette.
Definition: Scene.cpp:51
bool getRussianRoulette() const
Getter for the russian roulette.
Definition: Scene.cpp:32
void setMinBounces(unsigned int minBounces)
Setter for the minimum number of bounces.
Definition: Scene.cpp:50
void addObjectGroup(const Object3DGroup &group)
Adds an object group to the current ones.
Definition: Scene.cpp:70
Picture * render()
Start the render of the picture.
Definition: Scene.cpp:356
unsigned int getKDMaxObjectNumber() const
Getter for the maximum number of objects in a k-d tree leaf.
Definition: Scene.cpp:37
A struct binding a pointer to an Object3D, a distance, and a pointer to a KDTreeNode.
Definition: KDTreeNode.h:152