Helios++
Helios software for LiDAR simulations
KDTreeNode.h
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include <boost/archive/text_iarchive.hpp>
7 #include <boost/archive/text_oarchive.hpp>
8 #include <boost/serialization/vector.hpp>
9 
10 #include "Primitive.h"
11 #include "AABB.h"
12 
16 class KDTreeNode {
17  // *** SERIALIZATION *** //
18  // *********************** //
19  friend class boost::serialization::access;
20  template<class Archive>
21  void serialize(Archive & ar, const unsigned int version) {
22  ar & left;
23  ar & right;
24  ar & splitPos;
25  ar & splitAxis;
26  ar & primitives;
27  }
28 
29 public:
30  // *** ATTRIBUTES *** //
31  // ******************** //
36  KDTreeNode* left = nullptr;
41  KDTreeNode* right = nullptr;
45  double splitPos = 0;
49  int splitAxis = 0;
53  std::vector<Primitive*> primitives;
54 
55  //TODO serialization
56  //KDTreeNode() {}
57  // no default construct guarentees that no invalid object ever exists
58  // > save_construct_data will have to be overridden
59  // see https://www.boost.org/doc/libs/1_55_0/libs/serialization/doc/serialization.html
60  // see Triangle.h
61 
62  // *** CONSTRUCTION / DESTRUCTION *** //
63  // ************************************ //
64  virtual ~KDTreeNode() {
65  delete left;
66  delete right;
67  }
68 
69 
70  // *** CLASS METHODS *** //
71  // *********************** //
79  static KDTreeNode* buildRecursive(std::vector<Primitive*> primitives, int depth);
80 
81 
82  // *** OBJECT METHODS *** //
83  // ************************ //
91  void computeKDTreeStats(KDTreeNode *root, int depth=0);
96  void writeObject(std::string path);
102  static KDTreeNode* readObject(std::string path);
103 };
int splitAxis
Space axis to consider at current depth.
Definition: KDTreeNode.h:49
KDTreeNode * right
Definition: KDTreeNode.h:41
std::vector< Primitive * > primitives
Vector of primitives associated with the node.
Definition: KDTreeNode.h:53
static KDTreeNode * buildRecursive(std::vector< Primitive *> primitives, int depth)
Recursively build a KDTree for given primitives.
Definition: KDTreeNode.cpp:12
void computeKDTreeStats(KDTreeNode *root, int depth=0)
Analyze KDTree computing its max depth and the minimum and maximum number of primitives considering a...
Definition: KDTreeNode.cpp:75
KDTreeNode * left
Pointer to node at left side on space partition. Can be nullptr if there is no left side node...
Definition: KDTreeNode.h:36
double splitPos
Point position at corresponding split axis.
Definition: KDTreeNode.h:45
Class representing a KDTree node.
Definition: KDTreeNode.h:16
static KDTreeNode * readObject(std::string path)
Import a serialized KDTree from file.
Definition: KDTreeNode.cpp:103
void writeObject(std::string path)
Serialize KDTree.
Definition: KDTreeNode.cpp:96