diff --git a/include/gtsam_points/ann/impl/incremental_voxelmap_impl.hpp b/include/gtsam_points/ann/impl/incremental_voxelmap_impl.hpp index 53b6eb1b..45a5380a 100644 --- a/include/gtsam_points/ann/impl/incremental_voxelmap_impl.hpp +++ b/include/gtsam_points/ann/impl/incremental_voxelmap_impl.hpp @@ -20,6 +20,13 @@ IncrementalVoxelMap::IncrementalVoxelMap(double leaf_size) template IncrementalVoxelMap::~IncrementalVoxelMap() {} +template +void IncrementalVoxelMap::clear() { + lru_counter = 0; + flat_voxels.clear(); + voxels.clear(); +} + template void IncrementalVoxelMap::insert(const PointCloud& points) { // Insert points to the voxelmap @@ -184,4 +191,40 @@ std::vector IncrementalVoxelMap::voxel_intensities() cons return intensities; } +template +PointCloudCPU::Ptr IncrementalVoxelMap::voxel_data() const { + auto frame = std::make_shared(); + frame->points_storage.reserve(flat_voxels.size() * 10); + if (has_normals()) { + frame->normals_storage.reserve(flat_voxels.size() * 10); + } + if (has_covs()) { + frame->covs_storage.reserve(flat_voxels.size() * 10); + } + if (has_intensities()) { + frame->intensities_storage.reserve(flat_voxels.size() * 10); + } + + visit_points([&](const auto& voxel, const int i) { + frame->points_storage.emplace_back(frame::point(voxel, i)); + if (frame::has_normals(voxel)) { + frame->normals_storage.emplace_back(frame::normal(voxel, i)); + } + if (frame::has_covs(voxel)) { + frame->covs_storage.emplace_back(frame::cov(voxel, i)); + } + if (frame::has_intensities(voxel)) { + frame->intensities_storage.emplace_back(frame::intensity(voxel, i)); + } + }); + + frame->num_points = frame->points_storage.size(); + frame->points = frame->points_storage.data(); + frame->normals = frame->normals_storage.empty() ? nullptr : frame->normals_storage.data(); + frame->covs = frame->covs_storage.empty() ? nullptr : frame->covs_storage.data(); + frame->intensities = frame->intensities_storage.empty() ? nullptr : frame->intensities_storage.data(); + + return frame; +} + } // namespace gtsam_points diff --git a/include/gtsam_points/ann/incremental_covariance_voxelmap.hpp b/include/gtsam_points/ann/incremental_covariance_voxelmap.hpp index 156c28c7..4ace33a7 100644 --- a/include/gtsam_points/ann/incremental_covariance_voxelmap.hpp +++ b/include/gtsam_points/ann/incremental_covariance_voxelmap.hpp @@ -32,6 +32,9 @@ struct IncrementalCovarianceVoxelMap : public IncrementalVoxelMap #include -#include +#include #include namespace gtsam_points { @@ -59,6 +59,9 @@ struct IncrementalVoxelMap : public NearestNeighborSearch { /// @brief Number of voxels in the voxelmap. size_t num_voxels() const { return flat_voxels.size(); } + /// @brief Clear the voxelmap. + virtual void clear(); + /// @brief Insert points to the voxelmap. /// @param points Point cloud /// @param T Transformation matrix @@ -92,6 +95,8 @@ struct IncrementalVoxelMap : public NearestNeighborSearch { virtual std::vector voxel_covs() const; virtual std::vector voxel_intensities() const; + virtual PointCloudCPU::Ptr voxel_data() const; + protected: std::vector neighbor_offsets(const int neighbor_voxel_mode) const; diff --git a/src/gtsam_points/ann/incremental_covariance_voxelmap.cpp b/src/gtsam_points/ann/incremental_covariance_voxelmap.cpp index 6cb7d645..5f70215b 100644 --- a/src/gtsam_points/ann/incremental_covariance_voxelmap.cpp +++ b/src/gtsam_points/ann/incremental_covariance_voxelmap.cpp @@ -60,6 +60,12 @@ void IncrementalCovarianceVoxelMap::set_num_threads(int num_threads) { this->num_threads = num_threads; } +void IncrementalCovarianceVoxelMap::clear() { + IncrementalVoxelMap::clear(); + eig_stats.clear(); + eig_stats.resize(10); +} + void IncrementalCovarianceVoxelMap::insert(const PointCloud& points) { EasyProfiler prof("IncrementalCovarianceVoxelMap::insert");