Voxomap
A C++11 voxel container.
SparseContainer.hpp
Go to the documentation of this file.
1 #ifndef _VOXOMAP_SPARSECONTAINER_HPP_
2 #define _VOXOMAP_SPARSECONTAINER_HPP_
3 
4 #include <cstdint>
5 #include <vector>
6 #include "../iterator.hpp"
7 #include "../SparseIDArray.hpp"
8 
9 namespace voxomap
10 {
11 
12 template <typename T_Area> class VoxelNode;
13 
31 template <class T_Voxel, template<class...> class T_Container = std::vector>
33 {
34 public:
35  using VoxelData = T_Voxel;
38 
39  const static uint32_t NB_VOXELS = 8;
40  const static uint32_t COORD_MASK = ~(NB_VOXELS - 1);
41  const static uint32_t VOXEL_MASK = NB_VOXELS - 1;
42  const static uint32_t NB_SUPERCONTAINER = 0;
43 
47  SparseContainer() = default;
51  SparseContainer(SparseContainer const& other) = default;
52 
60  uint16_t getNbVoxel() const;
61 
67  bool hasVoxel(uint8_t x) const;
74  bool hasVoxel(uint8_t x, uint8_t y) const;
82  bool hasVoxel(uint8_t x, uint8_t y, uint8_t z) const;
83 
91  VoxelData* findVoxel(uint8_t x, uint8_t y, uint8_t z);
99  VoxelData const* findVoxel(uint8_t x, uint8_t y, uint8_t z) const;
105  template <typename Iterator>
106  VoxelData* findVoxel(Iterator& it);
112  template <typename Iterator>
113  VoxelData const* findVoxel(Iterator& it) const;
114 
121  template <typename Iterator, typename... Args>
122  bool addVoxel(Iterator& it, Args&&... args);
129  template <typename Iterator, typename... Args>
130  bool updateVoxel(Iterator& it, Args&&... args);
136  template <typename Iterator, typename... Args>
137  void putVoxel(Iterator& it, Args&&... args);
144  template <typename Iterator>
145  bool removeVoxel(Iterator const& it, VoxelData* voxel = nullptr);
146 
152  template <typename Iterator>
153  void exploreVoxel(Iterator& it, std::function<void(Iterator const&)> const& predicate) const;
154 
155  void exploreVoxelContainer(std::function<void(SparseContainer const&)> const& predicate) const;
156 
161  void serialize(std::string& str) const;
168  size_t unserialize(char const* str, size_t size);
169 
170 private:
172 };
173 
174 }
175 
176 #include "SparseContainer.ipp"
177 
178 #endif // _VOXOMAP_SPARSECONTAINER_HPP_
voxomap::SparseContainer::VOXEL_MASK
static const uint32_t VOXEL_MASK
Definition: SparseContainer.hpp:41
voxomap::SparseContainer::putVoxel
void putVoxel(Iterator &it, Args &&... args)
Add or update a voxel.
voxomap::SparseContainer::init
void init(VoxelNode< VoxelContainer > const &)
Initialization method, do nothing.
Definition: SparseContainer.hpp:56
voxomap
Definition: Node.hpp:8
voxomap::container_iterator
Definition: iterator.hpp:21
voxomap::SparseContainer::exploreVoxelContainer
void exploreVoxelContainer(std::function< void(SparseContainer const &)> const &predicate) const
voxomap::SparseContainer::SparseContainer
SparseContainer(SparseContainer const &other)=default
Default copy constructor.
voxomap::SparseContainer::getNbVoxel
uint16_t getNbVoxel() const
Returns number of voxels.
voxomap::SparseContainer::findVoxel
VoxelData * findVoxel(uint8_t x, uint8_t y, uint8_t z)
Find voxel.
voxomap::SparseContainer::hasVoxel
bool hasVoxel(uint8_t x, uint8_t y) const
Check if there is voxel inside.
voxomap::SparseContainer::unserialize
size_t unserialize(char const *str, size_t size)
Unserialize str inside this.
voxomap::VoxelNode
Node optimized for voxel.
Definition: VoxelNode.hpp:14
voxomap::SparseContainer::findVoxel
VoxelData const * findVoxel(Iterator &it) const
Find voxel.
voxomap::SparseContainer::SparseContainer
SparseContainer()=default
Default constructor.
voxomap::SparseContainer::_sparseArray
SparseIDArray< T_Voxel, NB_VOXELS, T_Container > _sparseArray
Definition: SparseContainer.hpp:171
voxomap::SparseContainer::hasVoxel
bool hasVoxel(uint8_t x, uint8_t y, uint8_t z) const
Check if voxel exist.
voxomap::SparseContainer::NB_SUPERCONTAINER
static const uint32_t NB_SUPERCONTAINER
Definition: SparseContainer.hpp:42
voxomap::SparseContainer::VoxelData
T_Voxel VoxelData
Definition: SparseContainer.hpp:35
voxomap::SparseIDArray
Definition: SparseIDArray.hpp:219
voxomap::SparseContainer::exploreVoxel
void exploreVoxel(Iterator &it, std::function< void(Iterator const &)> const &predicate) const
Go through all voxels of the container and call the predicate for each.
voxomap::SparseContainer::COORD_MASK
static const uint32_t COORD_MASK
Definition: SparseContainer.hpp:40
voxomap::SparseContainer::updateVoxel
bool updateVoxel(Iterator &it, Args &&... args)
Update an existing voxel, don't create a new one.
voxomap::SparseContainer::removeVoxel
bool removeVoxel(Iterator const &it, VoxelData *voxel=nullptr)
Remove an existing voxel.
voxomap::SparseContainer::hasVoxel
bool hasVoxel(uint8_t x) const
Check if there is voxel inside.
voxomap::SparseContainer::serialize
void serialize(std::string &str) const
Serialize the structure.
voxomap::SparseContainer::NB_VOXELS
static const uint32_t NB_VOXELS
Definition: SparseContainer.hpp:39
voxomap::SparseContainer::findVoxel
VoxelData * findVoxel(Iterator &it)
Find voxel.
voxomap::SparseContainer
Voxel container used in leaves of the VoxelOctree. Mix between a fixed size 3D array (like in ArrayCo...
Definition: SparseContainer.hpp:33
voxomap::SparseContainer::findVoxel
VoxelData const * findVoxel(uint8_t x, uint8_t y, uint8_t z) const
Find voxel.
voxomap::SparseContainer::addVoxel
bool addVoxel(Iterator &it, Args &&... args)
Add a voxel, don't update an existing voxel.