RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
reconstruct_surface.h
1//
2// Created by RainSure on 2024/2/20.
3//
4
5#ifndef RSMESH_RECONSTRUCT_SURFACE_H
6#define RSMESH_RECONSTRUCT_SURFACE_H
7
8#include <optional>
9#include "table.h"
10#include "types.h"
11#include "model.h"
12#include "geometry/point3d.h"
13#include "geometry/bbox3d.h"
14#include "point_cloud/distance_filter.h"
15#include "common/utils.h"
16#include "interpolant.h"
17#include "isosurface/isosurface.h"
18#include "isosurface/rbf_field_function.h"
19
20namespace rsmesh::examples {
22 std::string input;
23 std::string output;
24 std::string rbf_name;
25 double absolute_tolerance;
27 double mesh_resolution;
28 std::vector<double> rbf_parameters;
29 geometry::linear_transformation3d aniso = geometry::linear_transformation3d::Identity();
30 double min_distance = 1e-10;
31 double nugget = 0.0;
32 int poly_degree = 0;
33 int max_iterations = 30;
34 bool inequality;
35 bool reduce;
36 };
37 void reconstruct_surface(
38 const ReconstructionParameters& params
39 ) {
40 tabled table = read_table(params.input);
41 geometry::points3d points = table(Eigen::all, {0, 1, 2});
42 valuesd values = table.col(3);
43 std::optional<valuesd> values_lb;
44 std::optional<valuesd> values_ub;
45 if(params.inequality) {
46 values_lb = table.col(4);
47 values_ub = table.col(5);
48 }
49
50 // Remove very close points;
51 point_cloud::distance_filter filter(points, params.min_distance);
52 std::tie(points, values) = filter(points, values);
53 if(params.inequality) {
54 *values_lb = filter(*values_lb);
55 *values_ub = filter(*values_ub);
56 }
57
58 // Define the model
59 auto rbf = common::make_rbf(params.rbf_name, params.rbf_parameters);
60 rbf->set_anisotropy(params.aniso);
61 model model(*rbf, 3, params.poly_degree);
62 model.set_nugget(params.nugget);
63
64 // Fit
65 interpolant interpolant(model);
66 if(params.inequality) {
67 interpolant.fit_inequality(points, values, *values_lb, *values_ub, params.absolute_tolerance, params.max_iterations);
68 } else if(params.reduce) {
69 interpolant.fit_incrementally(points, values, params.absolute_tolerance, params.max_iterations);
70 } else {
71 interpolant.fit(points, values, params.absolute_tolerance, params.max_iterations);
72 }
73
74 // Generate the isosurfaces
75 auto n_surface_points = (values.array() == 0.0).count();
76 geometry::points3d surface_points(n_surface_points, 3);
77 index_t si{};
78 for(index_t i = 0; i < points.rows(); i ++) {
79 if(values(i) == 0.0) {
80 surface_points.row(si) = points.row(i);
81 si++;
82 }
83 }
84 isosurface::isosurface isosurface(params.bbox, params.mesh_resolution);
85 isosurface::rbf_field_function field_function(interpolant);
86
87 isosurface.generate_from_seed_points(surface_points, field_function).export_obj(params.output);
88 }
89}
90
91
92#endif //RSMESH_RECONSTRUCT_SURFACE_H
examples命名空间,包含一些使用RSMesh库的示例
vectors3d points3d
3维点的集合
Definition point3d.h:48
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > linear_transformation3d
线性变换矩阵
Definition point3d.h:53