diff --git a/Apps/Examples/viewer.cpp b/Apps/Examples/viewer.cpp index e9607aed9e167c967d7576439a0c5036fa0071f3..15afd5244b36357dad4793fc8bff51c7f6c5c830 100644 --- a/Apps/Examples/viewer.cpp +++ b/Apps/Examples/viewer.cpp @@ -175,9 +175,10 @@ void Viewer::cb_Open() void Viewer::cb_Save() { - std::string filters("off (*.off)") ; + std::string filters("all (*.*);; off (*.off);; ply (*.ply);; plygen (*.plygen)") ; std::string filename = selectFileSave("Save Mesh", "", filters) ; - Algo::Export::exportOFF(myMap, position, filename.c_str(), allDarts) ; + + exportMesh(filename) ; } void Viewer::importMesh(std::string& filename) @@ -224,6 +225,20 @@ void Viewer::importMesh(std::string& filename) updateGLMatrices() ; } +void Viewer::exportMesh(std::string& filename) +{ + size_t pos = filename.rfind(".") ; // position of "." in filename + std::string extension = filename.substr(pos) ; + + + if (extension.compare(std::string(".off")) == 0) + Algo::Export::exportOFF(myMap, position, filename.c_str(), allDarts) ; + else if (extension.compare(0, 4, std::string(".ply")) == 0) + Algo::Export::exportPLY(myMap, position, filename.c_str(), allDarts) ; + else + std::cerr << "Cannot save file " << filename << " : unknown or unhandled extension" << std::endl ; +} + void Viewer::slot_drawVertices(bool b) { m_drawVertices = b ; @@ -278,10 +293,19 @@ int main(int argc, char **argv) sqt.setGeometry(0, 0, 1000, 800) ; sqt.show() ; - if(argc == 2) + if(argc >= 2) { std::string filename(argv[1]) ; sqt.importMesh(filename) ; + if(argc >= 3) + { + std::string filenameExp(argv[2]) ; + std::cout << "Exporting " << filename << " as " << filenameExp << " ... "<< std::flush ; + sqt.exportMesh(filenameExp) ; + std::cout << "done!" << std::endl ; + + return (0) ; + } } sqt.initGUI() ; diff --git a/Apps/Examples/viewer.h b/Apps/Examples/viewer.h index beea4764ee49af0d0d950de21d0a4d9b506f0095..bd8c61e404ad126344bbdd53c4431706629b7c0f 100644 --- a/Apps/Examples/viewer.h +++ b/Apps/Examples/viewer.h @@ -112,6 +112,7 @@ public: void cb_Open() ; void cb_Save() ; + void exportMesh(std::string& filename) ; void importMesh(std::string& filename) ; public slots: