00001
00002 #ifndef _IOMESH_H
00003 #define _IOMESH_H
00004
00005 #include "IOManager.h"
00006
00007 #include "Mesh.h"
00008 #include "MeshOBJ.h"
00009
00010
00011 #define NO_MESHGK
00012
00013 namespace gk {
00014
00015
00016 class MeshIO : public IOManager<Mesh>
00017 {
00018
00019 MeshIO( const MeshIO& );
00020 MeshIO& operator=( const MeshIO& );
00021
00022
00023 MeshIO( )
00024 :
00025 IOManager<Mesh>()
00026 {}
00027
00028 ~MeshIO( ) {}
00029
00030 public:
00031
00032 static
00033 Mesh *read( const std::string& filename, const std::string& name= "" )
00034 {
00035
00036 Mesh *mesh= manager().find(filename, name);
00037 if(mesh != NULL)
00038 return mesh;
00039
00040
00041 mesh= new Mesh;
00042 if(isMeshOBJ(filename) && MeshLoadFromOBJ(filename, mesh) < 0)
00043 {
00044 printf("'%s' failed.\n", filename.c_str());
00045 delete mesh;
00046 return NULL;
00047 }
00048
00049 #ifndef NO_MESHGK
00050 if(isMeshGK(filename) && MeshLoadFromGK(filename, mesh) < 0)
00051 {
00052 printf("'%s' failed.\n", filename.c_str());
00053 delete mesh;
00054 return NULL;
00055 }
00056 #endif
00057
00058
00059 return manager().insert(mesh, filename, name);
00060 }
00061
00062 #ifndef NO_MESHGK
00063
00064
00065 static
00066 int write( const Mesh *mesh, const std::string& filename )
00067 {
00068 if(isMeshGK(filename) && MeshWriteToGK(mesh, filename) < 0)
00069 return -1;
00070 return 0;
00071 }
00072 #endif
00073
00074 static
00075 MeshIO& manager( )
00076 {
00077 static MeshIO manager;
00078 return manager;
00079 }
00080 };
00081
00082 }
00083
00084 #endif