-
Notifications
You must be signed in to change notification settings - Fork 0
/
DelaunayTetMeshMain_Hex.cpp
111 lines (97 loc) · 4.29 KB
/
DelaunayTetMeshMain_Hex.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
// Copyright (c) 2020-2021 Univaq (Italy)
// All rights reserved.
//
// Author(s): Claudia Di Marco <dimarco.claud@gmail.com>, Riccardo Mantini <mantini.riccardo@gmail.com>
//
//******************************************************************************
// File Description :
// Main file to generate a conforming hexahedral mesh using Univaq Split from Tet algorithm.
//******************************************************************************
#include <iostream>
#include "MyLCC.h"
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include "OFF_Reader.h"
#include "STL_reader3.h"
#include "UnivaqSplitFromTetAlgorithm.h"
#include "Writer.h"
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Mesh_polyhedron_3<K>::type Polyhedron;
using namespace CGAL::parameters;
int main(int argc, char* argv[]) {
if (argc == 3 || argc == 4) {
try {
//get the stl file fileName_without_extension
std::string inputPathFileName = argv[1]; // filename is path to filename with extension
size_t startIndex = inputPathFileName.find_last_of(".");
std::string fileName_extension = inputPathFileName.substr((startIndex + 1), (inputPathFileName.size()));
// read input from file
if (fileName_extension == "stl" || fileName_extension == "off") {
Polyhedron polyhedron;
if (fileName_extension == "stl") {
STL_reader3 reader;
polyhedron = reader.read(inputPathFileName);
}
else if(fileName_extension == "off") {
OFF_Reader reader;
polyhedron = reader.read(inputPathFileName);
}
if(polyhedron.empty())
{
std::cerr << "Empty polyhedron. \n";
return EXIT_FAILURE;
}
//mesh generation
double desired_edge_size;
UnivaqSplitFromTetAlgorithm univaqSplitFromTetAlgorithm;
LCC_3 hex_mesh;
if(argc == 4)
{
desired_edge_size = std::stod(argv[3]) * 2;
univaqSplitFromTetAlgorithm.run(polyhedron, hex_mesh, desired_edge_size);
}
else
{
univaqSplitFromTetAlgorithm.run(polyhedron, hex_mesh);
}
//Output
std::string outputFileName = argv[2]; // outputFileName is path to filename with extension
size_t outputStartIndex = outputFileName.find_last_of(".");
std::string outputFileName_extension = outputFileName.substr((outputStartIndex + 1), (outputFileName.size()));
Writer hex_writer;
if(outputFileName_extension == "mesh")
{
std::ofstream medit_file(outputFileName);
hex_writer.output_to_medit(medit_file, hex_mesh);
medit_file.close();
}
else if(outputFileName_extension == "vtk")
{
std::ofstream vtk_file(outputFileName);
// hex_writer.output_to_legacy_vtk_ascii_unstructured(vtk_file, hex_mesh);
hex_writer.output_to_legacy_vtk_ascii_unstructured(outputFileName, hex_mesh);
vtk_file.close();
}
else{
std::cerr << "Output File format not supported.\n";
return EXIT_FAILURE;
}
}
else{
std::cerr << "Input File format not supported.\n";
return EXIT_FAILURE;
};
}
catch (std::ios_base::failure e) {
std::cerr << "Exception opening/reading/closing file\n";
return EXIT_FAILURE;
}
}
else{
if(argc<3)
std::cerr << "Too few input parameters. At least : path to the STL file input; path to the output file\n";
if(argc>4)
std::cerr << "Too many input parameters. At most : path to the STL file input; path to the output file; the double cell_size\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}