RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
rbf_operator.h
1//
2// Created by RainSure on 2024/2/14.
3//
4
5#ifndef RSMESH_RBF_OPERATOR_H
6#define RSMESH_RBF_OPERATOR_H
7
8#include <memory>
9#include "common/macros.h"
10#include "fmm/fmm_symmetric_evaluator.h"
11#include "fmm/fmm_tree_height.h"
12#include "geometry/bbox3d.h"
13#include "geometry/point3d.h"
14#include "krylov/linear_operator.h"
15#include "model.h"
16#include "polynomial/monomial_basis.h"
17#include "types.h"
18#include <iostream>
19
20namespace rsmesh::interpolation {
21 template<int Order = 10>
23 rbf_operator(const model& model, const geometry::points3d& points) :
24 model_(model), n_poly_basis_(model.poly_basis_size()) {
25 auto n_points = points.rows();
26 auto bbox = geometry::bbox3d::from_points(points);
27 std::cout << n_points << std::endl;
28 a_ = std::make_unique<fmm::fmm_symmetric_evaluator<Order>>(model, fmm::fmm_tree_height(n_points), bbox);
29
30 if (n_poly_basis_ > 0) {
31 poly_basis_ = std::make_unique<polynomial::monomial_basis>(model.poly_dimension(), model.poly_degree());
32 }
33
34 set_points(points);
35 }
36
37 rbf_operator(const model& model, int tree_height, const geometry::bbox3d& bbox)
38 : model_(model), n_poly_basis_(model.poly_basis_size()),
39 a_(std::make_unique<fmm::fmm_symmetric_evaluator<Order>>(model, tree_height, bbox)){
40 if(n_poly_basis_ > 0) {
41 poly_basis_ = std::make_unique<polynomial::monomial_basis>(model.poly_dimension(), model.poly_degree());
42 }
43 }
44
45 valuesd operator()(const valuesd& weights) const override {
46 RSMESH_ASSERT(weights.rows() == size());
47
48 valuesd y = valuesd::Zero(size());
49 a_->set_weights(weights.head(n_points_));
50 y.head(n_points_) = a_->evaluate();
51
52 if(n_poly_basis_ > 0) {
53 // Add polynomial terms
54 y.head(n_points_) += pt_.transpose() * weights.tail(n_poly_basis_);
55 y.tail(n_poly_basis_) += pt_ * weights.head(n_points_);
56 }
57
58 y.head(n_points_) += weights.head(n_points_) * model_.nugget();
59 return y;
60 }
61
62 void set_points(const geometry::points3d& points) {
63 n_points_ = points.rows();
64
65 a_->set_points(points);
66 if (n_poly_basis_ > 0) {
67 pt_ = poly_basis_->evaluate(points);
68 }
69 }
70
71 [[nodiscard]] index_t size() const override {
72 return n_points_ + n_poly_basis_;
73 }
74
75
76 private:
77 const model& model_;
78 const index_t n_poly_basis_;
79
80 index_t n_points_{};
81 std::unique_ptr<fmm::fmm_symmetric_evaluator<Order>> a_;
82 std::unique_ptr<polynomial::monomial_basis> poly_basis_;
83 Eigen::MatrixXd pt_;
84 };
85} // namespace rsmesh::interpolation
86
87#endif //RSMESH_RBF_OPERATOR_H
描述了一个插值模型
Definition model.h:21
vectors3d points3d
3维点的集合
Definition point3d.h:48
该命名空间下主要定义了插值相关的类和函数