RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
rmt_primitive_lattice.h
1//
2// Created by RainSure on 2024/2/23.
3//
4
5#ifndef RSMESH_RMT_PRIMITIVE_LATTICE_H
6#define RSMESH_RMT_PRIMITIVE_LATTICE_H
7
8#include "Eigen/Geometry"
9#include <array>
10#include <cmath>
11#include <numbers>
12#include <stdexcept>
13#include "geometry/bbox3d.h"
14#include "geometry/point3d.h"
15#include "isosurface/isosurface_types.h"
16
17namespace rsmesh::isosurface {
18 namespace detail {
19 class lattice_vectors : public std::array<geometry::vector3d, 3> {
20 using base = std::array<geometry::vector3d, 3>;
21
22 public:
24 };
25
26 class dual_lattice_vectors : public std::array<geometry::vector3d, 3> {
27 using base = std::array<geometry::vector3d, 3>;
28
29 public:
31 };
32 } // namespace detail
33 inline geometry::linear_transformation3d rotation() {
35 Eigen::AngleAxisd(-std::numbers::pi / 2.0, geometry::vector3d::UnitZ()) *
36 Eigen::AngleAxisd(-std::numbers::pi / 4.0, geometry::vector3d::UnitY()));
37 }
38
39// Primitive vectors of the body-centered cubic lattice.
40 extern const detail::lattice_vectors LatticeVectors;
41
42// Reciprocal primitive vectors of the body-centered cubic lattice.
43 extern const detail::dual_lattice_vectors DualLatticeVectors;
44
46 public:
47 rmt_primitive_lattice(const geometry::bbox3d& bbox, double resolution)
48 : a0_(resolution * LatticeVectors[0]),
49 a1_(resolution * LatticeVectors[1]),
50 a2_(resolution * LatticeVectors[2]),
51 b0_(DualLatticeVectors[0] / resolution),
52 b1_(DualLatticeVectors[1] / resolution),
53 b2_(DualLatticeVectors[2] / resolution),
54 bbox_(bbox),
55 ext_bbox_(compute_extended_bbox(bbox, resolution)),
56 resolution_(resolution) {
57 geometry::points3d ext_bbox_vertices(8, 3);
58 ext_bbox_vertices << ext_bbox_.min()(0), ext_bbox_.min()(1), ext_bbox_.min()(2),
59 ext_bbox_.max()(0), ext_bbox_.min()(1), ext_bbox_.min()(2), ext_bbox_.min()(0),
60 ext_bbox_.max()(1), ext_bbox_.min()(2), ext_bbox_.min()(0), ext_bbox_.min()(1),
61 ext_bbox_.max()(2), ext_bbox_.min()(0), ext_bbox_.max()(1), ext_bbox_.max()(2),
62 ext_bbox_.max()(0), ext_bbox_.min()(1), ext_bbox_.max()(2), ext_bbox_.max()(0),
63 ext_bbox_.max()(1), ext_bbox_.min()(2), ext_bbox_.max()(0), ext_bbox_.max()(1),
64 ext_bbox_.max()(2);
65
66 cell_vectors cvs(8, 3);
67 for (auto i = 0; i < 8; i++) {
68 cvs.row(i) = cell_vector_from_point(ext_bbox_vertices.row(i));
69 }
70
71 // Bounds of cell vectors for enumerating all nodes in the extended bbox.
72 cv_min = cvs.colwise().minCoeff().array() + 1;
73 cv_max = cvs.colwise().maxCoeff();
74 }
75
76 const geometry::bbox3d& bbox() const { return bbox_; }
77
78 geometry::point3d cell_node_point(const cell_vector& cv) const {
79 return cv(0) * a0_ + cv(1) * a1_ + cv(2) * a2_;
80 }
81
82 cell_vector cell_vector_from_point(const geometry::point3d& p) const {
83 return {static_cast<int>(std::floor(p.dot(b0_))), static_cast<int>(std::floor(p.dot(b1_))),
84 static_cast<int>(std::floor(p.dot(b2_)))};
85 }
86
87 // All nodes in the extended bbox must be evaluated
88 // to ensure that the isosurface does not have boundary in the bbox.
89 const geometry::bbox3d& extended_bbox() const { return ext_bbox_; }
90
91 double resolution() const { return resolution_; }
92
93 protected:
94 cell_vector cv_min;
95 cell_vector cv_max;
96
97 private:
98 static geometry::bbox3d compute_extended_bbox(const geometry::bbox3d& bbox, double resolution) {
99 geometry::vector3d cell_bbox_size =
100 resolution * geometry::vector3d(3.0 / std::numbers::sqrt2, 2.0, 1.0);
101 geometry::vector3d ext = 1.01 * cell_bbox_size;
102 return {bbox.min() - ext, bbox.max() + ext};
103 }
104
105 const geometry::vector3d a0_;
106 const geometry::vector3d a1_;
107 const geometry::vector3d a2_;
108 const geometry::vector3d b0_;
109 const geometry::vector3d b1_;
110 const geometry::vector3d b2_;
111 const geometry::bbox3d bbox_;
112 const geometry::bbox3d ext_bbox_;
113 const double resolution_;
114 };
115
116}
117
118#endif //RSMESH_RMT_PRIMITIVE_LATTICE_H
vectors3d points3d
3维点的集合
Definition point3d.h:48
linear_transformation3d to_linear_transformation3d(T t)
从一个变换矩阵中提取出线性变换矩阵
Definition point3d.h:63
vector3d point3d
3维点
Definition point3d.h:39
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > linear_transformation3d
线性变换矩阵
Definition point3d.h:53
Eigen::RowVector3d vector3d
3维向量
Definition point3d.h:30
该命名空间下主要定义了等值面提取相关的类和函数