Skip to content

Commit 9befefb

Browse files
authored
sequential voxelmap accessor (#113)
* sequential voxelmap accessor * capital
1 parent 3466ea2 commit 9befefb

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

include/small_gicp/ann/incremental_voxelmap.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct VoxelInfo {
3434
/// This class supports incremental point cloud insertion and LRU-based voxel deletion that removes voxels that are not recently referenced.
3535
/// @note This class can be used as a point cloud as well as a neighbor search structure.
3636
/// @note This class can handle arbitrary number of voxels and arbitrary range of voxel coordinates (in 32-bit int range).
37+
/// @note To use this as a source point cloud for registration, use `SequentialVoxelMapAccessor`.
3738
template <typename VoxelContents>
3839
struct IncrementalVoxelMap {
3940
public:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-FileCopyrightText: Copyright 2024 Kenji Koide
2+
// SPDX-License-Identifier: MIT
3+
#pragma once
4+
5+
#include <small_gicp/points/traits.hpp>
6+
#include <small_gicp/ann/incremental_voxelmap.hpp>
7+
8+
namespace small_gicp {
9+
10+
/**
11+
* @brief A wrapper class to sequentially access points in a voxelmap (e.g., using points in a voxelmap as source point cloud for registration).
12+
* @note If the contents of the voxelmap are changed, the accessor must be recreated.
13+
* @example
14+
small_gicp::IncrementalVoxelMap<small_gicp::FlatContainerCov>::Ptr last_voxelmap = ...;
15+
small_gicp::IncrementalVoxelMap<small_gicp::FlatContainerCov>::Ptr voxelmap = ...;
16+
17+
// Create a sequential accessor
18+
const auto accessor = small_gicp::create_sequential_accessor(*voxelmap);
19+
20+
// Use the voxelmap as a source point cloud
21+
small_gicp::Registration<small_gicp::GICPFactor, small_gicp::ParallelReductionOMP> registration;
22+
auto result = registration.align(*last_voxelmap, accessor, *last_voxelmap, Eigen::Isometry3d::Identity());
23+
*/
24+
template <typename VoxelMap>
25+
class SequentialVoxelMapAccessor {
26+
public:
27+
/// @brief Constructor.
28+
/// @param voxelmap Voxelmap
29+
SequentialVoxelMapAccessor(const VoxelMap& voxelmap) : voxelmap(voxelmap), indices(traits::point_indices(voxelmap)) {}
30+
31+
/// @brief Number of points in the voxelmap.
32+
size_t size() const { return indices.size(); }
33+
34+
public:
35+
const VoxelMap& voxelmap; ///< Voxelmap
36+
const std::vector<size_t> indices; ///< Indices of points in the voxelmap
37+
};
38+
39+
/// @brief Create a sequential voxelmap accessor.
40+
template <typename VoxelMap>
41+
SequentialVoxelMapAccessor<VoxelMap> create_sequential_accessor(const VoxelMap& voxelmap) {
42+
return SequentialVoxelMapAccessor<VoxelMap>(voxelmap);
43+
}
44+
45+
template <typename VoxelMap>
46+
struct traits::Traits<SequentialVoxelMapAccessor<VoxelMap>> {
47+
static size_t size(const SequentialVoxelMapAccessor<VoxelMap>& accessor) { return accessor.size(); }
48+
49+
static bool has_points(const SequentialVoxelMapAccessor<VoxelMap>& accessor) { traits::has_points(accessor.voxelmap); }
50+
static bool has_normals(const SequentialVoxelMapAccessor<VoxelMap>& accessor) { return traits::has_normals(accessor.voxelmap); }
51+
static bool has_covs(const SequentialVoxelMapAccessor<VoxelMap>& accessor) { return traits::has_covs(accessor.voxelmap); }
52+
53+
static Eigen::Vector4d point(const SequentialVoxelMapAccessor<VoxelMap>& accessor, size_t i) { return traits::point(accessor.voxelmap, accessor.indices[i]); }
54+
static Eigen::Vector4d normal(const SequentialVoxelMapAccessor<VoxelMap>& accessor, size_t i) { return traits::normal(accessor.voxelmap, accessor.indices[i]); }
55+
static Eigen::Matrix4d cov(const SequentialVoxelMapAccessor<VoxelMap>& accessor, size_t i) { return traits::cov(accessor.voxelmap, accessor.indices[i]); }
56+
};
57+
58+
} // namespace small_gicp

0 commit comments

Comments
 (0)