diff --git a/wrap/io_trimesh/export.h b/wrap/io_trimesh/export.h new file mode 100644 index 00000000..c283e2e8 --- /dev/null +++ b/wrap/io_trimesh/export.h @@ -0,0 +1,121 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ + +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ + +****************************************************************************/ + +#ifndef __VCGLIB_TRIMESH_GENERIC_EXPORT +#define __VCGLIB_TRIMESH_GENERIC_EXPORT + +#include +#include +#include +#include + +#include + +namespace vcg { +namespace tri { +namespace io { + +/** +This class encapsulate a filter for automatically importing meshes by guessing +the right filter according to the extension +*/ + +template +class Exporter +{ +private: + enum KnownTypes { KT_UNKNOWN, KT_PLY, KT_STL, KT_DXF, KT_OFF }; +static int &LastType() +{ + static int lastType= KT_UNKNOWN; +return lastType; +} + +public: +// simple aux function that returns true if a given file has a given extesnion +static bool FileExtension(std::string filename, std::string extension) +{ + std::locale loc1 ; + std::use_facet > ( loc1 ).tolower(&*filename.begin(),&*filename.end()); + std::use_facet > ( loc1 ).tolower(&*extension.begin(),&*extension.end()); + std::string end=filename.substr(filename.length()-extension.length(),extension.length()); + return end==extension; +} + +// Open Mesh +static int Save(OpenMeshType &m, const char *filename, CallBackPos *cb=0) +{ + int err; + if(FileExtension(filename,"ply")) + { + err = ExporterPLY::Save(m,filename); + LastType()=KT_PLY; + } + else if(FileExtension(filename,"stl")) + { + err = ExporterSTL::Save(m,filename); + LastType()=KT_STL; + } + else if(FileExtension(filename,"off")) + { + err = ExporterOFF::Save(m,filename); + LastType()=KT_OFF; + } + else if(FileExtension(filename,"dxf")) + { + err = ExporterDXF::Save(m,filename); + LastType()=KT_DXF; + } + else { + err=1; + LastType()=KT_UNKNOWN; + } + + return err; +} + +static const char *ErrorMsg(int error) +{ + switch(LastType()) + { + case KT_PLY : return ExporterPLY::ErrorMsg(error); break; + case KT_STL : return ExporterSTL::ErrorMsg(error); break; + case KT_OFF : return ExporterOFF::ErrorMsg(error); break; + case KT_DXF : return ExporterDXF::ErrorMsg(error); break; + } + return "Unknown type"; +} + +}; // end class +} // end Namespace tri +} // end Namespace io +} // end Namespace vcg + +#endif