added treatment of HasPerVertexFlags absent

This commit is contained in:
ganovelli 2007-02-14 15:30:13 +00:00
parent f9e26cce1a
commit 30fb113d3c
2 changed files with 55 additions and 24 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.18 2006/12/18 09:46:39 callieri
camera+shot revamp: changed field names to something with more sense, cleaning of various functions, correction of minor bugs/incongruences, removal of the infamous reference in shot.
Revision 1.17 2006/11/30 22:49:32 cignoni Revision 1.17 2006/11/30 22:49:32 cignoni
Added save with (unused) callback Added save with (unused) callback
@ -91,6 +94,8 @@ Initial commit
//#include<wrap/ply/io_mask.h> //#include<wrap/ply/io_mask.h>
#include<wrap/io_trimesh/io_mask.h> #include<wrap/io_trimesh/io_mask.h>
#include<wrap/io_trimesh/io_ply.h> #include<wrap/io_trimesh/io_ply.h>
#include<vcg/container/simple_temporary_data.h>
#include <stdio.h> #include <stdio.h>
@ -220,7 +225,7 @@ static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &p
); );
if( pi.mask & Mask::IOM_VERTFLAGS ) if( m.HasPerVertexFlags() &&( pi.mask & Mask::IOM_VERTFLAGS) )
{ {
fprintf(fpout, fprintf(fpout,
"property int flags\n" "property int flags\n"
@ -253,7 +258,7 @@ static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &p
,m.fn ,m.fn
); );
if( pi.mask & Mask::IOM_FACEFLAGS ) if(m.HasPerFaceFlags() && (pi.mask & Mask::IOM_FACEFLAGS) )
{ {
fprintf(fpout, fprintf(fpout,
"property int flags\n" "property int flags\n"
@ -368,14 +373,21 @@ static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &p
int j; int j;
std::vector<int> FlagV; std::vector<int> FlagV;
VertexPointer vp; VertexPointer vp;
VertexIterator vi; VertexIterator vi;
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) SimpleTempData<SaveMeshType::VertContainer,int> indices(m.vert);
{ if(!m.HasPerVertexFlags())
indices.Start();
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi){
vp=&(*vi); vp=&(*vi);
FlagV.push_back(vp->UberFlags()); // Salva in ogni caso flag del vertice if(m.HasPerVertexFlags())
if( ! vp->IsD() ) FlagV.push_back(vp->UberFlags()); // Salva in ogni caso flag del vertice
else
indices[j] = j;
if( !m.HasPerVertexFlags() || !vp->IsD() )
{ {
if(binary) if(binary)
{ {
@ -385,7 +397,7 @@ std::vector<int> FlagV;
t = float(vp->UberP()[1]); 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); t = float(vp->UberP()[2]); fwrite(&t,sizeof(float),1,fpout);
if( pi.mask & Mask::IOM_VERTFLAGS ) if( m.HasPerVertexFlags() && (pi.mask & Mask::IOM_VERTFLAGS) )
fwrite(&(vp->UberFlags()),sizeof(int),1,fpout); fwrite(&(vp->UberFlags()),sizeof(int),1,fpout);
if( m.HasPerVertexColor() && (pi.mask & Mask::IOM_VERTCOLOR) ) if( m.HasPerVertexColor() && (pi.mask & Mask::IOM_VERTCOLOR) )
@ -414,7 +426,7 @@ std::vector<int> FlagV;
{ {
fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]); fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]);
if( pi.mask & Mask::IOM_VERTFLAGS ) if( m.HasPerVertexFlags() && (pi.mask & Mask::IOM_VERTFLAGS))
fprintf(fpout,"%d ",vp->UberFlags()); fprintf(fpout,"%d ",vp->UberFlags());
if( m.HasPerVertexColor() && (pi.mask & Mask::IOM_VERTCOLOR) ) if( m.HasPerVertexColor() && (pi.mask & Mask::IOM_VERTCOLOR) )
@ -441,8 +453,8 @@ std::vector<int> FlagV;
fprintf(fpout,"\n"); fprintf(fpout,"\n");
} }
if(m.HasPerVertexFlags())
vp->UberFlags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato! vp->UberFlags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato!
j++; j++;
} }
} }
@ -463,11 +475,20 @@ std::vector<int> FlagV;
{ fcnt++; { fcnt++;
if(binary) if(binary)
{ {
vv[0]=fp->cV(0)->UberFlags();
vv[1]=fp->cV(1)->UberFlags(); if(m.HasPerVertexFlags()){
vv[2]=fp->cV(2)->UberFlags(); vv[0]=fp->cV(0)->UberFlags();
fwrite(&c,1,1,fpout); vv[1]=fp->cV(1)->UberFlags();
fwrite(vv,sizeof(int),3,fpout); vv[2]=fp->cV(2)->UberFlags();
}
else
{
vv[0]=indices[fp->cV(0)];
vv[1]=indices[fp->cV(1)];
vv[2]=indices[fp->cV(2)];
}
fwrite(&c,1,1,fpout);
fwrite(vv,sizeof(int),3,fpout);
if( pi.mask & Mask::IOM_FACEFLAGS ) if( pi.mask & Mask::IOM_FACEFLAGS )
fwrite(&(fp->Flags()),sizeof(int),1,fpout); fwrite(&(fp->Flags()),sizeof(int),1,fpout);
@ -538,10 +559,14 @@ std::vector<int> FlagV;
} }
else // ***** ASCII ***** else // ***** ASCII *****
{ {
if(m.HasPerVertexFlags())
fprintf(fpout,"3 %d %d %d ", fprintf(fpout,"3 %d %d %d ",
fp->cV(0)->UberFlags(), fp->cV(1)->UberFlags(), fp->cV(2)->UberFlags() ); fp->cV(0)->UberFlags(), fp->cV(1)->UberFlags(), fp->cV(2)->UberFlags() );
else
fprintf(fpout,"3 %d %d %d ",
indices[fp->cV(0)], indices[fp->cV(1)], indices[fp->cV(2)] );
if( pi.mask & Mask::IOM_FACEFLAGS ) if(m.HasPerVertexFlags()&&( pi.mask & Mask::IOM_FACEFLAGS ))
fprintf(fpout,"%d ",fp->Flags()); fprintf(fpout,"%d ",fp->Flags());
if( m.HasPerVertexTexture() && (pi.mask & Mask::IOM_VERTTEXCOORD) ) if( m.HasPerVertexTexture() && (pi.mask & Mask::IOM_VERTTEXCOORD) )
@ -617,9 +642,12 @@ std::vector<int> FlagV;
fclose(fpout); fclose(fpout);
// Recupera i flag originali // Recupera i flag originali
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) if(!m.HasPerVertexFlags())
(*vi).UberFlags()=FlagV[j++]; for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
(*vi).UberFlags()=FlagV[j++];
else
indices.Stop();
return 0; return 0;
} }

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.32 2007/02/02 00:29:33 tarini
added a few typecasts to QualityTypefor vertices and faces (avoids warinings when short int or int is used for Quality).
Revision 1.31 2006/12/18 09:46:39 callieri Revision 1.31 2006/12/18 09:46:39 callieri
camera+shot revamp: changed field names to something with more sense, cleaning of various functions, correction of minor bugs/incongruences, removal of the infamous reference in shot. camera+shot revamp: changed field names to something with more sense, cleaning of various functions, correction of minor bugs/incongruences, removal of the infamous reference in shot.
@ -443,8 +446,8 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
// Descrittori facoltativi dei flags // Descrittori facoltativi dei flags
if(VertexType::HasFlags() && (pf.AddToRead(VertDesc(3))!=-1 ) ) if(VertexType::HasFlags() && pf.AddToRead(VertDesc(3))!=-1 )
pi.mask |= Mask::IOM_VERTFLAGS; pi.mask |= Mask::IOM_VERTFLAGS;
if( VertexType::HasQuality() ) if( VertexType::HasQuality() )
{ {
@ -623,7 +626,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
(*vi).P()[1] = va.p[1]; (*vi).P()[1] = va.p[1];
(*vi).P()[2] = va.p[2]; (*vi).P()[2] = va.p[2];
if( pi.mask & Mask::IOM_VERTFLAGS ) if( m.HasPerVertexFlags() && (pi.mask & Mask::IOM_VERTFLAGS) )
(*vi).UberFlags() = va.flags; (*vi).UberFlags() = va.flags;
if( pi.mask & Mask::IOM_VERTQUALITY ) if( pi.mask & Mask::IOM_VERTQUALITY )
@ -675,7 +678,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi )
} }
} }
if( pi.mask & Mask::IOM_FACEFLAGS ) if(m.HasPerFaceFlags() &&( pi.mask & Mask::IOM_FACEFLAGS) )
{ {
(*fi).UberFlags() = fa.flags; (*fi).UberFlags() = fa.flags;
} }