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