00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __VCGLIB_IMPORTERTS
00025 #define __VCGLIB_IMPORTERTS
00026 #define NULL 0
00027 #include <vcg/space/point3.h>
00028 #include <vcg/space/point4.h>
00029
00030 namespace vcg {
00031 namespace tetra {
00032 namespace io {
00033
00034 template <typename MESHTYPE>
00035 class ImporterTS{
00036 typedef MESHTYPE Tetramesh;
00037 typedef typename Tetramesh::VertexPointer VertexPointer;
00038 typedef typename Tetramesh::VertexType VertexType;
00039 typedef typename Tetramesh::TetraType FaceType;
00040 typedef typename Tetramesh::VertexIterator VertexIterator;
00041 typedef typename Tetramesh::TetraIterator FaceIterator;
00042 typedef typename Tetramesh::ScalarType ScalarType;
00043 typedef Point3<ScalarType> Point3x;
00044
00045 static FILE *& F(){static FILE * f; return f;}
00046
00047 inline static void ReadPos( Point3<double> &p){
00048 fscanf(F(),"%lg %lg %lg",&p[0],&p[1],&p[2]);
00049 }
00050 inline static void ReadPos( Point3<float> &p){
00051 fscanf(F(),"%f %f %f",&p[0],&p[1],&p[2]);
00052 }
00053 inline static void ReadPos( Point4<ScalarType> &p){
00054 fscanf(F(),"%g %g %g %g",&p[0],&p[1],&p[2],&p[3]);
00055 }
00056 public:
00057 static int Open( Tetramesh & m, const char * filename )
00058 {
00059 int nvertex;
00060 int ntetra;
00061 int tp0;
00062 int tp1;
00063 int tp2;
00064 int tp3;
00065 typename Tetramesh::VertexType p1;
00066 F() = fopen(filename,"r");
00067 if(F() == NULL )
00068 {
00069 printf( "The file was not opened\n" );
00070 return -1;
00071 }
00072 else
00073 {
00074 fscanf(F(), "%i", &nvertex );
00075 fscanf(F(), "%i", &ntetra );
00076 m.tetra.reserve(ntetra);
00077 m.vert.reserve(nvertex);
00078 int j;
00079 for (j=0;j<nvertex;j++)
00080 {
00081 m.vert.push_back(VertexType());
00082 ReadPos(m.vert.back().P());
00083 m.vert.back().ClearFlags();
00084 }
00085 for (j=0;j<ntetra;j++)
00086 {
00087 fscanf(F(), "%i", &tp0 );
00088 fscanf(F(), "%i", &tp1 );
00089 fscanf(F(), "%i", &tp2 );
00090 fscanf(F(), "%i", &tp3 );
00091
00092 m.tetra.push_back(typename Tetramesh::TetraType());
00093 m.tetra.back().V(0) = &m.vert[tp0];
00094 m.tetra.back().V(1) = &m.vert[tp1];
00095 m.tetra.back().V(2) = &m.vert[tp2];
00096 m.tetra.back().V(3) = &m.vert[tp3];
00097 m.tetra.back().UberFlags() = 0;
00098 }
00099 }
00100 m.vn = nvertex;
00101 m.tn = ntetra;
00102
00103 return 0;
00104 }
00105 };
00106 };
00107 };
00108 };
00109 #endif