supereight
Loading...
Searching...
No Matches
octree.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
3 * SPDX-FileCopyrightText: 2019-2024 Smart Robotics Lab, Imperial College London, Technical University of Munich
4 * SPDX-FileCopyrightText: 2019-2021 Nils Funk
5 * SPDX-FileCopyrightText: 2019-2024 Sotiris Papatheodorou
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#ifndef SE_OCTREE_HPP
10#define SE_OCTREE_HPP
11
12#include <Eigen/Geometry>
13#include <memory>
17#include <se/map/io/mesh_io.hpp>
20
21namespace se {
22
36template<typename DataT, Res ResT = Res::Single, int BlockSize = 8>
37class Octree {
38 public:
39 typedef std::shared_ptr<Octree<DataT, ResT, BlockSize>> Ptr;
40 typedef DataT DataType;
45
50 Octree(const int size);
51
53 Octree(const Octree&) = delete;
54
56 Octree& operator=(const Octree&) = delete;
57
64
67 bool contains(const Eigen::Vector3i& voxel_coord) const;
68
71
77
79 int getSize() const;
80
82 int getMaxScale() const;
83
85 int getBlockDepth() const;
86
94 SurfaceMesh mesh(const Eigen::Affine3f& T_OV = Eigen::Affine3f::Identity(),
95 const int min_desired_scale = 0) const;
96
102 int saveMesh(const std::string& filename,
103 const Eigen::Affine3f& T_OV = Eigen::Affine3f::Identity(),
104 const int min_desired_scale = 0) const;
105
110 StructureMesh structure(const Eigen::Affine3f& T_OV = Eigen::Affine3f::Identity(),
111 const bool only_leaves = true) const;
112
118 int saveStructure(const std::string& filename,
119 const Eigen::Affine3f& T_OV = Eigen::Affine3f::Identity(),
120 const bool only_leaves = true) const;
121
136
139
142
149 const Eigen::AlignedBox3i& aabb() const;
150
159 void aabbExtend(const Eigen::Vector3i& voxel_coord, const int size);
160
161 static constexpr Field fld_ = DataT::fld_;
162 static constexpr Colour col_ = DataT::col_;
163 static constexpr Semantics sem_ = DataT::sem_;
164 static constexpr Res res_ = ResT;
166 static constexpr int block_size = BlockSize;
169
170 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
171
172 private:
173 const int size_;
174 // Allocates and deallocates memory for nodes and blocks.
176 OctantBase* const root_ptr_; // The pointer lifetime is managed by memory_pool_.
177 Eigen::AlignedBox3i aabb_;
178};
179
180} // namespace se
181
182#include "impl/octree_impl.hpp"
183
184#endif // SE_OCTREE_HPP
Definition image.hpp:19
The base class of all octants (se::Node and se::Block) in an se::Octree.
Definition octant.hpp:19
The octree data structure containing the map data.
Definition octree.hpp:37
static constexpr Res res_
Definition octree.hpp:164
Octree & operator=(const Octree &)=delete
The copy assignment operator is explicitly deleted because copying octrees is expensive.
OctreeIterator< const Octree< DataT, ResT, BlockSize > > cend() const
Octree(const int size)
Initialize an octree with an edge length of at least size voxels.
DataT DataType
Definition octree.hpp:40
std::shared_ptr< Octree< DataT, ResT, BlockSize > > Ptr
Definition octree.hpp:39
OctreeIterator< const Octree< DataT, ResT, BlockSize > > end() const
int saveMesh(const std::string &filename, const Eigen::Affine3f &T_OV=Eigen::Affine3f::Identity(), const int min_desired_scale=0) const
Save the mesh returned by se::Octree::mesh() in filename.
int getMaxScale() const
Return the maximum octree scale, that is, the scale of the root node.
bool allocate(NodeType *const parent_ptr, const int child_idx, OctantBase *&child_ptr)
Allocate a child of a node.
StructureMesh structure(const Eigen::Affine3f &T_OV=Eigen::Affine3f::Identity(), const bool only_leaves=true) const
Return a mesh of the octree structure in the octree frame in units of voxels.
const Eigen::AlignedBox3i & aabb() const
Return the axis-aligned bounding box of the octree's allocated leaves.
bool contains(const Eigen::Vector3i &voxel_coord) const
Return whether point voxel_coord with coordinates in voxels is contained in the octree.
OctreeIterator< Octree< DataT, ResT, BlockSize > > end()
OctantBase * getRoot() const
Const version of se::Octree::getRoot().
Node< DataT, ResT > NodeType
Definition octree.hpp:41
static constexpr Semantics sem_
Definition octree.hpp:163
int getSize() const
Return the edge length of the octree volume in voxels.
QuadMesh< Colour::Off, Semantics::Off > StructureMesh
Definition octree.hpp:44
int saveStructure(const std::string &filename, const Eigen::Affine3f &T_OV=Eigen::Affine3f::Identity(), const bool only_leaves=true) const
Save the mesh returned by se::Octree::structure() in filename.
void deleteChildren(NodeType *const parent_ptr)
Recursively delete all the children of parent_ptr.
int getBlockDepth() const
Return the depth blocks are allocated at.
OctreeIterator< const Octree< DataT, ResT, BlockSize > > cbegin() const
OctreeIterator< const Octree< DataT, ResT, BlockSize > > begin() const
void aabbExtend(const Eigen::Vector3i &voxel_coord, const int size)
Extend the octree allocated leaf AABB to contain the octant with coordinates in voxels voxel_coord an...
Octree(const Octree &)=delete
The copy constructor is explicitly deleted because copying octrees is expensive.
void allocateChildren(NodeType *const parent_ptr)
Allocate all the children of parent_ptr.
static constexpr Field fld_
Definition octree.hpp:161
static constexpr Colour col_
Definition octree.hpp:162
OctreeIterator< Octree< DataT, ResT, BlockSize > > begin()
SurfaceMesh mesh(const Eigen::Affine3f &T_OV=Eigen::Affine3f::Identity(), const int min_desired_scale=0) const
Return a mesh of the reconstructed surface in the octree frame in units of voxels.
Block< DataT, ResT, BlockSize > BlockType
Definition octree.hpp:42
static constexpr scale_t max_block_scale
The maximum scale of a block.
Definition octree.hpp:168
TriangleMesh< DataT::col_, DataT::sem_ > SurfaceMesh
Definition octree.hpp:43
OctantBase * getRoot()
Return a non-null pointer to the octree's root node.
static constexpr int block_size
The edge length of a block in voxels.
Definition octree.hpp:166
constexpr int size_to_scale(const int octant_size)
Return the octree scale corresponding to octant_size in voxels.
Helper wrapper to allocate and de-allocate octants in the octree.
Definition bounded_vector.hpp:14
Res
Definition setup_util.hpp:23
Field
Definition setup_util.hpp:18
Semantics
Definition setup_util.hpp:20
uint64_t scale_t
The type of the scale in the morton code.
Definition type_util.hpp:45
Colour
Definition setup_util.hpp:19