4 #include <boost/spirit/include/qi.hpp>
6 #include <OpenVolumeMesh/FileManager/FileManager.hh>
8 #include "MeshGenerator.hpp"
10 #include "Grammars/Tetmesh.hpp"
11 #include "Grammars/Netgen.hpp"
14 std::cerr <<
"You need to specify a format and a source file to convert!" << std::endl << std::endl;
15 std::clog <<
"Usage: file_converter <format> <filename> [output_filename.ovm]" << std::endl << std::endl;
16 std::clog <<
"Available file formats:" << std::endl;
17 std::clog <<
" -t\tTetmesh" << std::endl;
18 std::clog <<
" -n\tNetgen" << std::endl;
19 std::clog << std::endl;
22 int main(
int _argc,
char* _argv[]) {
24 if(_argc < 3 || _argc > 4 ||
25 (_argc > 1 && (std::strcmp(_argv[1],
"--help") == 0 || std::strcmp(_argv[1],
"-h") == 0))) {
30 std::ifstream iff(_argv[2], std::ios::in);
33 std::cerr <<
"Could not open file " << _argv[1] <<
" for reading!" << std::endl;
40 std::ostringstream oss;
43 std::string fileContent = oss.str();
51 if(std::strcmp(_argv[1],
"-t") == 0) {
54 r = boost::spirit::qi::phrase_parse(fileContent.begin(), fileContent.end(),
tetmesh_grammar, qi::space);
56 }
else if(std::strcmp(_argv[1],
"-n") == 0) {
59 r = boost::spirit::qi::phrase_parse(fileContent.begin(), fileContent.end(),
netgen_grammar, qi::space);
67 std::cout <<
"Successfully read file data!" << std::endl;
69 std::cout <<
"Parsing failed!" << std::endl;
72 std::cerr <<
"Converted " << mesh.n_vertices() <<
" vertices," << std::endl;
73 std::cerr <<
"\t " << mesh.n_edges() <<
" edges," << std::endl;
74 std::cerr <<
"\t " << mesh.n_faces() <<
" faces," << std::endl;
75 std::cerr <<
"\t " << mesh.n_cells() <<
" cells!" << std::endl;
83 std::string::size_type idx = filename.rfind(
'.');
85 filename = filename.substr(0, idx);
86 filename.append(
".ovm");
92 fileManager.
writeFile(filename.c_str(), mesh);
Read/Write mesh data from/to files.
bool writeFile(const std::string &_filename, const MeshT &_mesh) const
Write a mesh to a file.