gtsam_points
Loading...
Searching...
No Matches
point_cloud.hpp
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2021 Kenji Koide (k.koide@aist.go.jp)
3
4#pragma once
5
6#include <memory>
7#include <vector>
8#include <unordered_map>
9#include <iostream>
10#include <Eigen/Core>
11#include <Eigen/Geometry>
12
13namespace gtsam_points {
14
19struct PointCloud {
20public:
21 using Ptr = std::shared_ptr<PointCloud>;
22 using ConstPtr = std::shared_ptr<const PointCloud>;
23
25 : num_points(0),
26 times(nullptr),
27 points(nullptr),
28 normals(nullptr),
29 covs(nullptr),
30 intensities(nullptr),
31 times_gpu(nullptr),
32 points_gpu(nullptr),
33 normals_gpu(nullptr),
34 covs_gpu(nullptr),
35 intensities_gpu(nullptr) {}
36 virtual ~PointCloud() {}
37
38 // Forbid copy
39 PointCloud(const PointCloud&) = delete;
40 PointCloud& operator=(PointCloud const&) = delete;
41
43 size_t size() const { return num_points; }
44
45 bool has_times() const;
46 bool has_points() const;
47 bool has_normals() const;
48 bool has_covs() const;
49 bool has_intensities() const;
50
51 bool check_times() const;
52 bool check_points() const;
53 bool check_normals() const;
54 bool check_covs() const;
55 bool check_intensities() const;
56
57 bool has_times_gpu() const;
58 bool has_points_gpu() const;
59 bool has_normals_gpu() const;
60 bool has_covs_gpu() const;
61 bool has_intensities_gpu() const;
62
63 bool check_times_gpu() const;
64 bool check_points_gpu() const;
65 bool check_normals_gpu() const;
66 bool check_covs_gpu() const;
67 bool check_intensities_gpu() const;
68
74 template <typename T>
75 const T* aux_attribute(const std::string& attrib) const {
76 const auto found = aux_attributes.find(attrib);
77 if (found == aux_attributes.end()) {
78 std::cerr << "warning: attribute " << attrib << " not found!!" << std::endl;
79 return nullptr;
80 }
81
82 if (sizeof(T) != found->second.first) {
83 std::cerr << "warning: attribute element size mismatch!! attrib:" << attrib << " size:" << found->second.first << " requested:" << sizeof(T)
84 << std::endl;
85 }
86
87 return static_cast<const T*>(found->second.second);
88 }
89
94 void save(const std::string& path) const;
95
100 void save_compact(const std::string& path) const;
101
102public:
103 size_t num_points;
104
105 double* times;
106 Eigen::Vector4d* points;
107 Eigen::Vector4d* normals;
108 Eigen::Matrix4d* covs;
109 double* intensities;
110
112 std::unordered_map<std::string, std::pair<size_t, void*>> aux_attributes;
113
114 float* times_gpu;
115 Eigen::Vector3f* points_gpu;
116 Eigen::Vector3f* normals_gpu;
117 Eigen::Matrix3f* covs_gpu;
119};
120} // namespace gtsam_points
121
122#ifndef DONT_DEFINE_FRAME_TRAITS
123#include <gtsam_points/types/frame_traits.hpp>
124
125namespace gtsam_points {
126namespace frame {
127
128template <>
130 static int size(const PointCloud& frame) { return frame.size(); }
131
132 static bool has_times(const PointCloud& frame) { return frame.has_times(); }
133 static bool has_points(const PointCloud& frame) { return frame.has_points(); }
134 static bool has_normals(const PointCloud& frame) { return frame.has_normals(); }
135 static bool has_covs(const PointCloud& frame) { return frame.has_covs(); }
136 static bool has_intensities(const PointCloud& frame) { return frame.has_intensities(); }
137
138 static double time(const PointCloud& frame, size_t i) { return frame.times[i]; }
139 static const Eigen::Vector4d& point(const PointCloud& frame, size_t i) { return frame.points[i]; }
140 static const Eigen::Vector4d& normal(const PointCloud& frame, size_t i) { return frame.normals[i]; }
141 static const Eigen::Matrix4d& cov(const PointCloud& frame, size_t i) { return frame.covs[i]; }
142 static double intensity(const PointCloud& frame, size_t i) { return frame.intensities[i]; }
143
144 static const Eigen::Vector4d* points_ptr(const PointCloud& frame) { return frame.points; }
145};
146
147} // namespace frame
148} // namespace gtsam_points
149#endif
Standard point cloud class that holds only pointers to point attributes.
Definition point_cloud.hpp:19
bool check_points_gpu() const
Warn if the point cloud doesn't have points on GPU.
void save(const std::string &path) const
Save the point cloud data.
void save_compact(const std::string &path) const
Save the point cloud data with a compact representation without unnecessary fields (e....
Eigen::Vector4d * normals
Point normals (nx, ny, nz, 0)
Definition point_cloud.hpp:107
bool check_times() const
Warn if the point cloud doesn't have times.
bool check_covs() const
Warn if the point cloud doesn't have covs.
bool has_points() const
Check if the point cloud has points.
bool check_normals_gpu() const
Warn if the point cloud doesn't have normals on GPU.
bool has_covs_gpu() const
Check if the point cloud has point covariances on GPU.
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
float * intensities_gpu
Point intensities on GPU.
Definition point_cloud.hpp:118
Eigen::Matrix3f * covs_gpu
Point covariances on GPU.
Definition point_cloud.hpp:117
bool has_normals() const
Check if the point cloud has point normals.
bool has_intensities_gpu() const
Check if the point cloud has point intensities on GPU.
Eigen::Matrix4d * covs
Point covariances cov(3, 3) = 0.
Definition point_cloud.hpp:108
Eigen::Vector3f * points_gpu
Point coordinates on GPU.
Definition point_cloud.hpp:115
bool check_intensities_gpu() const
Warn if the point cloud doesn't have intensities on GPU.
const T * aux_attribute(const std::string &attrib) const
Get the pointer to an aux attribute.
Definition point_cloud.hpp:75
size_t size() const
Number of points.
Definition point_cloud.hpp:43
bool has_intensities() const
Check if the point cloud has point intensities.
bool has_covs() const
Check if the point cloud has point covariances.
double * intensities
Point intensities.
Definition point_cloud.hpp:109
Eigen::Vector4d * points
Point coordinates (x, y, z, 1)
Definition point_cloud.hpp:106
bool has_times_gpu() const
Check if the point cloud has per-point timestamps on GPU.
bool has_times() const
Check if the point cloud has per-point timestamps.
Eigen::Vector3f * normals_gpu
Point normals on GPU.
Definition point_cloud.hpp:116
bool check_normals() const
Warn if the point cloud doesn't have normals.
bool check_covs_gpu() const
Warn if the point cloud doesn't have covs on GPU.
bool check_points() const
Warn if the point cloud doesn't have points.
bool check_times_gpu() const
Warn if the point cloud doesn't have times on GPU.
bool has_points_gpu() const
Check if the point cloud has points on GPU.
float * times_gpu
Per-point timestamp on GPU.
Definition point_cloud.hpp:114
bool has_normals_gpu() const
Check if the point cloud has point normals on GPU.
bool check_intensities() const
Warn if the point cloud doesn't have intensities.
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
Definition frame_traits.hpp:17