00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #ifndef __VCGLIB_TRIMESH_GENERIC_EXPORT
00050 #define __VCGLIB_TRIMESH_GENERIC_EXPORT
00051
00052 #include <wrap/io_trimesh/export_ply.h>
00053 #include <wrap/io_trimesh/export_stl.h>
00054 #include <wrap/io_trimesh/export_off.h>
00055 #include <wrap/io_trimesh/export_dxf.h>
00056 #include <wrap/io_trimesh/export_obj.h>
00057
00058 #include <locale>
00059
00060 namespace vcg {
00061 namespace tri {
00062 namespace io {
00063
00069 template <class OpenMeshType>
00070 class Exporter
00071 {
00072 private:
00073 enum KnownTypes { KT_UNKNOWN, KT_PLY, KT_STL, KT_DXF, KT_OFF, KT_OBJ};
00074 static int &LastType()
00075 {
00076 static int lastType= KT_UNKNOWN;
00077 return lastType;
00078 }
00079
00080 public:
00081
00082 static bool FileExtension(std::string filename, std::string extension)
00083 {
00084 std::locale loc1 ;
00085 std::use_facet<std::ctype<char> > ( loc1 ).tolower(&*filename.begin(),&(*filename.rbegin()));
00086 std::use_facet<std::ctype<char> > ( loc1 ).tolower(&*extension.begin(),&(*extension.rbegin()));
00087 std::string end=filename.substr(filename.length()-extension.length(),extension.length());
00088 return end==extension;
00089 }
00090
00091 static int Save(OpenMeshType &m, const char *filename, CallBackPos *cb=0)
00092 {
00093 return Save(m,filename,0,cb);
00094 }
00095
00096
00097 static int Save(OpenMeshType &m, const char *filename, const int mask, CallBackPos *cb=0)
00098 {
00099 int err;
00100 if(FileExtension(filename,"ply"))
00101 {
00102 err = ExporterPLY<OpenMeshType>::Save(m,filename,mask);
00103 LastType()=KT_PLY;
00104 }
00105 else if(FileExtension(filename,"stl"))
00106 {
00107 err = ExporterSTL<OpenMeshType>::Save(m,filename);
00108 LastType()=KT_STL;
00109 }
00110 else if(FileExtension(filename,"off"))
00111 {
00112 err = ExporterOFF<OpenMeshType>::Save(m,filename,mask);
00113 LastType()=KT_OFF;
00114 }
00115 else if(FileExtension(filename,"dxf"))
00116 {
00117 err = ExporterDXF<OpenMeshType>::Save(m,filename);
00118 LastType()=KT_DXF;
00119 }
00120 else if(FileExtension(filename,"obj"))
00121 {
00122 err = ExporterOBJ<OpenMeshType>::Save(m,filename,mask,cb);
00123 LastType()=KT_OBJ;
00124 }
00125 else {
00126 err=1;
00127 LastType()=KT_UNKNOWN;
00128 }
00129
00130 return err;
00131 }
00132
00133 static const char *ErrorMsg(int error)
00134 {
00135 switch(LastType())
00136 {
00137 case KT_PLY : return ExporterPLY<OpenMeshType>::ErrorMsg(error); break;
00138 case KT_STL : return ExporterSTL<OpenMeshType>::ErrorMsg(error); break;
00139 case KT_OFF : return ExporterOFF<OpenMeshType>::ErrorMsg(error); break;
00140 case KT_DXF : return ExporterDXF<OpenMeshType>::ErrorMsg(error); break;
00141 case KT_OBJ : return ExporterOBJ<OpenMeshType>::ErrorMsg(error); break;
00142 }
00143 return "Unknown type";
00144 }
00145
00146 };
00147 }
00148 }
00149 }
00150
00151 #endif