cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
pfh_extractor.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cmath>
5#include <vector>
6
7#include <cpp-toolbox/cpp-toolbox_export.hpp>
12
13namespace toolbox::pcl
14{
15
23template<typename DataType>
24struct pfh_signature_t : public base_signature_t<DataType, pfh_signature_t<DataType>>
25{
26 using value_type = DataType; // 为了兼容KNN接口 / For KNN interface compatibility
27 static constexpr std::size_t HISTOGRAM_SIZE = 125; // 5 � 5 � 5
28 std::array<DataType, HISTOGRAM_SIZE> histogram {};
29
30 // 提供data()和size()方法以兼容IMetric接口 / Provide data() and size() for IMetric compatibility
31 const DataType* data() const { return histogram.data(); }
32 DataType* data() { return histogram.data(); }
33 constexpr std::size_t size() const { return HISTOGRAM_SIZE; }
34
35 DataType distance_impl(const pfh_signature_t& other) const
36 {
37 DataType dist = 0;
38 for (std::size_t i = 0; i < HISTOGRAM_SIZE; ++i) {
39 DataType diff = histogram[i] - other.histogram[i];
40 dist += diff * diff;
41 }
42 return std::sqrt(dist);
43 }
44};
45
83template<typename DataType,
84 typename KNN = kdtree_generic_t<point_t<DataType>, toolbox::metrics::L2Metric<DataType>>>
85class CPP_TOOLBOX_EXPORT pfh_extractor_t
86 : public base_descriptor_extractor_t<pfh_extractor_t<DataType, KNN>,
87 DataType,
88 pfh_signature_t<DataType>>
89{
90public:
92 DataType,
94 using data_type = DataType;
96 using knn_type = KNN;
98 using point_cloud_ptr = std::shared_ptr<point_cloud>;
99
100 pfh_extractor_t() = default;
101
105 std::size_t set_input(const point_cloud& cloud);
106 std::size_t set_input(const point_cloud_ptr& cloud);
107
111 std::size_t set_knn(const knn_type& knn);
112
116 std::size_t set_search_radius(data_type radius);
117
121 std::size_t set_num_neighbors(std::size_t num_neighbors);
122
127 void set_normals(const point_cloud_ptr& normals);
128
132 void set_num_subdivisions(std::size_t subdivisions);
133
137 void enable_parallel_impl(bool enable);
138
142 void compute_impl(const point_cloud& cloud,
143 const std::vector<std::size_t>& keypoint_indices,
144 std::vector<signature_type>& descriptors) const;
145
146 void compute_impl(
147 const point_cloud& cloud,
148 const std::vector<std::size_t>& keypoint_indices,
149 std::unique_ptr<std::vector<signature_type>>& descriptors) const;
150
151private:
152 void compute_pfh_feature(const point_cloud& cloud,
153 const point_cloud& normals,
154 std::size_t index,
155 const std::vector<std::size_t>& neighbor_indices,
156 signature_type& pfh) const;
157
158 void compute_pair_features(const point_t<data_type>& p1,
159 const point_t<data_type>& n1,
160 const point_t<data_type>& p2,
161 const point_t<data_type>& n2,
162 data_type& f1,
163 data_type& f2,
164 data_type& f3,
165 data_type& f4) const;
166
167 std::size_t compute_feature_bin_index(data_type f1,
168 data_type f2,
169 data_type f3,
170 data_type f4) const;
171
172 bool m_enable_parallel = false;
173 data_type m_search_radius = 0.05;
174 std::size_t m_num_neighbors = 30;
175 std::size_t m_num_subdivisions = 5;
176 point_cloud_ptr m_cloud;
177 point_cloud_ptr m_normals;
178 knn_type* m_knn = nullptr;
179};
180
181} // namespace toolbox::pcl
182
Definition vector_metrics.hpp:18
描述子提取器的基类(CRTP模式) / Base class for descriptor extractors (CRTP pattern)
Definition base_descriptor_extractor.hpp:91
PFH (Point Feature Histogram) descriptor extractor.
Definition pfh_extractor.hpp:89
KNN knn_type
Definition pfh_extractor.hpp:96
std::shared_ptr< point_cloud > point_cloud_ptr
Definition pfh_extractor.hpp:98
DataType data_type
Definition pfh_extractor.hpp:94
Definition base_correspondence_generator.hpp:18
描述子签名的基类 / Base class for descriptor signatures
Definition base_descriptor_extractor.hpp:38
PFH (Point Feature Histogram) signature.
Definition pfh_extractor.hpp:25
DataType value_type
Definition pfh_extractor.hpp:26
const DataType * data() const
Definition pfh_extractor.hpp:31
static constexpr std::size_t HISTOGRAM_SIZE
Definition pfh_extractor.hpp:27
std::array< DataType, HISTOGRAM_SIZE > histogram
Definition pfh_extractor.hpp:28
DataType * data()
Definition pfh_extractor.hpp:32
DataType distance_impl(const pfh_signature_t &other) const
Definition pfh_extractor.hpp:35
constexpr std::size_t size() const
Definition pfh_extractor.hpp:33
3D点/向量模板类 / A 3D point/vector template class
Definition point.hpp:48