cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
norm.hpp
Go to the documentation of this file.
1#pragma once
2
37
38namespace toolbox::pcl
39{
40
86template<typename T>
88 return std::make_unique<pca_norm_extractor_t<T>>();
89}
90
108template<typename T>
111 const point_t<T>& viewpoint,
113{
114 for (size_t i = 0; i < normals.size(); ++i) {
115 // 计算从点到视点的向量 / Compute vector from point to viewpoint
116 T vx = viewpoint.x - cloud.points[i].x;
117 T vy = viewpoint.y - cloud.points[i].y;
118 T vz = viewpoint.z - cloud.points[i].z;
119
120 // 计算点积 / Compute dot product
121 T dot = normals.points[i].x * vx +
122 normals.points[i].y * vy +
123 normals.points[i].z * vz;
124
125 // 如果法向量背离视点,则翻转 / If normal points away from viewpoint, flip it
126 if (dot < 0) {
127 normals.points[i].x = -normals.points[i].x;
128 normals.points[i].y = -normals.points[i].y;
129 normals.points[i].z = -normals.points[i].z;
130 }
131 }
132}
133
148template<typename T>
150 size_t valid_count = 0;
151 const T epsilon = std::numeric_limits<T>::epsilon();
152
153 for (const auto& normal : normals.points) {
154 T length = std::sqrt(normal.x * normal.x +
155 normal.y * normal.y +
156 normal.z * normal.z);
157
158 // 检查是否为单位向量且不包含NaN / Check if unit vector and not NaN
159 if (std::abs(length - T(1)) < T(0.01) &&
160 !std::isnan(normal.x) &&
161 !std::isnan(normal.y) &&
162 !std::isnan(normal.z)) {
163 valid_count++;
164 }
165 }
166
167 return static_cast<double>(valid_count) / normals.size();
168}
169
// end of norm group
171
172} // namespace toolbox::pcl
包含点和相关数据的点云类 / A point cloud class containing points and associated data
Definition point.hpp:268
std::vector< point_t< T > > points
点坐标 / Point coordinates
Definition point.hpp:270
auto size() const -> std::size_t
获取点云中的点数 / Get number of points in cloud
Definition point_impl.hpp:293
void orient_normals_towards_viewpoint(toolbox::types::point_cloud_t< T > &normals, const point_t< T > &viewpoint, const toolbox::types::point_cloud_t< T > &cloud)
法向量方向一致性处理 / Normal orientation consistency processing
Definition norm.hpp:109
double validate_normals(const toolbox::types::point_cloud_t< T > &normals)
验证法向量的有效性 / Validate normal validity
Definition norm.hpp:149
auto create_normal_extractor()
法向量提取算法的选择指南 / Guide for choosing normal extraction algorithms
Definition norm.hpp:87
Definition base_correspondence_generator.hpp:18
3D点/向量模板类 / A 3D point/vector template class
Definition point.hpp:48
T x
X坐标 / X coordinate.
Definition point.hpp:51
T z
Z坐标 / Z coordinate.
Definition point.hpp:53
T y
Y坐标 / Y coordinate.
Definition point.hpp:52