Path Tracer
KDTreeNode.h
Go to the documentation of this file.
1 #ifndef DEF_KDTREENODE
2 #define DEF_KDTREENODE
3 
4 #include "InterfaceCreation.h"
5 
140 class KDTreeNode {
141 private:
142  unsigned int depth;
143  DoubleVec3D minCoord;
144  DoubleVec3D maxCoord;
145  std::vector<Object3D*> objects;
146 
147  KDTreeNode* parent = nullptr;
148  KDTreeNode* childSmaller = nullptr;
149  KDTreeNode* childGreater = nullptr;
150 
151 public:
152  struct Intersection {
154  double distance;
156 
157  Intersection(Object3D* object = nullptr, double distance = INFINITY, const KDTreeNode* kdTreeNode = nullptr);
158  };
159 
160  KDTreeNode();
161  KDTreeNode(std::vector<Object3D*> objects, unsigned int maxObjectNumber, unsigned int maxDepth, KDTreeNode* parent = nullptr, unsigned int depth = 0);
162  KDTreeNode(std::vector<Object3D*> objects, DoubleVec3D minCoord, DoubleVec3D maxCoord, unsigned int maxObjectNumber, unsigned int maxDepth, KDTreeNode* parent = nullptr, unsigned int depth = 0);
163  ~KDTreeNode();
164 
165  unsigned int getDepth() const;
166  DoubleVec3D getMinCoord() const;
167  DoubleVec3D getMaxCoord() const;
168  std::vector<Object3D*> getObjects() const;
169  KDTreeNode* getParent() const;
170  KDTreeNode* getChildSmaller() const;
171  KDTreeNode* getChildGreater() const;
172 
173  unsigned int getMaxDepth() const;
174  unsigned int getMaxObjectNumberLeaf() const;
175 
176  double intersectionDistance(const Ray& ray) const;
177  bool isIn(DoubleVec3D point) const;
178  Intersection getIntersectionForward(const Ray& ray) const;
179  Intersection getIntersectionBackwards(const Ray& ray, const KDTreeNode* ignore = nullptr) const;
180 };
181 
182 DoubleVec3D getMinPoint(std::vector<Object3D*> objects);
183 DoubleVec3D getMaxPoint(std::vector<Object3D*> objects);
184 
185 void to_json(json& j, const KDTreeNode& node);
186 
187 #endif
Defines functions that are used to ask for values to the user, and to interactively create 3D objects...
nlohmann::json json
Definition: InterfaceGestion.h:14
DoubleVec3D getMaxPoint(std::vector< Object3D * > objects)
Computes the maximum point of a cuboid containing all the objects.
Definition: KDTreeNode.cpp:318
DoubleVec3D getMinPoint(std::vector< Object3D * > objects)
Computes the minimum point of a cuboid containing all the objects.
Definition: KDTreeNode.cpp:300
void to_json(json &j, const KDTreeNode &node)
Conversion to json.
Definition: KDTreeNode.cpp:338
A three-dimensional vector using double values.
Definition: DoubleVec3D.h:190
A node of a k-d tree.
Definition: KDTreeNode.h:140
unsigned int getMaxObjectNumberLeaf() const
Gives the maximum number of objects in a leaf of this tree.
Definition: KDTreeNode.cpp:129
bool isIn(DoubleVec3D point) const
Returns whether a point is inside this node's cuboid-shaped volume.
Definition: KDTreeNode.cpp:196
std::vector< Object3D * > getObjects() const
Getter for this node's objects.
Definition: KDTreeNode.cpp:117
KDTreeNode()
Default constructor. Everything is set to 0 by default.
Definition: KDTreeNode.cpp:10
Intersection getIntersectionForward(const Ray &ray) const
Computes the intersection going from the top to the bottom of the tree.
Definition: KDTreeNode.cpp:205
unsigned int getDepth() const
Getter for this node's depth.
Definition: KDTreeNode.cpp:114
double intersectionDistance(const Ray &ray) const
Gives the distance to the closest intersection between this node's surface and a ray.
Definition: KDTreeNode.cpp:135
KDTreeNode * getParent() const
Getter for this node's parent.
Definition: KDTreeNode.cpp:118
~KDTreeNode()
Destructor.
Definition: KDTreeNode.cpp:107
KDTreeNode * getChildGreater() const
Getter for this node's greater child.
Definition: KDTreeNode.cpp:120
unsigned int getMaxDepth() const
Gives the maximum depth of this tree.
Definition: KDTreeNode.cpp:123
DoubleVec3D getMaxCoord() const
Getter for this node's maximum coordinate.
Definition: KDTreeNode.cpp:116
Intersection getIntersectionBackwards(const Ray &ray, const KDTreeNode *ignore=nullptr) const
Computes the intersection going from the bottom to the top of the tree.
Definition: KDTreeNode.cpp:265
DoubleVec3D getMinCoord() const
Getter for this node's minimum coordinate.
Definition: KDTreeNode.cpp:115
KDTreeNode * getChildSmaller() const
Getter for this node's smaller child.
Definition: KDTreeNode.cpp:119
Abstract class for a three-dimentional object.
Definition: Object3D.h:121
Combination of an origin and a direction.
Definition: Ray.h:44
A struct binding a pointer to an Object3D, a distance, and a pointer to a KDTreeNode.
Definition: KDTreeNode.h:152
Object3D * object
The Object3D with which the ray intersects.
Definition: KDTreeNode.h:153
const KDTreeNode * kdTreeNode
The KDTreeNode in which the ray and the object intersect.
Definition: KDTreeNode.h:155
double distance
The distance between the ray origin and the intersection point.
Definition: KDTreeNode.h:154
Intersection(Object3D *object=nullptr, double distance=INFINITY, const KDTreeNode *kdTreeNode=nullptr)
Main constructor.
Definition: KDTreeNode.cpp:5