Voxomap
A C++11 voxel container.
SparseSuperContainer.hpp
Go to the documentation of this file.
1 #ifndef _VOXOMAP_SPARSESUPERCONTAINER_HPP_
2 #define _VOXOMAP_SPARSESUPERCONTAINER_HPP_
3 
4 #include <cstdint>
5 #include <memory>
6 #include <string>
7 #include <vector>
8 #include <functional>
9 #include "../iterator.hpp"
10 #include "../SparseIDArray.hpp"
11 
12 namespace voxomap
13 {
14 
21 template <class Container> class VoxelNode;
22 
40 template <class T_Container, template <class...> class T_InternalContainer = std::vector>
42 {
43  using Container = T_Container;
44  using VoxelData = typename Container::VoxelData;
45  using VoxelContainer = typename Container::VoxelContainer;
47 
48  const static uint32_t NB_CONTAINERS = 8;
49  const static uint32_t CONTAINER_MASK = NB_CONTAINERS - 1;
50  const static uint32_t NB_VOXELS = NB_CONTAINERS * Container::NB_VOXELS;
51  const static uint32_t COORD_MASK = ~(NB_VOXELS - 1);
52  const static uint32_t VOXEL_MASK = Container::VOXEL_MASK;
53  const static uint32_t NB_SUPERCONTAINER = 1 + Container::NB_SUPERCONTAINER;
54  const static uint32_t SUPERCONTAINER_ID = NB_SUPERCONTAINER - 1;
55 
59  SparseSuperContainer() = default;
63  SparseSuperContainer(SparseSuperContainer const& other) = default;
71  ~SparseSuperContainer() = default;
72 
73 
81  uint32_t getNbVoxel() const;
87  template <typename Iterator>
88  VoxelData* findVoxel(Iterator& it);
94  template <typename Iterator>
95  VoxelData const* findVoxel(Iterator& it) const;
96 
102  bool hasContainer(uint8_t x) const;
109  bool hasContainer(uint8_t x, uint8_t y) const;
117  bool hasContainer(uint8_t x, uint8_t y, uint8_t z) const;
125  Container* findContainer(uint8_t x, uint8_t y, uint8_t z);
133  Container const* findContainer(uint8_t x, uint8_t y, uint8_t z) const;
134 
141  template <typename Iterator, typename... Args>
142  bool addVoxel(Iterator& it, Args&&... args);
149  template <typename Iterator, typename... Args>
150  bool updateVoxel(Iterator& it, Args&&... args);
156  template <typename Iterator, typename... Args>
157  void putVoxel(Iterator& it, Args&&... args);
164  template <typename Iterator, typename... Args>
165  bool removeVoxel(Iterator const& it, Args&&... args);
166 
171  void serialize(std::string& str) const;
178  size_t unserialize(char const* str, size_t size);
179 
185  template <typename Iterator>
186  void exploreVoxel(Iterator& it, std::function<void(Iterator const&)> const& predicate) const;
187 
188  void exploreVoxelContainer(std::function<void(typename T_Container::VoxelContainer const&)> const& predicate) const;
189 
190 private:
192  uint32_t _nbVoxels = 0;
193 };
194 
195 }
196 
197 #include "SparseSuperContainer.ipp"
198 
199 #endif // _VOXOMAP_SPARSESUPERCONTAINER_HPP_
voxomap::SparseSuperContainer::_nbVoxels
uint32_t _nbVoxels
Number of voxels.
Definition: SparseSuperContainer.hpp:192
voxomap::SparseSuperContainer::SparseSuperContainer
SparseSuperContainer()=default
Default constructor.
voxomap::SparseSuperContainer
Super container used in leaves of the VoxelOctree. Mix between a fixed size 3D array (like in ArraySu...
Definition: SparseSuperContainer.hpp:42
voxomap::SparseSuperContainer::NB_SUPERCONTAINER
static const uint32_t NB_SUPERCONTAINER
Definition: SparseSuperContainer.hpp:53
voxomap
Definition: Node.hpp:8
voxomap::SparseSuperContainer::removeVoxel
bool removeVoxel(Iterator const &it, Args &&... args)
Remove an existing voxel.
voxomap::SparseSuperContainer::~SparseSuperContainer
~SparseSuperContainer()=default
Default destructor.
voxomap::SparseSuperContainer::exploreVoxelContainer
void exploreVoxelContainer(std::function< void(typename T_Container::VoxelContainer const &)> const &predicate) const
voxomap::SparseSuperContainer::VoxelData
typename Container::VoxelData VoxelData
Definition: SparseSuperContainer.hpp:44
voxomap::SparseSuperContainer::findContainer
Container * findContainer(uint8_t x, uint8_t y, uint8_t z)
Find sub-container.
voxomap::SparseSuperContainer::Container
T_Container Container
Definition: SparseSuperContainer.hpp:43
voxomap::SparseSuperContainer::getNbVoxel
uint32_t getNbVoxel() const
Returns number of voxels.
voxomap::SparseSuperContainer::NB_CONTAINERS
static const uint32_t NB_CONTAINERS
Definition: SparseSuperContainer.hpp:48
voxomap::SparseSuperContainer::hasContainer
bool hasContainer(uint8_t x) const
Check if there is sub-container.
voxomap::SparseSuperContainer::hasContainer
bool hasContainer(uint8_t x, uint8_t y) const
Check if there is sub-container.
voxomap::SparseSuperContainer::SUPERCONTAINER_ID
static const uint32_t SUPERCONTAINER_ID
Definition: SparseSuperContainer.hpp:54
voxomap::SparseSuperContainer::updateVoxel
bool updateVoxel(Iterator &it, Args &&... args)
Update an existing voxel, don't create a new one.
voxomap::SparseSuperContainer::addVoxel
bool addVoxel(Iterator &it, Args &&... args)
Add a voxel, don't update an existing voxel.
voxomap::VoxelNode
Node optimized for voxel.
Definition: VoxelNode.hpp:14
voxomap::SparseSuperContainer::SparseSuperContainer
SparseSuperContainer(SparseSuperContainer &&other)=default
Default move constructor.
voxomap::SparseSuperContainer::_sparseArray
SparseIDArray< std::unique_ptr< Container >, NB_CONTAINERS, T_InternalContainer > _sparseArray
Definition: SparseSuperContainer.hpp:191
voxomap::SparseSuperContainer::VOXEL_MASK
static const uint32_t VOXEL_MASK
Definition: SparseSuperContainer.hpp:52
voxomap::SparseIDArray
Definition: SparseIDArray.hpp:219
voxomap::supercontainer_iterator
Definition: iterator.hpp:112
voxomap::SparseSuperContainer::hasContainer
bool hasContainer(uint8_t x, uint8_t y, uint8_t z) const
Check if there is sub-container.
voxomap::SparseSuperContainer::VoxelContainer
typename Container::VoxelContainer VoxelContainer
Definition: SparseSuperContainer.hpp:45
voxomap::SparseSuperContainer::COORD_MASK
static const uint32_t COORD_MASK
Definition: SparseSuperContainer.hpp:51
voxomap::SparseSuperContainer::findContainer
Container const * findContainer(uint8_t x, uint8_t y, uint8_t z) const
Find sub-container.
voxomap::SparseSuperContainer::CONTAINER_MASK
static const uint32_t CONTAINER_MASK
Definition: SparseSuperContainer.hpp:49
voxomap::SparseSuperContainer::init
void init(VoxelNode< SparseSuperContainer< Container, T_InternalContainer >> const &)
Initialization method, do nothing.
Definition: SparseSuperContainer.hpp:77
voxomap::SparseSuperContainer::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::SparseSuperContainer::unserialize
size_t unserialize(char const *str, size_t size)
Unserialize str inside this.
voxomap::SparseSuperContainer::putVoxel
void putVoxel(Iterator &it, Args &&... args)
Add or update a voxel.
voxomap::SparseSuperContainer::serialize
void serialize(std::string &str) const
Serialize the structure.
voxomap::SparseSuperContainer::SparseSuperContainer
SparseSuperContainer(SparseSuperContainer const &other)=default
Default Copy constructor.
voxomap::SparseSuperContainer::findVoxel
VoxelData * findVoxel(Iterator &it)
Find voxel.
voxomap::SparseSuperContainer::findVoxel
VoxelData const * findVoxel(Iterator &it) const
Find voxel.
voxomap::SparseSuperContainer::NB_VOXELS
static const uint32_t NB_VOXELS
Definition: SparseSuperContainer.hpp:50