-
Notifications
You must be signed in to change notification settings - Fork 0
/
ControlerFlow.h
289 lines (244 loc) · 6.69 KB
/
ControlerFlow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#include "BaseFlow.h"
#include "YamabeFlow.h"
#include "EuclideanEmbed.h"
#include "UtilitiesFlow.h"
#include "EuclideanCalabiFlow.h"
#ifndef _FLOW_CONTROLER_H_
#define _FLOW_CONTROLER_H_
namespace OpenMesh {
enum FlowType { EuclideanCalabi, EuclideanRicci, CETM, HyperbolicCalabi, HyperbolicRicci, SphericalCalabi, SphericalRicci };
class ControlerFlow
{
public:
ControlerFlow() { m_mesh = NULL; boundary_mode = Fixed; orbifold = false; flow_type = EuclideanRicci; }
~ControlerFlow() { delete m_mesh; }
/*IO*/
bool LoadMeshFromFile(const char* input);
bool SaveMeshToFile(const char* input);
void MeshConvertToMatrix(Eigen::MatrixXd& V, Eigen::MatrixXd& VN, Eigen::MatrixXd& UV, Eigen::MatrixXd& UV3, Eigen::MatrixXi& F, Eigen::MatrixXd& FN);
/*algorithms*/
void RunFlow();
//Flags, thses flags can be access outside the class
FlowType flow_type;
BoundaryMode boundary_mode;
bool orbifold;
int orbifold_mode;
protected:
MeshFlow* m_mesh;
inline void RunEuclideanRicciFlow();
inline void RunCETM();
inline void RunEuclideanCalabiFlow();
inline void RunHyperbolicRicciFlow();
inline void RunHyperbolicCalabiFlow();
inline void RunSphericalRicciFlow();
inline void RunSphericalCalabiFlow();
};
void ControlerFlow::RunCETM()
{
// flow
CYamabeFlow CETM(m_mesh);
switch (boundary_mode) {
case 0:
CETM.boundary_mode = Fixed;
break;
case 1:
CETM.boundary_mode = Circle;
break;
case 2:
CETM.boundary_mode = Free;
}
CETM.CalculateMetric();
m_mesh->RequestBoundary();
if (m_mesh->boundaries.size() == 0) {
//CMeshReconstructor Slice(m_mesh);
//MeshFlow* new_mesh = Slice.SliceToDisk();
//delete m_mesh;
//m_mesh = new_mesh;
}
//embed
EuclideanEmbed euc_ebd(m_mesh);
euc_ebd.embed();
}
inline bool ControlerFlow::LoadMeshFromFile(const char* input)
{
if (m_mesh) {
delete m_mesh;
}
m_mesh = new OpenMesh::MeshFlow;
/*Check extension of file*/
std::string mesh_file_name_string = std::string(input);
size_t last_dot = mesh_file_name_string.rfind('.');
if (last_dot == std::string::npos)
{
printf("Error: No file extension found in %s\n", input);
return false;
}
std::string extension = mesh_file_name_string.substr(last_dot + 1);
/*Choose load function according to extension*/
if (extension == "obj" || extension == "OBJ")
{
m_mesh->ReadObjFile(input);
}
if (extension == "m" || extension == "M")
{
m_mesh->ReadMFile(input);
}
NormalizeMesh(m_mesh);
}
inline bool ControlerFlow::SaveMeshToFile(const char* output)
{
if (!m_mesh) {
return false;
}
/*Check extension of file*/
std::string mesh_file_name_string = std::string(output);
size_t last_dot = mesh_file_name_string.rfind('.');
if (last_dot == std::string::npos)
{
printf("Error: No file extension found in %s\n", output);
return false;
}
std::string extension = mesh_file_name_string.substr(last_dot + 1);
/*Choose load function according to extension*/
if (extension == "obj" || extension == "OBJ")
{
m_mesh->WriteObjFile(output);
}
if (extension == "m" || extension == "M")
{
m_mesh->WriteMFile(output);
}
}
inline void ControlerFlow::MeshConvertToMatrix(Eigen::MatrixXd& V, Eigen::MatrixXd& VN, Eigen::MatrixXd& UV, Eigen::MatrixXd& UV3, Eigen::MatrixXi& F, Eigen::MatrixXd& FN)
{
LoadMeshDataToMatrix(m_mesh, V, VN, F, FN);
LoadMeshFlatMappingResultToMatrix(m_mesh, UV);
LoadMeshSphericalMappingResultToMatrix(m_mesh, UV3);
}
inline void ControlerFlow::RunFlow()
{
if (!m_mesh) {
return;
}
switch (flow_type)
{
case OpenMesh::EuclideanCalabi:
if (!orbifold) RunEuclideanCalabiFlow();
//else RunEuclideanCalabiFlowWithOrbifold();
break;
//case OpenMesh::EuclideanRicci:
// if (!orbifold) RunEuclideanRicciFlow();
// else RunEuclideanRicciFlowWithOrbifold();
// break;
//case OpenMesh::CETM:
// RunCETM();
// break;
//case OpenMesh::HyperbolicCalabi:
// if (!orbifold) RunHyperbolicCalabiFlow();
// else RunHyperbolicCalabiFlowWithOrbifold();
// break;
//case OpenMesh::HyperbolicRicci:
// if (!orbifold) RunHyperbolicRicciFlow();
// else RunHyperbolicRicciFlowWithOrbifold();
// break;
//case OpenMesh::SphericalCalabi:
// if (!orbifold) RunSphericalCalabiFlow();
// else RunSphericalCalabiFlowWithOrbifold();
// break;
//case OpenMesh::SphericalRicci:
// if (!orbifold) RunSphericalRicciFlow();
// else RunSphericalRicciFlowWithOrbifold();
// break;
default:
break;
}
}
void ControlerFlow::RunEuclideanRicciFlow()
{
//EuclideanRicciFlow euc_ricci(m_mesh);
//switch (boundary_mode) {
//case 0:
// euc_ricci.boundary_mode = Fixed;
// break;
//case 1:
// euc_ricci.boundary_mode = Circle;
// break;
//case 2:
// euc_ricci.boundary_mode = Free;
//}
//euc_ricci.CalculateMetric();
//m_mesh->RequestBoundary();
//if (m_mesh->boundaries.size() == 0) {
// CMeshReconstructor Slice(m_mesh);
// MeshFlow* new_mesh = Slice.SliceToDisk();
// delete m_mesh;
// m_mesh = new_mesh;
//}
////embed
//EuclideanEmbed euc_ebd(m_mesh);
//euc_ebd.embed();
}
void ControlerFlow::RunEuclideanCalabiFlow()
{
EuclideanCalabiFlow euc_calabi(m_mesh);
switch (boundary_mode) {
case 0:
euc_calabi.boundary_mode = Fixed;
break;
case 1:
euc_calabi.boundary_mode = Circle;
break;
case 2:
euc_calabi.boundary_mode = Free;
}
euc_calabi.CalculateMetric();
m_mesh->RequestBoundary();
//if (m_mesh->boundaries.size() == 0) {
// CMeshReconstructor Slice(m_mesh);
// MeshFlow* new_mesh = Slice.SliceToDisk();
// delete m_mesh;
// m_mesh = new_mesh;
//}
//embed
EuclideanEmbed euc_ebd(m_mesh);
euc_ebd.embed();
}
void ControlerFlow::RunHyperbolicRicciFlow()
{
//HyperbolicRicciFlow hyper_ricci(m_mesh);
//hyper_ricci.CalculateMetric();
//CMeshReconstructor Slice(m_mesh);
//MeshFlow* new_mesh = Slice.SliceToDisk();
//delete m_mesh;
//m_mesh = new_mesh;
//HyperbolicEmbed hyper_ebd(m_mesh);
//hyper_ebd.embed();
}
void ControlerFlow::RunHyperbolicCalabiFlow()
{
//HyperbolicCalabiFlow hyper_ricci(m_mesh);
//hyper_ricci.CalculateMetric();
//CMeshReconstructor Slice(m_mesh);
//MeshFlow* new_mesh = Slice.SliceToDisk();
//delete m_mesh;
//m_mesh = new_mesh;
//HyperbolicEmbed hyper_ebd(m_mesh);
//hyper_ebd.embed();
}
void ControlerFlow::RunSphericalRicciFlow()
{
//SphericalRicciFlow sph_ricci(m_mesh);
//sph_ricci.CalculateMetric();
//SphericalEmbed sph_ebd(m_mesh);
//sph_ebd.embed();
}
void ControlerFlow::RunSphericalCalabiFlow()
{
//SphericalRicciFlow sph_calabi(m_mesh);
//sph_calabi.CalculateMetric();
//SphericalEmbed sph_ebd(m_mesh);
//sph_ebd.embed();
}
}// end namespace OpenMesh
#endif // !_FLOW_CONTROLER_H_
#pragma once