cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
custom_function_sorter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <vector>
5
6#include <cpp-toolbox/cpp-toolbox_export.hpp>
8
9namespace toolbox::pcl
10{
11
48template<typename DataType>
49class CPP_TOOLBOX_EXPORT custom_function_sorter_t
50 : public base_correspondence_sorter_t<custom_function_sorter_t<DataType>,
51 DataType>
52{
53public:
54 using base_type =
56 DataType>;
57 using typename base_type::point_cloud;
58 using typename base_type::quality_scores_t;
59
70 using quality_function_t = std::function<DataType(
71 const correspondence_t& correspondence, std::size_t index,
72 const point_cloud& source_cloud, const point_cloud& target_cloud)>;
73
79 std::function<DataType(const correspondence_t& correspondence)>;
80
83
89 {
90 m_quality_function = std::move(func);
91 m_simple_function = nullptr;
92 this->m_cached = false;
93 }
94
101 {
102 m_simple_function = std::move(func);
103 m_quality_function = nullptr;
104 this->m_cached = false;
105 }
106
111 [[nodiscard]] bool has_quality_function() const
112 {
113 return m_quality_function || m_simple_function;
114 }
115
116protected:
117 // Friend declaration to allow base class access
119 DataType>;
120
126 {
127 if (!has_quality_function()) {
129 << "错误:未设置质量函数 / Error: Quality function not set";
130 std::fill(scores.begin(), scores.end(), 0);
131 return;
132 }
133
134 const auto& corrs = *this->m_correspondences;
135
136 if (m_simple_function) {
137 // 使用简化的质量函数 / Use simplified quality function
138 for (std::size_t i = 0; i < corrs.size(); ++i) {
139 scores[i] = m_simple_function(corrs[i]);
140 }
141 } else {
142 // 使用完整的质量函数 / Use full quality function
143 const auto& src_cloud = *this->m_source_cloud;
144 const auto& tgt_cloud = *this->m_target_cloud;
145
146 for (std::size_t i = 0; i < corrs.size(); ++i) {
147 scores[i] = m_quality_function(corrs[i], i, src_cloud, tgt_cloud);
148 }
149 }
150 }
151
156 [[nodiscard]] bool validate_input_impl() const
157 {
158 // 如果使用完整的质量函数,需要点云数据 / If using full quality function,
159 // need point cloud data
160 if (m_quality_function && (!this->m_source_cloud || !this->m_target_cloud)) {
161 LOG_ERROR_S << "错误:使用完整质量函数时需要点云数据 / Error: Point "
162 "cloud data required when using full quality function";
163 return false;
164 }
165 return true;
166 }
167
172 [[nodiscard]] std::string get_sorter_name_impl() const
173 {
174 return "CustomFunction";
175 }
176
177private:
178 quality_function_t m_quality_function;
180 simple_quality_function_t
181 m_simple_function;
182};
183
184} // namespace toolbox::pcl
对应关系排序器的基类(CRTP模式) / Base class for correspondence sorters (CRTP pattern)
Definition base_correspondence_sorter.hpp:51
std::vector< DataType > quality_scores_t
Definition base_correspondence_sorter.hpp:56
自定义函数的对应关系排序器 / Custom function-based correspondence sorter
Definition custom_function_sorter.hpp:52
void set_quality_function(quality_function_t func)
设置自定义质量函数 / Set custom quality function
Definition custom_function_sorter.hpp:88
std::function< DataType(const correspondence_t &correspondence, std::size_t index, const point_cloud &source_cloud, const point_cloud &target_cloud)> quality_function_t
质量函数类型定义 / Quality function type definition
Definition custom_function_sorter.hpp:72
bool validate_input_impl() const
验证输入数据的实现 / Implementation of input validation
Definition custom_function_sorter.hpp:156
std::string get_sorter_name_impl() const
获取排序器名称实现 / Get sorter name implementation
Definition custom_function_sorter.hpp:172
void compute_quality_scores_impl(quality_scores_t &scores)
计算质量分数的实现 / Implementation of quality score computation
Definition custom_function_sorter.hpp:125
std::function< DataType(const correspondence_t &correspondence)> simple_quality_function_t
简化的质量函数类型(仅基于对应关系) / Simplified quality function type (based on correspondence only)
Definition custom_function_sorter.hpp:79
void set_simple_quality_function(simple_quality_function_t func)
设置简化的质量函数(仅基于对应关系) / Set simplified quality function (based on correspondence only)
Definition custom_function_sorter.hpp:100
#define LOG_ERROR_S
ERROR级别流式日志的宏 / Macro for ERROR level stream logging.
Definition thread_logger.hpp:1332
Definition base_correspondence_generator.hpp:18
对应关系结构体 / Correspondence structure
Definition base_correspondence_generator.hpp:27