cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
shot_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>
13
14namespace toolbox::pcl
15{
16
25template<typename DataType>
26struct shot_signature_t : public base_signature_t<DataType, shot_signature_t<DataType>>
27{
28 using value_type = DataType; // 为了兼容KNN接口 / For KNN interface compatibility
29 static constexpr std::size_t HISTOGRAM_SIZE = 352; // 32 spatial � 11 angular
30 std::array<DataType, HISTOGRAM_SIZE> histogram {};
31
32 // 提供data()和size()方法以兼容IMetric接口 / Provide data() and size() for IMetric compatibility
33 const DataType* data() const { return histogram.data(); }
34 DataType* data() { return histogram.data(); }
35 constexpr std::size_t size() const { return HISTOGRAM_SIZE; }
36
37 DataType distance_impl(const shot_signature_t& other) const
38 {
39 DataType dist = 0;
40 for (std::size_t i = 0; i < HISTOGRAM_SIZE; ++i) {
41 DataType diff = histogram[i] - other.histogram[i];
42 dist += diff * diff;
43 }
44 return std::sqrt(dist);
45 }
46};
47
84template<typename DataType,
85 typename KNN = kdtree_generic_t<point_t<DataType>, toolbox::metrics::L2Metric<DataType>>>
86class CPP_TOOLBOX_EXPORT shot_extractor_t
87 : public base_descriptor_extractor_t<shot_extractor_t<DataType, KNN>,
88 DataType,
89 shot_signature_t<DataType>>
90{
91public:
93 DataType,
95 using data_type = DataType;
97 using knn_type = KNN;
99 using point_cloud_ptr = std::shared_ptr<point_cloud>;
100
101 shot_extractor_t() = default;
102
106 std::size_t set_input(const point_cloud& cloud);
107 std::size_t set_input(const point_cloud_ptr& cloud);
108
112 std::size_t set_knn(const knn_type& knn);
113
117 std::size_t set_search_radius(data_type radius);
118
122 std::size_t set_num_neighbors(std::size_t num_neighbors);
123
128 void set_normals(const point_cloud_ptr& normals);
129
133 void enable_parallel_impl(bool enable);
134
138 void compute_impl(const point_cloud& cloud,
139 const std::vector<std::size_t>& keypoint_indices,
140 std::vector<signature_type>& descriptors) const;
141
142 void compute_impl(
143 const point_cloud& cloud,
144 const std::vector<std::size_t>& keypoint_indices,
145 std::unique_ptr<std::vector<signature_type>>& descriptors) const;
146
147private:
148 struct local_rf_t
149 {
150 point_t<data_type> x_axis;
151 point_t<data_type> y_axis;
152 point_t<data_type> z_axis;
153 };
154
155 void compute_local_reference_frame(
156 const point_cloud& cloud,
157 const point_cloud& normals,
158 std::size_t index,
159 const std::vector<std::size_t>& neighbor_indices,
160 local_rf_t& lrf) const;
161
162 void compute_shot_feature(const point_cloud& cloud,
163 const point_cloud& normals,
164 std::size_t index,
165 const std::vector<std::size_t>& neighbor_indices,
166 const local_rf_t& lrf,
167 signature_type& shot) const;
168
169 void compute_weighted_covariance(const point_cloud& cloud,
170 std::size_t center_idx,
171 const std::vector<std::size_t>& indices,
172 const std::vector<data_type>& weights,
173 data_type cov[9]) const;
174
175 std::size_t compute_spatial_bin(const point_t<data_type>& point,
176 const point_t<data_type>& center,
177 const local_rf_t& lrf,
178 data_type radius) const;
179
180 std::size_t compute_angular_bin(const point_t<data_type>& normal,
181 const local_rf_t& lrf) const;
182
183 bool m_enable_parallel = false;
184 data_type m_search_radius = 0.1;
185 std::size_t m_num_neighbors = 100;
186 point_cloud_ptr m_cloud;
187 point_cloud_ptr m_normals;
188 knn_type* m_knn = nullptr;
189};
190
191} // namespace toolbox::pcl
192
Definition vector_metrics.hpp:18
描述子提取器的基类(CRTP模式) / Base class for descriptor extractors (CRTP pattern)
Definition base_descriptor_extractor.hpp:91
SHOT (Signature of Histograms of Orientations) descriptor extractor.
Definition shot_extractor.hpp:90
std::shared_ptr< point_cloud > point_cloud_ptr
Definition shot_extractor.hpp:99
DataType data_type
Definition shot_extractor.hpp:95
KNN knn_type
Definition shot_extractor.hpp:97
Definition base_correspondence_generator.hpp:18
描述子签名的基类 / Base class for descriptor signatures
Definition base_descriptor_extractor.hpp:38
SHOT (Signature of Histograms of Orientations) signature.
Definition shot_extractor.hpp:27
constexpr std::size_t size() const
Definition shot_extractor.hpp:35
DataType * data()
Definition shot_extractor.hpp:34
std::array< DataType, HISTOGRAM_SIZE > histogram
Definition shot_extractor.hpp:30
const DataType * data() const
Definition shot_extractor.hpp:33
DataType distance_impl(const shot_signature_t &other) const
Definition shot_extractor.hpp:37
DataType value_type
Definition shot_extractor.hpp:28
static constexpr std::size_t HISTOGRAM_SIZE
Definition shot_extractor.hpp:29
3D点/向量模板类 / A 3D point/vector template class
Definition point.hpp:48