Tetmesh.hpp 1.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Tetmesh.hpp
 *
 *  Created on: Mar 20, 2012
 *      Author: kremer
 */

#include <boost/spirit/include/qi.hpp>

#include <boost/bind.hpp>

#include "../MeshGenerator.hpp"

#include <iostream>

#ifndef TETMESH_HPP_
#define TETMESH_HPP_

namespace qi = boost::spirit::qi;
namespace spirit = boost::spirit;

template <typename Iterator>
class tetmesh_grammar : public qi::grammar<Iterator, qi::space_type> {
public:
Jan Möbius's avatar
Jan Möbius committed
25
    explicit tetmesh_grammar(MeshGenerator& _generator) :
26 27 28 29 30 31
        tetmesh_grammar::base_type(content),
        generator_(_generator) {

        content = node_section_header >> *node >> element_section_header >> *element;

        node_section_header = spirit::lit("Vertices") >> qi::int_;
Mike Kremer's avatar
Mike Kremer committed
32

33 34 35 36 37
        node = qi::double_[boost::bind(&MeshGenerator::add_vertex_component, &generator_, ::_1)] >>
               qi::double_[boost::bind(&MeshGenerator::add_vertex_component, &generator_, ::_1)] >>
               qi::double_[boost::bind(&MeshGenerator::add_vertex_component, &generator_, ::_1)] >>
               qi::double_;

Mike Kremer's avatar
Mike Kremer committed
38 39 40
        element_section_header = spirit::lit("Tetrahedra") >>
                qi::int_[boost::bind(&MeshGenerator::set_num_cells, &generator_, ::_1)];

41 42 43 44 45 46 47 48 49 50 51 52 53 54
        element = qi::int_[boost::bind(&MeshGenerator::add_cell_vertex, &generator_, ::_1)] >>
                  qi::int_[boost::bind(&MeshGenerator::add_cell_vertex, &generator_, ::_1)] >>
                  qi::int_[boost::bind(&MeshGenerator::add_cell_vertex, &generator_, ::_1)] >>
                  qi::int_[boost::bind(&MeshGenerator::add_cell_vertex, &generator_, ::_1)];
    }

private:

    qi::rule<Iterator, qi::space_type> node_section_header, element_section_header, node, element, content;

    MeshGenerator& generator_;
};

#endif /* TETMESH_HPP_ */