Helios++
Helios software for LiDAR simulations
KDTreeNodeRoot.h
1 #pragma once
2 
3 #include <KDTreeNode.h>
4 #include <vector>
5 using std::vector;
6 
12 class KDTreeNodeRoot : public KDTreeNode {
13 private:
14  // *** SERIALIZATION *** //
15  // *********************** //
16  friend class boost::serialization::access;
23  template <typename Archive>
24  void serialize(Archive& ar, const unsigned int version){
25  boost::serialization::void_cast_register<KDTreeNodeRoot, KDTreeNode>();
26  ar & boost::serialization::base_object<KDTreeNode>(*this);
30  ar & stats_numInterior;
31  ar & stats_numLeaves;
32  ar & stats_totalCost;
33  }
34 public:
35  // *** ATTRIBUTES *** //
36  // ******************** //
69  vector<LightKDTreeNode *> blocks;
74  vector<size_t> blocksSize;
75 
76 
77  // *** CONSTRUCTION / DESTRUCTION *** //
78  // ************************************ //
84  stats_minNumPrimsInLeaf(std::numeric_limits<int>::max()),
87  stats_numLeaves(0),
88  stats_totalCost(0.0)
89  {}
90 
91  ~KDTreeNodeRoot() override{
92  // Handle release when nodes have been allocated in blocks
93  if(!blocks.empty()){
94  // Root direct children to nullptr to prevent double free
95  left = nullptr;
96  right = nullptr;
97 
98  // Free each allocated block
99  size_t const numBlocks = blocks.size();
100  for(size_t i = 0 ; i < numBlocks ; ++i){
101  size_t const numNodes = blocksSize[i];
102  LightKDTreeNode *baseBlock = blocks[i];
103  // All children to nullptr to prevent double free
104  for(size_t j = 0 ; j < numNodes ; ++j){
105  LightKDTreeNode *block = baseBlock + j;
106  block->left = nullptr;
107  block->right = nullptr;
108  }
109  delete[] baseBlock;
110  }
111  }
112  }
113 
114  // *** GETTERs and SETTERs *** //
115  // ***************************** //
120  virtual bool isDynamic() const {return false;}
121 };
Class representing the root node of a KDTree.
Definition: KDTreeNodeRoot.h:12
virtual bool isDynamic() const
Check whether the KDTree is dynamic (true) or not (false)
Definition: KDTreeNodeRoot.h:120
int stats_maxDepthReached
Maximum depth of the KDTree.
Definition: KDTreeNodeRoot.h:48
void serialize(Archive &ar, const unsigned int version)
Serialize a KDTreeNodeRoot to a stream of bytes.
Definition: KDTreeNodeRoot.h:24
vector< LightKDTreeNode * > blocks
Vector of pointers to the start of each allocated block of LightKDTreeNode. If it is empty,...
Definition: KDTreeNodeRoot.h:69
int stats_numLeaves
Number of leaf nodes in the KDTree.
Definition: KDTreeNodeRoot.h:56
vector< size_t > blocksSize
The size (number of nodes) for each allocated block, if any.
Definition: KDTreeNodeRoot.h:74
int stats_minNumPrimsInLeaf
Minimum number of primitives considering all leaves.
Definition: KDTreeNodeRoot.h:44
int stats_maxNumPrimsInLeaf
Maximum number of primitives considering all leaves.
Definition: KDTreeNodeRoot.h:40
double stats_totalCost
The total cost of the tree. It changes depending on tree building strategy. It might be NaN if tree b...
Definition: KDTreeNodeRoot.h:62
int stats_numInterior
Number of interior nodes in the KDTree.
Definition: KDTreeNodeRoot.h:52
KDTreeNodeRoot()
Constructor for KDTree root node.
Definition: KDTreeNodeRoot.h:82
Class representing a KDTree node.
Definition: KDTreeNode.h:9
Class representing a light KDTree node. It is, the basic representation of a KDTree node with uses le...
Definition: LightKDTreeNode.h:28
LightKDTreeNode * right
Definition: LightKDTreeNode.h:70
LightKDTreeNode * left
Pointer to node at left side on space partition. Can be nullptr if there is no left side node.
Definition: LightKDTreeNode.h:65