10#include <gtsam_points/types/point_cloud.hpp>
14namespace gtsam_points {
21 using Ptr = std::shared_ptr<PointCloudCPU>;
22 using ConstPtr = std::shared_ptr<const PointCloudCPU>;
32 template <
typename T,
int D>
39 template <
typename T,
int D,
typename Alloc>
52 void add_times(
const std::vector<T>&
times) {
56 template <
typename T,
int D>
58 template <
typename T,
int D,
typename Alloc>
59 void add_points(
const std::vector<Eigen::Matrix<T, D, 1>, Alloc>&
points) {
63 template <
typename T,
int D>
65 template <
typename T,
int D,
typename Alloc>
66 void add_normals(
const std::vector<Eigen::Matrix<T, D, 1>, Alloc>&
normals) {
70 template <
typename T,
int D>
72 template <
typename T,
int D,
typename Alloc>
73 void add_covs(
const std::vector<Eigen::Matrix<T, D, D>, Alloc>&
covs) {
80 void add_intensities(
const std::vector<T>&
intensities) {
85 void add_aux_attribute(
const std::string& attrib_name,
const T* values,
int num_points) {
86 auto attributes = std::make_shared<std::vector<T>>(values, values +
num_points);
87 aux_attributes_storage[attrib_name] = attributes;
88 aux_attributes[attrib_name] = std::make_pair(
sizeof(T), attributes->data());
90 template <
typename T,
typename Alloc>
91 void add_aux_attribute(
const std::string& attrib_name,
const std::vector<T, Alloc>& values) {
92 add_aux_attribute(attrib_name, values.data(), values.size());
95 static PointCloudCPU::Ptr load(
const std::string& path);
101 std::vector<double> times_storage;
102 std::vector<Eigen::Vector4d> points_storage;
103 std::vector<Eigen::Vector4d> normals_storage;
104 std::vector<Eigen::Matrix4d> covs_storage;
105 std::vector<double> intensities_storage;
107 std::unordered_map<std::string, std::shared_ptr<void>> aux_attributes_storage;
116PointCloudCPU::Ptr sample(
const PointCloud::ConstPtr& points,
const std::vector<int>& indices);
125PointCloudCPU::Ptr random_sampling(
const PointCloud::ConstPtr& points,
const double sampling_rate, std::mt19937& mt);
136PointCloudCPU::Ptr voxelgrid_sampling(
const PointCloud::ConstPtr& points,
const double voxel_resolution,
int num_threads = 1);
151PointCloudCPU::Ptr randomgrid_sampling(
152 const PointCloud::ConstPtr& points,
153 const double voxel_resolution,
154 const double sampling_rate,
156 int num_threads = 1);
163template <
typename Func>
164PointCloudCPU::Ptr filter(
const PointCloud::ConstPtr& points,
const Func& pred) {
165 std::vector<int> indices;
166 indices.reserve(points->size());
167 for (
int i = 0; i < points->size(); i++) {
168 if (pred(points->points[i])) {
169 indices.push_back(i);
172 return sample(points, indices);
180template <
typename Func>
181PointCloudCPU::Ptr filter_by_index(
const PointCloud::ConstPtr& points,
const Func& pred) {
182 std::vector<int> indices;
183 indices.reserve(points->size());
184 for (
int i = 0; i < points->size(); i++) {
186 indices.push_back(i);
189 return sample(points, indices);
197template <
typename Compare>
198PointCloudCPU::Ptr sort(
const PointCloud::ConstPtr& points,
const Compare& comp) {
199 std::vector<int> indices(points->size());
200 std::iota(indices.begin(), indices.end(), 0);
201 std::sort(indices.begin(), indices.end(), comp);
202 return gtsam_points::sample(points, indices);
209PointCloudCPU::Ptr sort_by_time(
const PointCloud::ConstPtr& points);
218template <
typename Scalar,
int Mode>
219PointCloudCPU::Ptr transform(
const PointCloud::ConstPtr& points,
const Eigen::Transform<Scalar, 3, Mode>& transformation);
226template <
typename Scalar,
int Mode>
227void transform_inplace(PointCloud& points,
const Eigen::Transform<Scalar, 3, Mode>& transformation);
234template <
typename Scalar,
int Mode>
235void transform_inplace(PointCloud::Ptr points,
const Eigen::Transform<Scalar, 3, Mode>& transformation) {
236 transform_inplace(*points, transformation);
248find_inlier_points(
const PointCloud::ConstPtr& points,
const std::vector<int>& neighbors,
const int k,
const double std_thresh = 1.0);
258PointCloudCPU::Ptr remove_outliers(
const PointCloud::ConstPtr& points,
const std::vector<int>& neighbors,
const int k,
const double std_thresh = 1.0);
267PointCloudCPU::Ptr remove_outliers(
const PointCloud::ConstPtr& points,
const int k = 10,
const double std_thresh = 1.0,
const int num_threads = 1);
275std::vector<double> distances(
const PointCloud::ConstPtr& points,
size_t max_scan_count = std::numeric_limits<size_t>::max());
283std::pair<double, double> minmax_distance(
const PointCloud::ConstPtr& points,
size_t max_scan_count = std::numeric_limits<size_t>::max());
291double median_distance(
const PointCloud::ConstPtr& points,
size_t max_scan_count = std::numeric_limits<size_t>::max());
302merge_frames(
const std::vector<Eigen::Isometry3d>& poses,
const std::vector<PointCloud::ConstPtr>& frames,
double downsample_resolution);
305template <
typename Po
intCloudPtr>
306std::enable_if_t<!std::is_same_v<PointCloudPtr, PointCloud::ConstPtr>, PointCloud::Ptr>
307merge_frames(
const std::vector<Eigen::Isometry3d>& poses,
const std::vector<PointCloudPtr>& frames,
double downsample_resolution) {
308 std::vector<PointCloud::ConstPtr> frames_(frames.begin(), frames.end());
309 return merge_frames(poses, frames_, downsample_resolution);
321PointCloud::Ptr merge_frames_gpu(
322 const std::vector<Eigen::Isometry3d>& poses,
323 const std::vector<PointCloud::ConstPtr>& frames,
324 double downsample_resolution,
325 CUstream_st* stream = 0);
327template <
typename Po
intCloudPtr>
328std::enable_if_t<!std::is_same_v<PointCloudPtr, PointCloud::ConstPtr>, PointCloud::Ptr> merge_frames_gpu(
329 const std::vector<Eigen::Isometry3d>& poses,
330 const std::vector<PointCloudPtr>& frames,
331 double downsample_resolution,
332 CUstream_st* stream = 0) {
333 std::vector<PointCloud::ConstPtr> frames_(frames.begin(), frames.end());
334 return merge_frames_gpu(poses, frames_, downsample_resolution, stream);
346merge_frames_auto(
const std::vector<Eigen::Isometry3d>& poses,
const std::vector<PointCloud::ConstPtr>& frames,
double downsample_resolution);
348template <
typename Po
intCloudPtr>
349std::enable_if_t<!std::is_same_v<PointCloudPtr, PointCloud::ConstPtr>, PointCloud::Ptr>
350merge_frames_auto(
const std::vector<Eigen::Isometry3d>& poses,
const std::vector<PointCloud::ConstPtr>& frames,
double downsample_resolution) {
351 std::vector<PointCloud::ConstPtr> frames_(frames.begin(), frames.end());
352 return merge_frames_auto(poses, frames_, downsample_resolution);
Point cloud frame on CPU memory.
Definition point_cloud_cpu.hpp:19
size_t memory_usage() const
Memory usage in bytes.
static PointCloudCPU::Ptr clone(const PointCloud &points)
Deep copy.
PointCloudCPU(const std::vector< Eigen::Matrix< T, D, 1 >, Alloc > &points)
Constructor.
Definition point_cloud_cpu.hpp:40
PointCloudCPU(const Eigen::Matrix< T, D, 1 > *points, int num_points)
Constructor.
Standard point cloud class that holds only pointers to point attributes.
Definition point_cloud.hpp:19
Eigen::Vector4d * normals
Point normals (nx, ny, nz, 0)
Definition point_cloud.hpp:107
size_t num_points
Number of points.
Definition point_cloud.hpp:103
double * times
Per-point timestamp w.r.t. the first point (should be sorted)
Definition point_cloud.hpp:105
Eigen::Matrix4d * covs
Point covariances cov(3, 3) = 0.
Definition point_cloud.hpp:108
size_t size() const
Number of points.
Definition point_cloud.hpp:43
double * intensities
Point intensities.
Definition point_cloud.hpp:109
Eigen::Vector4d * points
Point coordinates (x, y, z, 1)
Definition point_cloud.hpp:106
std::unordered_map< std::string, std::pair< size_t, void * > > aux_attributes
Aux attributes <attribute_name, pair<element_size, data_ptr>>
Definition point_cloud.hpp:112