forked from Kallu-A/Tri-2-Quad-Mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.cpp
158 lines (123 loc) · 5.07 KB
/
entrypoint.cpp
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
/**
* Vetices: Point
* Facets: Triangle
* Attributes: PointAttribute, FacetAttribute
* Halfedges:
*/
#include "utils/helpers.h"
#include <ultimaille/all.h>
#include "triToQuadRegion.cpp"
#include <param_parser/param_parser.h>
using namespace UM;
// default save path
std::string resPath = "result";
std::string extensionValue = ".geogram";
// default mesh
std::string meshPath = "catorus.geogram";
// default path for the input
std::string inputPath = "";
bool isInputPath = false;
//default number of region
int numberRegion = 15;
bool isNumberRegion = false;
double percentage = 0.05;
bool gifmode = false;
int main(int argc, char* argv[]) {
Parameters params;
params.add(Parameters::Type::Input, "path", "").description("Path to the mest");
params.add(Parameters::Type::Bool, "gif", "false").description("Create a gif of the process");
params.add(Parameters::Type::Int, "n_region", "-414").description("Number of region to create");
params.add(Parameters::Type::Double, "p_area", "-0.01").description("Percentage of the area to cover by region");
params.init_from_args(argc, argv);
if (params.has_result_path()) {
resPath = params.result_path();
}
std::cout << "Parameters: " << std::string(params["path"]) << " " << int(params["n_region"]) << " " << double(params["p_area"]) << std::endl;
// param handling
if (std::string(params["path"]) != "") {
std::string param = params["path"];
meshPath = param;
isInputPath = true;
}
if (int(params["n_region"]) != -414) {
numberRegion = params["n_region"];
isNumberRegion = true;
if (numberRegion < 0) {
std::cout << "Error: number of region must be positive" << std::endl;
return 1;
}
}
if (!is_equal(double(params["p_area"]), -0.01)) {
percentage = params["p_area"];
isNumberRegion = true;
if (percentage > 1 || percentage < 0) {
std::cout << "Error: percentage must be between 0 and 1" << std::endl;
return 1;
}
}
if (std::string(params["gif"]) == "true") {
gifmode = true;
}
// Create a directory to save files
createDirectory("result");
if (!isInputPath)
inputPath = getAssetPath();
else
inputPath = "";
//Start timer
auto start = std::chrono::high_resolution_clock::now();
Triangles triangle;
Quads quad;
if (inputPath == "")
read_by_extension(meshPath, triangle);
else
read_by_extension(inputPath + meshPath, triangle);
if (triangle.nverts() == 0) {
std::cout << "Error: File " << inputPath + meshPath + " not found" << std::endl;
return 1;
}
if (!isNumberRegion) {
numberRegion = calculateNumberRegion(triangle, percentage);
numberRegion = -1;
}
triangle.connect();
std::cout << std::endl << "Initial file: " << inputPath + meshPath << std::endl
<< "vertices: " << triangle.nverts()
<< " facets: " << triangle.nfacets() << std::endl;
size_t last_slash = meshPath.find_last_of('/');
if (last_slash != std::string::npos) {
meshPath = meshPath.substr(last_slash + 1);
}
FacetAttribute<int> fa(triangle);
PointAttribute<int> pa(triangle.points);
PointAttribute<int> hardedge(triangle.points, 0);
CornerAttribute<int> ea(triangle, -1);
FacetAttribute<int> faQuad(quad);
for (int i = 0; i < triangle.ncorners(); i++) {
ea[i] = -1;
}
process(triangle, quad, fa, pa, hardedge, ea, numberRegion, faQuad, gifmode);
if (gifmode) {
write_by_extension("result/region/09999.geogram", triangle, {{{"border_group", pa.ptr}}, {{"group_number", fa.ptr}}, {{"edge_group", ea.ptr}}});
}
// --- FILE SAVING ---
std::filesystem::path fs_path(meshPath);
std::string base_name = fs_path.stem().string();
std::string extension = fs_path.extension().string();
bool isGeogram = true;
if (isGeogram)
extension = extensionValue;
std::string pathTri = (fs_path.parent_path() / std::string(base_name + "_tri" + extension)).string();
std::string pathQuad = (fs_path.parent_path() / std::string(base_name + "_quad" + extension)).string();
// Save mesh with previously created attribute
write_by_extension(resPath + "/" + pathTri, triangle, {{{"border_group", pa.ptr}, {"hard_edge", hardedge.ptr}}, {{"group_number", fa.ptr}}, {{"edge_group", ea.ptr}}});
write_by_extension(resPath + "/" + pathQuad, quad, {{}, {{"intial_region", faQuad.ptr}}, {}});
std::cout << std::endl << "Result file: " << resPath + "/" + pathTri << std::endl;
std::cout << std::endl << "Result file: " << resPath + "/" + pathQuad << std::endl;
std::cout << "Quad Mesh data: number of vertices: " << quad.nverts() << " number of facets: " << quad.nfacets() << std::endl << std::endl;
//End timer
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
std::cout << "Time taken: " << duration.count() << " miliseconds" << std::endl;
return 0;
}