Voxomap
A C++11 voxel container.
SidedContainer.hpp
Go to the documentation of this file.
1 #ifndef _VOXOMAP_SIDEDCONTAINER_HPP_
2 #define _VOXOMAP_SIDEDCONTAINER_HPP_
3 
4 #include <cstdint>
5 #include <utility>
6 #include <type_traits>
7 #include "../VoxelNode.hpp"
8 #include "../iterator.hpp"
9 
10 namespace voxomap
11 {
12 
23 enum SideEnum : uint8_t
24 {
25  XPOS = 1,
26  XNEG = 2,
27  YPOS = 4,
28  YNEG = 8,
29  ZPOS = 16,
30  ZNEG = 32,
31  ALL = XPOS | XNEG | YPOS | YNEG | ZPOS | ZNEG
32 };
33 
42 template <class T_Voxel>
43 struct SidedVoxel : T_Voxel
44 {
48  SidedVoxel() = default;
52  template <typename T, typename = typename std::enable_if<!std::is_class<T>::value, int>::type>
53  SidedVoxel(T arg);
57  template <typename T, typename = typename std::enable_if<std::is_class<T>::value, int>::type>
58  SidedVoxel(T const& arg);
62  template <typename T, typename U, typename... Args>
63  SidedVoxel(T&& arg_1, U&& arg_2, Args&&... args);
67  SidedVoxel(SidedVoxel const& other) = default;
71  SidedVoxel(SidedVoxel&& other) = default;
77  template <typename... Args>
78  SidedVoxel(SideEnum side, Args&&... args);
79 
83  SidedVoxel& operator=(SidedVoxel const& other) = default;
87  SidedVoxel& operator=(SidedVoxel&& other) = default;
88 
89  operator bool() const;
93  bool operator==(SidedVoxel const& other) const;
97  bool operator!=(SidedVoxel const& other) const;
101  bool operator==(T_Voxel const& other) const;
105  bool operator!=(T_Voxel const& other) const;
109  bool operator==(uint8_t s) const;
113  bool operator!=(uint8_t s) const;
117  uint8_t operator&(uint8_t s) const;
121  uint8_t operator|(uint8_t s) const;
125  uint8_t operator&(SideEnum s) const;
129  uint8_t operator|(SideEnum s) const;
134  SidedVoxel& operator&=(uint8_t s);
139  SidedVoxel& operator|=(uint8_t s);
143  uint8_t getSide() const;
144 
145 private:
146  uint8_t _voxel_side = 0;
147 };
148 
154 template <template <class...> class T_Container, class T_Voxel>
155 struct SidedContainer : public T_Container<SidedVoxel<T_Voxel>>
156 {
160 
161  const static uint32_t NB_VOXELS = T_Container<VoxelData>::NB_VOXELS;
162  const static uint32_t COORD_MASK = ~(NB_VOXELS - 1);
163  const static uint32_t VOXEL_MASK = NB_VOXELS - 1;
164  const static uint32_t NB_SUPERCONTAINER = 0;
165 
169  SidedContainer() = default;
173  SidedContainer(SidedContainer const& other) = default;
177  SidedContainer(SidedContainer&& other) = default;
178 
186  inline uint16_t getNbSide() const;
187 
194  template <typename Iterator, typename... Args>
195  bool addVoxel(Iterator& it, Args&&... args);
202  template <typename Iterator, typename... Args>
203  bool updateVoxel(Iterator& it, Args&&... args);
209  template <typename Iterator, typename... Args>
210  void putVoxel(Iterator& it, Args&&... args);
217  template <typename Iterator>
218  bool removeVoxel(Iterator const& it, VoxelData* voxel = nullptr);
219 
220  void exploreVoxelContainer(std::function<void(SidedContainer const&)> const& predicate) const;
221 
226  void serialize(std::string& str) const;
233  size_t unserialize(char const* str, size_t size);
234 
235 private:
236  // Side management
237  template <typename Iterator>
238  void addSide(Iterator const& it);
239  template <typename Iterator>
240  void removeSide(Iterator const& it);
241  template <typename Iterator>
242  void updateSide(Iterator const& it);
243  template <class Iterator> friend void addSide(Iterator const& otherIt, SideEnum side);
244  template <class Iterator> friend void removeSide(Iterator const& currentIt, Iterator const& otherIt, SideEnum s1, SideEnum s2);
245  template <class Iterator> friend void updateSide(Iterator const& currentIt, Iterator const& otherIt, SideEnum s1, SideEnum s2);
246 
247  uint16_t _nbSides = 0;
248 };
249 
250 }
251 
252 #include "SidedContainer.ipp"
253 
254 #endif // _VOXOMAP_SidedContainer_HPP_
voxomap::SidedContainer::NB_VOXELS
static const uint32_t NB_VOXELS
Definition: SidedContainer.hpp:161
voxomap::SidedContainer::getNbSide
uint16_t getNbSide() const
Returns number of sides.
voxomap::SidedVoxel::operator&
uint8_t operator&(uint8_t s) const
Returns AND of internal side with s.
voxomap::SidedContainer::updateVoxel
bool updateVoxel(Iterator &it, Args &&... args)
Update an existing voxel, don't create a new one.
voxomap::SidedVoxel::SidedVoxel
SidedVoxel(T arg)
Constructor with one argument forward to Voxel constructor.
voxomap::SidedVoxel::getSide
uint8_t getSide() const
Returns internal side.
voxomap::SidedVoxel::operator|
uint8_t operator|(SideEnum s) const
Returns OR of internal side with s.
voxomap
Definition: Node.hpp:8
voxomap::SidedContainer::addVoxel
bool addVoxel(Iterator &it, Args &&... args)
Add a voxel, don't update an existing voxel.
voxomap::SidedVoxel::SidedVoxel
SidedVoxel(SidedVoxel &&other)=default
Move constructor.
voxomap::SidedVoxel::_voxel_side
uint8_t _voxel_side
Definition: SidedContainer.hpp:146
voxomap::SidedVoxel::operator|=
SidedVoxel & operator|=(uint8_t s)
Apply OR.
voxomap::SidedContainer::init
void init(VoxelNode< SidedContainer > const &)
Initialization method, do nothing.
Definition: SidedContainer.hpp:182
voxomap::SidedVoxel::operator=
SidedVoxel & operator=(SidedVoxel const &other)=default
Default assignement operator.
voxomap::container_iterator
Definition: iterator.hpp:21
voxomap::ALL
@ ALL
All side enum.
Definition: SidedContainer.hpp:31
voxomap::SidedContainer::SidedContainer
SidedContainer()=default
Default constructor.
voxomap::SidedVoxel::operator!=
bool operator!=(uint8_t s) const
True if the side of this is different to s.
voxomap::SidedContainer::putVoxel
void putVoxel(Iterator &it, Args &&... args)
Add or update a voxel.
voxomap::SideEnum
SideEnum
List of the voxel sides.
Definition: SidedContainer.hpp:24
voxomap::ZNEG
@ ZNEG
z - 1 of the voxel
Definition: SidedContainer.hpp:30
voxomap::SidedContainer::VOXEL_MASK
static const uint32_t VOXEL_MASK
Definition: SidedContainer.hpp:163
voxomap::SidedContainer::SidedContainer
SidedContainer(SidedContainer &&other)=default
Default move constructor.
voxomap::SidedVoxel::SidedVoxel
SidedVoxel(T const &arg)
Constructor with one argument forward to Voxel constructor.
voxomap::SidedVoxel::operator!=
bool operator!=(SidedVoxel const &other) const
Call the T_Voxel method operator!=.
voxomap::YPOS
@ YPOS
y + 1 of the voxel
Definition: SidedContainer.hpp:27
voxomap::SidedContainer::updateSide
void updateSide(Iterator const &it)
voxomap::YNEG
@ YNEG
y - 1 of the voxel
Definition: SidedContainer.hpp:28
voxomap::SidedVoxel::SidedVoxel
SidedVoxel(T &&arg_1, U &&arg_2, Args &&... args)
Constructor with arguments forward to Voxel constructor.
voxomap::SidedContainer::removeSide
friend void removeSide(Iterator const &currentIt, Iterator const &otherIt, SideEnum s1, SideEnum s2)
voxomap::SidedVoxel::operator&
uint8_t operator&(SideEnum s) const
Returns AND of internal side with s.
voxomap::SidedVoxel::operator==
bool operator==(uint8_t s) const
True if the side of this is equal to s.
voxomap::SidedVoxel::SidedVoxel
SidedVoxel(SidedVoxel const &other)=default
Copy constructor.
voxomap::SidedContainer::serialize
void serialize(std::string &str) const
Serialize the structure.
voxomap::VoxelNode
Node optimized for voxel.
Definition: VoxelNode.hpp:14
voxomap::SidedContainer::SidedContainer
SidedContainer(SidedContainer const &other)=default
Default copy constructor.
voxomap::XPOS
@ XPOS
x + 1 of the voxel
Definition: SidedContainer.hpp:25
voxomap::SidedContainer::unserialize
size_t unserialize(char const *str, size_t size)
Unserialize str inside this.
voxomap::SidedContainer::removeSide
void removeSide(Iterator const &it)
voxomap::SidedVoxel::operator==
bool operator==(SidedVoxel const &other) const
Call the T_Voxel method operator==.
voxomap::SidedVoxel::SidedVoxel
SidedVoxel()=default
Default constructor.
voxomap::XNEG
@ XNEG
x - 1 of the voxel
Definition: SidedContainer.hpp:26
voxomap::SidedContainer::exploreVoxelContainer
void exploreVoxelContainer(std::function< void(SidedContainer const &)> const &predicate) const
voxomap::SidedContainer::COORD_MASK
static const uint32_t COORD_MASK
Definition: SidedContainer.hpp:162
voxomap::SidedContainer::removeVoxel
bool removeVoxel(Iterator const &it, VoxelData *voxel=nullptr)
Remove an existing voxel.
voxomap::SidedVoxel::operator==
bool operator==(T_Voxel const &other) const
Call the T_Voxel method operator==.
voxomap::SidedVoxel
Voxel with side informations Side is present if the corresponding neighbor voxel exist....
Definition: SidedContainer.hpp:44
voxomap::SidedContainer::addSide
friend void addSide(Iterator const &otherIt, SideEnum side)
voxomap::SidedContainer
Wrap a voxel container to add side features.
Definition: SidedContainer.hpp:156
voxomap::SidedContainer::NB_SUPERCONTAINER
static const uint32_t NB_SUPERCONTAINER
Definition: SidedContainer.hpp:164
voxomap::SidedContainer::addSide
void addSide(Iterator const &it)
voxomap::SidedContainer::_nbSides
uint16_t _nbSides
Definition: SidedContainer.hpp:247
voxomap::SidedVoxel::operator=
SidedVoxel & operator=(SidedVoxel &&other)=default
Default move assignement operator.
voxomap::SidedVoxel::operator|
uint8_t operator|(uint8_t s) const
Returns OR of internal side with s.
voxomap::SidedVoxel::SidedVoxel
SidedVoxel(SideEnum side, Args &&... args)
Constructor with side information.
voxomap::SidedVoxel::operator!=
bool operator!=(T_Voxel const &other) const
Call the T_Voxel method operator!=.
voxomap::SidedVoxel::operator&=
SidedVoxel & operator&=(uint8_t s)
Apply AND.
voxomap::ZPOS
@ ZPOS
z + 1 of the voxel
Definition: SidedContainer.hpp:29
voxomap::SidedContainer::updateSide
friend void updateSide(Iterator const &currentIt, Iterator const &otherIt, SideEnum s1, SideEnum s2)