-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cpp
695 lines (592 loc) · 25.3 KB
/
main.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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
/*
* @author Alessandro Muntoni (muntoni.alessandro@gmail.com)
* @copyright Alessandro Muntoni 2016.
*/
#include "cg3/viewer/mainwindow.h"
#include "cg3/viewer/managers/dcel_manager.h"
#include "GUI/managers/enginemanager.h"
#include "common.h"
#include <QApplication>
//#include "common/comparators.h"
#include "engine/engine.h"
//#include "trimesh/gui/trimeshmanager.h"
#include "lib/graph/directedgraph.h"
#include "cg3/viewer/managers/eigenmesh_manager.h"
#include "cg3/viewer/managers/booleans_manager.h"
#include <cg3/utilities/string.h>
#include <cg3/utilities/system.h>
#include <typeinfo> // operator typeid
#include "engine/reconstruction.h"
#include "cg3/utilities/command_line_argument_manager.h"
using namespace cg3;
#if defined(SERVER_MODE) || defined(SERVER_HOME) || defined(SERVER_AFTER)
void serializeBeforeBooleans(const std::string& filename, const Dcel& d, const EigenMesh& originalMesh, const BoxList& solutions, double factor, double kernel);
void deserializeBeforeBooleans(const std::string& filename, Dcel& d, EigenMesh& originalMesh, BoxList& solutions, double &factor, double &kernel);
void serializeAfterBooleans(const std::string& filename, const Dcel& d, const EigenMesh& originalMesh, const BoxList& solutions, const EigenMesh& baseComplex, const HeightfieldsList& he, double factor, double kernel, const BoxList& originalSolutions, const std::map<unsigned int, unsigned int>& splittedBoxesToOriginals, const std::list<unsigned int> &priorityBoxes);
void deserializeAfterBooleans(const std::string& filename, Dcel& d, EigenMesh& originalMesh, BoxList& solutions, EigenMesh& baseComplex, HeightfieldsList& he, double &factor, double &kernel, BoxList& originalSolutions, std::map<unsigned int, unsigned int>& splittedBoxesToOriginals, std::list<unsigned int> &priorityBoxes);
#endif
static Point3d getCustomLimits(const Dcel &m, double lx, double ly, double lz)
{
Point3d limits;
limits.x() = m.boundingBox().diag() * lx;
limits.y() = m.boundingBox().diag() * ly;
limits.z() = m.boundingBox().diag() * lz;
return limits;
}
int main(int argc, char *argv[]) {
#ifdef SERVER_MODE
/**
* Implementation of the paper Axis-Aligned Height-Field Block Decomposition of 3D Shapes, TOG(2018).
*
* usage
* ./HeightFieldDecomposition <filename>.obj -<option>=<value>
*
* Possible options:
*
* [-s, -smooth]=<filename>: To use smoothed mesh for the optimization and then reintroduce details after
* (Sec 4.5 of the paper, Fig. 11). If not set, checks if <filename>_smooth.obj is inside the same directory of filename.obj.
* You can use any type of smoothing you want to obtain filename_smooth.obj (ex: taubin smoothing).
*
* [-p, -precision]=<value> (double > 0, default=1): controls the how fit is the grid constructed in the input mesh. precision = 1 means that the unit
* edge of the grid is the avg of the edge-length of the input mesh;
* precision = 2 -> avg_length * 0.5;
* precision = 0.5 -> avg_length * 2;
*
* [-k, -kernel]=<value> (double [0-1], default=0): controls the constraint of the intirior void of the decomposition. 0 means that no intirior void
* is required. The values between 0 and 1 are proportional to the farthest and nearest point from the surface.
*
* [-s, -snapping]=<value> (double > 0, default=2): numer of grid unit to snap boxes when they have similar coordinates.
*
* [-o, -orientat]=<value> (t/f, default=t): true if we want to execute a suboptimal orientation on the input mesh in preprocessing
* (sec 4.1 of the paper);
*
* [-c, -conservative]=<value> (t/f, default=f): how grid vertices in borders are set in the initial interpolation scheme.
*
* [-x], [-y], [-z] = <value> (double [0, 1...], default=2): maximum block sizes constraints wrt the diagonal of the bounding box. For no limit, use a value
* greater than 1.
*
* Example of calls:
* ./HeightFieldDecomposition cube_spike.obj
* ./HeightFieldDecomposition cube_spike.obj -s=cssmooth.obj -k=0.1 -p=1.1 -z=0.2
*/
cg3::CommandLineArgumentManager argManager(argc, argv);
std::string filename = argManager[0];
std::string filename_smooth;
//variables
Dcel d;
EigenMesh original;
bool smoothed = false, optimal_orientation = true, conservative = false;
double precision = 1, kernel = 0, snapStep = 2;
double lx = 2, ly = 2, lz = 2; //size constraints
/**** Argument Management */
//input mesh
if (! fileExists(filename)){
std::cerr << filename << " not found. Exiting.";
return -1;
}
original.loadFromObj(filename);
//smooth mesh
if (argManager.exists("smooth") && fileExists(argManager.value("smooth"))){
filename_smooth = argManager.value("smooth");
if (!fileExists(filename_smooth)){
std::cerr << filename_smooth << " not found. Exiting.";
return -1;
}
else {
d.loadFromObj(filename_smooth);
smoothed = true;
std::cerr << "Using smoothed mesh.\n";
}
}
else {
std::string rawname, extension;
separateExtensionFromFilename(filename, rawname, extension);
filename_smooth = rawname + "_smooth" + extension;
if (fileExists(filename_smooth)){
d.loadFromObj(filename_smooth);
smoothed = true;
std::cerr << filename_smooth << " found!\n";
}
else{
d = cg3::Dcel(original);
}
}
//precision
if (argManager.exists("p") || argManager.exists("precision")){
if (argManager.exists("p"))
precision = std::stod(argManager.value("p"));
else
precision = std::stod(argManager.value("precision"));
}
//kernel
if (argManager.exists("k") || argManager.exists("kernel")){
if (argManager.exists("k"))
kernel = std::stod(argManager.value("k"));
else
kernel = std::stod(argManager.value("kernel"));
}
//kernel
if (argManager.exists("s") || argManager.exists("snap")){
if (argManager.exists("s"))
snapStep = std::stod(argManager.value("s"));
else
snapStep = std::stod(argManager.value("snap"));
}
//optimal orientation
if (argManager.exists("o") || argManager.exists("orient")){
if (argManager.exists("o")){
if (argManager.value("o") != "")
optimal_orientation = !(argManager.value("o") == "f");
}
else{
if (argManager.value("orient") != "")
optimal_orientation = !(argManager.value("orient") == "f");
}
}
//conservative
if (argManager.exists("c") || argManager.exists("conservative")){
if (argManager.exists("c")){
conservative = argManager.value("c") == "t";
}
else{
conservative = argManager.value("conservative") == "t";
}
}
//x
if (argManager.exists("x")){
lx = std::stod(argManager.value("x"));
}
//y
if (argManager.exists("y")){
ly = std::stod(argManager.value("y"));
}
//z
if (argManager.exists("z")){
lz = std::stod(argManager.value("z"));
}
//actual algorithm ...
//setting up paths
std::string rawname, extension;
separateExtensionFromFilename(filename, rawname, extension);
std::string foldername = rawname + "_";
if (!optimal_orientation)
foldername += "noo_";
if (conservative)
foldername += "cons_";
foldername += toStringWithPrecision(precision) + "_" + toStringWithPrecision(kernel) + "/";
executeCommand("mkdir " + foldername);
//log
std::ofstream logFile;
logFile.open(foldername + "log.txt");
if (smoothed)
logFile << "Using Smoothed Mesh.\n";
else
logFile << "No smoothing was applied.\n";
//optimal orientation
if (optimal_orientation){ // if optimal orientation
logFile << "Using Optimal Orientation! \n";
}
else {
logFile << "Not using Optimal Orientation.\n";
}
if (conservative){
logFile << "Conservative Strategy used.\n";
}
else {
logFile << "Non-conservative Strategy used.\n";
}
logFile << "Parameters: \n\tPrecision: " << precision << "\n\tKernel: " << kernel << "\n\tSnapping: " << snapStep << "\n";
logFile << "\tSize X limit: " << lx << "\n\tSize Y limit: " << ly << "\n\tSize Z limit: " << lz << "\n";
logFile.flush();
//scaling meshes
BoundingBox3 bb= d.boundingBox();
Engine::scaleAndRotateDcel(d, 0, precision);
original.scale(bb, d.boundingBox());
//optimal orientation
if (optimal_orientation){ // if optimal orientation
Eigen::Matrix3d m3d = Engine::findOptimalOrientation(d, original);
logFile << "Optimal Orientation Rotation Matrix:\n";
logFile << m3d << "\n";
}
logFile.flush();
d.updateFaceNormals();
d.updateVertexNormals();
d.saveOnObj(foldername + rawname + "r_smooth.obj");
original.saveOnObj(foldername + rawname + "r.obj");
//solutions
BoxList solutions;
//grow boxes //boxes mesh kernel limit limit toler only areatol angletol fileus decim
//double timerBoxGrowing = Engine::optimize(solutions, d, kernelDistance, false, Pointd(), !conservative, true, 0, 0, false, true);
double timerBoxGrowing = Engine::optimize(solutions, d, kernel, true, getCustomLimits(d, lx, ly, lz), !conservative, true, 0, 0, false, true);
logFile << timerBoxGrowing << ": Box Growing\n";
logFile.flush();
serializeBeforeBooleans(foldername + "all.bin", d, original, solutions, precision, kernel);
Engine::boxPostProcessing(solutions, d);
Timer tGurobi("Gurobi");
Engine::minimalCovering(solutions, d);
tGurobi.stopAndPrint();
logFile << tGurobi.delay() << ": Minimal Covering\n";
logFile.flush();
//
logFile << tGurobi.delay() << ": Minimal Covering\n";
logFile << "Total Survived boxes: " << solutions.getNumberBoxes() << "\n";
logFile.flush();
std::cerr << "Total Survived boxes: " << solutions.getNumberBoxes() << "\n";
serializeBeforeBooleans(foldername + "mc.bin", d, original, solutions, precision, kernel);
//snapping
Engine::stupidSnapping(d, solutions, snapStep);
//new: forced snapping
Engine::smartSnapping(d, solutions);
//merging
Engine::merging(d, solutions);
//setting ids
solutions.sortByTrianglesCovered();
solutions.setIds();
BoxList originalSolutions = solutions;
std::map<unsigned int, unsigned int> splittedBoxesToOriginals;
std::list<unsigned int> priorityBoxes;
std::vector<std::pair<unsigned int, unsigned int>> userArcs;
HeightfieldsList he;
EigenMesh baseComplex;
double timerSplitting = 0;
double timerBooleans = 0;
//splitting and sorting
solutions = originalSolutions;
Timer tSplitting("ts");
Array2D<int> ordering = Splitting::getOrdering(solutions, d, splittedBoxesToOriginals, priorityBoxes, userArcs);
solutions.sort(ordering);
tSplitting.stop();
timerSplitting += tSplitting.delay();
logFile << tSplitting.delay() << ": Splitting\n";
logFile.flush();
//booleans
d.updateFaceNormals();
d.updateVertexNormals();
baseComplex = d;
he = HeightfieldsList();
Timer tBooleans("tb");
Engine::booleanOperations(he, baseComplex, solutions, false);
Engine::splitConnectedComponents(he, solutions, splittedBoxesToOriginals);
Engine::glueInternHeightfieldsToBaseComplex(he, solutions, baseComplex, d);
tBooleans.stop();
timerBooleans += tBooleans.delay();
logFile << tBooleans.delay() << ": Booleans \n";
logFile.flush();
cgal::AABBTree3 tree(d);
Engine::updatePiecesNormals(tree, he);
Engine::colorPieces(d, he);
logFile << timerSplitting << ": Total time Splitting\n";
logFile << timerBooleans << ": Total time Booleans\n";
logFile.close();
//restore hf
if (smoothed){
//Common::executeCommand("./restorehf " + foldername + "bools" + std::to_string(it-1) + ".hfd " + foldername);
std::vector< std::pair<int,int> > mapping = Reconstruction::getMapping(d, he);
Reconstruction::reconstruction(d, mapping, original, solutions);
baseComplex = d;
d.updateFaceNormals();
d.updateVertexNormals();
he = HeightfieldsList();
Engine::booleanOperations(he, baseComplex, solutions, false);
Engine::splitConnectedComponents(he, solutions, splittedBoxesToOriginals);
Engine::glueInternHeightfieldsToBaseComplex(he, solutions, baseComplex, d);
cgal::AABBTree3 tree(d);
Engine::updatePiecesNormals(tree, he);
Engine::colorPieces(d, he);
}
serializeAfterBooleans(foldername + "final.hfd", d, original, solutions, baseComplex, he, precision, kernel, originalSolutions, splittedBoxesToOriginals, priorityBoxes);
for(unsigned int i = 0; i < he.getNumHeightfields(); ++i){
he.getHeightfield(i).saveOnObj(foldername + "block" + std::to_string(i) + ".obj");
}
#else
#ifdef SERVER_HOME
if (argc > 3){
bool smoothed = true;
std::string filename(argv[1]);
if (! fileExists(filename)){
std::cerr << filename << " not found. Exiting.";
return -1;
}
std::string rawname, extension;
separateExtensionFromFilename(filename, rawname, extension);
std::string filename_smooth = rawname + "_smooth" + extension;
//reading files
EigenMesh original;
original.readFromObj(filename);
Dcel d;
if (fileExists(filename_smooth)){
d.loadFromObjFile(filename_smooth);
std::cerr << "Smooth File found.\n";
}
else {
std::cerr << "Smooth File not found. Using original file.\n";
d = original;
smoothed = false;
}
//precision and kernel
double precision = std::stod(argv[2]);
double kernelDistance = std::stod(argv[3]);
//creating folder
std::string foldername = rawname + "_";
bool optimal = true;
if (argc == 5 && std::string(argv[5]) == "f"){ // if no optimal orientation required, there will be different foldername
foldername += "noo_";
optimal = false;
}
foldername += toStringWithPrecision(precision) + "_" + toStringWithPrecision(kernelDistance) + "/";
executeCommand("mkdir " + foldername);
//log
std::ofstream logFile;
logFile.open(foldername + "log.txt");
//scaling meshes
BoundingBox bb= d.getBoundingBox();
Engine::scaleAndRotateDcel(d, 0, precision);
original.scale(bb, d.getBoundingBox());
//optimal orientation
if (optimal){
Engine::findOptimalOrientation(d, original);
}
d.updateFaceNormals();
d.updateVertexNormals();
d.saveOnObjFile(foldername + rawname + "r_smooth.obj");
original.saveOnObj(foldername + rawname + "r.obj");
//solutions
BoxList solutions;
//grow boxes
double timerBoxGrowing = Engine::optimize(solutions, d, kernelDistance, false, Pointd(), true, true, 0, 0, false, true);
logFile << timerBoxGrowing << ": Box Growing\n";
serializeBeforeBooleans(foldername + "all.bin", d, original, solutions, precision, kernelDistance);
logFile.close();
}
#else
#ifdef SERVER_AFTER
if (argc > 1){
std::string foldername(argv[1]);
if (foldername[foldername.size()-1] != '/')
foldername +="/";
EigenMesh original;
Dcel d;
bool smoothed = true;
BoxList solutions;
//precision and kernel
double precision;
double kernelDistance;
//log
std::ofstream logFile;
logFile.open(foldername + "log.txt", std::ofstream::out | std::ofstream::app);
//deserialize all.bin
deserializeBeforeBooleans(foldername + "all.bin", d, original, solutions, precision, kernelDistance);
Engine::boxPostProcessing(solutions, d);
double timerMinimalCovering = Engine::deleteBoxes(solutions, d);
logFile << timerMinimalCovering << ": Minimal Covering\n";
serializeBeforeBooleans(foldername + "mc.bin", d, original, solutions, precision, kernelDistance);
double snapStep;
if (argc == 3)
snapStep = std::stod(argv[2]);
else
snapStep = 2;
//snapping
Engine::stupidSnapping(d, solutions, snapStep);
//new: forced snapping
Engine::smartSnapping(d, solutions);
//merging
Engine::merging(d, solutions);
//setting ids
solutions.sortByTrianglesCovered();
solutions.setIds();
BoxList originalSolutions = solutions;
std::map<unsigned int, unsigned int> splittedBoxesToOriginals;
std::list<unsigned int> priorityBoxes;
std::vector<std::pair<unsigned int, unsigned int>> userArcs;
HeightfieldsList he;
EigenMesh baseComplex;
double timerSplitting = 0;
double timerBooleans = 0;
int it = 0;
do {
//splitting and sorting
solutions = originalSolutions;
Timer tSplitting("ts");
Array2D<int> ordering = Splitting::getOrdering(solutions, d, splittedBoxesToOriginals, priorityBoxes, userArcs);
solutions.sort(ordering);
tSplitting.stop();
timerSplitting += tSplitting.delay();
logFile << tSplitting.delay() << ": Splitting n. " << std::to_string(it) << "\n";
//booleans
d.updateFaceNormals();
d.updateVertexNormals();
baseComplex = d;
he = HeightfieldsList();
Timer tBooleans("tb");
Engine::booleanOperations(he, baseComplex, solutions, false);
Engine::splitConnectedComponents(he, solutions, splittedBoxesToOriginals);
Engine::glueInternHeightfieldsToBaseComplex(he, solutions, baseComplex, d);
tBooleans.stop();
timerBooleans += tBooleans.delay();
logFile << tBooleans.delay() << ": Booleans n. " << std::to_string(it) << "\n";
cgal::AABBTree tree(d);
Engine::updatePiecesNormals(tree, he);
Engine::colorPieces(d, he);
serializeAfterBooleans(foldername + "bools" + std::to_string(it) + ".hfd", d, original, solutions, baseComplex, he, precision, kernelDistance, originalSolutions, splittedBoxesToOriginals, priorityBoxes);
it++;
} while(false);
logFile << timerSplitting << ": Total time Splitting\n";
logFile << timerBooleans << ": Total time Booleans\n";
logFile.close();
//restore hf
if (smoothed){
//Common::executeCommand("./restorehf " + foldername + "bools" + std::to_string(it-1) + ".hfd " + foldername);
std::vector< std::pair<int,int> > mapping = Reconstruction::getMapping(d, he);
Reconstruction::reconstruction(d, mapping, original, solutions);
baseComplex = d;
d.updateFaceNormals();
d.updateVertexNormals();
he = HeightfieldsList();
Engine::booleanOperations(he, baseComplex, solutions, false);
Engine::splitConnectedComponents(he, solutions, splittedBoxesToOriginals);
Engine::glueInternHeightfieldsToBaseComplex(he, solutions, baseComplex, d);
cgal::AABBTree tree(d);
Engine::updatePiecesNormals(tree, he);
Engine::colorPieces(d, he);
}
serializeAfterBooleans(foldername + "final.hfd", d, original, solutions, baseComplex, he, precision, kernelDistance, originalSolutions, splittedBoxesToOriginals, priorityBoxes);
}
else
std::cerr << "Error! Number argument lower than 2\n";
#else
#ifdef CONVERTER_MODE
if (argc > 1){
std::string filename(argv[1]);
std::string tmp, ext;
cg3::separateExtensionFromFilename(filename, tmp, ext);
if (ext == ".bin"){
cg3::executeCommand("mkdir new/");
DrawableDcel tmpd;
BoxList tmpsol;
EigenMesh originalMesh;
double factor, kernel;
bool b;
std::ifstream infile;
infile.open(filename, std::ios::in | std::ios::binary);
tmpd.deserializeOld(infile);
SerializerOld::deserialize(b, infile);
tmpsol.deserializeOld(infile);
SerializerOld::deserialize(b, infile);
originalMesh.deserializeOld(infile);
SerializerOld::deserialize(factor, infile);
SerializerOld::deserialize(kernel, infile);
infile.close();
std::ofstream outfile;
outfile.open("new/" + filename, std::ios::out | std::ios::binary);
Serializer::serializeObjectAttributes("HFDBeforeSplitting", outfile, tmpd, tmpsol, originalMesh, factor, kernel);
outfile.close();
}
else if ( ext == ".hfd"){
cg3::executeCommand("mkdir new/");
DrawableDcel tmpd;
BoxList tmpsol;
EigenMesh originalMesh;
EigenMesh baseComplex;
HeightfieldsList he;
double factor, kernel;
bool b;
std::ifstream infile;
infile.open(filename, std::ios::in | std::ios::binary);
tmpd.deserializeOld(infile);
tmpsol.deserializeOld(infile);
baseComplex.deserializeOld(infile);
he.deserializeOld(infile);
originalMesh.deserializeOld(infile);
SerializerOld::deserialize(factor, infile);
SerializerOld::deserialize(kernel, infile);
BoxList originalSolutions;
std::map<unsigned int, unsigned int> splittedBoxesToOriginals;
std::list<unsigned int> priorityBoxes;
SerializerOld::deserialize(b, infile);
originalSolutions.deserializeOld(infile);
SerializerOld::deserialize(splittedBoxesToOriginals, infile);
SerializerOld::deserialize(priorityBoxes, infile);
infile.close();
std::ofstream outfile;
outfile.open("new/" + filename, std::ios::out | std::ios::binary);
Serializer::serializeObjectAttributes("HFDBeforeSplitting", outfile, tmpd, tmpsol, originalMesh, factor, kernel);
Serializer::serializeObjectAttributes("HFDAfterBooleans", outfile, baseComplex, he, originalSolutions, splittedBoxesToOriginals, priorityBoxes);
outfile.close();
}
}
#else
QApplication app(argc, argv);
cg3::viewer::MainWindow gui; // finestra principale, contiene la canvas di QGLViewer
mw = &gui;
// Creo un dcel manager e lo aggiungo alla mainwindow
cg3::viewer::DcelManager d(&gui);
DCEL_MANAGER_ID = gui.addManager(&d, "Dcel");
EngineManager e(&gui);
ENGINE_MANAGER_ID = gui.addManager(&e, "Engine");
cg3::viewer::BooleansManager bm(&gui);
gui.addManager(&bm, "Booleans Manager");
//TrimeshManager tm(&gui);
//gui.addManager(&tm, "Trimesh Manager");
cg3::viewer::EigenMeshManager em(&gui);
gui.addManager(&em, "EigenMesh Manager");
if (argc >= 2){
std::cerr << argv[1] << "\n";
std::string filename = argv[1];
std::string rawname, extension, path, fn;
separateExtensionFromFilename(filename, rawname, extension);
separateFilenameFromPath(filename, path, fn);
std::cerr << rawname << "; " << extension << "\n";
if (extension == ".hfd"){
e.deserializeBC(filename);
e.setHfdPath(path);
e.setBinPath(path);
e.setObjPath(path);
}
else if (extension == ".bin"){
std::ifstream myfile;
myfile.open (filename, std::ios::in | std::ios::binary);
e.deserialize(myfile);
myfile.close();
e.setHfdPath(path);
e.setBinPath(path);
e.setObjPath(path);
}
}
gui.setCurrentManager(ENGINE_MANAGER_ID); // il dcel manager sarà quello visualizzato di default
gui.canvas.update();
gui.show();
return app.exec();
#endif
#endif
#endif
#endif
return 0;
}
#if defined(SERVER_MODE) || defined(SERVER_HOME) || defined(SERVER_AFTER)
void serializeBeforeBooleans(const std::string& filename, const Dcel& d, const EigenMesh& originalMesh, const BoxList& solutions, double factor, double kernel) {
std::ofstream binaryFile;
binaryFile.open (filename, std::ios::out | std::ios::binary);
cg3::serializeObjectAttributes("HFDBeforeSplitting", binaryFile, d, solutions, originalMesh, factor, kernel);
binaryFile.close();
}
void deserializeBeforeBooleans(const std::string& filename, Dcel& d, EigenMesh& originalMesh, BoxList& solutions, double &factor, double &kernel) {
std::ifstream binaryFile;
binaryFile.open (filename, std::ios::in | std::ios::binary);
cg3::deserializeObjectAttributes("HFDBeforeSplitting", binaryFile, d, solutions, originalMesh, factor, kernel);
binaryFile.close();
}
void serializeAfterBooleans(const std::string& filename, const Dcel& d, const EigenMesh& originalMesh, const BoxList& solutions, const EigenMesh& baseComplex, const HeightfieldsList& he, double factor, double kernel, const BoxList& originalSolutions, const std::map<unsigned int, unsigned int>& splittedBoxesToOriginals, const std::list<unsigned int> &priorityBoxes) {
std::ofstream myfile;
myfile.open (filename, std::ios::out | std::ios::binary);
cg3::serializeObjectAttributes("HFDBeforeSplitting", myfile, d, solutions, originalMesh, factor, kernel);
cg3::serializeObjectAttributes("HFDAfterBooleans", myfile, baseComplex, he, originalSolutions, splittedBoxesToOriginals, priorityBoxes);
myfile.close();
}
void deserializeAfterBooleans(const std::string& filename, Dcel& d, EigenMesh& originalMesh, BoxList& solutions, EigenMesh& baseComplex, HeightfieldsList& he, double &factor, double &kernel, BoxList& originalSolutions, std::map<unsigned int, unsigned int>& splittedBoxesToOriginals, std::list<unsigned int> &priorityBoxes){
std::ifstream myfile;
myfile.open (filename, std::ios::in | std::ios::binary);
cg3::deserializeObjectAttributes("HFDBeforeSplitting", myfile, d, solutions, originalMesh, factor, kernel);
cg3::deserializeObjectAttributes("HFDAfterBooleans", myfile, baseComplex, he, originalSolutions, splittedBoxesToOriginals, priorityBoxes);
myfile.close();
}
#endif