Voxomap
A C++11 voxel container.
Octree.hpp
Go to the documentation of this file.
1 #ifndef _VOXOMAP_OCTREE_HPP_
2 #define _VOXOMAP_OCTREE_HPP_
3 
4 #include <cstdint>
5 #include <memory>
6 #include <vector>
7 #include <assert.h>
8 
9 namespace voxomap
10 {
11 
21 template <class T_Node>
22 class Octree
23 {
24 public:
25  using Node = T_Node;
26 
30  Octree();
34  Octree(Octree const& other);
38  Octree(Octree&& other);
42  virtual ~Octree() = default;
48  Octree& operator=(Octree const& other);
54  Octree& operator=(Octree&& other);
55 
60  virtual T_Node* push(T_Node& node);
65  virtual std::unique_ptr<T_Node> pop(T_Node& node);
74  T_Node* findNode(int x, int y, int z, int size) const;
75 
80  virtual void clear();
81 
86  T_Node* getRootNode() const;
87 
88 protected:
94  uint8_t findNodeNb(T_Node const& node) const;
95 
96  // Node method
102  void setChild(T_Node& parent, T_Node& child);
109  void setChild(T_Node& parent, T_Node& child, uint8_t childId);
113  void removeParent(T_Node& child);
118  T_Node* removeChild(T_Node& parent, uint8_t id);
126  T_Node* findParentNode(T_Node& parent, T_Node& node, uint8_t& childId) const;
133  T_Node* push(T_Node& parent, T_Node& node);
141  T_Node* push(T_Node& parent, T_Node& child, uint8_t childId);
145  void insertNode(T_Node& child, T_Node& newChild);
151  void merge(T_Node& currentNode, T_Node& newNode);
152 
153  std::unique_ptr<T_Node> _rootNode;
154 };
155 
156 }
157 
158 #include "Octree.ipp"
159 
160 #endif // _VOXOMAP_OCTREE_HPP_
voxomap::Octree::removeChild
T_Node * removeChild(T_Node &parent, uint8_t id)
Remove the child with id from the parent node.
voxomap::Octree::Node
T_Node Node
Definition: Octree.hpp:25
voxomap::Octree::findNodeNb
uint8_t findNodeNb(T_Node const &node) const
Method use to find the index of node inside the root node.
voxomap
Definition: Node.hpp:8
voxomap::Octree::insertNode
void insertNode(T_Node &child, T_Node &newChild)
Create parent node that can contain child and newChild and push it into octree.
voxomap::Octree::getRootNode
T_Node * getRootNode() const
Getter of the root node.
voxomap::Octree::removeParent
void removeParent(T_Node &child)
Remove the parent node of child from the octree.
voxomap::Octree::pop
virtual std::unique_ptr< T_Node > pop(T_Node &node)
Removes node from the octree.
voxomap::Octree::clear
virtual void clear()
Clear the octree Removes all nodes and all elements.
voxomap::Octree
Octree container.
Definition: Octree.hpp:23
voxomap::Octree::Octree
Octree()
Default constructor.
voxomap::Octree::merge
void merge(T_Node &currentNode, T_Node &newNode)
Merge two nodes.
voxomap::Octree::findParentNode
T_Node * findParentNode(T_Node &parent, T_Node &node, uint8_t &childId) const
Find node inside parent that can contain node.
voxomap::Octree::push
T_Node * push(T_Node &parent, T_Node &child, uint8_t childId)
Push node inside parent.
voxomap::Octree::~Octree
virtual ~Octree()=default
Default virtual destructor.
voxomap::Octree::operator=
Octree & operator=(Octree const &other)
Assignement operator.
voxomap::Octree::push
T_Node * push(T_Node &parent, T_Node &node)
Push node inside parent.
voxomap::Octree::setChild
void setChild(T_Node &parent, T_Node &child)
Set child as child of parent.
voxomap::Octree::findNode
T_Node * findNode(int x, int y, int z, int size) const
Search the node that corresponds to the parameters.
voxomap::Octree::Octree
Octree(Octree const &other)
Copy constructor.
voxomap::Octree::_rootNode
std::unique_ptr< T_Node > _rootNode
Main node of the octree.
Definition: Octree.hpp:153
voxomap::Octree::setChild
void setChild(T_Node &parent, T_Node &child, uint8_t childId)
Set child as child of parent.
voxomap::Octree::push
virtual T_Node * push(T_Node &node)
Pushes node into the octree.
voxomap::Octree::Octree
Octree(Octree &&other)
Move constructor.
voxomap::Octree::operator=
Octree & operator=(Octree &&other)
Assignement move operator.