RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
random_points.cpp
1//
2// Created by RainSure on 2023/11/3.
3//
4
5#include "point_cloud/random_points.h"
6
7#include <cmath>
8#include <stdexcept>
9
10#include "common/eigen_utility.h"
11
12namespace rsmesh {
13 namespace point_cloud {
14 geometry::points3d random_points(const geometry::cuboid3d& cuboid,
15 index_t n,
16 seed_type seed) {
17 auto size = cuboid.max() - cuboid.min();
18 if (size.minCoeff() <= 0.0)
19 throw std::invalid_argument("cuboid must have a positive volume.");
20
21 std::mt19937 gen(seed);
22 std::uniform_real_distribution<> dist(0.0, 1.0);
23
24 geometry::points3d points(n, 3);
25
26 for (auto p : common::row_range(points)) {
27 auto x = dist(gen) * size(0);
28 auto y = dist(gen) * size(1);
29 auto z = dist(gen) * size(2);
30
31 p = cuboid.min() + geometry::vector3d(x, y, z);
32 }
33
34 return points;
35 }
36
37 // See Marsaglia (1972) at:
38 // http://mathworld.wolfram.com/SpherePointPicking.html
39 geometry::points3d random_points(const geometry::sphere3d& sphere,
40 index_t n,
41 seed_type seed) {
42 if (sphere.radius() <= 0.0)
43 throw std::invalid_argument("sphere must have a positive volume.");
44
45 std::mt19937 gen(seed);
46 std::uniform_real_distribution<> dist(-1.0, 1.0);
47
48 geometry::points3d points(n, 3);
49
50 for (auto p : common::row_range(points)) {
51 double x1;
52 double x2;
53 double rsq;
54 do {
55 x1 = dist(gen);
56 x2 = dist(gen);
57 rsq = x1 * x1 + x2 * x2;
58 } while (rsq >= 1.0);
59
60 auto x = 2.0 * x1 * std::sqrt(1.0 - rsq);
61 auto y = 2.0 * x2 * std::sqrt(1.0 - rsq);
62 auto z = 1.0 - 2.0 * rsq;
63
64 p = sphere.center() + sphere.radius() * geometry::vector3d(x, y, z);
65 }
66
67 return points;
68 }
69
70 } // rsmesh
71} // point_cloud
vectors3d points3d
3维点的集合
Definition point3d.h:48
Eigen::RowVector3d vector3d
3维向量
Definition point3d.h:30
本系统的主命名空间,包含了common, examples, fmm, geometry, numeric, point_cloud等子命名空间