Voxomap
A C++11 voxel container.
VoxelOctree.hpp
Go to the documentation of this file.
1 #ifndef _VOXOMAP_VOXELOCTREE_HPP_
2 #define _VOXOMAP_VOXELOCTREE_HPP_
3 
4 #include <type_traits>
5 #include "../octree/Octree.hpp"
6 #include "VoxelNode.hpp"
7 #include "../utils/BoundingBox.hpp"
8 
9 namespace voxomap
10 {
11 
17 template <class T_Container> class VoxelNode;
18 
23 template <class T_Container>
24 class VoxelOctree : public Octree<VoxelNode<T_Container>>
25 {
26 public:
27  using VoxelData = typename T_Container::VoxelData;
28  using iterator = typename T_Container::iterator;
29 
45  virtual ~VoxelOctree() = default;
54 
66  std::unique_ptr<VoxelNode<T_Container>> pop(VoxelNode<T_Container>& node) override;
71  void clear() override;
79  template <typename T>
80  iterator findVoxel(T x, T y, T z);
88  template <typename T>
89  VoxelNode<T_Container>* findVoxelNode(T x, T y, T z) const;
90 
99  template <typename T, typename... Args>
100  std::pair<iterator, bool> addVoxel(T x, T y, T z, Args&&... args);
109  template <typename T, typename... Args>
110  iterator updateVoxel(T x, T y, T z, Args&&... args);
117  template <typename... Args>
118  iterator updateVoxel(iterator it, Args&&... args);
127  template <typename T, typename... Args>
128  iterator putVoxel(T x, T y, T z, Args&&... args);
129 
138  template <typename T, typename... Args>
139  bool removeVoxel(T x, T y, T z, Args&&... args);
146  template <typename... Args>
147  bool removeVoxel(iterator it, Args&&... args);
148 
152  unsigned int getContainerSize() const;
153 
157  //void calculBoundingBox(Core::RectHitbox &hitbox) const;
159 
164  void exploreVoxel(std::function<void(iterator const&)> const& predicate) const;
169  void exploreVoxelContainer(std::function<void(typename T_Container::VoxelContainer const&)> const& predicate) const;
174  void exploreVoxelNode(std::function<void(VoxelNode<T_Container> const&)> const& predicate) const;
181  void exploreBoundingBox(BoundingBox<int> const& bounding_box,
182  std::function<void(VoxelNode<T_Container>&)> const& in_predicate,
183  std::function<void(VoxelNode<T_Container>&)> const& out_predicate);
184 
188  unsigned int getNbVoxels() const;
193  void setNbVoxels(unsigned int nbVoxels);
194 
203 
208  void serialize(std::string& str) const;
215  size_t unserialize(char const* str, size_t strsize);
216 
217 private:
225  iterator _findVoxel(int x, int y, int z);
233  template <typename T>
234  typename std::enable_if<std::is_floating_point<T>::value, iterator>::type _findVoxel(T x, T y, T z);
235 
243  VoxelNode<T_Container>* _findVoxelNode(int x, int y, int z) const;
251  template <typename T>
252  typename std::enable_if<std::is_floating_point<T>::value, VoxelNode<T_Container>*>::type _findVoxelNode(T x, T y, T z) const;
253 
254 protected:
270  template <typename T>
271  typename std::enable_if<std::is_floating_point<T>::value, VoxelNode<T_Container>*>::type pushContainerNode(T x, T y, T z);
272 
273  mutable VoxelNode<T_Container>* _nodeCache = nullptr;
274  unsigned int _nbVoxels = 0;
275 };
276 
277 }
278 
279 #include "VoxelOctree.ipp"
280 
281 #endif // _VOXOMAP_VOXELOCTREE_HPP_
voxomap::VoxelOctree::_findVoxel
iterator _findVoxel(int x, int y, int z)
Method to find voxel (for integer arguments)
voxomap::VoxelOctree::removeOfCache
void removeOfCache(VoxelNode< T_Container > const &node)
Calcul the bounding box.
voxomap
Definition: Node.hpp:8
voxomap::VoxelOctree::removeVoxel
bool removeVoxel(iterator it, Args &&... args)
Removes a voxel.
voxomap::VoxelOctree::findVoxel
iterator findVoxel(T x, T y, T z)
Returns a voxel iterator.
voxomap::VoxelOctree::_findVoxel
std::enable_if< std::is_floating_point< T >::value, iterator >::type _findVoxel(T x, T y, T z)
Method to find voxel (for floating point arguments)
voxomap::VoxelOctree::putVoxel
iterator putVoxel(T x, T y, T z, Args &&... args)
Add or update the voxel.
voxomap::VoxelOctree::removeVoxel
bool removeVoxel(T x, T y, T z, Args &&... args)
Removes a voxel.
voxomap::VoxelOctree::clear
void clear() override
Clear the octree Removes all nodes and all elements.
voxomap::VoxelOctree::operator=
VoxelOctree & operator=(VoxelOctree< T_Container > &&other)
Move assignement operator.
voxomap::VoxelOctree::addVoxel
std::pair< iterator, bool > addVoxel(T x, T y, T z, Args &&... args)
Add the voxel if not exist.
voxomap::VoxelOctree::updateVoxel
iterator updateVoxel(iterator it, Args &&... args)
Update the voxel if already exist.
voxomap::VoxelOctree::VoxelData
typename T_Container::VoxelData VoxelData
Definition: VoxelOctree.hpp:27
voxomap::VoxelOctree::~VoxelOctree
virtual ~VoxelOctree()=default
Default destructor.
voxomap::VoxelOctree::exploreBoundingBox
void exploreBoundingBox(BoundingBox< int > const &bounding_box, std::function< void(VoxelNode< T_Container > &)> const &in_predicate, std::function< void(VoxelNode< T_Container > &)> const &out_predicate)
Browse all voxel containers.
voxomap::VoxelOctree::end
iterator end()
Returns an iterator to the element folowing the last voxel of the octree.
voxomap::VoxelNode
Node optimized for voxel.
Definition: VoxelNode.hpp:14
voxomap::VoxelOctree::_nbVoxels
unsigned int _nbVoxels
Number of voxels.
Definition: VoxelOctree.hpp:274
voxomap::VoxelOctree::getContainerSize
unsigned int getContainerSize() const
Returns the size of containers.
voxomap::VoxelOctree::_findVoxelNode
std::enable_if< std::is_floating_point< T >::value, VoxelNode< T_Container > * >::type _findVoxelNode(T x, T y, T z) const
Method to find node that contain voxel (for floating point arguments)
voxomap::VoxelOctree::VoxelOctree
VoxelOctree(VoxelOctree< T_Container > const &other)
Copy constructor.
voxomap::VoxelOctree
Octree optimized for voxel.
Definition: VoxelOctree.hpp:17
voxomap::VoxelOctree::push
VoxelNode< T_Container > * push(VoxelNode< T_Container > &node) override
Pushes node into the octree.
voxomap::VoxelOctree::pop
std::unique_ptr< VoxelNode< T_Container > > pop(VoxelNode< T_Container > &node) override
Removes node from the octree.
voxomap::VoxelOctree::operator=
VoxelOctree & operator=(VoxelOctree< T_Container > const &other)
Assignement operator.
voxomap::VoxelOctree::VoxelOctree
VoxelOctree(VoxelOctree< T_Container > &&other)
Move constructor.
voxomap::VoxelOctree::unserialize
size_t unserialize(char const *str, size_t strsize)
Unserialize str.
voxomap::VoxelOctree::begin
iterator begin()
Returns an iterator to the first voxel of the octree.
voxomap::VoxelOctree::VoxelOctree
VoxelOctree()
Default constructor.
voxomap::VoxelOctree::exploreVoxelContainer
void exploreVoxelContainer(std::function< void(typename T_Container::VoxelContainer const &)> const &predicate) const
Browse all voxel containers.
voxomap::VoxelOctree::exploreVoxel
void exploreVoxel(std::function< void(iterator const &)> const &predicate) const
Browse all voxels.
voxomap::VoxelOctree::exploreVoxelNode
void exploreVoxelNode(std::function< void(VoxelNode< T_Container > const &)> const &predicate) const
Browse all voxel nodes.
voxomap::VoxelOctree::pushContainerNode
std::enable_if< std::is_floating_point< T >::value, VoxelNode< T_Container > * >::type pushContainerNode(T x, T y, T z)
Adds the leaf node that contain the voxel container.
voxomap::VoxelOctree::_nodeCache
VoxelNode< T_Container > * _nodeCache
Cache for improve performance.
Definition: VoxelOctree.hpp:273
voxomap::VoxelOctree::findVoxelNode
VoxelNode< T_Container > * findVoxelNode(T x, T y, T z) const
Returns a node, can be NULL.
voxomap::VoxelOctree::iterator
typename T_Container::iterator iterator
Definition: VoxelOctree.hpp:28
voxomap::VoxelOctree::serialize
void serialize(std::string &str) const
Serialize the structure.
voxomap::VoxelOctree::getNbVoxels
unsigned int getNbVoxels() const
Get the number of voxels.
VoxelNode.hpp
voxomap::VoxelOctree::updateVoxel
iterator updateVoxel(T x, T y, T z, Args &&... args)
Update the voxel if already exist.
voxomap::VoxelOctree::pushContainerNode
VoxelNode< T_Container > * pushContainerNode(int x, int y, int z)
Adds the leaf node that contain the voxel container.
voxomap::VoxelOctree::setNbVoxels
void setNbVoxels(unsigned int nbVoxels)
Set the number of voxels.
voxomap::VoxelOctree::_findVoxelNode
VoxelNode< T_Container > * _findVoxelNode(int x, int y, int z) const
Method to find node that contain voxel (for integer arguments)