-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeshFile.h
116 lines (92 loc) · 2.84 KB
/
MeshFile.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
/* Created on: 10/03/2021
* Author: Ziniu Lu ([email protected])
*/
#pragma once
#include "project.h"
#include "cgalHeader.hpp"
#include "iglHeader.h"
#include <vector>
typedef std::vector<std::string> v_string;
BEGIN_PROJECT_NAMESPACE
class MeshFile
{
private:
std::vector<std::string> filePath; // fileDir + fileName + fileType
std::ifstream input1;
std::ifstream input2;
bool isOpen = false;
public:
MeshFile();
MeshFile(const std::string& filePath);
bool open(const std::string& filePath);
const bool is_open() const;
const std::vector<std::string>& get_file_path() const;
std::ifstream& get_ifstream1();
std::ifstream& get_ifstream2();
static int isotropic_remeshing(std::string& in_path, std::string& out_path, double edge_length, size_t nb_iter);
};
class Mesh
{
private:
v_string filePath; // path, filename, suffix
bool is_tmesh = false;
Triangle_mesh tmesh;
Polyhedron pmesh;
public:
Mesh();
Mesh(const std::string& filePath);
Mesh(MeshFile& meshFile);
inline bool load(const std::string& filePath)
{
MeshFile meshFile(filePath);
return this->load_mesh_file(meshFile);
}
inline bool load_mesh_file(MeshFile& meshFile)
{
this->filePath = meshFile.get_file_path();
// build triangle mesh
const auto& suffix = this->filePath[2];
Print("\t\tfile format: " + suffix);
Print("\t\tAnalyzing triangle mesh ... ");
bool loaded = false;
if (suffix == ".off") { loaded = this->load_off(meshFile); }
else if (suffix == ".obj") { loaded = this->load_obj(meshFile); }
else
{
Print("[error] Currently does not support \"" + this->filePath[2] + "\"!");
Print("[error] Please convert the file format to \".off\" or \".obj\" first!");
loaded = false;
}
if (loaded) { Print("\t\tdone.\n"); }
return loaded;
}
inline bool is_triangle_mesh() { return this->is_tmesh; }
inline v_string& get_file_path() { return this->filePath; }
inline Triangle_mesh& get_tmesh() { return this->tmesh; }
inline Polyhedron& get_pmesh() { return this->pmesh; }
static inline void get_tmesh(Triangle_mesh& tmesh, double scaling)
{
PMP::transform(Transform(CGAL::SCALING, scaling), tmesh);
}
static inline void get_pmesh(Polyhedron& pmesh, double scaling)
{
PMP::transform(Transform(CGAL::SCALING, scaling), pmesh);
}
static inline void get_VF(MAT_3d& V, MAT_3i& F, Triangle_mesh& tmesh)
{
get_VF(V, F, tmesh, 1.0);
}
static inline void get_VF(MAT_3d& V, MAT_3i& F, Polyhedron& pmesh)
{
get_VF(V, F, pmesh, 1.0);
}
static void get_VF(MAT_3d& V, MAT_3i& F, Triangle_mesh& tmesh, double scaling);
static void get_VF(MAT_3d& V, MAT_3i& F, Polyhedron& pmesh, double scaling);
private:
bool load_obj(MeshFile& meshFile);
bool load_off(MeshFile& meshFile);
};
END_PROJECT_NAMESPACE
extern PROJECT_NAME::Mesh* mesh;
extern Triangle_mesh* tmesh;
extern Polyhedron* pmesh;