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 #ifndef __VCGLIB_EXPORT_SMF
00033 #define __VCGLIB_EXPORT_SMF
00034
00035 #include <stdio.h>
00036
00037 namespace vcg {
00038 namespace tri {
00039 namespace io {
00040
00041 template <class SaveMeshType>
00045 class ExporterSMF
00046 {
00047 public:
00048 typedef typename SaveMeshType::VertexPointer VertexPointer;
00049 typedef typename SaveMeshType::ScalarType ScalarType;
00050 typedef typename SaveMeshType::VertexType VertexType;
00051 typedef typename SaveMeshType::FaceType FaceType;
00052 typedef typename SaveMeshType::VertexIterator VertexIterator;
00053 typedef typename SaveMeshType::FaceIterator FaceIterator;
00054
00056 static int Save(SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0)
00057 {
00058 VertexIterator vi;
00059 FaceIterator fi;
00060 FILE *fp;
00061 fp = fopen(filename,"wb");
00062 fprintf(fp,"#SMF \n" );
00063
00064 std::map<VertexPointer,int> index;
00065 int ind;
00066
00067 for(ind=1,vi=m.vert.begin(); vi!=m.vert.end(); ++vi,++ind)
00068 {
00069 fprintf(fp,"v " );
00070 fprintf(fp,"%f%s",(*vi).P()[0]," " );
00071 fprintf(fp,"%f%s",(*vi).P()[1]," " );
00072 fprintf(fp,"%f%s",(*vi).P()[2],"\n");
00073
00074 index[&*vi] = ind;
00075 }
00076 for (fi=m.face.begin(); fi!=m.face.end(); ++fi)
00077 {
00078 fprintf(fp,"%s","f ");
00079 for (int j = 0; j < 3; j++)
00080 fprintf(fp,"%i%s",index[(*fi).V(j)]," ");
00081 fprintf(fp,"%s","\n");
00082 }
00083 fclose(fp);
00084 return 0;
00085 }
00086
00088 static const char *ErrorMsg(int error)
00089 {
00090 static std::vector<std::string> smf_error_msg;
00091 if(smf_error_msg.empty())
00092 {
00093 smf_error_msg.resize(2 );
00094 smf_error_msg[0]="No errors";
00095 smf_error_msg[1]="Can't open file";
00096 }
00097
00098 if(error>1 || error<0) return "Unknown error";
00099 else return smf_error_msg[error].c_str();
00100 }
00101 };
00102 }
00103 }
00104 }
00105
00106 #endif
00107