supereight
octree.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
3  * SPDX-FileCopyrightText: 2019-2021 Smart Robotics Lab, Imperial College London, Technical University of Munich
4  * SPDX-FileCopyrightText: 2019-2021 Nils Funk
5  * SPDX-FileCopyrightText: 2019-2021 Sotiris Papatheodorou
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef SE_OCTREE_HPP
10 #define SE_OCTREE_HPP
11 
12 #include <memory>
13 
14 #include "se/map/octant/octant.hpp"
19 
20 
21 
22 namespace se {
23 
35 template<typename DataT, Res ResT = Res::Single, int BlockSize = 8>
36 class Octree {
37  public:
38  typedef std::shared_ptr<Octree<DataT, ResT, BlockSize>> Ptr;
39 
40  typedef DataT DataType;
43 
45 
46  // Compile-time constant expressions
47  // # of voxels per side in a voxel block
48  static constexpr unsigned int block_size = BlockSize;
49  // The maximum scale of a block
50  static constexpr se::scale_t max_block_scale = math::log2_const(BlockSize);
51 
57  Octree(const int size);
58 
59  ~Octree(){};
60  Octree(const Octree&) = delete;
61  Octree& operator=(const Octree&) = delete;
62 
65 
73  inline bool contains(const Eigen::Vector3i& voxel_coord) const;
74 
81  {
82  return root_ptr_;
83  };
84 
90  inline se::OctantBase* getRoot() const
91  {
92  return root_ptr_;
93  };
94 
100  inline int getSize() const
101  {
102  return size_;
103  }
104 
110  inline int getMaxScale() const
111  {
112  return se::math::log2_const(size_);
113  }
114 
120  inline int getBlockDepth() const
121  {
122  return se::math::log2_const(size_) - se::math::log2_const(BlockSize);
123  }
124 
139  inline bool allocate(NodeType* parent_ptr,
140  const int child_idx,
141  se::OctantBase*& child_ptr);
142 
156  inline se::OctantBase* allocate(NodeType* parent_ptr, const int child_idx);
157 
169  inline bool allocateAll(NodeType* parent_ptr,
170  const int child_idx,
171  se::OctantBase*& child_ptr);
172 
184  inline se::OctantBase* allocateAll(NodeType* parent_ptr, const int child_idx);
185 
191  inline void deleteChildren(NodeType* parent_ptr);
192 
193  static constexpr se::Field fld_ = DataT::fld_;
194  static constexpr se::Colour col_ = DataT::col_;
195  static constexpr se::Semantics sem_ = DataT::sem_;
196 
197  static constexpr se::Res res_ = ResT;
198 
199  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
200 
201  private:
202  int size_;
203  se::OctantBase* root_ptr_ = nullptr;
204 
205  MemoryPool memory_pool_;
206 };
207 
208 
209 
210 template<typename DataT, Res ResT, int BlockSize>
212 
213 } // namespace se
214 
215 #include "impl/octree_impl.hpp"
216 
217 #endif // SE_OCTREE_HPP
int getSize() const
Get the size of the octree in [voxel] units.
Definition: octree.hpp:100
static constexpr se::Field fld_
Definition: octree.hpp:193
OctreeIterator< Octree< DataT, ResT, BlockSize > > end()
uint64_t scale_t
The type of the scale in the morton code.
Definition: type_util.hpp:46
bool allocateAll(NodeType *parent_ptr, const int child_idx, se::OctantBase *&child_ptr)
Allocate all of the parent node&#39;s child octants.
Res
Definition: setup_util.hpp:23
The node type of the octant.
Definition: block.hpp:18
OctreeIterator< Octree< DataT, ResT, BlockSize > > begin()
bool contains(const Eigen::Vector3i &voxel_coord) const
Verify if the voxel coordinates are contained in the octree.
Definition: iterator.hpp:101
se::BoostMemoryPool< NodeType, BlockType > MemoryPool
Definition: octree.hpp:44
~Octree()
Definition: octree.hpp:59
Colour
Definition: setup_util.hpp:19
int getMaxScale() const
Get the maximum scale of the octree.
Definition: octree.hpp:110
std::shared_ptr< Octree< DataT, ResT, BlockSize > > Ptr
Definition: octree.hpp:38
Octree(const int size)
The octree needs to be initialised during the allocation.
static constexpr se::Res res_
Definition: octree.hpp:197
static constexpr se::Semantics sem_
Definition: octree.hpp:195
static constexpr unsigned int block_size
Definition: octree.hpp:48
static constexpr se::Colour col_
Definition: octree.hpp:194
static constexpr se::scale_t max_block_scale
Definition: octree.hpp:50
Field
Definition: setup_util.hpp:18
bool allocate(NodeType *parent_ptr, const int child_idx, se::OctantBase *&child_ptr)
Allocate a node for a given parent node.
se::OctantBase * getRoot()
Get the node pointer to the root of the octree.
Definition: octree.hpp:80
The actual block used in the tree.
Definition: block.hpp:267
The octree is the memory manager of the map.
Definition: octree.hpp:36
Octree & operator=(const Octree &)=delete
Delete copy assignment operator.
Block< DataT, ResT, BlockSize > BlockType
Definition: octree.hpp:42
This class only helps to dynamic cast the octant to the right type and builds the base of nodes and b...
Definition: octant.hpp:24
Semantics
Definition: setup_util.hpp:20
DataT DataType
Definition: octree.hpp:40
Node< DataT, ResT > NodeType
Definition: octree.hpp:41
int getBlockDepth() const
Get the octree depth the blocks are allocated at.
Definition: octree.hpp:120
Helper wrapper to allocate and de-allocate octants in the octree.
Definition: colour_utils.hpp:17
constexpr int log2_const(int n)
void deleteChildren(NodeType *parent_ptr)
Recursively delete all children of a given node pointer.
se::OctantBase * getRoot() const
Get the node pointer to the root of the octree.
Definition: octree.hpp:90