RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
offset_points_generator.cpp
1//
2// Created by RainSure on 2023/11/10.
3//
4
5#include "point_cloud/offset_points_generator.h"
6#include "point_cloud/kdtree.h"
7#include "types.h"
8
9namespace rsmesh {
10 namespace point_cloud {
11 offset_points_generator::offset_points_generator(const geometry::points3d &points,
12 const geometry::vectors3d &normals, double offset) :
13 offset_points_generator(points, normals, valuesd::Constant(points.rows(), offset)){}
14
15 offset_points_generator::offset_points_generator(const geometry::points3d &points,
16 const geometry::vectors3d &normals, const valuesd &offsets) {
17 if(normals.rows() != points.rows()) {
18 throw std::invalid_argument("normals.rows() must be equal to points.rows().");
19 }
20 if(offsets.size() != points.size()) {
21 throw std::invalid_argument("offsets.rows() must be equal to points.rows().");
22 }
23
24 kdtree tree(points, true);
25
26 index_t n_points = points.rows();
27 index_t n_new_points = 0;
28
29 new_points_ = geometry::points3d(n_points, 3);
30 new_normals_ = geometry::vectors3d(n_points, 3);
31
32 for (index_t i = 0; i < n_points; i++) {
33 auto p = points.row(i);
34 auto n = normals.row(i);
35
36 if (n == geometry::vector3d::Zero()) {
37 continue;
38 }
39
40 auto d = offsets(i);
41 geometry::point3d q = p + d * n;
42
43 auto [nn_indices, nn_distaces] = tree.knn_search(q, 1);
44 auto i_nearest = nn_indices.at(0);
45
46 if (i_nearest != i) {
47 continue;
48 }
49
50 new_points_.row(n_new_points) = q;
51 new_normals_.row(n_new_points) = n;
52 n_new_points ++;
53 }
54
55 new_points_.conservativeResize(n_new_points, 3);
56 new_normals_.conservativeResize(n_new_points, 3);
57 }
58
59 const geometry::points3d &offset_points_generator::new_points() const {
60 return new_points_;
61 }
62
63 const geometry::vectors3d &offset_points_generator::new_normals() const {
64 return new_normals_;
65 }
66 } // rsmesh
67} // point_cloud
Eigen::Matrix< double, Eigen::Dynamic, 3, Eigen::RowMajor > vectors3d
3维向量的集合
Definition point3d.h:44
vectors3d points3d
3维点的集合
Definition point3d.h:48
本系统的主命名空间,包含了common, examples, fmm, geometry, numeric, point_cloud等子命名空间