export_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 Revision 1.3  2006/11/21 19:23:50  e_cerisoli
00027 Added comments for documentation
00028 
00029 Revision 1.2  2006/11/16 11:24:44 
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         }; // end class
00102 } // end Namespace tri
00103 } // end Namespace io
00104 } // end Namespace vcg
00105 
00106 #endif
00107 


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