Go to the documentation of this file.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 #ifndef __VCGLIB_IMPORTER_SMF
00029 #define __VCGLIB_IMPORTER_SMF
00030
00031 #include <stdio.h>
00032 #include <vcg/space/point3.h>
00033
00034 namespace vcg {
00035 namespace tri {
00036 namespace io {
00037 template<class OpenMeshType>
00041 class ImporterSMF
00042 {
00043 public:
00044 typedef typename OpenMeshType::VertexPointer VertexPointer;
00045 typedef typename OpenMeshType::ScalarType ScalarType;
00046 typedef typename OpenMeshType::VertexType VertexType;
00047 typedef typename OpenMeshType::FaceType FaceType;
00048 typedef typename OpenMeshType::VertexIterator VertexIterator;
00049 typedef typename OpenMeshType::FaceIterator FaceIterator;
00050
00051
00052 enum {SMF_LABEL_SIZE=80};
00053
00054 class SMFFacet
00055 {
00056 public:
00057 vcg::Point3f n;
00058 vcg::Point3f v[3];
00059 };
00060
00061 enum SMFError {
00062 E_NOERROR,
00063
00064 E_CANTOPEN,
00065 E_UNESPECTEDEOF
00066 };
00067
00069 static const char *ErrorMsg(int error)
00070 {
00071 static const char * smf_error_msg[] =
00072 {
00073 "No errors",
00074 "Can't open file",
00075 "Premature End of file",
00076 };
00077 if(error>2 || error<0) return "Unknown error";
00078 else return smf_error_msg[error];
00079 };
00081 static int Open(OpenMeshType &m, const char * filename )
00082 {
00083 VertexType v;
00084 FaceType f;
00085 FILE *fp;
00086 float x,y,z;
00087 bool one = true;
00088 std::map<int,VertexPointer> mv;
00089 fp = fopen(filename,"r");
00090 if(!fp) return -1;
00091 char buf[1024];
00092 while( fgets(buf,1024,fp) )
00093 {
00094 char *vf, *comm_pt;
00095 if((comm_pt = strstr(buf,"#")) != NULL)
00096 *comm_pt = '\0';
00097 if( (vf = strstr(buf,"v")) != NULL )
00098 {
00099 sscanf(vf+1,"%f %f %f", &x, &y, &z);
00100 v.P()[0] = x;
00101 v.P()[1] = y;
00102 v.P()[2] = z;
00103 m.vert.push_back(v);
00104 }
00105 else if( (vf = strstr(buf,"f")) != NULL)
00106 {
00107 if(one)
00108 {
00109 VertexIterator vi;
00110 int ind;
00111 for(ind=1,vi=m.vert.begin(); vi!=m.vert.end(); ++vi,++ind)
00112 mv[ind]=&*vi;
00113 one = false;
00114 }
00115 int v1,v2,v3;
00116 sscanf(vf+1,"%d %d %d", &v1, &v2, &v3);
00117 f.V(0) = mv[v1];
00118 f.V(1) = mv[v2];
00119 f.V(2) = mv[v3];
00120 m.face.push_back(f);
00121 }
00122 }
00123 m.vn = m.vert.size();
00124 m.fn = m.face.size();
00125 return 0;
00126 }
00127 };
00128 }
00129 }
00130 }
00131
00132 #endif
00133