added
This commit is contained in:
parent
60e18f9b17
commit
dfdb436eab
|
@ -1,54 +0,0 @@
|
||||||
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
|
|
||||||
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
|
|
||||||
/****************************************************************************
|
|
||||||
History
|
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
|
||||||
Revision 1.3 2004/05/10 13:14:28 ganovelli
|
|
||||||
converted to library style (namespaces etc..)
|
|
||||||
|
|
||||||
|
|
||||||
****************************************************************************/
#ifndef __VCGLIB_IMPORTERSMF
|
|
||||||
#define __VCGLIB_IMPORTERSMF
#include <vcg/space/point3.h>
|
|
||||||
|
|
||||||
namespace vcg {
|
|
||||||
namespace tetra {
|
|
||||||
namespace io {
|
|
||||||
|
|
||||||
template <typename MESHTYPE>
|
|
||||||
class ExporterTS{
|
|
||||||
|
|
||||||
typedef typename MESHTYPE::VertexPointer VertexPointer;
|
|
||||||
typedef typename MESHTYPE::VertexType VertexType;
|
|
||||||
typedef typename MESHTYPE::TetraType FaceType;
|
|
||||||
typedef typename MESHTYPE::VertexIterator VertexIterator;
|
|
||||||
typedef typename MESHTYPE::FaceIterator FaceIterator;
|
|
||||||
typedef MESHTYPE::ScalarType ScalarType;
|
|
||||||
typedef Point3<ScalarType> Point3x;
|
|
||||||
|
|
||||||
|
|
||||||
int Save( MESHTYPE & m, const char * filename )
{
|
|
||||||
FILE *f;
|
|
||||||
f = fopen(filename,"w");
|
|
||||||
if(f == NULL )
|
|
||||||
{
|
|
||||||
printf( "The file could not be opened\n" );
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(f, "%i", m.vn );
|
|
||||||
fprintf(f, "%i", m.tn );
|
|
||||||
VertexIterator vi;
|
|
||||||
for (vi = m.vert.begin(); vi != m.vert.end();++vi)
|
|
||||||
fprintf(f, "%f %f %f \n", (*vi).P()[0],(*vi).P()[1],(*vi).P()[2] );
|
|
||||||
|
|
||||||
TetraIterator ti;
|
|
||||||
fr( ti = m.tetra.begin(); ti != m.tetra.end(); ++ti)
|
|
||||||
fprintf(f, "%d %d %d %d \n",
|
|
||||||
(*ti)->V(0)-&*m.tetra.begin(),
|
|
||||||
(*ti)->V(1)-&*m.tetra.begin(),
|
|
||||||
(*ti)->V(2)-&*m.tetra.begin(),
|
|
||||||
(*ti)->V(3)-&*m.tetra.begin());
|
|
||||||
}
return 0;
}
};// end class
};// end of io
};// end of tri
};// end of vcg
#endif
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* VCGLib o o *
|
||||||
|
* Visual and Computer Graphics Library o o *
|
||||||
|
* _ O _ *
|
||||||
|
* Copyright(C) 2004 \/)\/ *
|
||||||
|
* Visual Computing Lab /\/| *
|
||||||
|
* ISTI - Italian National Research Council | *
|
||||||
|
* \ *
|
||||||
|
* All rights reserved. *
|
||||||
|
* *
|
||||||
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
|
* (at your option) any later version. *
|
||||||
|
* *
|
||||||
|
* This program is distributed in the hope that it will be useful, *
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
||||||
|
* for more details. *
|
||||||
|
* *
|
||||||
|
****************************************************************************/
|
||||||
|
/****************************************************************************
|
||||||
|
History
|
||||||
|
|
||||||
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.1 2004/06/03 13:16:32 ganovelli
|
||||||
|
created
|
||||||
|
|
||||||
|
Revision 1.3 2004/05/10 13:14:28 ganovelli
|
||||||
|
converted to library style (namespaces etc..)
|
||||||
|
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __VCGLIB_EXPORTERSMF
|
||||||
|
#define __VCGLIB_EXPORTERSMF
|
||||||
|
|
||||||
|
#include <vcg/space/point3.h>
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
namespace tetra {
|
||||||
|
namespace io {
|
||||||
|
|
||||||
|
template <typename MESHTYPE>
|
||||||
|
struct ExporterTS{
|
||||||
|
|
||||||
|
typedef typename MESHTYPE::VertexPointer VertexPointer;
|
||||||
|
typedef typename MESHTYPE::VertexType VertexType;
|
||||||
|
typedef typename MESHTYPE::TetraType FaceType;
|
||||||
|
typedef typename MESHTYPE::VertexIterator VertexIterator;
|
||||||
|
typedef typename MESHTYPE::TetraIterator TetraIterator;
|
||||||
|
typedef MESHTYPE::ScalarType ScalarType;
|
||||||
|
typedef Point3<ScalarType> Point3x;
|
||||||
|
|
||||||
|
static FILE *& F(){static FILE * f; return f;}
|
||||||
|
|
||||||
|
inline static void WritePos(const Point3<ScalarType> &p){
|
||||||
|
fprintf(F(),"%g %g %g\n",p[0],p[1],p[2]);
|
||||||
|
}
|
||||||
|
inline static void WritePos(const Point4<ScalarType> &p){
|
||||||
|
fprintf(F(),"%g %g %g %g\n",p[0],p[1],p[2],p[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int Save( MESHTYPE & m, const char * filename )
|
||||||
|
{
|
||||||
|
|
||||||
|
F() = fopen(filename,"w");
|
||||||
|
if(F() == NULL )
|
||||||
|
{
|
||||||
|
printf( "The file could not be opened\n" );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(F(), "%i\n", m.vn );
|
||||||
|
fprintf(F(), "%i\n", m.tn );
|
||||||
|
VertexIterator vi;
|
||||||
|
for (vi = m.vert.begin(); vi != m.vert.end();++vi)
|
||||||
|
//fprintf(F(), "%f %f %f \n", (*vi).P()[0],(*vi).P()[1],(*vi).P()[2] );
|
||||||
|
WritePos((*vi).P());
|
||||||
|
|
||||||
|
TetraIterator ti;
|
||||||
|
for( ti = m.tetra.begin(); ti != m.tetra.end(); ++ti)
|
||||||
|
fprintf(F(), "%d %d %d %d \n",
|
||||||
|
(*ti).V(0)-&*m.vert.begin(),
|
||||||
|
(*ti).V(1)-&*m.vert.begin(),
|
||||||
|
(*ti).V(2)-&*m.vert.begin(),
|
||||||
|
(*ti).V(3)-&*m.vert.begin());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};// end class
|
||||||
|
};// end of io
|
||||||
|
};// end of tri
|
||||||
|
};// end of vcg
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -18,6 +18,14 @@ class ImporterTS{
|
||||||
typedef typename Tetramesh::ScalarType ScalarType;
|
typedef typename Tetramesh::ScalarType ScalarType;
|
||||||
typedef Point3<ScalarType> Point3x;
|
typedef Point3<ScalarType> Point3x;
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
static int Open( Tetramesh & m, const char * filename )
{
|
static int Open( Tetramesh & m, const char * filename )
{
|
||||||
int nvertex;
|
int nvertex;
|
||||||
|
@ -30,41 +38,39 @@ static int Open( Tetramesh & m, const char * filename )
{
|
||||||
int tp2;
|
int tp2;
|
||||||
int tp3;
|
int tp3;
|
||||||
float mass;
|
float mass;
|
||||||
FILE *f;
|
|
||||||
typename Tetramesh::VertexType p1;
|
typename Tetramesh::VertexType p1;
|
||||||
f = fopen(filename,"r");
|
F() = fopen(filename,"r");
|
||||||
if(f == NULL )
|
if(F() == NULL )
|
||||||
{
|
{
|
||||||
printf( "The file was not opened\n" );
|
printf( "The file was not opened\n" );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fscanf(f, "%i", &nvertex );
|
fscanf(F(), "%i", &nvertex );
|
||||||
fscanf(f, "%i", &ntetra );
|
fscanf(F(), "%i", &ntetra );
|
||||||
int j;
|
int j;
|
||||||
for (j=0;j<nvertex;j++)
|
for (j=0;j<nvertex;j++)
|
||||||
{
|
{
|
||||||
fscanf(f, "%f", &x );
|
m.vert.push_back(VertexType());
|
||||||
fscanf(f, "%f", &y );
|
ReadPos(m.vert.back().P());
|
||||||
fscanf(f, "%f", &z );
|
m.vert.back().ClearFlags();
|
||||||
//fscanf(f, "%f", &mass );
|
|
||||||
p1.ClearFlags();
|
|
||||||
p1.P()=Point3x(x, y,z );
|
|
||||||
m.vert.push_back(p1);
|
|
||||||
}
|
}
|
||||||
m.tetra.reserve(ntetra);
|
m.tetra.reserve(ntetra);
|
||||||
m.vert.reserve(nvertex);
|
m.vert.reserve(nvertex);
|
||||||
for (j=0;j<ntetra;j++)
|
for (j=0;j<ntetra;j++)
|
||||||
{
|
{
|
||||||
fscanf(f, "%i", &tp0 );
|
fscanf(F(), "%i", &tp0 );
|
||||||
fscanf(f, "%i", &tp1 );
|
fscanf(F(), "%i", &tp1 );
|
||||||
fscanf(f, "%i", &tp2 );
|
fscanf(F(), "%i", &tp2 );
|
||||||
fscanf(f, "%i", &tp3 );
|
fscanf(F(), "%i", &tp3 );
|
||||||
|
|
||||||
typename Tetramesh::TetraType newTetra;
|
m.tetra.push_back(typename Tetramesh::TetraType());
|
||||||
m.tetra.push_back(newTetra);
|
m.tetra.back().V(0) = &m.vert[tp0];
|
||||||
m.tetra.back().Init(&m.vert[tp0],&m.vert[tp1],&m.vert[tp2],&m.vert[tp3]);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.vn = nvertex;
|
m.vn = nvertex;
|
||||||
|
|
Loading…
Reference in New Issue