Commit c4cd6d50 authored by Mike Kremer's avatar Mike Kremer

Added progress bar

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@158 66977474-1d4b-4f09-8fe9-267525286df2
parent 79e324a3
......@@ -29,12 +29,15 @@ public:
content = node_section_header >> *node >> element_section_header >> *element;
node_section_header = spirit::lit("Vertices") >> qi::int_;
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_;
element_section_header = spirit::lit("Tetrahedra") >> qi::int_;
element_section_header = spirit::lit("Tetrahedra") >>
qi::int_[boost::bind(&MeshGenerator::set_num_cells, &generator_, ::_1)];
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)] >>
......
......@@ -13,6 +13,8 @@
#include <map>
#include <algorithm>
#include <boost/shared_ptr.hpp>
#include <boost/progress.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
......@@ -37,8 +39,8 @@ public:
typedef OpenVolumeMesh::Geometry::Vec3d Vec3d;
MeshGenerator(PolyhedralMesh& _mesh) : v_component_(0), mesh_(_mesh) {}
MeshGenerator(const MeshGenerator& _cpy) : v_component_(_cpy.v_component_), mesh_(_cpy.mesh_) {}
MeshGenerator(PolyhedralMesh& _mesh) : v_component_(0), mesh_(_mesh), progress_() {}
MeshGenerator(const MeshGenerator& _cpy) : v_component_(_cpy.v_component_), mesh_(_cpy.mesh_), progress_() {}
void add_vertex_component(double _comp) {
......@@ -74,6 +76,13 @@ public:
}
}
void set_num_cells(unsigned int _n) {
if(progress_.get() == NULL) {
progress_.reset(new boost::progress_display(_n));
}
}
void add_tetrahedral_cell() {
if(c_vertices_.size() != 4) {
......@@ -175,7 +184,15 @@ public:
assert(cell_halffaces.size() == 4);
// Finally, add cell
#ifndef NDEBUG
mesh_.add_cell(cell_halffaces, true);
#else
mesh_.add_cell(cell_halffaces, false);
#endif
// Increase progress counter
if((progress_.get() != NULL) && (progress_->expected_count() != 0))
++(*progress_);
}
private:
......@@ -190,6 +207,8 @@ private:
FaceMap faceMap_;
PolyhedralMesh& mesh_;
boost::shared_ptr<boost::progress_display> progress_;
};
#endif /* MESHGENERATOR_HH_ */
......@@ -10,13 +10,17 @@
int main(int _argc, char* _argv[]) {
if(_argc != 3) {
std::cerr << "You need to specify a source and a target file!" << std::endl;
if(_argc != 3 ||
(_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>" << std::endl << std::endl;
std::clog << "Available file formats:" << std::endl;
std::clog << " -t\tTetmesh" << std::endl;
std::clog << std::endl;
return -1;
}
std::ifstream iff(_argv[1], std::ios::in);
//iff.unsetf(std::ios::skipws);
std::ifstream iff(_argv[2], std::ios::in);
if(!iff.good()) {
std::cerr << "Could not open file " << _argv[1] << " for reading!" << std::endl;
......@@ -31,29 +35,37 @@ int main(int _argc, char* _argv[]) {
std::string fileContent = oss.str();
// Instantiate grammar object
// Instantiate grammar objects
tetmesh_grammar<std::string::iterator> grammar(generator);
// Use iterator to parse file data
bool r = false;
//bool r = boost::spirit::qi::parse(fileContent.begin(), fileContent.end(), grammar);
bool r = boost::spirit::qi::phrase_parse(fileContent.begin(), fileContent.end(), grammar, qi::space);
if(std::strcmp(_argv[1], "-t") == 0) {
// Tetmesh format
r = boost::spirit::qi::phrase_parse(fileContent.begin(), fileContent.end(), grammar, qi::space);
}
if(r) {
std::cout << "Parsed all data successfully!" << std::endl;
std::cout << "Successfully read file data!" << std::endl;
} else {
std::cout << "Parsing failed!" << std::endl;
}
std::cerr << "Added " << mesh.n_vertices() << " vertices!" << std::endl;
std::cerr << "Added " << mesh.n_edges() << " edges!" << std::endl;
std::cerr << "Added " << mesh.n_faces() << " faces!" << std::endl;
std::cerr << "Added " << mesh.n_cells() << " cells!" << std::endl;
std::cerr << "Converted " << mesh.n_vertices() << " vertices," << std::endl;
std::cerr << "\t " << mesh.n_edges() << " edges," << std::endl;
std::cerr << "\t " << mesh.n_faces() << " faces," << std::endl;
std::cerr << "\t " << mesh.n_cells() << " cells!" << std::endl;
OpenVolumeMesh::IO::FileManager fileManager;
std::string filename(_argv[2]);
std::string::size_type idx = filename.rfind('.');
std::string out_filename = filename.substr(0, idx);
out_filename.append(".ovm");
// Write mesh to file
fileManager.writeFile(_argv[2], mesh);
fileManager.writeFile(out_filename.c_str(), mesh);
return 0;
}
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