Voxomap
A C++11 voxel container.
ArrayContainer.hpp
Go to the documentation of this file.
1 #ifndef _VOXOMAP_ARRAYCONTAINER_HPP_
2 #define _VOXOMAP_ARRAYCONTAINER_HPP_
3 
4 #include <cstdint>
5 #include "../iterator.hpp"
6 
7 namespace voxomap
8 {
9 
16 template <class T_Container> class VoxelNode;
17 
27 template <class T_Voxel>
29 {
30  static_assert(std::is_trivially_copyable<T_Voxel>::value, "ArrayContainer only accept trivially copyable object");
31 
32  using VoxelData = T_Voxel;
35 
36  const static uint32_t NB_VOXELS = 8;
37  const static uint32_t COORD_MASK = ~(NB_VOXELS - 1);
38  const static uint32_t VOXEL_MASK = NB_VOXELS - 1;
39  const static uint32_t NB_SUPERCONTAINER = 0;
40 
52  ArrayContainer(ArrayContainer&& other) = default;
53 
61  uint16_t getNbVoxel() const;
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;
90  VoxelData* findVoxel(uint8_t x, uint8_t y, uint8_t z);
98  VoxelData const* findVoxel(uint8_t x, uint8_t y, uint8_t z) const;
104  template <typename Iterator>
105  VoxelData* findVoxel(Iterator& it);
111  template <typename Iterator>
112  VoxelData const* findVoxel(Iterator& it) const;
113 
120  template <typename Iterator, typename... Args>
121  bool addVoxel(Iterator& it, Args&&... args);
128  template <typename Iterator, typename... Args>
129  bool updateVoxel(Iterator& it, Args&&... args);
135  template <typename Iterator, typename... Args>
136  void putVoxel(Iterator& it, Args&&... args);
143  template <typename Iterator>
144  bool removeVoxel(Iterator const& it, VoxelData* voxel = nullptr);
145 
151  template <typename Iterator>
152  void exploreVoxel(Iterator& it, std::function<void(Iterator const&)> const& predicate) const;
153 
154  void exploreVoxelContainer(std::function<void(ArrayContainer const&)> const& predicate) const;
155 
160  void serialize(std::string& str) const;
167  size_t unserialize(char const* str, size_t size);
168 
169 
170 public:
171  uint16_t nbVoxels = 0;
172  union {
174  char _;
175  };
176 
177 private:
181  template <typename T>
182  typename std::enable_if<std::is_trivially_constructible<T>::value>::type copy(T const& other);
186  template <typename T>
187  typename std::enable_if<!std::is_trivially_constructible<T>::value>::type copy(T const& other);
188 
193 };
194 
195 }
196 
197 #include "ArrayContainer.ipp"
198 
199 #endif // _VOXOMAP_ARRAYCONTAINER_HPP_
voxomap::ArrayContainer::NB_VOXELS
static const uint32_t NB_VOXELS
Definition: ArrayContainer.hpp:36
voxomap::ArrayContainer::_emptyArea
static const VoxelData _emptyArea[NB_VOXELS][NB_VOXELS][NB_VOXELS]
Definition: ArrayContainer.hpp:192
voxomap
Definition: Node.hpp:8
voxomap::ArrayContainer::ArrayContainer
ArrayContainer()
Default constructor.
voxomap::ArrayContainer::putVoxel
void putVoxel(Iterator &it, Args &&... args)
Add or update a voxel.
voxomap::container_iterator
Definition: iterator.hpp:21
voxomap::ArrayContainer::getNbVoxel
uint16_t getNbVoxel() const
Returns number of voxels.
voxomap::ArrayContainer::copy
std::enable_if<!std::is_trivially_constructible< T >::value >::type copy(T const &other)
Method use to copy data when voxel is not trivially constructible.
voxomap::ArrayContainer::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::ArrayContainer::findVoxel
VoxelData * findVoxel(Iterator &it)
Find voxel.
voxomap::ArrayContainer
Voxel container used in leaves of the VoxelOctree. Based on a fixed size 3D array,...
Definition: ArrayContainer.hpp:29
voxomap::ArrayContainer::VoxelData
T_Voxel VoxelData
Definition: ArrayContainer.hpp:32
voxomap::ArrayContainer::findVoxel
VoxelData const * findVoxel(Iterator &it) const
Find voxel.
voxomap::ArrayContainer::NB_SUPERCONTAINER
static const uint32_t NB_SUPERCONTAINER
Definition: ArrayContainer.hpp:39
voxomap::ArrayContainer::init
void init(VoxelNode< ArrayContainer< VoxelData >> const &)
Initialization method, do nothing.
Definition: ArrayContainer.hpp:57
voxomap::ArrayContainer::serialize
void serialize(std::string &str) const
Serialize the structure.
voxomap::ArrayContainer::hasVoxel
bool hasVoxel(uint8_t x, uint8_t y) const
Check if there is voxel inside.
voxomap::ArrayContainer::ArrayContainer
ArrayContainer(ArrayContainer &&other)=default
Default move constructor.
voxomap::VoxelNode
Node optimized for voxel.
Definition: VoxelNode.hpp:14
voxomap::ArrayContainer::ArrayContainer
ArrayContainer(ArrayContainer const &other)
Copy constructor.
voxomap::ArrayContainer::VOXEL_MASK
static const uint32_t VOXEL_MASK
Definition: ArrayContainer.hpp:38
voxomap::ArrayContainer::findVoxel
VoxelData const * findVoxel(uint8_t x, uint8_t y, uint8_t z) const
Find voxel.
voxomap::ArrayContainer::nbVoxels
uint16_t nbVoxels
Number of voxels.
Definition: ArrayContainer.hpp:171
voxomap::ArrayContainer::copy
std::enable_if< std::is_trivially_constructible< T >::value >::type copy(T const &other)
Method use to copy data when voxel is trivially constructible.
voxomap::ArrayContainer::_
char _
Compiler hack to avoid the call of the default constructor of each VoxelData of area.
Definition: ArrayContainer.hpp:174
voxomap::ArrayContainer::findVoxel
VoxelData * findVoxel(uint8_t x, uint8_t y, uint8_t z)
Find voxel.
voxomap::ArrayContainer::exploreVoxelContainer
void exploreVoxelContainer(std::function< void(ArrayContainer const &)> const &predicate) const
voxomap::ArrayContainer::removeVoxel
bool removeVoxel(Iterator const &it, VoxelData *voxel=nullptr)
Remove an existing voxel.
voxomap::ArrayContainer::updateVoxel
bool updateVoxel(Iterator &it, Args &&... args)
Update an existing voxel, don't create a new one.
voxomap::ArrayContainer::hasVoxel
bool hasVoxel(uint8_t x, uint8_t y, uint8_t z) const
Check if voxel exist.
voxomap::ArrayContainer::hasVoxel
bool hasVoxel(uint8_t x) const
Check if there is voxel inside.
voxomap::ArrayContainer::unserialize
size_t unserialize(char const *str, size_t size)
Unserialize str inside this.
voxomap::ArrayContainer::addVoxel
bool addVoxel(Iterator &it, Args &&... args)
Add a voxel, don't update an existing voxel.
voxomap::ArrayContainer::COORD_MASK
static const uint32_t COORD_MASK
Definition: ArrayContainer.hpp:37
voxomap::ArrayContainer::area
VoxelData area[NB_VOXELS][NB_VOXELS][NB_VOXELS]
Array of voxels.
Definition: ArrayContainer.hpp:173