RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
dense_undirected_graph.h
1//
2// Created by RainSure on 2024/2/23.
3//
4
5#ifndef RSMESH_DENSE_UNDIRECTED_GRAPH_H
6#define RSMESH_DENSE_UNDIRECTED_GRAPH_H
7
8#include "Eigen/Core"
9#include <algorithm>
10#include <stack>
11#include <stdexcept>
12#include <utility>
13#include <vector>
14#include "types.h"
15
16namespace rsmesh::isosurface {
18 public:
19 explicit dense_undirected_graph(index_t order) : m_(Eigen::MatrixXi::Zero(order, order)) {
20 if (order <= 0) {
21 throw std::invalid_argument("order must be greater than 0.");
22 }
23 }
24
25 void add_edge(index_t i, index_t j) {
26 if (i > j) {
27 std::swap(i, j);
28 }
29 m_(i, j)++;
30 }
31
32 index_t degree(index_t i) const {
33 return m_.col(i).cast<index_t>().sum() + m_.row(i).cast<index_t>().sum() - m_(i, i);
34 }
35
36 bool has_edge(index_t i, index_t j) const {
37 if (i > j) {
38 std::swap(i, j);
39 }
40 return m_(i, j) != 0;
41 }
42
43 bool is_connected() const {
44 std::vector<bool> visited(order());
45 std::stack<index_t> to_visit;
46
47 // DFS
48 to_visit.push(0);
49 while (!to_visit.empty()) {
50 auto i = to_visit.top();
51 to_visit.pop();
52
53 visited.at(i) = true;
54
55 for (index_t j = 0; j < order(); j++) {
56 if (has_edge(i, j) && !visited.at(j)) {
57 to_visit.push(j);
58 }
59 }
60 }
61
62 return std::find(visited.begin(), visited.end(), false) == visited.end();
63 }
64
65 bool is_simple() const {
66 for (index_t i = 0; i < order(); i++) {
67 if (m_(i, i) != 0) {
68 return false;
69 }
70
71 for (index_t j = i + 1; j < order(); j++) {
72 if (m_(i, j) > 1) {
73 return false;
74 }
75 }
76 }
77
78 return true;
79 }
80
81 index_t max_degree() const {
82 index_t max_degree{};
83 for (index_t i = 0; i < order(); i++) {
84 max_degree = std::max(max_degree, degree(i));
85 }
86 return max_degree;
87 }
88
89 index_t order() const { return m_.rows(); }
90
91 private:
92 Eigen::MatrixXi m_;
93 };
94}
95
96
97#endif //RSMESH_DENSE_UNDIRECTED_GRAPH_H
该命名空间下主要定义了等值面提取相关的类和函数