5#include "point_cloud/sdf_data_generator.h"
6#include "point_cloud/kdtree.h"
9 namespace point_cloud {
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()");
16 if(min_distance > max_distance) {
17 throw std::invalid_argument(
"min_distance must be less than or equal to max_distance");
20 if(multiplication <= 1.0 || multiplication > 3.0) {
21 throw std::invalid_argument(
"multiplication must be within the range (1.0, 3.0]");
24 kdtree tree(points,
true);
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)));
30 auto n_max_sdf_points = n_points + 2 * n_reduced_points;
31 auto n_sdf_points = n_points;
34 sdf_points_.topRows(n_points) = points;
35 sdf_values_ = valuesd::Zero(n_max_sdf_points);
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);
42 if(n == geometry::vector3d::Zero()) {
46 auto d = max_distance;
49 auto [nn_indices, nn_distances] = tree.knn_search(q, 1);
50 auto i_nearest = nn_indices.at(0);
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());
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);
65 if(d < min_distance) {
69 sdf_points_.row(n_sdf_points) = q;
70 sdf_values_(n_sdf_points) = sign * d;
75 sdf_points_.conservativeResize(n_sdf_points, 3);
76 sdf_values_.conservativeResize(n_sdf_points);
83 const valuesd &sdf_data_generator::sdf_values()
const {
Eigen::Matrix< double, Eigen::Dynamic, 3, Eigen::RowMajor > vectors3d
3维向量的集合
本系统的主命名空间,包含了common, examples, fmm, geometry, numeric, point_cloud等子命名空间