Helios++
Helios software for LiDAR simulations
KDTreeFactory.h
1 #pragma once
2 
3 #include <LightKDTreeNode.h>
4 #include <KDTreeNode.h>
5 #include <KDTreeNodeRoot.h>
6 #include <LightKDTreeNodeBlockAllocator.h>
7 
8 #include <vector>
9 
10 using std::vector;
11 
23 private:
24  // *** SERIALIZATION *** //
25  // *********************** //
26  friend class boost::serialization::access;
33  template <class Archive>
34  void serialize(Archive &ar, const unsigned int version) {
35  // Register KDTree node classes
36  ar.template register_type<LightKDTreeNode>();
37  ar.template register_type<KDTreeNode>();
38  ar.template register_type<KDTreeNodeRoot>();
39 
40  // Serialization itself
41  ar &buildLightNodes;
42  //LightKDTreeNodeBlockAllocator lkdtnBlockAllocator; // No need, deflt.
43  }
44 
45 protected:
46  // *** ATTRIBUTES *** //
47  // ******************** //
56  bool buildLightNodes = true;
64 
65 public:
66  // *** CONSTRUCTION / DESTRUCTION *** //
67  // ************************************ //
72  virtual ~KDTreeFactory() = default;
73 
74  // *** CLONE *** //
75  // *************** //
80  virtual KDTreeFactory * clone() const = 0;
81 
82  // *** K-DIMENSIONAL TREE FACTORY METHODS *** //
83  // **********************+********************* //
95  vector<Primitive *> &primitives,
96  bool const computeStats=false,
97  bool const reportStats=false
98  ) = 0;
112  vector<Primitive *> const &primitives,
113  bool const computeStats=false,
114  bool const reportStats=false
115  )
116  {
117  vector<Primitive *> prims = primitives; // Copy to work over
118  return makeFromPrimitivesUnsafe(prims, computeStats, reportStats);
119  };
120 
121  // *** GETTERs and SETTERs *** //
122  // ***************************** //
128  virtual inline bool isBuildingLightNodes() {return buildLightNodes;}
134  virtual inline void setBuildingLightNodes(bool const buildLightNodes)
135  {this->buildLightNodes = buildLightNodes;}
152  virtual void setChild(LightKDTreeNode *&child, KDTreeNode *node)
153  {if(node != nullptr) child = node;}
154 
155 protected:
156  // *** LIGHTEN *** //
157  // ***************** //
167  virtual void lighten(KDTreeNodeRoot *root);
175  virtual LightKDTreeNode * _lighten(KDTreeNode *node);
176 };
Class that must be extended by any class which provides factory methods for k-dimensional trees....
Definition: KDTreeFactory.h:22
virtual bool isBuildingLightNodes()
Check if KDTreeFactory is building light nodes.
Definition: KDTreeFactory.h:128
void serialize(Archive &ar, const unsigned int version)
Serialize a KDTree factory to a stream of bytes.
Definition: KDTreeFactory.h:34
virtual KDTreeFactory * clone() const =0
Create a clone of the KDTreeFactory.
LightKDTreeNodeBlockAllocator lkdtnBlockAllocator
The block allocator to speed-up lighten of KDTree by reducing allocation calls when instantiating mul...
Definition: KDTreeFactory.h:63
virtual void setChild(LightKDTreeNode *&child, KDTreeNode *node)
Set child to given node if and only if node is not null. It must be used to assign children nodes in ...
Definition: KDTreeFactory.h:152
virtual void lighten(KDTreeNodeRoot *root)
Rebuild all children of given root KDTree node as LightKDTeeeNode nodes.
Definition: KDTreeFactory.cpp:32
virtual void setBuildingLightNodes(bool const buildLightNodes)
Set KDTreeFactory so it build light nodes (true) or not (false)
Definition: KDTreeFactory.h:134
virtual KDTreeNodeRoot * makeFromPrimitivesUnsafe(vector< Primitive * > &primitives, bool const computeStats=false, bool const reportStats=false)=0
Build a KDTree from given primitives.
bool buildLightNodes
When it is true, the KDTreeFactory is expected to build light nodes. It is, built KDTree must have a ...
Definition: KDTreeFactory.h:56
virtual LightKDTreeNode * _lighten(KDTreeNode *node)
Assist KDTreeFactory::lighten function by handling the lighten of a given non-root node.
Definition: KDTreeFactory.cpp:5
KDTreeFactory()
K dimensional tree factory default constructor.
Definition: KDTreeFactory.h:71
virtual KDTreeNodeRoot * makeFromPrimitives(vector< Primitive * > const &primitives, bool const computeStats=false, bool const reportStats=false)
Safe wrapper from makeFromPrimitivesUnsafe which handles a copy to make from primitives by default....
Definition: KDTreeFactory.h:111
Class representing the root node of a KDTree.
Definition: KDTreeNodeRoot.h:12
Class representing a KDTree node.
Definition: KDTreeNode.h:9
Block allocator for LightKDTreeNode instances.
Definition: LightKDTreeNodeBlockAllocator.h:12
Class representing a light KDTree node. It is, the basic representation of a KDTree node with uses le...
Definition: LightKDTreeNode.h:28