import.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.11  2006/03/29 09:27:07  cignoni
00029 Added managemnt of non critical errors
00030 
00031 Revision 1.10  2006/03/29 08:16:31  corsini
00032 Minor change in LoadMask
00033 
00034 Revision 1.9  2006/03/27 07:17:49  cignoni
00035 Added generic LoadMask
00036 
00037 Revision 1.8  2006/03/07 13:19:29  cignoni
00038 First Release with OBJ import support
00039 
00040 Revision 1.7  2006/02/28 14:50:00  corsini
00041 Fix comments
00042 
00043 Revision 1.6  2006/02/10 16:14:53  corsini
00044 Fix typo
00045 
00046 Revision 1.5  2006/02/10 08:14:32  cignoni
00047 Refactored import. No more duplicated code
00048 
00049 Revision 1.4  2006/02/09 16:04:45  corsini
00050 Expose load mask
00051 
00052 Revision 1.3  2006/01/11 10:37:45  cignoni
00053 Added use of Callback
00054 
00055 Revision 1.2  2005/01/26 22:43:19  cignoni
00056 Add std:: to stl containers
00057 
00058 Revision 1.1  2004/11/29 08:12:10  cignoni
00059 Initial Update
00060 
00061 
00062 ****************************************************************************/
00063 
00064 #ifndef __VCGLIB_IMPORT
00065 #define __VCGLIB_IMPORT
00066 
00067 #include <wrap/io_trimesh/import_obj.h>
00068 #include <wrap/io_trimesh/import_ply.h>
00069 #include <wrap/io_trimesh/import_stl.h>
00070 #include <wrap/io_trimesh/import_off.h>
00071 #include <wrap/io_trimesh/import_vmi.h>
00072 
00073 #include <locale>
00074 
00075 namespace vcg {
00076 namespace tri {
00077 namespace io {
00078 
00084 template <class OpenMeshType>
00085 class Importer
00086 {
00087 private:
00088   enum KnownTypes { KT_UNKNOWN, KT_PLY, KT_STL, KT_OFF, KT_OBJ, KT_VMI };
00089 static int &LastType()
00090 {
00091   static int lastType= KT_UNKNOWN;
00092 return lastType;
00093 }
00094 
00095 public:
00096 // simple aux function that returns true if a given file has a given extesnion
00097 static bool FileExtension(std::string filename, std::string extension)
00098 {
00099   std::transform(filename.begin(), filename.end(), filename.begin(), ::tolower);
00100   std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
00101   std::string end=filename.substr(filename.length()-extension.length(),extension.length());
00102   return end==extension;
00103 }
00104 // Open Mesh, returns 0 on success.
00105 static int Open(OpenMeshType &m, const char *filename, CallBackPos *cb=0)
00106 {
00107   int dummymask = 0;
00108   return Open(m,filename,dummymask,cb);
00109 }
00110 
00112 static int Open(OpenMeshType &m, const char *filename, int &loadmask, CallBackPos *cb=0)
00113 {
00114         int err;
00115         if(FileExtension(filename,"ply"))
00116         {
00117                 err = ImporterPLY<OpenMeshType>::Open(m, filename, loadmask, cb);
00118                 LastType()=KT_PLY;
00119         }
00120         else if(FileExtension(filename,"stl"))
00121         {
00122                 err = ImporterSTL<OpenMeshType>::Open(m, filename, loadmask, cb);
00123                 LastType()=KT_STL;
00124         }
00125         else if(FileExtension(filename,"off"))
00126         {
00127                 err = ImporterOFF<OpenMeshType>::Open(m, filename, loadmask, cb);
00128                 LastType()=KT_OFF;
00129         }
00130         else if(FileExtension(filename,"obj"))
00131         {
00132                 err = ImporterOBJ<OpenMeshType>::Open(m, filename, loadmask, cb);
00133                 LastType()=KT_OBJ;
00134         }
00135     else if(FileExtension(filename,"vmi"))
00136     {
00137         err = ImporterVMI<OpenMeshType>::Open(m, filename, loadmask, cb);
00138         LastType()=KT_VMI;
00139     }
00140   else {
00141                 err=1;
00142                 LastType()=KT_UNKNOWN;
00143         }
00144 
00145         return err;
00146 }
00147 
00148 static bool ErrorCritical(int error)
00149 {
00150   switch(LastType())
00151   {
00152     case KT_PLY : return (error>0); break;
00153     case KT_STL : return (error>0); break;
00154     case KT_OFF : return (error>0); break;
00155     case KT_OBJ : return ImporterOBJ<OpenMeshType>::ErrorCritical(error); break;
00156   }
00157 
00158   return true;
00159 }
00160 
00161 static const char *ErrorMsg(int error)
00162 {
00163   switch(LastType())
00164   {
00165     case KT_PLY : return ImporterPLY<OpenMeshType>::ErrorMsg(error); break;
00166     case KT_STL : return ImporterSTL<OpenMeshType>::ErrorMsg(error); break;
00167     case KT_OFF : return ImporterOFF<OpenMeshType>::ErrorMsg(error); break;
00168     case KT_OBJ : return ImporterOBJ<OpenMeshType>::ErrorMsg(error); break;
00169     case KT_VMI : return ImporterVMI<OpenMeshType>::ErrorMsg(error); break;
00170   }
00171   return "Unknown type";
00172 }
00173 
00174 static bool LoadMask(const char * filename, int &mask)
00175 {
00176         bool err;
00177 
00178         if(FileExtension(filename,"ply"))
00179         {
00180                 err = ImporterPLY<OpenMeshType>::LoadMask(filename, mask);
00181                 LastType()=KT_PLY;
00182         }
00183         else if(FileExtension(filename,"stl"))
00184         {
00185                 mask = Mask::IOM_VERTCOORD | Mask::IOM_FACEINDEX;
00186                 err = true;
00187                 LastType()=KT_STL;
00188         }
00189         else if(FileExtension(filename,"off"))
00190         {
00191                 mask = Mask::IOM_VERTCOORD | Mask::IOM_FACEINDEX;
00192                 err = ImporterOFF<OpenMeshType>::LoadMask(filename, mask);
00193                 LastType()=KT_OFF;
00194         }
00195         else if(FileExtension(filename,"obj"))
00196         {
00197                 err = ImporterOBJ<OpenMeshType>::LoadMask(filename, mask);
00198                 LastType()=KT_OBJ;
00199         }
00200         else
00201         {
00202                 err = false;
00203                 LastType()=KT_UNKNOWN;
00204         }
00205 
00206         return err;
00207 }
00208 }; // end class
00209 } // end Namespace tri
00210 } // end Namespace io
00211 } // end Namespace vcg
00212 
00213 #endif


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