small_gicp
pcl_point_traits.hpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright 2024 Kenji Koide
2 // SPDX-License-Identifier: MIT
3 #pragma once
4 
5 #include <pcl/point_types.h>
6 #include <pcl/point_cloud.h>
7 
9 
10 namespace small_gicp {
11 
12 namespace traits {
13 
14 template <typename PointType>
15 struct Traits<pcl::PointCloud<PointType>> {
16  static_assert(std::is_same_v<pcl::shared_ptr<void>, std::shared_ptr<void>>, "Old PCL version detected. Please update PCL to 1.11 or later.");
17 
18  using Points = pcl::PointCloud<PointType>;
19 
20  static size_t size(const Points& points) { return points.size(); }
21  static void resize(Points& points, size_t n) { points.resize(n); }
22 
23  static bool has_points(const Points& points) { return !points.empty(); }
24  static bool has_normals(const Points& points) { return !points.empty(); }
25  static bool has_covs(const Points& points) { return !points.empty(); }
26 
27  static void set_point(Points& points, size_t i, const Eigen::Vector4d& pt) { points.at(i).getVector4fMap() = pt.template cast<float>(); }
28  static void set_normal(Points& points, size_t i, const Eigen::Vector4d& pt) { points.at(i).getNormalVector4fMap() = pt.template cast<float>(); }
29  static void set_cov(Points& points, size_t i, const Eigen::Matrix4d& cov) { points.at(i).getCovariance4fMap() = cov.template cast<float>(); }
30 
31  static Eigen::Vector4d point(const Points& points, size_t i) { return points.at(i).getVector4fMap().template cast<double>(); }
32  static Eigen::Vector4d normal(const Points& points, size_t i) { return points.at(i).getNormalVector4fMap().template cast<double>(); }
33  static Eigen::Matrix4d cov(const Points& points, size_t i) { return points.at(i).getCovariance4fMap().template cast<double>(); }
34 };
35 
36 } // namespace traits
37 
38 } // namespace small_gicp
Definition: pcl_point.hpp:7
auto cov(const T &points, size_t i)
Get i-th covariance. Only the top-left 3x3 matrix is filled, and the bottom row and the right col mus...
Definition: traits.hpp:52
Definition: flat_container.hpp:12
Point cloud.
Definition: point_cloud.hpp:15
static bool has_points(const Points &points)
Definition: pcl_point_traits.hpp:23
static Eigen::Vector4d normal(const Points &points, size_t i)
Definition: pcl_point_traits.hpp:32
static bool has_covs(const Points &points)
Definition: pcl_point_traits.hpp:25
static size_t size(const Points &points)
Definition: pcl_point_traits.hpp:20
static void resize(Points &points, size_t n)
Definition: pcl_point_traits.hpp:21
pcl::PointCloud< PointType > Points
Definition: pcl_point_traits.hpp:18
static Eigen::Vector4d point(const Points &points, size_t i)
Definition: pcl_point_traits.hpp:31
static void set_point(Points &points, size_t i, const Eigen::Vector4d &pt)
Definition: pcl_point_traits.hpp:27
static void set_cov(Points &points, size_t i, const Eigen::Matrix4d &cov)
Definition: pcl_point_traits.hpp:29
static void set_normal(Points &points, size_t i, const Eigen::Vector4d &pt)
Definition: pcl_point_traits.hpp:28
static Eigen::Matrix4d cov(const Points &points, size_t i)
Definition: pcl_point_traits.hpp:33
static bool has_normals(const Points &points)
Definition: pcl_point_traits.hpp:24
Definition: traits.hpp:13