Commit 476ef94c authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

Added utility in viewer to export a mesh into all available exported types.

Added utility in viewer to do this in command-line using 2 arguments : for example "./viewer input.off output.ply"
parent 167905bb
...@@ -175,9 +175,10 @@ void Viewer::cb_Open() ...@@ -175,9 +175,10 @@ void Viewer::cb_Open()
void Viewer::cb_Save() 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) ; std::string filename = selectFileSave("Save Mesh", "", filters) ;
Algo::Export::exportOFF<PFP>(myMap, position, filename.c_str(), allDarts) ;
exportMesh(filename) ;
} }
void Viewer::importMesh(std::string& filename) void Viewer::importMesh(std::string& filename)
...@@ -224,6 +225,20 @@ void Viewer::importMesh(std::string& filename) ...@@ -224,6 +225,20 @@ void Viewer::importMesh(std::string& filename)
updateGLMatrices() ; 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<PFP>(myMap, position, filename.c_str(), allDarts) ;
else if (extension.compare(0, 4, std::string(".ply")) == 0)
Algo::Export::exportPLY<PFP>(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) void Viewer::slot_drawVertices(bool b)
{ {
m_drawVertices = b ; m_drawVertices = b ;
...@@ -278,10 +293,19 @@ int main(int argc, char **argv) ...@@ -278,10 +293,19 @@ int main(int argc, char **argv)
sqt.setGeometry(0, 0, 1000, 800) ; sqt.setGeometry(0, 0, 1000, 800) ;
sqt.show() ; sqt.show() ;
if(argc == 2) if(argc >= 2)
{ {
std::string filename(argv[1]) ; std::string filename(argv[1]) ;
sqt.importMesh(filename) ; 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() ; sqt.initGUI() ;
......
...@@ -112,6 +112,7 @@ public: ...@@ -112,6 +112,7 @@ public:
void cb_Open() ; void cb_Open() ;
void cb_Save() ; void cb_Save() ;
void exportMesh(std::string& filename) ;
void importMesh(std::string& filename) ; void importMesh(std::string& filename) ;
public slots: public slots:
......
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