RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
rbf_residual_evaluator.h
1//
2// Created by RainSure on 2024/2/14.
3//
4
5#ifndef RSMESH_RBF_RESIDUAL_EVALUATOR_H
6#define RSMESH_RBF_RESIDUAL_EVALUATOR_H
7
8#include "Eigen/Core"
9#include "common/macros.h"
10#include "geometry/bbox3d.h"
11#include "geometry/point3d.h"
12#include "rbf_evaluator.h"
13#include "model.h"
14#include "types.h"
15#include <cmath>
16#include <algorithm>
17#include <memory>
18#include <utility>
19
20namespace rsmesh::interpolation {
22 static constexpr index_t chunk_size = 1024;
23
24 public:
26 : model_(model),
27 n_poly_basis_(model.poly_basis_size()),
28 n_points_(points.rows()),
29 points_(points) {
30 evaluator_ = std::make_unique<rbf_evaluator<>>(model, points_);
31 }
32
33 rbf_residual_evaluator(const model& model, int tree_height, const geometry::bbox3d& bbox)
34 : model_(model), n_poly_basis_(model.poly_basis_size()) {
35 evaluator_ = std::make_unique<rbf_evaluator<>>(model, tree_height, bbox);
36 }
37
38 template <class Derived, class Derived2>
39 std::pair<bool, double> converged(const Eigen::MatrixBase<Derived>& values,
40 const Eigen::MatrixBase<Derived2>& weights,
41 double absolute_tolerance) const {
42 RSMESH_ASSERT(values.rows() == n_points_);
43 RSMESH_ASSERT(weights.rows() == n_points_ + n_poly_basis_);
44
45 evaluator_->set_weights(weights);
46
47 auto nugget = model_.nugget();
48
49 auto max_residual = 0.0;
50 for (index_t i = 0; i < n_points_ / chunk_size + 1; i++) {
51 auto begin = i * chunk_size;
52 auto end = std::min(n_points_, begin + chunk_size);
53 if (begin == end) {
54 break;
55 }
56
57 evaluator_->set_field_points(points_.middleRows(begin, end - begin));
58 valuesd fit = evaluator_->evaluate() + weights.segment(begin, end - begin) * nugget;
59
60 for (index_t j = 0; j < end - begin; j++) {
61 auto res = std::abs(values(begin + j) - fit(j));
62 if (res >= absolute_tolerance) {
63 return {false, 0.0};
64 }
65
66 max_residual = std::max(max_residual, res);
67 }
68 }
69
70 return {true, max_residual};
71 }
72
73 void set_points(const geometry::points3d& points) {
74 n_points_ = points.rows();
75 points_ = points;
76
77 evaluator_->set_source_points(points);
78 }
79
80 private:
81 const model& model_;
82 const index_t n_poly_basis_;
83
84 index_t n_points_{};
85 geometry::points3d points_;
86
87 std::unique_ptr<rbf_evaluator<>> evaluator_;
88 };
89}
90
91#endif //RSMESH_RBF_RESIDUAL_EVALUATOR_H
描述了一个插值模型
Definition model.h:21
vectors3d points3d
3维点的集合
Definition point3d.h:48
该命名空间下主要定义了插值相关的类和函数