Voxomap
A C++11 voxel container.
ArraySuperContainer.hpp
Go to the documentation of this file.
1 #ifndef _VOXOMAP_ARRAYSUPERCONTAINER_HPP_
2 #define _VOXOMAP_ARRAYSUPERCONTAINER_HPP_
3 
4 #include <cstdint>
5 #include <memory>
6 #include <string>
7 #include "../iterator.hpp"
8 
9 namespace voxomap
10 {
11 
18 template <class Container> class VoxelNode;
19 
29 template <class T_Container>
31 {
32  using Container = T_Container;
33  using VoxelData = typename Container::VoxelData;
34  using VoxelContainer = typename Container::VoxelContainer;
36 
37  const static uint32_t NB_CONTAINERS = 8;
38  const static uint32_t CONTAINER_MASK = NB_CONTAINERS - 1;
39  const static uint32_t NB_VOXELS = NB_CONTAINERS * Container::NB_VOXELS;
40  const static uint32_t COORD_MASK = ~(NB_VOXELS - 1);
41  const static uint32_t VOXEL_MASK = Container::VOXEL_MASK;
42  const static uint32_t NB_SUPERCONTAINER = 1 + Container::NB_SUPERCONTAINER;
43  const static uint32_t SUPERCONTAINER_ID = NB_SUPERCONTAINER - 1;
44 
48  ArraySuperContainer() = default;
60  ~ArraySuperContainer() = default;
61 
62 
70  uint32_t getNbVoxel() const;
76  template <typename Iterator>
77  VoxelData* findVoxel(Iterator& it);
83  template <typename Iterator>
84  VoxelData const* findVoxel(Iterator& it) const;
85 
91  bool hasContainer(uint8_t x) const;
98  bool hasContainer(uint8_t x, uint8_t y) const;
106  bool hasContainer(uint8_t x, uint8_t y, uint8_t z) const;
114  Container* findContainer(uint8_t x, uint8_t y, uint8_t z);
122  Container const* findContainer(uint8_t x, uint8_t y, uint8_t z) const;
123 
130  template <typename Iterator, typename... Args>
131  bool addVoxel(Iterator& it, Args&&... args);
138  template <typename Iterator, typename... Args>
139  bool updateVoxel(Iterator& it, Args&&... args);
145  template <typename Iterator, typename... Args>
146  void putVoxel(Iterator& it, Args&&... args);
153  template <typename Iterator, typename... Args>
154  bool removeVoxel(Iterator const& it, Args&&... args);
155 
160  void serialize(std::string& str) const;
167  size_t unserialize(char const* str, size_t size);
168 
174  template <typename Iterator>
175  void exploreVoxel(Iterator& it, std::function<void(Iterator const&)> const& predicate) const;
176 
177  void exploreVoxelContainer(std::function<void(typename Container::VoxelContainer const&)> const& predicate) const;
178 
179 private:
180  std::unique_ptr<Container> _containerArray[NB_CONTAINERS][NB_CONTAINERS][NB_CONTAINERS] = { 0 };
181  uint32_t _nbVoxels = 0;
182 };
183 
184 }
185 
186 #include "ArraySuperContainer.ipp"
187 
188 #endif // _VOXOMAP_ARRAYSUPERCONTAINER_HPP_
voxomap::ArraySuperContainer::unserialize
size_t unserialize(char const *str, size_t size)
Unserialize str inside this.
voxomap
Definition: Node.hpp:8
voxomap::ArraySuperContainer::hasContainer
bool hasContainer(uint8_t x, uint8_t y, uint8_t z) const
Check if there is sub-container.
voxomap::ArraySuperContainer::serialize
void serialize(std::string &str) const
Serialize the structure.
voxomap::ArraySuperContainer::findVoxel
VoxelData const * findVoxel(Iterator &it) const
Find voxel.
voxomap::ArraySuperContainer::findContainer
Container const * findContainer(uint8_t x, uint8_t y, uint8_t z) const
Find sub-container.
voxomap::ArraySuperContainer::~ArraySuperContainer
~ArraySuperContainer()=default
Default destructor.
voxomap::ArraySuperContainer::putVoxel
void putVoxel(Iterator &it, Args &&... args)
Add or update a voxel.
voxomap::ArraySuperContainer::addVoxel
bool addVoxel(Iterator &it, Args &&... args)
Add a voxel, don't update an existing voxel.
voxomap::ArraySuperContainer::NB_SUPERCONTAINER
static const uint32_t NB_SUPERCONTAINER
Definition: ArraySuperContainer.hpp:42
voxomap::ArraySuperContainer::init
void init(VoxelNode< ArraySuperContainer< Container >> const &)
Initialization method, do nothing.
Definition: ArraySuperContainer.hpp:66
voxomap::ArraySuperContainer::Container
T_Container Container
Definition: ArraySuperContainer.hpp:32
voxomap::ArraySuperContainer::getNbVoxel
uint32_t getNbVoxel() const
Returns number of voxels.
voxomap::ArraySuperContainer::ArraySuperContainer
ArraySuperContainer()=default
Default constructor.
voxomap::ArraySuperContainer::COORD_MASK
static const uint32_t COORD_MASK
Definition: ArraySuperContainer.hpp:40
voxomap::ArraySuperContainer::exploreVoxelContainer
void exploreVoxelContainer(std::function< void(typename Container::VoxelContainer const &)> const &predicate) const
voxomap::ArraySuperContainer::updateVoxel
bool updateVoxel(Iterator &it, Args &&... args)
Update an existing voxel, don't create a new one.
voxomap::ArraySuperContainer::_containerArray
std::unique_ptr< Container > _containerArray[NB_CONTAINERS][NB_CONTAINERS][NB_CONTAINERS]
Array of voxel containers.
Definition: ArraySuperContainer.hpp:180
voxomap::VoxelNode
Node optimized for voxel.
Definition: VoxelNode.hpp:14
voxomap::ArraySuperContainer::NB_VOXELS
static const uint32_t NB_VOXELS
Definition: ArraySuperContainer.hpp:39
voxomap::ArraySuperContainer::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::ArraySuperContainer::hasContainer
bool hasContainer(uint8_t x) const
Check if there is sub-container.
voxomap::ArraySuperContainer::ArraySuperContainer
ArraySuperContainer(ArraySuperContainer const &other)
Copy constructor.
voxomap::ArraySuperContainer::VoxelData
typename Container::VoxelData VoxelData
Definition: ArraySuperContainer.hpp:33
voxomap::supercontainer_iterator
Definition: iterator.hpp:112
voxomap::ArraySuperContainer::findContainer
Container * findContainer(uint8_t x, uint8_t y, uint8_t z)
Find sub-container.
voxomap::ArraySuperContainer::NB_CONTAINERS
static const uint32_t NB_CONTAINERS
Definition: ArraySuperContainer.hpp:37
voxomap::ArraySuperContainer::VOXEL_MASK
static const uint32_t VOXEL_MASK
Definition: ArraySuperContainer.hpp:41
voxomap::ArraySuperContainer::CONTAINER_MASK
static const uint32_t CONTAINER_MASK
Definition: ArraySuperContainer.hpp:38
voxomap::ArraySuperContainer::findVoxel
VoxelData * findVoxel(Iterator &it)
Find voxel.
voxomap::ArraySuperContainer::_nbVoxels
uint32_t _nbVoxels
Number of voxels.
Definition: ArraySuperContainer.hpp:181
voxomap::ArraySuperContainer::removeVoxel
bool removeVoxel(Iterator const &it, Args &&... args)
Remove an existing voxel.
voxomap::ArraySuperContainer
Super container used in leaves of the VoxelOctree. Based on a fixed size 3D array,...
Definition: ArraySuperContainer.hpp:31
voxomap::ArraySuperContainer::ArraySuperContainer
ArraySuperContainer(ArraySuperContainer &&other)=default
Default move constructor.
voxomap::ArraySuperContainer::SUPERCONTAINER_ID
static const uint32_t SUPERCONTAINER_ID
Definition: ArraySuperContainer.hpp:43
voxomap::ArraySuperContainer::hasContainer
bool hasContainer(uint8_t x, uint8_t y) const
Check if there is sub-container.
voxomap::ArraySuperContainer::VoxelContainer
typename Container::VoxelContainer VoxelContainer
Definition: ArraySuperContainer.hpp:34