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