RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
sdf_data_generator.cpp
1//
2// Created by RainSure on 2023/11/8.
3//
4
5#include "point_cloud/sdf_data_generator.h"
6#include "point_cloud/kdtree.h"
7
8namespace rsmesh {
9 namespace point_cloud {
10 sdf_data_generator::sdf_data_generator(const geometry::points3d &points, const geometry::vectors3d &normals,
11 double min_distance, double max_distance, double multiplication) {
12 if(normals.rows() != points.rows()) {
13 throw std::invalid_argument("normals.rows() must be equal to points.rows()");
14 }
15
16 if(min_distance > max_distance) {
17 throw std::invalid_argument("min_distance must be less than or equal to max_distance");
18 }
19
20 if(multiplication <= 1.0 || multiplication > 3.0) {
21 throw std::invalid_argument("multiplication must be within the range (1.0, 3.0]");
22 }
23
24 kdtree tree(points, true);
25
26 auto n_points = points.rows();
27 auto n_reduced_points =
28 static_cast<index_t>(((multiplication - 1.0) / 2.0 * static_cast<double>(n_points)));
29
30 auto n_max_sdf_points = n_points + 2 * n_reduced_points;
31 auto n_sdf_points = n_points;
32
33 sdf_points_ = geometry::points3d(n_max_sdf_points, 3);
34 sdf_points_.topRows(n_points) = points;
35 sdf_values_ = valuesd::Zero(n_max_sdf_points);
36
37 for(auto sign : {1.0, -1.0}) {
38 for(index_t i = 0; i < n_reduced_points; i ++) {
39 auto p = points.row(i);
40 auto n = normals.row(i);
41
42 if(n == geometry::vector3d::Zero()) {
43 continue;
44 }
45
46 auto d = max_distance;
47 geometry::point3d q = p + sign * d * n;
48
49 auto [nn_indices, nn_distances] = tree.knn_search(q, 1);
50 auto i_nearest = nn_indices.at(0);
51
52 while(i_nearest != i) {
53 auto p_nearest = points.row(i_nearest);
54 auto r = (p_nearest - p).norm() / 2.0;
55 auto cos = (q - p).normalized().dot((p_nearest - p).normalized());
56
57 d = 0.99 * r / cos;
58 q = p + sign * d * n;
59
60 if(d < min_distance) break;
61 std::tie(nn_indices, nn_distances) = tree.knn_search(q, 1);
62 i_nearest = nn_indices.at(0);
63 }
64
65 if(d < min_distance) {
66 continue;
67 }
68
69 sdf_points_.row(n_sdf_points) = q;
70 sdf_values_(n_sdf_points) = sign * d;
71 n_sdf_points ++;
72 }
73 }
74
75 sdf_points_.conservativeResize(n_sdf_points, 3);
76 sdf_values_.conservativeResize(n_sdf_points);
77 }
78
79 const geometry::points3d &sdf_data_generator::sdf_points() const {
80 return sdf_points_;
81 }
82
83 const valuesd &sdf_data_generator::sdf_values() const {
84 return sdf_values_;
85 }
86 } // rsmesh
87} // point_cloud
Eigen::Matrix< double, Eigen::Dynamic, 3, Eigen::RowMajor > vectors3d
3维向量的集合
Definition point3d.h:44
vectors3d points3d
3维点的集合
Definition point3d.h:48
vector3d point3d
3维点
Definition point3d.h:39
本系统的主命名空间,包含了common, examples, fmm, geometry, numeric, point_cloud等子命名空间