| 1 |
#ifndef __VCGLIB_IMPORTERTS |
| 2 |
#define __VCGLIB_IMPORTERTS |
| 3 |
#define NULL 0 |
| 4 |
#include <vcg/space/point3.h> |
| 5 |
#include <vcg/space/point4.h> |
| 6 |
|
| 7 |
namespace vcg { |
| 8 |
namespace tetra { |
| 9 |
namespace io { |
| 10 |
|
| 11 |
template <typename MESHTYPE> |
| 12 |
class ImporterTS{ |
| 13 |
typedef MESHTYPE Tetramesh; |
| 14 |
typedef typename Tetramesh::VertexPointer VertexPointer; |
| 15 |
typedef typename Tetramesh::VertexType VertexType; |
| 16 |
typedef typename Tetramesh::TetraType FaceType; |
| 17 |
typedef typename Tetramesh::VertexIterator VertexIterator; |
| 18 |
typedef typename Tetramesh::TetraIterator FaceIterator; |
| 19 |
typedef typename Tetramesh::ScalarType ScalarType; |
| 20 |
typedef Point3<ScalarType> Point3x; |
| 21 |
|
| 22 |
static FILE *& F(){static FILE * f; return f;} |
| 23 |
|
| 24 |
inline static void ReadPos( Point3<double> &p){ |
| 25 |
fscanf(F(),"%lg %lg %lg",&p[0],&p[1],&p[2]); |
| 26 |
} |
| 27 |
inline static void ReadPos( Point3<float> &p){ |
| 28 |
fscanf(F(),"%f %f %f",&p[0],&p[1],&p[2]); |
| 29 |
} |
| 30 |
inline static void ReadPos( Point4<ScalarType> &p){ |
| 31 |
fscanf(F(),"%g %g %g %g",&p[0],&p[1],&p[2],&p[3]); |
| 32 |
} |
| 33 |
public: |
| 34 |
static int Open( Tetramesh & m, const char * filename ) |
| 35 |
{ |
| 36 |
int nvertex; |
| 37 |
int ntetra; |
| 38 |
int tp0; |
| 39 |
int tp1; |
| 40 |
int tp2; |
| 41 |
int tp3; |
| 42 |
typename Tetramesh::VertexType p1; |
| 43 |
F() = fopen(filename,"r"); |
| 44 |
if(F() == NULL ) |
| 45 |
{ |
| 46 |
printf( "The file was not opened\n" ); |
| 47 |
return -1; |
| 48 |
} |
| 49 |
else |
| 50 |
{ |
| 51 |
fscanf(F(), "%i", &nvertex ); |
| 52 |
fscanf(F(), "%i", &ntetra ); |
| 53 |
m.tetra.reserve(ntetra); |
| 54 |
m.vert.reserve(nvertex); |
| 55 |
int j; |
| 56 |
for (j=0;j<nvertex;j++) |
| 57 |
{ |
| 58 |
m.vert.push_back(VertexType()); |
| 59 |
ReadPos(m.vert.back().P()); |
| 60 |
m.vert.back().ClearFlags(); |
| 61 |
} |
| 62 |
for (j=0;j<ntetra;j++) |
| 63 |
{ |
| 64 |
fscanf(F(), "%i", &tp0 ); |
| 65 |
fscanf(F(), "%i", &tp1 ); |
| 66 |
fscanf(F(), "%i", &tp2 ); |
| 67 |
fscanf(F(), "%i", &tp3 ); |
| 68 |
|
| 69 |
m.tetra.push_back(typename Tetramesh::TetraType()); |
| 70 |
m.tetra.back().V(0) = &m.vert[tp0]; |
| 71 |
m.tetra.back().V(1) = &m.vert[tp1]; |
| 72 |
m.tetra.back().V(2) = &m.vert[tp2]; |
| 73 |
m.tetra.back().V(3) = &m.vert[tp3]; |
| 74 |
m.tetra.back().UberFlags() = 0; |
| 75 |
} |
| 76 |
} |
| 77 |
m.vn = nvertex; |
| 78 |
m.tn = ntetra; |
| 79 |
|
| 80 |
return 0; |
| 81 |
} |
| 82 |
}; |
| 83 |
}; |
| 84 |
}; |
| 85 |
}; |
| 86 |
#endif |