PolyFEM
Loading...
Searching...
No Matches
Mesh3DStorage.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4#include <Eigen/Dense>
5#include <cassert>
6
7namespace polyfem
8{
9 namespace mesh
10 {
11 struct Vertex
12 {
13 int id;
14 std::vector<double> v;
15 std::vector<uint32_t> neighbor_vs;
16 std::vector<uint32_t> neighbor_es;
17 std::vector<uint32_t> neighbor_fs;
18 std::vector<uint32_t> neighbor_hs;
19
22 };
23 struct Edge
24 {
25 int id;
26 std::vector<uint32_t> vs;
27 std::vector<uint32_t> neighbor_fs;
28 std::vector<uint32_t> neighbor_hs;
29
32 };
33 struct Face
34 {
35 int id;
36 std::vector<uint32_t> vs;
37 std::vector<uint32_t> es;
38 std::vector<uint32_t> neighbor_hs;
41 };
42
43 struct Element
44 {
45 int id;
46 // Vertex order in the input mesh, when available. The `vs` array is
47 // reserved for the canonical ordering used by mesh navigation.
48 std::vector<uint32_t> input_vs;
49 std::vector<uint32_t> vs;
50 std::vector<uint32_t> es;
51 std::vector<uint32_t> fs;
52 std::vector<bool> fs_flag;
53 bool hex = false;
54 std::vector<double> v_in_Kernel;
55 };
56
57 enum class MeshType
58 {
59 TRI = 0,
60 QUA,
61 H_SUR,
62 TET,
63 HYB,
64 HEX
65 };
66
68 {
69 public:
71 Eigen::MatrixXd points;
72 std::vector<Vertex> vertices;
73 std::vector<Edge> edges;
74 std::vector<Face> faces;
75 std::vector<Element> elements;
76
77 Eigen::MatrixXi EV; // EV(2, ne)
78 Eigen::MatrixXi FV, FE, FH, FHi; // FV (3, nf), FE(3, nf), FH (2, nf), FHi(2, nf)
79 Eigen::MatrixXi HV, HF; // HV(4, nh), HE(6, nh), HF(4, nh)
80
81 void append(const Mesh3DStorage &other)
82 {
83 if (other.type != type)
85
86 const int n_v = points.cols();
87 const int n_e = edges.size();
88 const int n_f = faces.size();
89 const int n_c = elements.size();
90 assert(n_v == vertices.size());
91
92 assert(points.rows() == other.points.rows());
93 points.conservativeResize(points.rows(), n_v + other.points.cols());
94 points.rightCols(other.points.cols()) = other.points;
95
96 for (const auto &v : other.vertices)
97 {
98 auto tmp = v;
99 tmp.id += n_v;
100 for (auto &e : tmp.neighbor_vs)
101 e += n_v;
102
103 for (auto &e : tmp.neighbor_es)
104 e += n_e;
105
106 for (auto &e : tmp.neighbor_fs)
107 e += n_f;
108
109 for (auto &e : tmp.neighbor_hs)
110 e += n_c;
111
112 vertices.push_back(tmp);
113 }
114 assert(points.cols() == vertices.size());
115 assert(vertices.size() == n_v + other.vertices.size());
116
117 for (const auto &e : other.edges)
118 {
119 auto tmp = e;
120 tmp.id += n_e;
121 for (auto &e : tmp.vs)
122 e += n_v;
123
124 for (auto &e : tmp.neighbor_fs)
125 e += n_f;
126
127 for (auto &e : tmp.neighbor_hs)
128 e += n_c;
129
130 edges.push_back(tmp);
131 }
132 assert(edges.size() == n_e + other.edges.size());
133
134 for (const auto &f : other.faces)
135 {
136 auto tmp = f;
137 tmp.id += n_f;
138 for (auto &e : tmp.vs)
139 e += n_v;
140
141 for (auto &e : tmp.es)
142 e += n_e;
143
144 for (auto &e : tmp.neighbor_hs)
145 e += n_c;
146
147 faces.push_back(tmp);
148 }
149 assert(faces.size() == n_f + other.faces.size());
150
151 for (const auto &c : other.elements)
152 {
153 auto tmp = c;
154 tmp.id += n_c;
155 for (auto &e : tmp.input_vs)
156 e += n_v;
157 for (auto &e : tmp.vs)
158 e += n_v;
159
160 for (auto &e : tmp.es)
161 e += n_e;
162
163 for (auto &e : tmp.fs)
164 e += n_f;
165
166 elements.push_back(tmp);
167 }
168 assert(elements.size() == n_c + other.elements.size());
169 EV.resize(0, 0);
170 // assert(EV.size() == 0 || EV.rows() == other.EV.rows());
171 // EV.conservativeResize(std::max(EV.rows(), other.EV.rows()), other.EV.cols() + EV.cols());
172 // EV.rightCols(other.EV.cols()) = other.EV.array() + n_v;
173
174 // //////////////////
175 FV.resize(0, 0);
176 // assert(FV.size() == 0 || FV.rows() == other.FV.rows());
177 // FV.conservativeResize(std::max(FV.rows(), other.FV.rows()), other.FV.cols() + FV.cols());
178 // FV.rightCols(other.FV.cols()) = other.FV.array() + n_v;
179 FE.resize(0, 0);
180 // assert(FE.size() == 0 || FE.rows() == other.FE.rows());
181 // FE.conservativeResize(std::max(FE.rows(), other.FE.rows()), other.FE.cols() + FE.cols());
182 // FE.rightCols(other.FE.cols()) = other.FE.array() + n_e;
183 FH.resize(0, 0);
184 // assert(FH.size() == 0 || FH.rows() == other.FH.rows());
185 // FH.conservativeResize(std::max(FH.rows(), other.FH.rows()), other.FH.cols() + FH.cols());
186 // FH.rightCols(other.FH.cols()) = other.FH.array() + n_c;
187 FHi.resize(0, 0);
188 // assert(FHi.size() == 0 || FHi.rows() == other.FHi.rows());
189 // FHi.conservativeResize(std::max(FHi.rows(), other.FHi.rows()), other.FHi.cols() + FHi.cols());
190 // FHi.rightCols(other.FHi.cols()) = other.FHi.array();
191
192 // /////////////////
193 HV.resize(0, 0);
194 // assert(HV.size() == 0 || HV.rows() == other.HV.rows());
195 // HV.conservativeResize(std::max(HV.rows(), other.HV.rows()), other.HV.cols() + HV.cols());
196 // HV.rightCols(other.HV.cols()) = other.HV.array() + n_v;
197 HF.resize(0, 0);
198 // assert(HF.size() == 0 || HF.rows() == other.HF.rows());
199 // HF.conservativeResize(std::max(HF.rows(), other.HF.rows()), other.HF.cols() + HF.cols());
200 // HF.rightCols(other.HF.cols()) = other.HF.array() + n_f;
201 }
202 };
203
205 {
206 std::string Name;
210 Eigen::VectorXd V_Js;
211 Eigen::VectorXd H_Js;
212 Eigen::VectorXd Num_Js;
213 int32_t V_num, H_num;
214 };
215 } // namespace mesh
216} // namespace polyfem
void append(const Mesh3DStorage &other)
std::vector< Element > elements
std::vector< Vertex > vertices
std::vector< uint32_t > neighbor_hs
std::vector< uint32_t > vs
std::vector< uint32_t > neighbor_fs
std::vector< double > v_in_Kernel
std::vector< uint32_t > fs
std::vector< uint32_t > vs
std::vector< uint32_t > es
std::vector< uint32_t > input_vs
std::vector< bool > fs_flag
std::vector< uint32_t > es
std::vector< uint32_t > vs
std::vector< uint32_t > neighbor_hs
std::vector< uint32_t > neighbor_es
std::vector< uint32_t > neighbor_vs
std::vector< uint32_t > neighbor_hs
std::vector< uint32_t > neighbor_fs
std::vector< double > v