RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
table.h
1//
2// Created by RainSure on 2023/11/11.
3//
4
5#ifndef RSMESH_TABLE_H
6#define RSMESH_TABLE_H
7
8#include <iostream>
9#include <fstream>
10#include <vector>
11#include <numeric>
12#include "Eigen/Core"
13#include "types.h"
14#include "numeric/roundtrip_string.h"
15#include "boost/algorithm/string.hpp"
16
21namespace rsmesh {
22 using tabled = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
23
24 inline tabled read_table(const std::string& filename, const char* delimiters = " \t,") {
25 std::ifstream ifs(filename);
26 if(!ifs) {
27 throw std::runtime_error("Failed to open file '" + filename + "'.");
28 }
29
30 std::vector<double> buffer;
31 std::string line;
32
33 auto n_cols = index_t{0};
34 auto line_no = 0;
35
36 while(std::getline(ifs, line)) {
37 line_no ++;
38
39 if (boost::starts_with(line, "#")) {
40 continue;
41 }
42
43 std::vector<std::string> row;
44 boost::split(row, line, boost::is_any_of(delimiters));
45
46 auto row_size = static_cast<index_t>(row.size());
47
48 if(n_cols == 0) {
49 n_cols = row_size;
50 } else if(row_size != n_cols) {
51 std::cerr << "Skipping line " << line_no << " with a different number of columns." << std::endl;
52 continue;
53 }
54
55 for(const auto& cell : row) {
56 buffer.push_back(numeric::to_double(boost::trim_copy(cell)));
57 }
58 }
59
60 if(n_cols == 0) {
61 throw std::runtime_error("File '" + filename + "' is empty.");
62 }
63
64 auto n_rows = static_cast<index_t>(buffer.size()) / n_cols;
65 return tabled::Map(buffer.data(), n_rows, n_cols);
66 }
67
68 template<class Derived>
69 void write_table(const std::string& filename, const Eigen::MatrixBase<Derived>& table, char delimiter = ' ') {
70 std::ofstream ofs(filename);
71 if(!ofs) {
72 throw std::runtime_error("Failed to open file '" + filename + "'.");
73 }
74
75 auto n_cols = table.cols();
76 for(auto row : table.rowwise()) {
77 for(index_t i = 0; i < n_cols; i ++) {
78 ofs << numeric::to_string(row(i));
79 if(i != n_cols - 1) {
80 ofs << delimiter;
81 }
82 }
83 ofs << "\n";
84 }
85 }
86}
87
88
89#endif //RSMESH_TABLE_H
本系统的主命名空间,包含了common, examples, fmm, geometry, numeric, point_cloud等子命名空间