cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
法向量提取 / Normal Extraction

Functions

template<typename T >
auto toolbox::pcl::create_normal_extractor ()
 法向量提取算法的选择指南 / Guide for choosing normal extraction algorithms
 
template<typename T >
void toolbox::pcl::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
 
template<typename T >
double toolbox::pcl::validate_normals (const toolbox::types::point_cloud_t< T > &normals)
 验证法向量的有效性 / Validate normal validity
 

Detailed Description

Function Documentation

◆ create_normal_extractor()

template<typename T >
auto toolbox::pcl::create_normal_extractor ( )
inline

法向量提取算法的选择指南 / Guide for choosing normal extraction algorithms

当前实现:

  • pca_norm_extractor_t: 基于PCA的法向量提取,最常用和稳定的方法 / PCA-based normal extraction, the most commonly used and stable method

参数选择建议 / Parameter selection recommendations:

  • 近邻数量:通常选择10-50个点,取决于点云密度和噪声水平 / Number of neighbors: typically 10-50 points, depending on point cloud density and noise level
  • 小的近邻数量:保留更多细节,但对噪声敏感 / Small number of neighbors: preserves more details but sensitive to noise
  • 大的近邻数量:更加平滑,但可能丢失细节 / Large number of neighbors: smoother but may lose details
// 根据点云特性选择参数 / Choose parameters based on point cloud characteristics
size_t num_neighbors;
if (has_high_noise) {
num_neighbors = 50; // 噪声较大时使用更多近邻 / Use more neighbors for high noise
} else if (need_fine_details) {
num_neighbors = 10; // 需要细节时使用较少近邻 / Use fewer neighbors for fine details
} else {
num_neighbors = 30; // 一般情况下的默认值 / Default value for general cases
}

创建带有默认KNN的法向量提取器 / Create normal extractor with default KNN

Template Parameters
T数据类型 / Data type
Returns
PCA法向量提取器 / PCA normal extractor
auto norm_extractor = create_normal_extractor<float>();
norm_extractor->set_input(cloud);
norm_extractor->set_num_neighbors(30);
auto normals = norm_extractor->extract();

◆ orient_normals_towards_viewpoint()

template<typename T >
void toolbox::pcl::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

确保所有法向量指向一致的方向(如朝向视点或朝外) Ensures all normals point in a consistent direction (e.g., towards viewpoint or outward)

Template Parameters
T数据类型 / Data type
Parameters
normals法向量点云 / Normal point cloud
viewpoint视点位置 / Viewpoint position
cloud原始点云 / Original point cloud
// 使法向量朝向视点 / Make normals point towards viewpoint
point_t<float> viewpoint = {0, 0, 0}; // 相机位置 / Camera position
orient_normals_towards_viewpoint(normals, viewpoint, cloud);
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
3D点/向量模板类 / A 3D point/vector template class
Definition point.hpp:48

◆ validate_normals()

template<typename T >
double toolbox::pcl::validate_normals ( const toolbox::types::point_cloud_t< T > &  normals)

验证法向量的有效性 / Validate normal validity

Template Parameters
T数据类型 / Data type
Parameters
normals法向量点云 / Normal point cloud
Returns
有效法向量的比例 / Ratio of valid normals
auto validity_ratio = validate_normals(normals);
if (validity_ratio < 0.9) {
std::cerr << "警告:只有 / Warning: Only " << validity_ratio * 100
<< "% 的法向量有效 / of normals are valid" << std::endl;
}
double validate_normals(const toolbox::types::point_cloud_t< T > &normals)
验证法向量的有效性 / Validate normal validity
Definition norm.hpp:149