RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
plane_estimator.cpp
1//
2// Created by RainSure on 2023/11/3.
3//
4
5#include "point_cloud/plane_estimator.h"
6
7#include <cmath>
8#include <limits>
9
10#include "common/macros.h"
11
12namespace rsmesh {
13 namespace point_cloud {
14 plane_estimator::plane_estimator(const geometry::points3d &points) {
15 RSMESH_ASSERT(points.rows() >= 3);
16
17 auto n_points = points.rows();
18
19 auto svd = pca_svd(points);
20 auto s0 = svd.singularValues()(0);
21 auto s1 = svd.singularValues()(1);
22 auto s2 = svd.singularValues()(2);
23
24 point_err_ = std::sqrt(s0 * s0 + s1 * s1 + s2 * s2) / std::sqrt(n_points);
25 line_err_ = std::hypot(s1, s2) / std::sqrt(n_points);
26 plane_err_ = std::abs(s2) / std::sqrt(n_points);
27
28 if(s0 == 0.0) {
29 plane_factor_ = std::numeric_limits<double>::quiet_NaN();
30 } else if(s1 == 0.0) {
31 plane_factor_ = 0.0;
32 } else if(s2 == 0.0) {
33 plane_factor_ = std::numeric_limits<double>::infinity();
34 } else {
35 plane_factor_ = line_err_ * line_err_ / (plane_err_ * point_err_);
36 }
37
38 basis_ = svd.matrixV();
39 }
40
41 double plane_estimator::line_error() const {
42 return line_err_;
43 }
44
45 double plane_estimator::plane_factor() const {
46 return plane_factor_;
47 }
48
49 geometry::vector3d plane_estimator::plane_normal() const {
50 return basis_.col(2);
51 }
52
53 double plane_estimator::plane_error() const {
54 return plane_err_;
55 }
56
57 double plane_estimator::point_error() const {
58 return point_err_;
59 }
60
61 Eigen::JacobiSVD<Eigen::MatrixXd> plane_estimator::pca_svd(const geometry::points3d &points) {
62 geometry::point3d barycenter = points.colwise().mean();
63 return Eigen::JacobiSVD<Eigen::MatrixXd>(points.rowwise() - barycenter, Eigen::ComputeThinV);
64 }
65
66 } // rsmesh
67} // point_cloud
vectors3d points3d
3维点的集合
Definition point3d.h:48
vector3d point3d
3维点
Definition point3d.h:39
Eigen::RowVector3d vector3d
3维向量
Definition point3d.h:30
本系统的主命名空间,包含了common, examples, fmm, geometry, numeric, point_cloud等子命名空间