export.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 /****************************************************************************
00025   History
00026 
00027 $Log: not supported by cvs2svn $
00028 Revision 1.6  2006/11/04 14:01:00  granzuglia
00029 fixed bug: &(*filename.end()) ---> &(*filename.rbegin())
00030 
00031 Revision 1.5  2006/07/09 05:32:15  cignoni
00032 Uncommented obj export. Now obj saving is enabled by default
00033 
00034 Revision 1.4  2006/03/29 08:14:20  corsini
00035 Add LoadMask to OFF importer
00036 
00037 Revision 1.3  2006/02/16 19:28:36  fmazzant
00038 transfer of Export_3ds.h, Export_obj.h, Io_3ds_obj_material.h from Meshlab to vcg
00039 
00040 Revision 1.2  2006/01/13 15:47:42  cignoni
00041 Uniformed return type to the style of Open. Now every export function returns 0 in case of success.
00042 
00043 Revision 1.1  2005/11/12 18:34:17  cignoni
00044 Initial Commit
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 // simple aux function that returns true if a given file has a given extesnion
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 // Open Mesh
00091 static int Save(OpenMeshType &m, const char *filename, CallBackPos *cb=0)
00092 {
00093  return Save(m,filename,0,cb);
00094 }
00095 
00096 // Open Mesh
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 }; // end class
00147 } // end Namespace tri
00148 } // end Namespace io
00149 } // end Namespace vcg
00150 
00151 #endif


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