import_smf.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *   
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024   History
00025 $Log: not supported by cvs2svn $
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                 // if it is binary there are 80 char of comment, the number fn of faces and then exactly fn*4*3 bytes.
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,                              // 0
00063                         // Errori di open
00064                         E_CANTOPEN,                             // 1
00065                         E_UNESPECTEDEOF         // 2
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 }// end of io
00129 }// end of tri
00130 }// end of vcg
00131 
00132 #endif
00133 


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:31:58