-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnivaqHexMesh_External_Facet_Finder_Main.cpp
More file actions
109 lines (93 loc) · 4.88 KB
/
UnivaqHexMesh_External_Facet_Finder_Main.cpp
File metadata and controls
109 lines (93 loc) · 4.88 KB
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
// 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 count the external facets from a conforming hexahedral mesh
// generated using Univaq Hex Mesh algorithm.
//******************************************************************************
#include <iostream>
#include <chrono>
//#include "test_congif.h" //TODO da aggiungere
#include "STL_reader.h"
#include "STL_reader3.h"
#include "OFF_Reader.h"
#include "Grid_maker.h"
#include "Initial_mesh_maker.h"
#include "External_block_remover.h"
#include "Grid_boundary_connector.h"
#include "Volume_Validator.h"
#include "Degenerate_element_finder.h"
#include "Writer.h"
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Mesh_polyhedron_3<K>::type Polyhedron;
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()));
if (fileName_extension == "stl" || fileName_extension == "off") {
// read input from file
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);
} else {
std::cerr << "Output File format not supported.\n";
return EXIT_FAILURE;
}
Grid_maker gridMaker = Grid_maker();
if (argc == 4) {
gridMaker.set_resolution(std::stod(argv[3]));
}
LCC_3 hex_mesh = gridMaker.make(polyhedron);
External_block_remover externalBlockRemover = External_block_remover();
externalBlockRemover.removeBlocks(hex_mesh, polyhedron);
//fit on boundary blocks to polyhedron boundary
CGAL::Grid_boundary_connector gridBoundaryConnector;
gridBoundaryConnector.connect(hex_mesh, polyhedron);
//delete element with Volume <= volume treshold
double volume_treshold = std::pow(gridMaker.getGridDimension(), 3) / 1000;
Volume_Validator volumeValidator;
volumeValidator.setVolumeTreshold(volume_treshold);
volumeValidator.delete_blocks_with_less_than_or_equal_to_volume_treshold(hex_mesh);
std::string outputPathFileName = argv[2]; // filename is path to filename with extension of the output
//size_t startIndex = outputPathFileName.find_last_of("/");
//std::string output_fileName_with_extension = outputPathFileName.substr(startIndex + 1,outputPathFileName.size());
// std::string fileName_without_extension = output_fileName_with_extension.substr(0,(output_fileName_with_extension.size()-4));
// std::string output_file_extension = output_fileName_with_extension.substr((output_fileName_with_extension.size()-3),(output_fileName_with_extension.size()));
size_t startIndex = outputPathFileName.find_last_of(".");
Writer writer;
std::string output_file_extension = outputPathFileName.substr(startIndex + 1,
outputPathFileName.size());
External_facet_finder externalFacetFinder;
const std::vector<Dart_handle> external_facets = externalFacetFinder.findFacets(hex_mesh);
unsigned long numberOfExternalFacets = external_facets.size();
std::cout<< "external facets : "<< numberOfExternalFacets <<std::endl;
}
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 integer grid resolution\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}