Helios++
Helios software for LiDAR simulations
LightKDTreeNode.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 <IBinaryTreeNode.h>
11 #include <BinaryTreeDepthIterator.h>
12 #include <BinaryTreeFastDepthIterator.h>
13 #include <BinaryTreeBreadthIterator.h>
14 #include <BinaryTreeFastBreadthIterator.h>
15 
16 #include <Primitive.h>
17 #include <AABB.h>
18 
19 // Including primitives below is necessary for serialization
20 #include <Triangle.h>
21 #include <Voxel.h>
22 #include <DetailedVoxel.h>
23 
29 private:
30  // *** SERIALIZATION *** //
31  // *********************** //
32  friend class boost::serialization::access;
39  template <class Archive>
40  void serialize(Archive &ar, const unsigned int version){
41  // Register classes derived from Primitive
42  ar.template register_type<Vertex>();
43  ar.template register_type<AABB>();
44  ar.template register_type<Triangle>();
45  ar.template register_type<Voxel>();
46  ar.template register_type<DetailedVoxel>();
47 
48  boost::serialization::void_cast_register<
50  >();
51  ar & left;
52  ar & right;
53  ar & splitPos;
54  ar & splitAxis;
55  ar & primitives;
56  }
57 
58 public:
59  // *** ATTRIBUTES *** //
60  // ******************** //
65  LightKDTreeNode* left = nullptr;
70  LightKDTreeNode* right = nullptr;
74  double splitPos = 0;
78  int splitAxis = 0;
82  std::shared_ptr<std::vector<Primitive*>> primitives;
83 
84  // *** CONSTRUCTION / DESTRUCTION *** //
85  // ************************************ //
89  LightKDTreeNode() = default;
94  LightKDTreeNode(LightKDTreeNode const &kdtn);
103  virtual ~LightKDTreeNode() {
104  delete left;
105  delete right;
106  }
107 
108  // *** ASSIGNMENT OPERATORS *** //
109  // ****************************** //
122 
123  // *** S W A P *** //
124  // ******************* //
130  void swap(LightKDTreeNode &kdtn);
131 
132  // *** BINARY TREE INTERFACE *** //
133  // ******************************* //
137  LightKDTreeNode * getLeftChild() const override
138  {return left;}
142  LightKDTreeNode * getRightChild() const override
143  {return right;}
144 
145  // *** ITERATION METHODS *** //
146  // *************************** //
154  int const depth=0
155  )
156  {return {this, depth};}
164  {return {this};}
172  int const depth=0
173  )
174  {return {this, depth};}
182  {return {this};}
183 };
Like fast breadth first iterator but wrapping tree nodes inside a IterableTreeNode instance.
Definition: BinaryTreeBreadthIterator.h:30
Like fast depth first iterator but wrapping tree nodes inside a IterableTreeNode instance.
Definition: BinaryTreeDepthIterator.h:30
Fast breadth first iterator for binary tree like nodes.
Definition: BinaryTreeFastBreadthIterator.h:43
Fast depth first iterator for binary tree like nodes.
Definition: BinaryTreeFastDepthIterator.h:47
Binary tree node interface that must be implemented by any class providing binary tree node based fun...
Definition: IBinaryTreeNode.h:10
Class representing a light KDTree node. It is, the basic representation of a KDTree node with uses le...
Definition: LightKDTreeNode.h:28
BinaryTreeBreadthIterator< LightKDTreeNode > buildBreadthIterator(int const depth=0)
Build a breadth iterator starting at this node.
Definition: LightKDTreeNode.h:171
LightKDTreeNode & operator=(LightKDTreeNode const &kdtn)
Copy assignment operator for LightKDTreeNode.
Definition: LightKDTreeNode.cpp:27
LightKDTreeNode * getRightChild() const override
Definition: LightKDTreeNode.h:142
std::shared_ptr< std::vector< Primitive * > > primitives
Vector of primitives associated with the node.
Definition: LightKDTreeNode.h:82
LightKDTreeNode()=default
Default constructor for LightKDTreeNode.
BinaryTreeFastDepthIterator< LightKDTreeNode > buildFastDepthIterator()
Build a fast depth iterator starting at this node.
Definition: LightKDTreeNode.h:163
double splitPos
Point position at corresponding split axis.
Definition: LightKDTreeNode.h:74
LightKDTreeNode * right
Definition: LightKDTreeNode.h:70
BinaryTreeFastBreadthIterator< LightKDTreeNode > buildFastBreadthIterator()
Build a fast breadth iterator starting at this node.
Definition: LightKDTreeNode.h:181
BinaryTreeDepthIterator< LightKDTreeNode > buildDepthIterator(int const depth=0)
Build a depth iterator starting at this node.
Definition: LightKDTreeNode.h:153
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
void swap(LightKDTreeNode &kdtn)
Swap attributes of given LightKDTreeNode and current LightKDTreeNode.
Definition: LightKDTreeNode.cpp:41
void serialize(Archive &ar, const unsigned int version)
Serialize a LightKDTreeNode to a stream of bytes.
Definition: LightKDTreeNode.h:40
virtual ~LightKDTreeNode()
Destructor for LightKDTreeNode.
Definition: LightKDTreeNode.h:103
LightKDTreeNode * getLeftChild() const override
Definition: LightKDTreeNode.h:137
int splitAxis
Space axis to consider at current depth.
Definition: LightKDTreeNode.h:78