6#include <gtsam_points/util/vector3i_hash.hpp>
7#include <gtsam_points/types/point_cloud_cpu.hpp>
8#include <gtsam_points/ann/nearest_neighbor_search.hpp>
10namespace gtsam_points {
34template <
typename VoxelContents>
37 using Ptr = std::shared_ptr<IncrementalVoxelMap>;
38 using ConstPtr = std::shared_ptr<const IncrementalVoxelMap>;
81 double max_sq_dist = std::numeric_limits<double>::max())
const override;
88 bool has_points()
const;
89 bool has_normals()
const;
90 bool has_covs()
const;
91 bool has_intensities()
const;
98 virtual std::vector<Eigen::Vector4d> voxel_points()
const;
99 virtual std::vector<Eigen::Vector4d> voxel_normals()
const;
100 virtual std::vector<Eigen::Matrix4d> voxel_covs()
const;
101 virtual std::vector<double> voxel_intensities()
const;
103 virtual PointCloudCPU::Ptr voxel_data()
const;
106 std::vector<Eigen::Vector3i> neighbor_offsets(
const int neighbor_voxel_mode)
const;
108 template <
typename Func>
109 void visit_points(
const Func& f)
const {
111 for (
int i = 0; i < frame::size(voxel->second); i++) {
118 static_assert(
sizeof(size_t) == 8,
"size_t must be 64-bit");
129 std::vector<std::shared_ptr<std::pair<VoxelInfo, VoxelContents>>>
flat_voxels;
130 std::unordered_map<Eigen::Vector3i, size_t, XORVector3iHash>
voxels;
135template <
typename VoxelContents>
137 static bool has_points(
const IncrementalVoxelMap<VoxelContents>& ivox) {
return ivox.has_points(); }
138 static bool has_normals(
const IncrementalVoxelMap<VoxelContents>& ivox) {
return ivox.has_normals(); }
139 static bool has_covs(
const IncrementalVoxelMap<VoxelContents>& ivox) {
return ivox.has_covs(); }
140 static bool has_intensities(
const IncrementalVoxelMap<VoxelContents>& ivox) {
return ivox.has_intensities(); }
142 static const Eigen::Vector4d& point(
const IncrementalVoxelMap<VoxelContents>& ivox,
size_t i) {
return ivox.point(i); }
143 static const Eigen::Vector4d& normal(
const IncrementalVoxelMap<VoxelContents>& ivox,
size_t i) {
return ivox.normal(i); }
144 static const Eigen::Matrix4d& cov(
const IncrementalVoxelMap<VoxelContents>& ivox,
size_t i) {
return ivox.cov(i); }
145 static double intensity(
const IncrementalVoxelMap<VoxelContents>& ivox,
size_t i) {
return ivox.intensity(i); }
Incremental voxelmap. This class supports incremental point cloud insertion and LRU-based voxel delet...
Definition incremental_voxelmap.hpp:35
double inv_leaf_size
Inverse of the voxel size.
Definition incremental_voxelmap.hpp:121
size_t num_voxels() const
Number of voxels in the voxelmap.
Definition incremental_voxelmap.hpp:60
size_t point_id(const size_t i) const
Extract the voxel ID from a global index.
Definition incremental_voxelmap.hpp:86
virtual void clear()
Clear the voxelmap.
Definition incremental_voxelmap_impl.hpp:24
std::vector< Eigen::Vector3i > offsets
Neighbor voxel offsets.
Definition incremental_voxelmap.hpp:122
void set_neighbor_voxel_mode(const int mode)
Neighboring voxel search mode (1, 7, 19, or 27).
Definition incremental_voxelmap.hpp:52
size_t voxel_id(const size_t i) const
Extract the point ID from a global index.
Definition incremental_voxelmap.hpp:85
VoxelContents::Setting & voxel_insertion_setting()
Voxel setting.
Definition incremental_voxelmap.hpp:54
void set_lru_horizon(const int lru_horizon)
LRU cache horizon.
Definition incremental_voxelmap.hpp:50
void set_voxel_resolution(const double leaf_size)
Voxel resolution.
Definition incremental_voxelmap.hpp:46
size_t lru_counter
LRU counter. Incremented every step.
Definition incremental_voxelmap.hpp:126
virtual void insert(const PointCloud &points)
Insert points to the voxelmap.
Definition incremental_voxelmap_impl.hpp:31
std::unordered_map< Eigen::Vector3i, size_t, XORVector3iHash > voxels
Voxel index map.
Definition incremental_voxelmap.hpp:130
static constexpr int point_id_bits
Use the first 32 bits for point id.
Definition incremental_voxelmap.hpp:119
size_t lru_horizon
LRU horizon size. Voxels that have not been accessed for lru_horizon steps are deleted.
Definition incremental_voxelmap.hpp:124
VoxelContents::Setting voxel_setting
Voxel setting.
Definition incremental_voxelmap.hpp:128
double leaf_size() const
Voxel size.
Definition incremental_voxelmap.hpp:57
size_t calc_index(const size_t voxel_id, const size_t point_id) const
Calculate the global point index from the voxel index and the point index.
Definition incremental_voxelmap.hpp:84
size_t lru_clear_cycle
LRU clear cycle. Voxel deletion is performed every lru_clear_cycle steps.
Definition incremental_voxelmap.hpp:125
void set_lru_clear_cycle(const int lru_clear_cycle)
LRU cache clearing cycle.
Definition incremental_voxelmap.hpp:48
virtual size_t knn_search(const double *pt, size_t k, size_t *k_indices, double *k_sq_dists, double max_sq_dist=std::numeric_limits< double >::max()) const override
Find k nearest neighbors.
Definition incremental_voxelmap_impl.hpp:71
std::vector< std::shared_ptr< std::pair< VoxelInfo, VoxelContents > > > flat_voxels
Voxel contents.
Definition incremental_voxelmap.hpp:129
static constexpr int voxel_id_bits
Use the remaining bits for voxel id.
Definition incremental_voxelmap.hpp:120
Nearest neighbor search interface.
Definition nearest_neighbor_search.hpp:16
Standard point cloud class that holds only pointers to point attributes.
Definition point_cloud.hpp:19
Voxel meta information.
Definition incremental_voxelmap.hpp:13
VoxelInfo()
Default constructor.
Definition incremental_voxelmap.hpp:16
Eigen::Vector3i coord
Voxel coordinate.
Definition incremental_voxelmap.hpp:25
VoxelInfo(const Eigen::Vector3i &coord, size_t lru)
Constructor.
Definition incremental_voxelmap.hpp:21
size_t lru
Last used time.
Definition incremental_voxelmap.hpp:24
Definition frame_traits.hpp:17