Voxomap
A C++11 voxel container.
Node.hpp
Go to the documentation of this file.
1 #ifndef _VOXOMAP_NODE_HPP_
2 #define _VOXOMAP_NODE_HPP_
3 
4 #include <array>
5 #include <memory>
6 
7 namespace voxomap
8 {
9 
10 template <typename T_Node> class Octree;
11 
16 template <typename T_Node>
17 class Node
18 {
19 public:
27  Node(int x, int y, int z, int size);
31  Node(Node const& other);
35  virtual ~Node();
36 
40  inline int getSize() const;
44  inline int getX() const;
48  inline int getY() const;
52  inline int getZ() const;
56  inline int getNbChildren() const;
60  inline std::array<T_Node*, 8> const& getChildren() const;
64  inline T_Node* getParent() const;
68  inline Octree<T_Node>* getOctree() const;
73  inline bool empty() const;
78  inline bool operator==(Node const& other) const;
83  inline bool operator!=(Node const& other) const;
84 
88  void merge(T_Node const& other);
89 
98  T_Node* findNode(int x, int y, int z, int size) const;
99 
107  inline T_Node* getChild(int x, int y, int z) const;
115  inline int getChildPos(int x, int y, int z) const;
119  inline uint8_t getChildId() const;
120 
131  template <typename T>
132  inline bool isInside(T x, T y, T z, T sx, T sy, T sz) const;
140  template <typename T>
141  inline bool isInside(T x, T y, T z) const;
150  template <typename T>
151  inline bool isInside(T x, T y, T z, T size) const;
157  inline bool isInside(T_Node& node) const;
158 
159 protected:
165 
166  std::array<T_Node*, 8> _children;
167  T_Node* _parent = nullptr;
168  Octree<T_Node>* _octree = nullptr;
169  int _x = 0;
170  int _y = 0;
171  int _z = 0;
172  int _size = 0;
173  uint8_t _childId = 0;
174  uint8_t _nbChildren = 0;
176 };
177 
178 }
179 
180 #include "Node.ipp"
181 
182 #endif // _VOXOMAP_NODE_HPP_
voxomap::Node::Node
Node(int x, int y, int z, int size)
Constructs Node with its properties.
voxomap
Definition: Node.hpp:8
voxomap::Node::getChildPos
int getChildPos(int x, int y, int z) const
Get the child node position that can contain the point at coordinate xyz.
voxomap::Node::findNode
T_Node * findNode(int x, int y, int z, int size) const
Find node.
voxomap::Node::getX
int getX() const
Returns x position of the node.
voxomap::Node::isInside
bool isInside(T x, T y, T z, T sx, T sy, T sz) const
Check if box is inside the node.
voxomap::Node::getY
int getY() const
Returns y position of the node.
voxomap::Node::Node
Node(Node const &other)
Copy constructor.
voxomap::Node::getChildId
uint8_t getChildId() const
voxomap::Node::_octree
Octree< T_Node > * _octree
Parent octree.
Definition: Node.hpp:168
voxomap::Node::_children
std::array< T_Node *, 8 > _children
Array of children.
Definition: Node.hpp:166
voxomap::Node::_y
int _y
Y coordinate.
Definition: Node.hpp:170
voxomap::Node::getOctree
Octree< T_Node > * getOctree() const
Returns the octree.
voxomap::Node::_size
int _size
Size of the node.
Definition: Node.hpp:172
voxomap::Node::_x
int _x
X coordinate.
Definition: Node.hpp:169
voxomap::Octree
Octree container.
Definition: Octree.hpp:23
voxomap::Node::isInside
bool isInside(T x, T y, T z, T size) const
Check if box is inside the node.
voxomap::Node::_nbChildren
uint8_t _nbChildren
Number of node inside the children array.
Definition: Node.hpp:174
voxomap::Node::getParent
T_Node * getParent() const
Returns the parent node.
voxomap::Node::getChild
T_Node * getChild(int x, int y, int z) const
Get the child node that can contain the point at coordinate xyz.
voxomap::Node::changeOctree
void changeOctree(Octree< T_Node > &octree)
Change octree of the node and all its children.
voxomap::Node::empty
bool empty() const
Check if node has children.
voxomap::Node::getZ
int getZ() const
Returns z position of the node.
voxomap::Node::operator!=
bool operator!=(Node const &other) const
Compare coordinate and size of the node.
voxomap::Node::getSize
int getSize() const
Returns size of node.
voxomap::Node
Basic node of Octree.
Definition: Node.hpp:18
voxomap::Node::merge
void merge(T_Node const &other)
Merge method of the node, do nothing.
voxomap::Node::_z
int _z
Z coordinate.
Definition: Node.hpp:171
voxomap::Node::isInside
bool isInside(T x, T y, T z) const
Check if point is inside the node.
voxomap::Node::getNbChildren
int getNbChildren() const
Returns the number of children, [0, 8].
voxomap::Node::~Node
virtual ~Node()
Destructor method.
voxomap::Node::operator==
bool operator==(Node const &other) const
Compare coordinate and size of the node.
voxomap::Node::_parent
T_Node * _parent
Parent node.
Definition: Node.hpp:167
voxomap::Node::_childId
uint8_t _childId
Child id inside parent's children array.
Definition: Node.hpp:173
voxomap::Node::getChildren
std::array< T_Node *, 8 > const & getChildren() const
Returns the children array.
voxomap::Node::isInside
bool isInside(T_Node &node) const
Check if node is inside the node.