Commit 0dd0d435 authored by Mike Kremer's avatar Mike Kremer

Added grammar for netgen files

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@160 66977474-1d4b-4f09-8fe9-267525286df2
parent 8dde221c
/*
* Netgen.hpp
*
* Created on: Apr 16, 2012
* Author: kremer
*/
#ifndef NETGEN_HPP_
#define NETGEN_HPP_
#include <boost/spirit/include/qi.hpp>
#include <boost/bind.hpp>
#include "../MeshGenerator.hpp"
#include <iostream>
namespace qi = boost::spirit::qi;
namespace spirit = boost::spirit;
void print() {
static int c = 0;
std::cerr << "Hey there!" << c++ << std::endl;
}
template <typename Iterator>
class netgen_grammar : public qi::grammar<Iterator/*, qi::space_type*/> {
public:
netgen_grammar(MeshGenerator& _generator) :
netgen_grammar::base_type(content),
generator_(_generator) {
content = node_section_header >> *node >>
element_section_header >> *element >>
face_section_header >> *face;
node_section_header = qi::int_ /* Number of vertices */ >> spirit::eol;
node = *space >> qi::double_[boost::bind(&MeshGenerator::add_vertex_component, &generator_, ::_1)] >>
*space >> qi::double_[boost::bind(&MeshGenerator::add_vertex_component, &generator_, ::_1)] >>
*space >> qi::double_[boost::bind(&MeshGenerator::add_vertex_component, &generator_, ::_1)] >> spirit::eol;
element_section_header = qi::int_[boost::bind(&MeshGenerator::set_num_cells, &generator_, ::_1)] /* Number of tetrahedra */ >>
spirit::eol;;
element = *space >> qi::int_ >>
*space >> qi::int_[boost::bind(&MeshGenerator::add_cell_vertex, &generator_, ::_1)] >>
*space >> qi::int_[boost::bind(&MeshGenerator::add_cell_vertex, &generator_, ::_1)] >>
*space >> qi::int_[boost::bind(&MeshGenerator::add_cell_vertex, &generator_, ::_1)] >>
*space >> qi::int_[boost::bind(&MeshGenerator::add_cell_vertex, &generator_, ::_1)] >>
spirit::eol;;
face_section_header = qi::int_ /* Number of faces */ >> spirit::eol;
face = *space >> qi::int_ >>
*space >> qi::int_ >>
*space >> qi::int_ >>
*space >> qi::int_ >>
spirit::eol;
space = spirit::ascii::space - spirit::eol;
}
private:
qi::rule<Iterator/*, qi::space_type*/> node_section_header, element_section_header, face_section_header,
node, element, face, space, content;
MeshGenerator& generator_;
};
#endif /* NETGEN_HPP_ */
......@@ -6,17 +6,24 @@
#include <OpenVolumeMesh/FileManager/FileManager.hh>
#include "MeshGenerator.hpp"
#include "Grammars/Tetmesh.hpp"
#include "Grammars/Netgen.hpp"
void printUsage() {
std::cerr << "You need to specify a format and a source file to convert!" << std::endl << std::endl;
std::clog << "Usage: file_converter <format> <filename> [output_filename.ovm]" << std::endl << std::endl;
std::clog << "Available file formats:" << std::endl;
std::clog << " -t\tTetmesh" << std::endl;
std::clog << " -n\tNetgen" << std::endl;
std::clog << std::endl;
}
int main(int _argc, char* _argv[]) {
if(_argc < 3 || _argc > 4 ||
(_argc > 1 && (std::strcmp(_argv[1], "--help") == 0 || std::strcmp(_argv[1], "-h") == 0))) {
std::cerr << "You need to specify a source file to convert!" << std::endl << std::endl;
std::clog << "Usage: file_converter <format> <filename> [output_filename]" << std::endl << std::endl;
std::clog << "Available file formats:" << std::endl;
std::clog << " -t\tTetmesh" << std::endl;
std::clog << std::endl;
printUsage();
return -1;
}
......@@ -36,13 +43,24 @@ int main(int _argc, char* _argv[]) {
std::string fileContent = oss.str();
// Instantiate grammar objects
tetmesh_grammar<std::string::iterator> grammar(generator);
tetmesh_grammar<std::string::iterator> tetmesh_grammar(generator);
netgen_grammar<std::string::iterator> netgen_grammar(generator);
bool r = false;
if(std::strcmp(_argv[1], "-t") == 0) {
// Tetmesh format
r = boost::spirit::qi::phrase_parse(fileContent.begin(), fileContent.end(), grammar, qi::space);
r = boost::spirit::qi::phrase_parse(fileContent.begin(), fileContent.end(), tetmesh_grammar, qi::space);
} else if(std::strcmp(_argv[1], "-n") == 0) {
// Netgen format
r = boost::spirit::qi::phrase_parse(fileContent.begin(), fileContent.end(), netgen_grammar, qi::space);
} else {
printUsage();
return -1;
}
if(r) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment