RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
surface.h
1//
2// Created by RainSure on 2024/2/23.
3//
4
5#ifndef RSMESH_SURFACE_H
6#define RSMESH_SURFACE_H
7
8#include <fstream>
9#include <stdexcept>
10#include <string>
11#include <vector>
12#include "geometry/point3d.h"
13#include "numeric/roundtrip_string.h"
14#include "types.h"
15
16namespace rsmesh::isosurface {
17 class surface {
18 public:
19 using vertices_type = geometry::points3d;
20 using face_type = Eigen::Matrix<index_t, 1, 3>;
21 using faces_type = Eigen::Matrix<index_t, Eigen::Dynamic, 3, Eigen::RowMajor>;
22
23 surface(const vertices_type& vertices, const faces_type& faces)
24 : vertices_(vertices.rows(), 3), faces_(faces.rows(), 3) {
25 std::vector<index_t> vi_map(vertices.rows(), -1);
26 face_type new_face;
27
28 auto v_it = vertices_.rowwise().begin();
29 auto f_it = faces_.rowwise().begin();
30 index_t n_vertices = 0;
31 index_t n_faces = 0;
32
33 for (auto face : faces.rowwise()) {
34 for (auto i = 0; i < 3; i++) {
35 auto& vi = vi_map.at(face(i));
36 if (vi == -1) {
37 vi = n_vertices;
38 *v_it++ = vertices.row(face(i));
39 n_vertices++;
40 }
41 new_face(i) = vi;
42 }
43 *f_it++ = new_face;
44 n_faces++;
45 }
46
47 vertices_.conservativeResize(n_vertices, 3);
48 faces_.conservativeResize(n_faces, 3);
49 }
50
51 void export_obj(const std::string& filename) const {
52 std::ofstream ofs(filename);
53 if (!ofs) {
54 throw std::runtime_error("Failed to open file '" + filename + "'.");
55 }
56
57 for (auto v : vertices_.rowwise()) {
58 ofs << "v " << numeric::to_string(v(0)) << ' ' << numeric::to_string(v(1)) << ' '
59 << numeric::to_string(v(2)) << '\n';
60 }
61
62 for (auto f : faces_.rowwise()) {
63 ofs << "f " << f(0) + 1 << ' ' << f(1) + 1 << ' ' << f(2) + 1 << '\n';
64 }
65 }
66
67 const faces_type& faces() const { return faces_; }
68
69 const vertices_type& vertices() const { return vertices_; }
70
71 private:
72 vertices_type vertices_;
73 faces_type faces_;
74 };
75} // namespace rsmesh::isosurface
76
77
78#endif //RSMESH_SURFACE_H
vectors3d points3d
3维点的集合
Definition point3d.h:48
该命名空间下主要定义了等值面提取相关的类和函数