vcglib/wrap/io_tetramesh/import_ts.h

84 lines
1.9 KiB
C
Raw Normal View History

2004-06-03 17:46:15 +02:00
#ifndef __VCGLIB_IMPORTERTS
#define __VCGLIB_IMPORTERTS
#define NULL 0
#include <vcg/space/point3.h>
2005-02-07 16:27:19 +01:00
#include <vcg/space/point4.h>
2004-06-03 15:16:32 +02:00
namespace vcg {
namespace tetra {
namespace io {
template <typename MESHTYPE>
class ImporterTS{
typedef MESHTYPE Tetramesh;
2004-06-03 17:46:15 +02:00
typedef typename Tetramesh::VertexPointer VertexPointer;
typedef typename Tetramesh::VertexType VertexType;
typedef typename Tetramesh::TetraType FaceType;
typedef typename Tetramesh::VertexIterator VertexIterator;
typedef typename Tetramesh::TetraIterator FaceIterator;
typedef typename Tetramesh::ScalarType ScalarType;
2004-06-03 15:16:32 +02:00
typedef Point3<ScalarType> Point3x;
2004-10-11 19:42:55 +02:00
static FILE *& F(){static FILE * f; return f;}
inline static ReadPos( Point3<ScalarType> &p){
fscanf(F(),"%g %g %g\n",&p[0],&p[1],&p[2]);
}
inline static ReadPos( Point4<ScalarType> &p){
fscanf(F(),"%g %g %g %g\n",&p[0],&p[1],&p[2],&p[3]);
}
2004-06-03 17:46:15 +02:00
public:
2005-02-18 12:58:26 +01:00
static int Open( Tetramesh & m, const char * filename )
{
2004-06-03 15:16:32 +02:00
int nvertex;
int ntetra;
int tp0;
int tp1;
int tp2;
int tp3;
typename Tetramesh::VertexType p1;
2004-10-11 19:42:55 +02:00
F() = fopen(filename,"r");
if(F() == NULL )
2004-06-03 15:16:32 +02:00
{
printf( "The file was not opened\n" );
return -1;
}
else
{
2004-10-11 19:42:55 +02:00
fscanf(F(), "%i", &nvertex );
fscanf(F(), "%i", &ntetra );
2004-06-03 15:16:32 +02:00
int j;
for (j=0;j<nvertex;j++)
{
2004-10-11 19:42:55 +02:00
m.vert.push_back(VertexType());
ReadPos(m.vert.back().P());
m.vert.back().ClearFlags();
2004-06-03 15:16:32 +02:00
}
2004-07-09 12:06:02 +02:00
m.tetra.reserve(ntetra);
m.vert.reserve(nvertex);
2004-06-03 15:16:32 +02:00
for (j=0;j<ntetra;j++)
{
2004-10-11 19:42:55 +02:00
fscanf(F(), "%i", &tp0 );
fscanf(F(), "%i", &tp1 );
fscanf(F(), "%i", &tp2 );
fscanf(F(), "%i", &tp3 );
2004-06-03 15:16:32 +02:00
2004-10-11 19:42:55 +02:00
m.tetra.push_back(typename Tetramesh::TetraType());
m.tetra.back().V(0) = &m.vert[tp0];
m.tetra.back().V(1) = &m.vert[tp1];
m.tetra.back().V(2) = &m.vert[tp2];
m.tetra.back().V(3) = &m.vert[tp3];
m.tetra.back().UberFlags() = 0;
2004-06-03 15:16:32 +02:00
}
}
2004-07-09 12:06:02 +02:00
m.vn = nvertex;
m.tn = ntetra;
2004-06-03 17:46:15 +02:00
return 0;
}
};// end class
};// end of io
};// end of tri
};// end of vcg
#endif