created
This commit is contained in:
parent
dc9c863f3a
commit
be69a22a35
|
@ -0,0 +1,582 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* 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 $
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
@name Load and Save in Ply format
|
||||||
|
*/
|
||||||
|
//@{
|
||||||
|
|
||||||
|
#ifndef __VCGLIB_TETRAEXPORT_PLY
|
||||||
|
#define __VCGLIB_TETRAEXPORT_PLY
|
||||||
|
|
||||||
|
#include<wrap/ply/io_mask.h>
|
||||||
|
#include<wrap/io_tetramesh/io_ply.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
namespace tetra {
|
||||||
|
namespace io {
|
||||||
|
|
||||||
|
|
||||||
|
template <class SaveMeshType>
|
||||||
|
class ExporterPLY
|
||||||
|
{
|
||||||
|
// Si occupa di convertire da un tipo all'altro.
|
||||||
|
// usata nella saveply per matchare i tipi tra stotype e memtype.
|
||||||
|
// Ad es se in memoria c'e' un int e voglio salvare un float
|
||||||
|
// src sara in effetti un puntatore a int il cui valore deve
|
||||||
|
// essere convertito al tipo di ritorno desiderato (stotype)
|
||||||
|
|
||||||
|
template <class StoType>
|
||||||
|
static void PlyConv(int mem_type, void *src, StoType &dest)
|
||||||
|
{
|
||||||
|
switch (mem_type){
|
||||||
|
case ply::T_FLOAT : dest = (StoType) (* ((float *) src)); break;
|
||||||
|
case ply::T_DOUBLE: dest = (StoType) (* ((double *) src)); break;
|
||||||
|
case ply::T_INT : dest = (StoType) (* ((int *) src)); break;
|
||||||
|
case ply::T_SHORT : dest = (StoType) (* ((short *) src)); break;
|
||||||
|
case ply::T_CHAR : dest = (StoType) (* ((char *) src)); break;
|
||||||
|
case ply::T_UCHAR : dest = (StoType) (* ((unsigned char *)src)); break;
|
||||||
|
default : assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef ::vcg::ply::PropDescriptor PropDescriptor ;
|
||||||
|
typedef typename SaveMeshType::VertexPointer VertexPointer;
|
||||||
|
typedef typename SaveMeshType::ScalarType ScalarType;
|
||||||
|
typedef typename SaveMeshType::VertexType VertexType;
|
||||||
|
typedef typename SaveMeshType::TetraType TetraType;
|
||||||
|
typedef typename SaveMeshType::TetraPointer TetraPointer;
|
||||||
|
typedef typename SaveMeshType::VertexIterator VertexIterator;
|
||||||
|
typedef typename SaveMeshType::TetraIterator TetraIterator;
|
||||||
|
|
||||||
|
static bool Save(SaveMeshType &m, const char * filename, bool binary=true)
|
||||||
|
{
|
||||||
|
PlyInfo pi;
|
||||||
|
return Save(m,filename,binary,pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool Save(SaveMeshType &m, const char * filename, int savemask )
|
||||||
|
{
|
||||||
|
PlyInfo pi;
|
||||||
|
pi.mask=savemask;
|
||||||
|
return Save(m,filename,true,pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &pi ) // V1.0
|
||||||
|
{
|
||||||
|
FILE * fpout;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
const char * hbin = "binary_little_endian";
|
||||||
|
const char * hasc = "ascii";
|
||||||
|
const char * h;
|
||||||
|
|
||||||
|
bool multit = false;
|
||||||
|
|
||||||
|
if(binary) h=hbin;
|
||||||
|
else h=hasc;
|
||||||
|
|
||||||
|
fpout = fopen(filename,"wb");
|
||||||
|
if(fpout==NULL) {
|
||||||
|
pi.status=::vcg::ply::E_CANTOPEN;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fprintf(fpout,
|
||||||
|
"ply\n"
|
||||||
|
"format %s 1.0\n"
|
||||||
|
"comment VCGLIB generated\n"
|
||||||
|
,h
|
||||||
|
);
|
||||||
|
|
||||||
|
//if( pi.mask & ply::PLYMask::PM_WEDGTEXCOORD )
|
||||||
|
//{
|
||||||
|
// //const char * TFILE = "TextureFile";
|
||||||
|
|
||||||
|
// //for(i=0;i<textures.size();++i)
|
||||||
|
// // fprintf(fpout,"comment %s %s\n", TFILE, (const char *)(textures[i]) );
|
||||||
|
|
||||||
|
// //if(textures.size()>1 && (HasPerWedgeTexture() || HasPerVertexTexture())) multit = true;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//if( (pi.mask & PLYMask::PM_CAMERA) && camera.IsValid() )
|
||||||
|
/*{
|
||||||
|
fprintf(fpout,
|
||||||
|
"element camera 1\n"
|
||||||
|
"property float view_px\n"
|
||||||
|
"property float view_py\n"
|
||||||
|
"property float view_pz\n"
|
||||||
|
"property float x_axisx\n"
|
||||||
|
"property float x_axisy\n"
|
||||||
|
"property float x_axisz\n"
|
||||||
|
"property float y_axisx\n"
|
||||||
|
"property float y_axisy\n"
|
||||||
|
"property float y_axisz\n"
|
||||||
|
"property float z_axisx\n"
|
||||||
|
"property float z_axisy\n"
|
||||||
|
"property float z_axisz\n"
|
||||||
|
"property float focal\n"
|
||||||
|
"property float scalex\n"
|
||||||
|
"property float scaley\n"
|
||||||
|
"property float centerx\n"
|
||||||
|
"property float centery\n"
|
||||||
|
"property int viewportx\n"
|
||||||
|
"property int viewporty\n"
|
||||||
|
"property float k1\n"
|
||||||
|
"property float k2\n"
|
||||||
|
"property float k3\n"
|
||||||
|
"property float k4\n"
|
||||||
|
);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
fprintf(fpout,
|
||||||
|
"element vertex %d\n"
|
||||||
|
"property float x\n"
|
||||||
|
"property float y\n"
|
||||||
|
"property float z\n"
|
||||||
|
,m.vn
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
|
||||||
|
{
|
||||||
|
fprintf(fpout,
|
||||||
|
"property int flags\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( m.HasPerVertexColor() && (pi.mask & ply::PLYMask::PM_VERTCOLOR) )
|
||||||
|
{
|
||||||
|
fprintf(fpout,
|
||||||
|
"property uchar red\n"
|
||||||
|
"property uchar green\n"
|
||||||
|
"property uchar blue\n"
|
||||||
|
"property uchar alpha\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( m.HasPerVertexQuality() && (pi.mask & ply::PLYMask::PM_VERTQUALITY) )
|
||||||
|
{
|
||||||
|
fprintf(fpout,
|
||||||
|
"property float quality\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0;i<pi.vdn;i++)
|
||||||
|
fprintf(fpout,"property %s %s\n",pi.VertexData[i].stotypename(),pi.VertexData[i].propname);
|
||||||
|
|
||||||
|
fprintf(fpout,
|
||||||
|
"element tetra %d\n"
|
||||||
|
"property list uchar int vertex_indices\n"
|
||||||
|
,m.tn
|
||||||
|
);
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
|
||||||
|
{
|
||||||
|
fprintf(fpout,
|
||||||
|
"property int flags\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( VertexType::HasTexture() /*|| VertexType::HasPerWedgeTexture()*/ )
|
||||||
|
{
|
||||||
|
fprintf(fpout,
|
||||||
|
"property list uchar float texcoord\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
if(multit)
|
||||||
|
fprintf(fpout,
|
||||||
|
"property int texnumber\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( TetraType::HasTetraColor() && (pi.mask & ply::PLYMask::PM_TETRACOLOR) )
|
||||||
|
{
|
||||||
|
fprintf(fpout,
|
||||||
|
"property uchar red\n"
|
||||||
|
"property uchar green\n"
|
||||||
|
"property uchar blue\n"
|
||||||
|
"property uchar alpha\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//if ( m.HasPerWedgeColor() && (pi.mask & ply::PLYMask::PM_WEDGCOLOR) )
|
||||||
|
//{
|
||||||
|
// fprintf(fpout,
|
||||||
|
// "property list uchar float color\n"
|
||||||
|
// );
|
||||||
|
//}
|
||||||
|
|
||||||
|
if( m.HasPerTetraQuality() && (pi.mask & ply::PLYMask::PM_TETRAQUALITY) )
|
||||||
|
{
|
||||||
|
fprintf(fpout,
|
||||||
|
"property float quality\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0;i<pi.fdn;i++)
|
||||||
|
fprintf(fpout,"property %s %s\n",pi.TetraData[i].stotypename(),pi.TetraData[i].propname);
|
||||||
|
|
||||||
|
fprintf(fpout, "end_header\n" );
|
||||||
|
|
||||||
|
// Salvataggio camera
|
||||||
|
//if( (pi.mask & ply::PLYMask::PM_CAMERA) && camera.IsValid() )
|
||||||
|
//{
|
||||||
|
//if(binary)
|
||||||
|
//{
|
||||||
|
// float t[17];
|
||||||
|
|
||||||
|
// t[ 0] = camera.view_p[0];
|
||||||
|
// t[ 1] = camera.view_p[1];
|
||||||
|
// t[ 2] = camera.view_p[2];
|
||||||
|
// t[ 3] = camera.x_axis[0];
|
||||||
|
// t[ 4] = camera.x_axis[1];
|
||||||
|
// t[ 5] = camera.x_axis[2];
|
||||||
|
// t[ 6] = camera.y_axis[0];
|
||||||
|
// t[ 7] = camera.y_axis[1];
|
||||||
|
// t[ 8] = camera.y_axis[2];
|
||||||
|
// t[ 9] = camera.z_axis[0];
|
||||||
|
// t[10] = camera.z_axis[1];
|
||||||
|
// t[11] = camera.z_axis[2];
|
||||||
|
// t[12] = camera.f;
|
||||||
|
// t[13] = camera.s[0];
|
||||||
|
// t[14] = camera.s[1];
|
||||||
|
// t[15] = camera.c[0];
|
||||||
|
// t[16] = camera.c[1];
|
||||||
|
// fwrite(t,sizeof(float),17,fpout);
|
||||||
|
|
||||||
|
// fwrite( camera.viewport,sizeof(int),2,fpout );
|
||||||
|
|
||||||
|
// t[ 0] = camera.k[0];
|
||||||
|
// t[ 1] = camera.k[1];
|
||||||
|
// t[ 2] = camera.k[2];
|
||||||
|
// t[ 3] = camera.k[3];
|
||||||
|
// fwrite(t,sizeof(float),4,fpout);
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// fprintf(fpout,"%g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %g %d %d %g %g %g %g\n"
|
||||||
|
// ,camera.view_p[0]
|
||||||
|
// ,camera.view_p[1]
|
||||||
|
// ,camera.view_p[2]
|
||||||
|
// ,camera.x_axis[0]
|
||||||
|
// ,camera.x_axis[1]
|
||||||
|
// ,camera.x_axis[2]
|
||||||
|
// ,camera.y_axis[0]
|
||||||
|
// ,camera.y_axis[1]
|
||||||
|
// ,camera.y_axis[2]
|
||||||
|
// ,camera.z_axis[0]
|
||||||
|
// ,camera.z_axis[1]
|
||||||
|
// ,camera.z_axis[2]
|
||||||
|
// ,camera.f
|
||||||
|
// ,camera.s[0]
|
||||||
|
// ,camera.s[1]
|
||||||
|
// ,camera.c[0]
|
||||||
|
// ,camera.c[1]
|
||||||
|
// ,camera.viewport[0]
|
||||||
|
// ,camera.viewport[1]
|
||||||
|
// ,camera.k[0]
|
||||||
|
// ,camera.k[1]
|
||||||
|
// ,camera.k[2]
|
||||||
|
// ,camera.k[3]
|
||||||
|
// );
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
int j;
|
||||||
|
std::vector<int> FlagV;
|
||||||
|
VertexPointer vp;
|
||||||
|
VertexIterator vi;
|
||||||
|
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
|
{
|
||||||
|
vp=&(*vi);
|
||||||
|
FlagV.push_back(vp->UberFlags()); // Salva in ogni caso flag del vertice
|
||||||
|
if( ! vp->IsD() )
|
||||||
|
{
|
||||||
|
if(binary)
|
||||||
|
{
|
||||||
|
float t;
|
||||||
|
|
||||||
|
t = float(vp->UberP()[0]); fwrite(&t,sizeof(float),1,fpout);
|
||||||
|
t = float(vp->UberP()[1]); fwrite(&t,sizeof(float),1,fpout);
|
||||||
|
t = float(vp->UberP()[2]); fwrite(&t,sizeof(float),1,fpout);
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
|
||||||
|
fwrite(&(vp->UberFlags()),sizeof(int),1,fpout);
|
||||||
|
|
||||||
|
if( m.HasPerVertexColor() && (pi.mask & ply::PLYMask::PM_VERTCOLOR) )
|
||||||
|
fwrite(&( vp->C() ),sizeof(char),4,fpout);
|
||||||
|
|
||||||
|
if( m.HasPerVertexQuality() && (pi.mask & ply::PLYMask::PM_VERTQUALITY) )
|
||||||
|
fwrite(&( vp->Q() ),sizeof(float),1,fpout);
|
||||||
|
|
||||||
|
|
||||||
|
for(i=0;i<pi.vdn;i++)
|
||||||
|
{
|
||||||
|
double td; float tf;int ti;short ts; char tc; unsigned char tuc;
|
||||||
|
switch (pi.VertexData[i].stotype1)
|
||||||
|
{
|
||||||
|
case ply::T_FLOAT : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, tf ); fwrite(&tf, sizeof(float),1,fpout); break;
|
||||||
|
case ply::T_DOUBLE : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, td ); fwrite(&td, sizeof(double),1,fpout); break;
|
||||||
|
case ply::T_INT : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, ti ); fwrite(&ti, sizeof(int),1,fpout); break;
|
||||||
|
case ply::T_SHORT : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, ts ); fwrite(&ts, sizeof(short),1,fpout); break;
|
||||||
|
case ply::T_CHAR : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, tc ); fwrite(&tc, sizeof(char),1,fpout); break;
|
||||||
|
case ply::T_UCHAR : PlyConv(pi.VertexData[i].memtype1, ((char *)vp)+pi.VertexData[i].offset1, tuc); fwrite(&tuc,sizeof(unsigned char),1,fpout); break;
|
||||||
|
default : assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // ***** ASCII *****
|
||||||
|
{
|
||||||
|
fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]);
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
|
||||||
|
fprintf(fpout,"%d ",vp->UberFlags());
|
||||||
|
|
||||||
|
if( m.HasPerVertexColor() && (pi.mask & ply::PLYMask::PM_VERTCOLOR) )
|
||||||
|
fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] );
|
||||||
|
|
||||||
|
if( m.HasPerVertexQuality() && (pi.mask & ply::PLYMask::PM_VERTQUALITY) )
|
||||||
|
fprintf(fpout,"%g ",vp->Q());
|
||||||
|
|
||||||
|
for(i=0;i<pi.vdn;i++)
|
||||||
|
{
|
||||||
|
float tf; double td;
|
||||||
|
int ti;
|
||||||
|
switch (pi.VertexData[i].memtype1)
|
||||||
|
{
|
||||||
|
case ply::T_FLOAT : tf=*( (float *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%g ",tf); break;
|
||||||
|
case ply::T_DOUBLE : td=*( (double *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%g ",tf); break;
|
||||||
|
case ply::T_INT : ti=*( (int *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%i ",ti); break;
|
||||||
|
case ply::T_SHORT : ti=*( (short *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%i ",ti); break;
|
||||||
|
case ply::T_CHAR : ti=*( (char *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%i ",ti); break;
|
||||||
|
case ply::T_UCHAR : ti=*( (unsigned char *) (((char *)vp)+pi.VertexData[i].offset1)); fprintf(fpout,"%i ",ti); break;
|
||||||
|
default : assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fpout,"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
vp->UberFlags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato!
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(j==m.vn);
|
||||||
|
|
||||||
|
char c = 4;
|
||||||
|
unsigned char b9 = 9;
|
||||||
|
unsigned char b6 = 6;
|
||||||
|
TetraPointer fp;
|
||||||
|
int vv[4];
|
||||||
|
TetraIterator fi;
|
||||||
|
int fcnt=0;
|
||||||
|
for(j=0,fi=m.tetra.begin();fi!=m.tetra.end();++fi)
|
||||||
|
{
|
||||||
|
fp=&(*fi);
|
||||||
|
if( ! fp->IsD() )
|
||||||
|
{ fcnt++;
|
||||||
|
if(binary)
|
||||||
|
{
|
||||||
|
vv[0]=fp->cV(0)->UberFlags();
|
||||||
|
vv[1]=fp->cV(1)->UberFlags();
|
||||||
|
vv[2]=fp->cV(2)->UberFlags();
|
||||||
|
vv[3]=fp->cV(2)->UberFlags();
|
||||||
|
fwrite(&c,1,1,fpout);
|
||||||
|
fwrite(vv,sizeof(int),4,fpout);
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
|
||||||
|
fwrite(&(fp->Flags()),sizeof(int),1,fpout);
|
||||||
|
|
||||||
|
if( m.HasPerVertexTexture() && (pi.mask & ply::PLYMask::PM_VERTTEXCOORD) )
|
||||||
|
{
|
||||||
|
fwrite(&b6,sizeof(char),1,fpout);
|
||||||
|
float t[6];
|
||||||
|
for(int k=0;k<4;++k)
|
||||||
|
{
|
||||||
|
t[k*2+0] = fp->V(k)->T().u();
|
||||||
|
t[k*2+1] = fp->V(k)->T().v();
|
||||||
|
}
|
||||||
|
fwrite(t,sizeof(float),6,fpout);
|
||||||
|
}
|
||||||
|
//else if( m.HasPerWedgeTexture() && (pi.mask & ply::PLYMask::PM_WEDGTEXCOORD) )
|
||||||
|
//{
|
||||||
|
// fwrite(&b6,sizeof(char),1,fpout);
|
||||||
|
// float t[6];
|
||||||
|
// for(int k=0;k<3;++k)
|
||||||
|
// {
|
||||||
|
// t[k*2+0] = fp->WT(k).u();
|
||||||
|
// t[k*2+1] = fp->WT(k).v();
|
||||||
|
// }
|
||||||
|
// fwrite(t,sizeof(float),6,fpout);
|
||||||
|
//}
|
||||||
|
|
||||||
|
/* if(multit)
|
||||||
|
{
|
||||||
|
int t = fp->WT(0).n();
|
||||||
|
fwrite(&t,sizeof(int),1,fpout);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( m.HasPerTetraColor() && (pi.mask & ply::PLYMask::PM_TETRACOLOR) )
|
||||||
|
fwrite(&( fp->C() ),sizeof(char),4,fpout);*/
|
||||||
|
|
||||||
|
|
||||||
|
//if( m.HasPerWedgeColor() && (pi.mask & ply::PLYMask::PM_WEDGCOLOR) )
|
||||||
|
//{
|
||||||
|
// fwrite(&b9,sizeof(char),1,fpout);
|
||||||
|
// float t[3];
|
||||||
|
// for(int z=0;z<3;++z)
|
||||||
|
// {
|
||||||
|
// t[0] = float(fp->WC(z)[0])/255;
|
||||||
|
// t[1] = float(fp->WC(z)[1])/255;
|
||||||
|
// t[2] = float(fp->WC(z)[2])/255;
|
||||||
|
// fwrite( t,sizeof(float),3,fpout);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
if( TetraType::HasTetraQuality() && (pi.mask & ply::PLYMask::PM_TETRAQUALITY) )
|
||||||
|
fwrite( &(fp->Q()),sizeof(float),1,fpout);
|
||||||
|
|
||||||
|
|
||||||
|
for(i=0;i<pi.fdn;i++)
|
||||||
|
{
|
||||||
|
double td; float tf;int ti;short ts; char tc; unsigned char tuc;
|
||||||
|
switch (pi.TetraData[i].stotype1){
|
||||||
|
case ply::T_FLOAT : PlyConv(pi.TetraData[i].memtype1, ((char *)fp)+pi.TetraData[i].offset1, tf ); fwrite(&tf, sizeof(float),1,fpout); break;
|
||||||
|
case ply::T_DOUBLE : PlyConv(pi.TetraData[i].memtype1, ((char *)fp)+pi.TetraData[i].offset1, td ); fwrite(&td, sizeof(double),1,fpout); break;
|
||||||
|
case ply::T_INT : PlyConv(pi.TetraData[i].memtype1, ((char *)fp)+pi.TetraData[i].offset1, ti ); fwrite(&ti, sizeof(int),1,fpout); break;
|
||||||
|
case ply::T_SHORT : PlyConv(pi.TetraData[i].memtype1, ((char *)fp)+pi.TetraData[i].offset1, ts ); fwrite(&ts, sizeof(short),1,fpout); break;
|
||||||
|
case ply::T_CHAR : PlyConv(pi.TetraData[i].memtype1, ((char *)fp)+pi.TetraData[i].offset1, tc ); fwrite(&tc, sizeof(char),1,fpout); break;
|
||||||
|
case ply::T_UCHAR : PlyConv(pi.TetraData[i].memtype1, ((char *)fp)+pi.TetraData[i].offset1, tuc); fwrite(&tuc,sizeof(unsigned char),1,fpout); break;
|
||||||
|
default : assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // ***** ASCII *****
|
||||||
|
{
|
||||||
|
fprintf(fpout,"3 %d %d %d ",
|
||||||
|
fp->cV(0)->UberFlags(), fp->cV(1)->UberFlags(), fp->cV(2)->UberFlags() );
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
|
||||||
|
fprintf(fpout,"%d ",fp->Flags());
|
||||||
|
|
||||||
|
if( m.HasPerVertexTexture() && (pi.mask & ply::PLYMask::PM_VERTTEXCOORD) )
|
||||||
|
{
|
||||||
|
fprintf(fpout,"6 ");
|
||||||
|
for(int k=0;k<4;++k)
|
||||||
|
fprintf(fpout,"%g %g "
|
||||||
|
,fp->V(k)->T().u()
|
||||||
|
,fp->V(k)->T().v()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
//else if( m.HasPerWedgeTexture() && (pi.mask & ply::PLYMask::PM_WEDGTEXCOORD) )
|
||||||
|
//{
|
||||||
|
// fprintf(fpout,"6 ");
|
||||||
|
// for(int k=0;k<3;++k)
|
||||||
|
// fprintf(fpout,"%g %g "
|
||||||
|
// ,fp->WT(k).u()
|
||||||
|
// ,fp->WT(k).v()
|
||||||
|
// );
|
||||||
|
//}
|
||||||
|
|
||||||
|
/* if(multit)
|
||||||
|
{
|
||||||
|
fprintf(fpout,"%d ",fp->WT(0).n());
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if( TetraType::HasTetraColor() && (pi.mask & ply::PLYMask::PM_TETRACOLOR) )
|
||||||
|
{
|
||||||
|
float t[3];
|
||||||
|
t[0] = float(fp->C()[0])/255;
|
||||||
|
t[1] = float(fp->C()[1])/255;
|
||||||
|
t[2] = float(fp->C()[2])/255;
|
||||||
|
fprintf(fpout,"9 ");
|
||||||
|
fprintf(fpout,"%g %g %g ",t[0],t[1],t[2]);
|
||||||
|
fprintf(fpout,"%g %g %g ",t[0],t[1],t[2]);
|
||||||
|
fprintf(fpout,"%g %g %g ",t[0],t[1],t[2]);
|
||||||
|
}
|
||||||
|
//else if( m.HasPerWedgeColor() && (pi.mask & ply::PLYMask::PM_WEDGCOLOR) )
|
||||||
|
//{
|
||||||
|
// fprintf(fpout,"9 ");
|
||||||
|
// for(int z=0;z<3;++z)
|
||||||
|
// fprintf(fpout,"%g %g %g "
|
||||||
|
// ,double(fp->WC(z)[0])/255
|
||||||
|
// ,double(fp->WC(z)[1])/255
|
||||||
|
// ,double(fp->WC(z)[2])/255
|
||||||
|
// );
|
||||||
|
//}
|
||||||
|
|
||||||
|
if( m.HasPerTetraQuality() && (pi.mask & ply::PLYMask::PM_TETRAQUALITY) )
|
||||||
|
fprintf(fpout,"%g ",fp->Q());
|
||||||
|
|
||||||
|
for(i=0;i<pi.fdn;i++)
|
||||||
|
{
|
||||||
|
float tf; double td;
|
||||||
|
int ti;
|
||||||
|
switch (pi.TetraData[i].memtype1)
|
||||||
|
{
|
||||||
|
case ply::T_FLOAT : tf=*( (float *) (((char *)fp)+pi.TetraData[i].offset1)); fprintf(fpout,"%g ",tf); break;
|
||||||
|
case ply::T_DOUBLE : td=*( (double *) (((char *)fp)+pi.TetraData[i].offset1)); fprintf(fpout,"%g ",tf); break;
|
||||||
|
case ply::T_INT : ti=*( (int *) (((char *)fp)+pi.TetraData[i].offset1)); fprintf(fpout,"%i ",ti); break;
|
||||||
|
case ply::T_SHORT : ti=*( (short *) (((char *)fp)+pi.TetraData[i].offset1)); fprintf(fpout,"%i ",ti); break;
|
||||||
|
case ply::T_CHAR : ti=*( (char *) (((char *)fp)+pi.TetraData[i].offset1)); fprintf(fpout,"%i ",ti); break;
|
||||||
|
case ply::T_UCHAR : ti=*( (unsigned char *) (((char *)fp)+pi.TetraData[i].offset1)); fprintf(fpout,"%i ",ti); break;
|
||||||
|
default : assert(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fpout,"\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert(fcnt==m.tn);
|
||||||
|
fclose(fpout);
|
||||||
|
|
||||||
|
// Recupera i flag originali
|
||||||
|
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
|
(*vi).UberFlags()=FlagV[j++];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}; // end class
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // end namespace tri
|
||||||
|
} // end namespace io
|
||||||
|
} // end namespace vcg
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,54 @@
|
||||||
|
/****************************************************************************
* 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,776 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* 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 $
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __VCGLIB_TETRAIMPORTERPLY
|
||||||
|
#define __VCGLIB_TETRAIMPORTERPLY
|
||||||
|
|
||||||
|
#include<wrap/callback.h>
|
||||||
|
#include<wrap/ply/plylib.h>
|
||||||
|
#include<wrap/ply/io_mask.h>
|
||||||
|
#include<wrap/io_tetramesh/io_ply.h>
|
||||||
|
#include<vcg/complex/tetramesh/allocate.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
namespace tetra {
|
||||||
|
namespace io {
|
||||||
|
|
||||||
|
template <class TYPE>
|
||||||
|
int PlyType () { return 0;}
|
||||||
|
|
||||||
|
template <> int PlyType <float >() { return ply::T_FLOAT; }
|
||||||
|
template <> int PlyType <double>() { return ply::T_DOUBLE; }
|
||||||
|
template <> int PlyType <int >() { return ply::T_INT; }
|
||||||
|
template <> int PlyType <short >() { return ply::T_SHORT; }
|
||||||
|
template <> int PlyType <unsigned char >() { return ply::T_UCHAR; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
This class encapsulate a filter for opening ply meshes.
|
||||||
|
The ply file format is quite extensible...
|
||||||
|
*/
|
||||||
|
template <class OpenMeshType>
|
||||||
|
class ImporterPLY
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef ::vcg::ply::PropDescriptor PropDescriptor ;
|
||||||
|
typedef typename OpenMeshType::VertexPointer VertexPointer;
|
||||||
|
typedef typename OpenMeshType::ScalarType ScalarType;
|
||||||
|
typedef typename OpenMeshType::VertexType VertexType;
|
||||||
|
typedef typename OpenMeshType::TetraType TetraType;
|
||||||
|
typedef typename OpenMeshType::VertexIterator VertexIterator;
|
||||||
|
typedef typename OpenMeshType::TetraIterator TetraIterator;
|
||||||
|
|
||||||
|
//template <class T> int PlyType () { assert(0); return 0;}
|
||||||
|
|
||||||
|
#define MAX_USER_DATA 256
|
||||||
|
// Struttura ausiliaria per la lettura del file ply
|
||||||
|
struct LoadPly_TetraAux
|
||||||
|
{
|
||||||
|
unsigned char size;
|
||||||
|
int v[512];
|
||||||
|
int flags;
|
||||||
|
float q;
|
||||||
|
float tcoord[32];
|
||||||
|
unsigned char ntcoord;
|
||||||
|
int tcoordind;
|
||||||
|
float colors[32];
|
||||||
|
unsigned char ncolors;
|
||||||
|
|
||||||
|
unsigned char r;
|
||||||
|
unsigned char g;
|
||||||
|
unsigned char b;
|
||||||
|
|
||||||
|
unsigned char data[MAX_USER_DATA];
|
||||||
|
};
|
||||||
|
|
||||||
|
//struct LoadPly_TristripAux
|
||||||
|
//{
|
||||||
|
// int size;
|
||||||
|
// int *v;
|
||||||
|
// unsigned char data[MAX_USER_DATA];
|
||||||
|
//};
|
||||||
|
|
||||||
|
// Struttura ausiliaria per la lettura del file ply
|
||||||
|
template<class S>
|
||||||
|
struct LoadPly_VertAux
|
||||||
|
{
|
||||||
|
S p[3];
|
||||||
|
int flags;
|
||||||
|
float q;
|
||||||
|
unsigned char r;
|
||||||
|
unsigned char g;
|
||||||
|
unsigned char b;
|
||||||
|
unsigned char data[MAX_USER_DATA];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Struttura ausiliaria caricamento camera
|
||||||
|
//struct LoadPly_Camera
|
||||||
|
//{
|
||||||
|
// float view_px;
|
||||||
|
// float view_py;
|
||||||
|
// float view_pz;
|
||||||
|
// float x_axisx;
|
||||||
|
// float x_axisy;
|
||||||
|
// float x_axisz;
|
||||||
|
// float y_axisx;
|
||||||
|
// float y_axisy;
|
||||||
|
// float y_axisz;
|
||||||
|
// float z_axisx;
|
||||||
|
// float z_axisy;
|
||||||
|
// float z_axisz;
|
||||||
|
// float focal;
|
||||||
|
// float scalex;
|
||||||
|
// float scaley;
|
||||||
|
// float centerx;
|
||||||
|
// float centery;
|
||||||
|
// int viewportx;
|
||||||
|
// int viewporty;
|
||||||
|
// float k1;
|
||||||
|
// float k2;
|
||||||
|
// float k3;
|
||||||
|
// float k4;
|
||||||
|
//};
|
||||||
|
|
||||||
|
static const PropDescriptor &VertDesc(int i)
|
||||||
|
{
|
||||||
|
const static PropDescriptor pv[9]={
|
||||||
|
{"vertex", "x", ply::T_FLOAT, PlyType<ScalarType>(),offsetof(LoadPly_VertAux<ScalarType>,p[0]),0,0,0,0,0},
|
||||||
|
{"vertex", "y", ply::T_FLOAT, PlyType<ScalarType>(),offsetof(LoadPly_VertAux<ScalarType>,p[1]),0,0,0,0,0},
|
||||||
|
{"vertex", "z", ply::T_FLOAT, PlyType<ScalarType>(),offsetof(LoadPly_VertAux<ScalarType>,p[2]),0,0,0,0,0},
|
||||||
|
{"vertex", "flags", ply::T_INT, ply::T_INT, offsetof(LoadPly_VertAux<ScalarType>,flags),0,0,0,0,0},
|
||||||
|
{"vertex", "quality", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux<ScalarType>,q),0,0,0,0,0},
|
||||||
|
{"vertex", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,r),0,0,0,0,0},
|
||||||
|
{"vertex", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,g),0,0,0,0,0},
|
||||||
|
{"vertex", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_VertAux<ScalarType>,b),0,0,0,0,0},
|
||||||
|
{"vertex", "confidence",ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_VertAux<ScalarType>,q),0,0,0,0,0},
|
||||||
|
};
|
||||||
|
return pv[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const PropDescriptor &TetraDesc(int i)
|
||||||
|
{
|
||||||
|
const static PropDescriptor qf[10]=
|
||||||
|
{
|
||||||
|
{"tetra", "vertex_indices", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,v), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_TetraAux,size) },
|
||||||
|
{"tetra", "flags", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,flags), 0,0,0,0,0},
|
||||||
|
{"tetra", "quality", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_TetraAux,q), 0,0,0,0,0},
|
||||||
|
{"tetra", "texcoord", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_TetraAux,tcoord), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_TetraAux,ntcoord) },
|
||||||
|
{"tetra", "color", ply::T_FLOAT, ply::T_FLOAT, offsetof(LoadPly_TetraAux,colors), 1,0,ply::T_UCHAR,ply::T_UCHAR,offsetof(LoadPly_TetraAux,ncolors) },
|
||||||
|
{"tetra", "texnumber", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,tcoordind), 0,0,0,0,0},
|
||||||
|
{"tetra", "red" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,r), 0,0,0,0,0},
|
||||||
|
{"tetra", "green", ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,g), 0,0,0,0,0},
|
||||||
|
{"tetra", "blue" , ply::T_UCHAR, ply::T_UCHAR, offsetof(LoadPly_TetraAux,b), 0,0,0,0,0},
|
||||||
|
{"tetra", "vertex_index", ply::T_INT, ply::T_INT, offsetof(LoadPly_TetraAux,v), 1,0,ply::T_UCHAR,ply::T_CHAR,offsetof(LoadPly_TetraAux,size) },
|
||||||
|
};
|
||||||
|
return qf[i];
|
||||||
|
}
|
||||||
|
//static const PropDescriptor &TristripDesc(int i)
|
||||||
|
//{
|
||||||
|
// const static PropDescriptor qf[1]=
|
||||||
|
// {
|
||||||
|
// {"tristrips","vertex_indices", ply::T_INT, ply::T_INT, offsetof(LoadPly_TristripAux,v), 1,1,ply::T_INT,ply::T_INT,offsetof(LoadPly_TristripAux,size) },
|
||||||
|
// };
|
||||||
|
// return qf[i];
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
//static const PropDescriptor &CameraDesc(int i)
|
||||||
|
//{
|
||||||
|
// const static PropDescriptor cad[23] =
|
||||||
|
// {
|
||||||
|
// {"camera","view_px",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_px),0,0,0,0,0},
|
||||||
|
// {"camera","view_py",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_py),0,0,0,0,0},
|
||||||
|
// {"camera","view_pz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,view_pz),0,0,0,0,0},
|
||||||
|
// {"camera","x_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisx),0,0,0,0,0},
|
||||||
|
// {"camera","x_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisy),0,0,0,0,0},
|
||||||
|
// {"camera","x_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,x_axisz),0,0,0,0,0},
|
||||||
|
// {"camera","y_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisx),0,0,0,0,0},
|
||||||
|
// {"camera","y_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisy),0,0,0,0,0},
|
||||||
|
// {"camera","y_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,y_axisz),0,0,0,0,0},
|
||||||
|
// {"camera","z_axisx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisx),0,0,0,0,0},
|
||||||
|
// {"camera","z_axisy",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisy),0,0,0,0,0},
|
||||||
|
// {"camera","z_axisz",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,z_axisz),0,0,0,0,0},
|
||||||
|
// {"camera","focal" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,focal ),0,0,0,0,0},
|
||||||
|
// {"camera","scalex" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,scalex ),0,0,0,0,0},
|
||||||
|
// {"camera","scaley" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,scaley ),0,0,0,0,0},
|
||||||
|
// {"camera","centerx",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,centerx),0,0,0,0,0},
|
||||||
|
// {"camera","centery",ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,centery),0,0,0,0,0},
|
||||||
|
// {"camera","viewportx",ply::T_INT,ply::T_INT ,offsetof(LoadPly_Camera,viewportx),0,0,0,0,0},
|
||||||
|
// {"camera","viewporty",ply::T_INT,ply::T_INT ,offsetof(LoadPly_Camera,viewporty),0,0,0,0,0},
|
||||||
|
// {"camera","k1" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k1 ),0,0,0,0,0},
|
||||||
|
// {"camera","k2" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k2 ),0,0,0,0,0},
|
||||||
|
// {"camera","k3" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k3 ),0,0,0,0,0},
|
||||||
|
// {"camera","k4" ,ply::T_FLOAT,ply::T_FLOAT,offsetof(LoadPly_Camera,k4 ),0,0,0,0,0}
|
||||||
|
// };
|
||||||
|
// return cad[i];
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
/// Standard call for reading a mesh
|
||||||
|
static int Open( OpenMeshType &m, const char * filename, CallBackPos *cb=0)
|
||||||
|
{
|
||||||
|
PlyInfo pi;
|
||||||
|
pi.cb=cb;
|
||||||
|
return Open(m, filename, pi);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read a mesh and store in loadmask the loaded field
|
||||||
|
static int Open( OpenMeshType &m, const char * filename, int & loadmask, CallBackPos *cb =0)
|
||||||
|
{
|
||||||
|
PlyInfo pi;
|
||||||
|
pi.mask=loadmask;
|
||||||
|
return Open(m, filename,pi);
|
||||||
|
loadmask=pi.mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// read a mesh with all the possible option specified in the PlyInfo obj.
|
||||||
|
static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
|
||||||
|
{
|
||||||
|
assert(filename!=0);
|
||||||
|
vector<VertexPointer> index;
|
||||||
|
LoadPly_TetraAux fa;
|
||||||
|
// LoadPly_TristripAux tsa;
|
||||||
|
LoadPly_VertAux<ScalarType> va;
|
||||||
|
|
||||||
|
pi.mask = 0;
|
||||||
|
bool multit = false; // true if texture has a per face int spec the texture index
|
||||||
|
|
||||||
|
va.flags = 42;
|
||||||
|
|
||||||
|
pi.status = ::vcg::ply::E_NOERROR;
|
||||||
|
|
||||||
|
// init defaults
|
||||||
|
VertexType tv;
|
||||||
|
tv.UberFlags() = 0;
|
||||||
|
if( VertexType::HasQuality() ) tv.Q()=1.0;
|
||||||
|
if( VertexType::HasColor() ) tv.C()=Color4b(Color4b::White);
|
||||||
|
|
||||||
|
TetraType tf;
|
||||||
|
tf.UberFlags() = 0;
|
||||||
|
//if( FaceType::HasFaceQuality() ) tf.Q()=1.0;
|
||||||
|
//if( FaceType::HasWedgeColor() ) tf.WC(0)=tf.WC(1)=tf.WC(2)=Color4b(Color4b::White);
|
||||||
|
//if( FaceType::HasFaceColor() ) tf.C()=Color4b(Color4b::White);
|
||||||
|
// Descrittori delle strutture
|
||||||
|
|
||||||
|
//bool isvflags = false; // Il file contiene i flags
|
||||||
|
|
||||||
|
|
||||||
|
// The main descriptor of the ply file
|
||||||
|
vcg::ply::PlyFile pf;
|
||||||
|
|
||||||
|
// Open the file and parse the header
|
||||||
|
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
||||||
|
{
|
||||||
|
pi.status = pf.GetError();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pi.header = pf.GetHeader();
|
||||||
|
|
||||||
|
// Descrittori della camera
|
||||||
|
{ // Check that all the camera properties are present.
|
||||||
|
/* bool found = true;
|
||||||
|
for(int i=0;i<23;++i)
|
||||||
|
{
|
||||||
|
if( pf.AddToRead(CameraDesc(i))==-1 ) {
|
||||||
|
found = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(found) pi.mask |= ply::PLYMask::PM_CAMERA;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// Descrittori dati standard (vertex coord e faces)
|
||||||
|
if( pf.AddToRead(VertDesc(0))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; }
|
||||||
|
if( pf.AddToRead(VertDesc(1))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; }
|
||||||
|
if( pf.AddToRead(VertDesc(2))==-1 ) { pi.status = PlyInfo::E_NO_VERTEX; return -1; }
|
||||||
|
if( pf.AddToRead(TetraDesc(0))==-1 ){ pi.status = PlyInfo::E_NO_VERTEX; return -1; }
|
||||||
|
|
||||||
|
|
||||||
|
// Se fallisce si prova anche la sintassi di rapidform con index al posto di indices
|
||||||
|
// if( pf.AddToRead(TetraDesc(9))==-1 )
|
||||||
|
// if(pf.AddToRead(TristripDesc(0))==-1) // Se fallisce tutto si prova a vedere se ci sono tristrip alla levoy.
|
||||||
|
// { pi.status = PlyInfo::E_NO_FACE; return -1; }
|
||||||
|
|
||||||
|
// Descrittori facoltativi dei flags
|
||||||
|
if( pf.AddToRead(VertDesc(3))!=-1 )
|
||||||
|
pi.mask |= ply::PLYMask::PM_VERTFLAGS;
|
||||||
|
|
||||||
|
if( VertexType::HasQuality() )
|
||||||
|
{
|
||||||
|
if( pf.AddToRead(VertDesc(4))!=-1 ||
|
||||||
|
pf.AddToRead(VertDesc(8))!=-1 )
|
||||||
|
pi.mask |= ply::PLYMask::PM_VERTQUALITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( VertexType::HasColor() )
|
||||||
|
{
|
||||||
|
if( pf.AddToRead(VertDesc(5))!=-1 )
|
||||||
|
{
|
||||||
|
pf.AddToRead(VertDesc(6));
|
||||||
|
pf.AddToRead(VertDesc(7));
|
||||||
|
pi.mask |= ply::PLYMask::PM_VERTCOLOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// se ci sono i flag per vertice ci devono essere anche i flag per faccia
|
||||||
|
if( pf.AddToRead(TetraDesc(1))!=-1 )
|
||||||
|
pi.mask |= ply::PLYMask::PM_TETRAFLAGS;
|
||||||
|
|
||||||
|
if( TetraType::HasTetraQuality())
|
||||||
|
{
|
||||||
|
if( pf.AddToRead(TetraDesc(2))!=-1 )
|
||||||
|
pi.mask |= ply::PLYMask::PM_TETRAQUALITY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( TetraType::HasTetraColor() )
|
||||||
|
{
|
||||||
|
if( pf.AddToRead(TetraDesc(6))!=-1 )
|
||||||
|
{
|
||||||
|
pf.AddToRead(TetraDesc(7));
|
||||||
|
pf.AddToRead(TetraDesc(8));
|
||||||
|
pi.mask |= ply::PLYMask::PM_TETRACOLOR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if( FaceType::HasWedgeColor() || FaceType::HasFaceColor() || VertexType::HasColor())
|
||||||
|
//{
|
||||||
|
// if( pf.AddToRead(TetraDesc(4))!=-1 )
|
||||||
|
// {
|
||||||
|
// pi.mask |= ply::PLYMask::PM_WEDGCOLOR;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Descrittori definiti dall'utente,
|
||||||
|
vector<PropDescriptor> VPV(pi.vdn); // property descriptor relative al tipo LoadPly_VertexAux
|
||||||
|
vector<PropDescriptor> FPV(pi.fdn); // property descriptor relative al tipo LoadPly_FaceAux
|
||||||
|
if(pi.vdn>0){
|
||||||
|
// Compute the total size needed to load additional per vertex data.
|
||||||
|
size_t totsz=0;
|
||||||
|
for(int i=0;i<pi.vdn;i++){
|
||||||
|
VPV[i] = pi.VertexData[i];
|
||||||
|
VPV[i].offset1=offsetof(LoadPly_VertAux<ScalarType>,data)+totsz;
|
||||||
|
totsz+=pi.VertexData[i].memtypesize();
|
||||||
|
if( pf.AddToRead(VPV[i])==-1 ) { pi.status = pf.GetError(); return -1; }
|
||||||
|
}
|
||||||
|
if(totsz > MAX_USER_DATA)
|
||||||
|
{
|
||||||
|
pi.status = vcg::ply::E_BADTYPE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(pi.fdn>0){
|
||||||
|
size_t totsz=0;
|
||||||
|
for(int i=0;i<pi.fdn;i++){
|
||||||
|
FPV[i] = pi.TetraData[i];
|
||||||
|
FPV[i].offset1=offsetof(LoadPly_TetraAux,data)+totsz;
|
||||||
|
totsz+=pi.TetraData[i].memtypesize();
|
||||||
|
if( pf.AddToRead(FPV[i])==-1 ) { pi.status = pf.GetError(); return -1; }
|
||||||
|
}
|
||||||
|
if(totsz > MAX_USER_DATA)
|
||||||
|
{
|
||||||
|
pi.status = vcg::ply::E_BADTYPE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************/
|
||||||
|
/* Main Reading Loop */
|
||||||
|
/**************************************************************/
|
||||||
|
m.Clear();
|
||||||
|
for(int i=0;i<int(pf.elements.size());i++)
|
||||||
|
{
|
||||||
|
int n = pf.ElemNumber(i);
|
||||||
|
|
||||||
|
if( !strcmp( pf.ElemName(i),"camera" ) )
|
||||||
|
{
|
||||||
|
pf.SetCurElement(i);
|
||||||
|
|
||||||
|
// LoadPly_Camera ca;
|
||||||
|
|
||||||
|
for(int j=0;j<n;++j)
|
||||||
|
{
|
||||||
|
/* if( pf.Read( (void *)&(ca) )==-1 )
|
||||||
|
{
|
||||||
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
|
return -1;
|
||||||
|
} */
|
||||||
|
//camera.valid = true;
|
||||||
|
//camera.view_p[0] = ca.view_px;
|
||||||
|
//camera.view_p[1] = ca.view_py;
|
||||||
|
//camera.view_p[2] = ca.view_pz;
|
||||||
|
//camera.x_axis[0] = ca.x_axisx;
|
||||||
|
//camera.x_axis[1] = ca.x_axisy;
|
||||||
|
//camera.x_axis[2] = ca.x_axisz;
|
||||||
|
//camera.y_axis[0] = ca.y_axisx;
|
||||||
|
//camera.y_axis[1] = ca.y_axisy;
|
||||||
|
//camera.y_axis[2] = ca.y_axisz;
|
||||||
|
//camera.z_axis[0] = ca.z_axisx;
|
||||||
|
//camera.z_axis[1] = ca.z_axisy;
|
||||||
|
//camera.z_axis[2] = ca.z_axisz;
|
||||||
|
//camera.f = ca.focal;
|
||||||
|
//camera.s[0] = ca.scalex;
|
||||||
|
//camera.s[1] = ca.scaley;
|
||||||
|
//camera.c[0] = ca.centerx;
|
||||||
|
//camera.c[1] = ca.centery;
|
||||||
|
//camera.viewport[0] = ca.viewportx;
|
||||||
|
//camera.viewport[1] = ca.viewporty;
|
||||||
|
//camera.k[0] = ca.k1;
|
||||||
|
//camera.k[1] = ca.k2;
|
||||||
|
//camera.k[2] = ca.k3;
|
||||||
|
//camera.k[3] = ca.k4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( !strcmp( pf.ElemName(i),"vertex" ) )
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
|
||||||
|
pf.SetCurElement(i);
|
||||||
|
VertexIterator vi=Allocator<OpenMeshType>::AddVertices(m,n);
|
||||||
|
|
||||||
|
for(j=0;j<n;++j)
|
||||||
|
{
|
||||||
|
if(pi.cb && (j%1000)==0) pi.cb(j*50/n,"Vertex Loading");
|
||||||
|
(*vi).UberFlags()=0;
|
||||||
|
if( pf.Read( (void *)&(va) )==-1 )
|
||||||
|
{
|
||||||
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*vi).P()[0] = va.p[0];
|
||||||
|
(*vi).P()[1] = va.p[1];
|
||||||
|
(*vi).P()[2] = va.p[2];
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_VERTFLAGS )
|
||||||
|
(*vi).UberFlags() = va.flags;
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_VERTQUALITY )
|
||||||
|
(*vi).Q() = va.q;
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_VERTCOLOR )
|
||||||
|
{
|
||||||
|
(*vi).C()[0] = va.r;
|
||||||
|
(*vi).C()[1] = va.g;
|
||||||
|
(*vi).C()[2] = va.b;
|
||||||
|
(*vi).C()[3] = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for(int k=0;k<pi.vdn;k++)
|
||||||
|
memcpy((char *)(&*vi) + pi.VertexData[k].offset1,
|
||||||
|
(char *)(&va) + VPV[k].offset1,
|
||||||
|
VPV[k].memtypesize());
|
||||||
|
++vi;
|
||||||
|
}
|
||||||
|
|
||||||
|
index.resize(n);
|
||||||
|
for(j=0,vi=m.vert.begin();j<n;++j,++vi)
|
||||||
|
index[j] = &*vi;
|
||||||
|
}
|
||||||
|
else if( !strcmp( pf.ElemName(i),"tetra") )/************************************************************/
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
int k;
|
||||||
|
TetraIterator fi=Allocator<OpenMeshType>::AddTetra(m,n);
|
||||||
|
pf.SetCurElement(i);
|
||||||
|
|
||||||
|
for(j=0;j<n;++j)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(pi.cb && (j%1000)==0) pi.cb(50+j*50/n,"Tetra Loading");
|
||||||
|
if( pf.Read(&fa)==-1 )
|
||||||
|
{
|
||||||
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(fa.size!=4)
|
||||||
|
{
|
||||||
|
pi.status = PlyInfo::E_NO_3VERTINFACE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(k=0;k<4;++k)
|
||||||
|
{
|
||||||
|
if( fa.v[k]<0 || fa.v[k]>=m.vn )
|
||||||
|
{
|
||||||
|
pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
(*fi).V(k) = index[ fa.v[k] ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_TETRAFLAGS )
|
||||||
|
{
|
||||||
|
(*fi).UberFlags() = fa.flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_TETRAQUALITY )
|
||||||
|
{
|
||||||
|
(*fi).Q() = fa.q;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( pi.mask & ply::PLYMask::PM_TETRACOLOR )
|
||||||
|
{
|
||||||
|
(*fi).C()[0] = fa.r;
|
||||||
|
(*fi).C()[1] = fa.g;
|
||||||
|
(*fi).C()[2] = fa.b;
|
||||||
|
(*fi).C()[3] = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(TetraType::HasTetraColor()){
|
||||||
|
{
|
||||||
|
(*fi).C()[0] = (unsigned char)((fa.colors[0*3+0]*255+fa.colors[1*3+0]*255+fa.colors[2*3+0]*255)/3.0f);
|
||||||
|
(*fi).C()[1] = (unsigned char)((fa.colors[0*3+1]*255+fa.colors[1*3+1]*255+fa.colors[2*3+1]*255)/3.0f);
|
||||||
|
(*fi).C()[2] = (unsigned char)((fa.colors[0*3+2]*255+fa.colors[1*3+2]*255+fa.colors[2*3+2]*255)/3.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(k=0;k<pi.fdn;k++)
|
||||||
|
memcpy((char *)(&(*fi)) + pi.TetraData[k].offset1,
|
||||||
|
(char *)(&fa) + FPV[k].offset1,
|
||||||
|
FPV[k].memtypesize());
|
||||||
|
++fi;
|
||||||
|
}
|
||||||
|
// }
|
||||||
|
//else if( !strcmp( pf.ElemName(i),"tristrips") )//////////////////// LETTURA TRISTRIP DI STANFORD
|
||||||
|
// {
|
||||||
|
// int j;
|
||||||
|
// pf.SetCurElement(i);
|
||||||
|
// int numvert_tmp = m.vert.size();
|
||||||
|
// for(j=0;j<n;++j)
|
||||||
|
// {
|
||||||
|
// int k;
|
||||||
|
// if(pi.cb && (j%1000)==0) pi.cb(50+j*50/n,"Tristrip Face Loading");
|
||||||
|
// if( pf.Read(&tsa)==-1 )
|
||||||
|
// {
|
||||||
|
// pi.status = PlyInfo::E_SHORTFILE;
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
// int remainder=0;
|
||||||
|
// //int startface=m.face.size();
|
||||||
|
// for(k=0;k<tsa.size-2;++k)
|
||||||
|
// {
|
||||||
|
// if(pi.cb && (k%1000)==0) pi.cb(50+k*50/tsa.size,"Tristrip Face Loading");
|
||||||
|
// if(tsa.v[k]<0 || tsa.v[k]>=numvert_tmp ) {
|
||||||
|
// pi.status = PlyInfo::E_BAD_VERT_INDEX;
|
||||||
|
// return -1;
|
||||||
|
// }
|
||||||
|
// if(tsa.v[k+2]==-1)
|
||||||
|
// {
|
||||||
|
// k+=2;
|
||||||
|
// if(k%2) remainder=0;
|
||||||
|
// else remainder=1;
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// tf.V(0) = index[ tsa.v[k+0] ];
|
||||||
|
// tf.V(1) = index[ tsa.v[k+1] ];
|
||||||
|
// tf.V(2) = index[ tsa.v[k+2] ];
|
||||||
|
// if((k+remainder)%2) swap (tf.V(0), tf.V(1) );
|
||||||
|
// m.face.push_back( tf );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Skippaggio elementi non gestiti
|
||||||
|
int n = pf.ElemNumber(i);
|
||||||
|
pf.SetCurElement(i);
|
||||||
|
|
||||||
|
for(int j=0;j<n;j++)
|
||||||
|
{
|
||||||
|
if( pf.Read(0)==-1)
|
||||||
|
{
|
||||||
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Parsing texture names
|
||||||
|
//textures.clear();
|
||||||
|
//normalmaps.clear();
|
||||||
|
|
||||||
|
//for(int co=0;co<int(pf.comments.size());++co)
|
||||||
|
//{
|
||||||
|
// const char * TFILE = "TextureFile";
|
||||||
|
// const char * NFILE = "TextureNormalFile";
|
||||||
|
// const char * c = pf.comments[co];
|
||||||
|
// char buf[256];
|
||||||
|
// int i,j,n;
|
||||||
|
|
||||||
|
// if( !strncmp(c,TFILE,strlen(TFILE)) )
|
||||||
|
// {
|
||||||
|
// strcpy(buf,c+strlen(TFILE)+1);
|
||||||
|
// n = strlen(buf);
|
||||||
|
// for(i=j=0;i<n;i++)
|
||||||
|
// if( buf[i]!=' ' && buf[i]!='\t' && buf[i]>32 && buf[i]<125 ) buf[j++] = buf[i];
|
||||||
|
//
|
||||||
|
// buf[j] = 0;
|
||||||
|
// char buf2[255];
|
||||||
|
// __interpret_texture_name( buf,filename,buf2 );
|
||||||
|
// textures.push_back( xstring(buf2) );
|
||||||
|
// }
|
||||||
|
// if( !strncmp(c,NFILE,strlen(NFILE)) )
|
||||||
|
// {
|
||||||
|
// strcpy(buf,c+strlen(NFILE)+1);
|
||||||
|
// n = strlen(buf);
|
||||||
|
// for(i=j=0;i<n;i++)
|
||||||
|
// if( buf[i]!=' ' && buf[i]!='\t' && buf[i]>32 && buf[i]<125 ) buf[j++] = buf[i];
|
||||||
|
//
|
||||||
|
// buf[j] = 0;
|
||||||
|
// char buf2[255];
|
||||||
|
// __interpret_texture_name( buf,filename,buf2 );
|
||||||
|
// normalmaps.push_back( xstring(buf2) );
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
// vn and fn should be correct but if someone wrongly saved some deleted elements they can be wrong.
|
||||||
|
m.vn = 0;
|
||||||
|
VertexIterator vi;
|
||||||
|
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
|
if( ! (*vi).IsD() )
|
||||||
|
++m.vn;
|
||||||
|
|
||||||
|
m.tn = 0;
|
||||||
|
TetraIterator fi;
|
||||||
|
for(fi=m.tetra.begin();fi!=m.tetra.end();++fi)
|
||||||
|
if( ! (*fi).IsD() )
|
||||||
|
++m.tn;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Caricamento camera da un ply
|
||||||
|
int LoadCamera(const char * filename)
|
||||||
|
{
|
||||||
|
vcg::ply::PlyFile pf;
|
||||||
|
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
||||||
|
{
|
||||||
|
pi.status = pf.GetError();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool found = true;
|
||||||
|
int i;
|
||||||
|
for(i=0;i<23;++i)
|
||||||
|
{
|
||||||
|
if( pf.AddToRead(CameraDesc(i))==-1 )
|
||||||
|
{
|
||||||
|
found = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!found)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
for(i=0;i<int(pf.elements.size());i++)
|
||||||
|
{
|
||||||
|
int n = pf.ElemNumber(i);
|
||||||
|
|
||||||
|
if( !strcmp( pf.ElemName(i),"camera" ) )
|
||||||
|
{
|
||||||
|
pf.SetCurElement(i);
|
||||||
|
|
||||||
|
//LoadPly_Camera ca;
|
||||||
|
|
||||||
|
for(int j=0;j<n;++j)
|
||||||
|
{
|
||||||
|
if( pf.Read( (void *)&(ca) )==-1 )
|
||||||
|
{
|
||||||
|
pi.status = PlyInfo::E_SHORTFILE;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
camera.valid = true;
|
||||||
|
camera.view_p[0] = ca.view_px;
|
||||||
|
camera.view_p[1] = ca.view_py;
|
||||||
|
camera.view_p[2] = ca.view_pz;
|
||||||
|
camera.x_axis[0] = ca.x_axisx;
|
||||||
|
camera.x_axis[1] = ca.x_axisy;
|
||||||
|
camera.x_axis[2] = ca.x_axisz;
|
||||||
|
camera.y_axis[0] = ca.y_axisx;
|
||||||
|
camera.y_axis[1] = ca.y_axisy;
|
||||||
|
camera.y_axis[2] = ca.y_axisz;
|
||||||
|
camera.z_axis[0] = ca.z_axisx;
|
||||||
|
camera.z_axis[1] = ca.z_axisy;
|
||||||
|
camera.z_axis[2] = ca.z_axisz;
|
||||||
|
camera.f = ca.focal;
|
||||||
|
camera.s[0] = ca.scalex;
|
||||||
|
camera.s[1] = ca.scaley;
|
||||||
|
camera.c[0] = ca.centerx;
|
||||||
|
camera.c[1] = ca.centery;
|
||||||
|
camera.viewport[0] = ca.viewportx;
|
||||||
|
camera.viewport[1] = ca.viewporty;
|
||||||
|
camera.k[0] = ca.k1;
|
||||||
|
camera.k[1] = ca.k2;
|
||||||
|
camera.k[2] = ca.k3;
|
||||||
|
camera.k[3] = ca.k4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool LoadMask(const char * filename, int &mask)
|
||||||
|
{
|
||||||
|
mask=0;
|
||||||
|
vcg::ply::PlyFile pf;
|
||||||
|
if( pf.Open(filename,vcg::ply::PlyFile::MODE_READ)==-1 )
|
||||||
|
{
|
||||||
|
pi.status = pf.GetError();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( pf.AddToRead(VertDesc(0))!=-1 &&
|
||||||
|
pf.AddToRead(VertDesc(1))!=-1 &&
|
||||||
|
pf.AddToRead(VertDesc(2))!=-1 ) mask |= ply::PLYMask::PM_VERTCOORD;
|
||||||
|
|
||||||
|
if( pf.AddToRead(VertDesc(3))!=-1 ) mask |= ply::PLYMask::PM_VERTFLAGS;
|
||||||
|
if( pf.AddToRead(VertDesc(4))!=-1 ) mask |= ply::PLYMask::PM_VERTQUALITY;
|
||||||
|
if( pf.AddToRead(VertDesc(8))!=-1 ) mask |= ply::PLYMask::PM_VERTQUALITY;
|
||||||
|
if( ( pf.AddToRead(VertDesc(5))!=-1 ) &&
|
||||||
|
( pf.AddToRead(VertDesc(6))!=-1 ) &&
|
||||||
|
( pf.AddToRead(VertDesc(7))!=-1 ) ) mask |= ply::PLYMask::PM_VERTCOLOR;
|
||||||
|
|
||||||
|
if( pf.AddToRead(TetraDesc(0))!=-1 ) mask |= ply::PLYMask::PM_TETRAINDEX;
|
||||||
|
if( pf.AddToRead(TetraDesc(1))!=-1 ) mask |= ply::PLYMask::PM_TETRAFLAGS;
|
||||||
|
|
||||||
|
if( pf.AddToRead(TetraDesc(2))!=-1 ) mask |= ply::PLYMask::PM_TETRAQUALITY;
|
||||||
|
//if( pf.AddToRead(TetraDesc(3))!=-1 ) mask |= ply::PLYMask::PM_WEDGTEXCOORD;
|
||||||
|
//if( pf.AddToRead(TetraDesc(5))!=-1 ) mask |= ply::PLYMask::PM_WEDGTEXMULTI;
|
||||||
|
if( pf.AddToRead(TetraDesc(4))!=-1 ) mask |= ply::PLYMask::PM_WEDGCOLOR;
|
||||||
|
if( ( pf.AddToRead(TetraDesc(6))!=-1 ) &&
|
||||||
|
( pf.AddToRead(TetraDesc(7))!=-1 ) &&
|
||||||
|
( pf.AddToRead(TetraDesc(8))!=-1 ) ) mask |= ply::PLYMask::PM_TETRACOLOR;
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}; // end class
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // end namespace tri
|
||||||
|
} // end namespace io
|
||||||
|
} // end namespace vcg
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,79 @@
|
||||||
|
/****************************************************************************
* 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 ImporterTS{
|
||||||
|
|
||||||
|
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 Load( MESHTYPE & m, const char * filename )
{
|
||||||
|
int nvertex;
|
||||||
|
int ntetra;
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
float z;
|
||||||
|
int tp0;
|
||||||
|
int tp1;
|
||||||
|
int tp2;
|
||||||
|
int tp3;
|
||||||
|
float mass;
|
||||||
|
FILE *f;
|
||||||
|
Tetramesh::VertexType p1;
|
||||||
|
f = fopen(filename,"r");
|
||||||
|
if(f == NULL )
|
||||||
|
{
|
||||||
|
printf( "The file was not opened\n" );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fscanf(f, "%i", &nvertex );
|
||||||
|
fscanf(f, "%i", &ntetra );
|
||||||
|
int j;
|
||||||
|
for (j=0;j<nvertex;j++)
|
||||||
|
{
|
||||||
|
fscanf(f, "%f", &x );
|
||||||
|
fscanf(f, "%f", &y );
|
||||||
|
fscanf(f, "%f", &z );
|
||||||
|
//fscanf(f, "%f", &mass );
|
||||||
|
p1.ClearFlags();
|
||||||
|
p1.P()=Point3x(x, y,z );
|
||||||
|
vert.push_back(p1);
|
||||||
|
}
|
||||||
|
tetra.reserve(ntetra*10);
|
||||||
|
vert.reserve(nvertex*10);
|
||||||
|
for (j=0;j<ntetra;j++)
|
||||||
|
{
|
||||||
|
fscanf(f, "%i", &tp0 );
|
||||||
|
fscanf(f, "%i", &tp1 );
|
||||||
|
fscanf(f, "%i", &tp2 );
|
||||||
|
fscanf(f, "%i", &tp3 );
|
||||||
|
|
||||||
|
Tetramesh::TetraType newTetra;
|
||||||
|
tetra.push_back(newTetra);
|
||||||
|
tetra.back().Init(&vert[tp0],&vert[tp1],&vert[tp2],&vert[tp3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
}
};// end class
};// end of io
};// end of tri
};// end of vcg
#endif
|
|
@ -0,0 +1,113 @@
|
||||||
|
/****************************************************************************
|
||||||
|
* 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/12 10:19:30 ganovelli
|
||||||
|
new line added at the end of file
|
||||||
|
|
||||||
|
Revision 1.2 2004/03/09 21:26:47 cignoni
|
||||||
|
cr lf mismatch
|
||||||
|
|
||||||
|
Revision 1.1 2004/03/08 09:21:34 cignoni
|
||||||
|
Initial commit
|
||||||
|
|
||||||
|
Revision 1.1 2004/03/03 15:00:51 cignoni
|
||||||
|
Initial commit
|
||||||
|
|
||||||
|
****************************************************************************/
|
||||||
|
#ifndef __VCGLIB_IOTRIMESH_IO_PLY
|
||||||
|
#define __VCGLIB_IOTRIMESH_IO_PLY
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
@name Load and Save in Ply format
|
||||||
|
*/
|
||||||
|
//@{
|
||||||
|
#include<wrap/callback.h>
|
||||||
|
#include<wrap/ply/plylib.h>
|
||||||
|
|
||||||
|
namespace vcg {
|
||||||
|
namespace tetra {
|
||||||
|
namespace io {
|
||||||
|
|
||||||
|
|
||||||
|
/** Additional data needed or useful for parsing a ply mesh.
|
||||||
|
This class can be passed to the ImporterPLY::Open() function for
|
||||||
|
- retrieving additional per-vertex per-tetra data
|
||||||
|
- specifying a callback for long ply parsing
|
||||||
|
- knowing what data is contained in a ply file
|
||||||
|
*/
|
||||||
|
class PlyInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef ::vcg::ply::PropDescriptor PropDescriptor ;
|
||||||
|
|
||||||
|
PlyInfo()
|
||||||
|
{
|
||||||
|
status=0;
|
||||||
|
mask=0;
|
||||||
|
cb=0;
|
||||||
|
vdn=fdn=0;
|
||||||
|
VertexData=TetraData=0;
|
||||||
|
}
|
||||||
|
/// Store the error codes enconutered when parsing a ply
|
||||||
|
int status;
|
||||||
|
/// It returns a bit mask describing the field preesnt in the ply file
|
||||||
|
int mask;
|
||||||
|
|
||||||
|
/// a Simple callback that can be used for long ply parsing.
|
||||||
|
// it returns the current position, and formats a string with a description of what th efunction is doing (loading vertexes, faces...)
|
||||||
|
CallBackPos *cb;
|
||||||
|
|
||||||
|
/// the number of per-vertex descriptor (usually 0)
|
||||||
|
int vdn;
|
||||||
|
/// The additional vertex descriptor that a user can specify to load additional per-vertex non-standard data stored in a ply
|
||||||
|
PropDescriptor *VertexData;
|
||||||
|
/// the number of per-face descriptor (usually 0)
|
||||||
|
int fdn;
|
||||||
|
|
||||||
|
/// The additional vertex descriptor that a user can specify to load additional per-face non-standard data stored in a ply
|
||||||
|
PropDescriptor *TetraData;
|
||||||
|
|
||||||
|
/// a string containing the current ply header. Useful for showing it to the user.
|
||||||
|
std::string header;
|
||||||
|
|
||||||
|
enum Error
|
||||||
|
{
|
||||||
|
// Funzioni superiori
|
||||||
|
E_NO_VERTEX, // 14
|
||||||
|
E_NO_FACE, // 15
|
||||||
|
E_SHORTFILE, // 16
|
||||||
|
E_NO_3VERTINFACE, // 17
|
||||||
|
E_BAD_VERT_INDEX, // 18
|
||||||
|
E_NO_6TCOORD, // 19
|
||||||
|
E_DIFFER_COLORS, // 20
|
||||||
|
};
|
||||||
|
|
||||||
|
}; // end class
|
||||||
|
} // end namespace tri
|
||||||
|
} // end namespace io
|
||||||
|
} // end namespace vcg
|
||||||
|
#endif
|
Loading…
Reference in New Issue