Added managment of face color in saving off files
This commit is contained in:
parent
54875ffa0a
commit
7364bbdb61
|
@ -36,145 +36,146 @@
|
||||||
|
|
||||||
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
namespace tri {
|
namespace tri {
|
||||||
namespace io {
|
namespace io {
|
||||||
template <class SaveMeshType>
|
template <class SaveMeshType>
|
||||||
class ExporterOFF
|
class ExporterOFF
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef typename SaveMeshType::VertexPointer VertexPointer;
|
typedef typename SaveMeshType::VertexPointer VertexPointer;
|
||||||
typedef typename SaveMeshType::ScalarType ScalarType;
|
typedef typename SaveMeshType::ScalarType ScalarType;
|
||||||
typedef typename SaveMeshType::VertexType VertexType;
|
typedef typename SaveMeshType::VertexType VertexType;
|
||||||
typedef typename SaveMeshType::FaceType FaceType;
|
typedef typename SaveMeshType::FaceType FaceType;
|
||||||
typedef typename SaveMeshType::FacePointer FacePointer;
|
typedef typename SaveMeshType::FacePointer FacePointer;
|
||||||
typedef typename SaveMeshType::VertexIterator VertexIterator;
|
typedef typename SaveMeshType::VertexIterator VertexIterator;
|
||||||
typedef typename SaveMeshType::FaceIterator FaceIterator;
|
typedef typename SaveMeshType::FaceIterator FaceIterator;
|
||||||
|
|
||||||
static int Save(SaveMeshType &m, const char * filename, int mask=0 )
|
static int Save(SaveMeshType &m, const char * filename, int mask=0 )
|
||||||
{
|
{
|
||||||
vcg::face::Pos<FaceType> he;
|
vcg::face::Pos<FaceType> he;
|
||||||
vcg::face::Pos<FaceType> hei;
|
vcg::face::Pos<FaceType> hei;
|
||||||
FILE * fpout = fopen(filename,"w");
|
FILE * fpout = fopen(filename,"w");
|
||||||
if(fpout==NULL) return 1; // 1 is the error code for cant'open, see the ErrorMsg function
|
if(fpout==NULL) return 1; // 1 is the error code for cant'open, see the ErrorMsg function
|
||||||
|
|
||||||
|
|
||||||
|
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTNORMAL))
|
||||||
|
fprintf(fpout,"N");
|
||||||
|
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR))
|
||||||
|
fprintf(fpout,"C");
|
||||||
|
if( tri::HasPerVertexTexCoord(m) && (mask & io::Mask::IOM_VERTTEXCOORD))
|
||||||
|
fprintf(fpout,"ST");
|
||||||
|
fprintf(fpout,"OFF\n");
|
||||||
|
|
||||||
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTNORMAL))
|
int polynumber;
|
||||||
fprintf(fpout,"N");
|
if (mask &io::Mask::IOM_BITPOLYGONAL)
|
||||||
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR))
|
polynumber = tri::Clean<SaveMeshType>::CountBitLargePolygons(m);
|
||||||
fprintf(fpout,"C");
|
else
|
||||||
if( tri::HasPerVertexTexCoord(m) && (mask & io::Mask::IOM_VERTTEXCOORD))
|
polynumber = m.fn;
|
||||||
fprintf(fpout,"ST");
|
|
||||||
fprintf(fpout,"OFF\n");
|
|
||||||
|
|
||||||
int polynumber;
|
fprintf(fpout,"%d %d 0\n", m.vn, polynumber); // note that as edge number we simply write zero
|
||||||
if (mask &io::Mask::IOM_BITPOLYGONAL)
|
|
||||||
polynumber = tri::Clean<SaveMeshType>::CountBitLargePolygons(m);
|
|
||||||
else
|
|
||||||
polynumber = m.fn;
|
|
||||||
|
|
||||||
fprintf(fpout,"%d %d 0\n", m.vn, polynumber); // note that as edge number we simply write zero
|
//vertices
|
||||||
typename SaveMeshType::FaceIterator fi;
|
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->Flags()); // Save vertex flags
|
||||||
|
if( ! vp->IsD() )
|
||||||
|
{ // ***** ASCII *****
|
||||||
|
|
||||||
//vertices
|
fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]);
|
||||||
int j;
|
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR) )
|
||||||
std::vector<int> FlagV;
|
fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] );
|
||||||
VertexPointer vp;
|
|
||||||
VertexIterator vi;
|
|
||||||
for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi)
|
|
||||||
{
|
|
||||||
vp=&(*vi);
|
|
||||||
FlagV.push_back(vp->Flags()); // Save vertex flags
|
|
||||||
if( ! vp->IsD() )
|
|
||||||
{ // ***** ASCII *****
|
|
||||||
|
|
||||||
fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]);
|
if( tri::HasPerVertexNormal(m) && (mask & io::Mask::IOM_VERTNORMAL) )
|
||||||
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR) )
|
fprintf(fpout,"%g %g %g ", vp->N()[0],vp->N()[1],vp->N()[2]);
|
||||||
fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] );
|
|
||||||
|
|
||||||
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTNORMAL) )
|
if( tri::HasPerVertexTexCoord(m) && (mask & io::Mask::IOM_VERTTEXCOORD) )
|
||||||
fprintf(fpout,"%g %g %g ", vp->N()[0],vp->N()[1],vp->N()[2]);
|
fprintf(fpout,"%g %g ",vp->T().u(),vp->T().v());
|
||||||
|
|
||||||
if( tri::HasPerVertexTexCoord(m) && (mask & io::Mask::IOM_VERTTEXCOORD) )
|
fprintf(fpout,"\n");
|
||||||
fprintf(fpout,"%g %g ",vp->T().u(),vp->T().v());
|
|
||||||
|
|
||||||
fprintf(fpout,"\n");
|
|
||||||
|
|
||||||
|
|
||||||
vp->Flags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato!
|
vp->Flags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato!
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(j==m.vn);
|
assert(j==m.vn);
|
||||||
|
|
||||||
|
|
||||||
if (mask &io::Mask::IOM_BITPOLYGONAL) {
|
if (mask &io::Mask::IOM_BITPOLYGONAL) {
|
||||||
tri::RequireFFAdjacency(m);
|
tri::RequireFFAdjacency(m);
|
||||||
std::vector<VertexPointer> polygon;
|
std::vector<VertexPointer> polygon;
|
||||||
tri::UpdateFlags<SaveMeshType>::FaceClearV(m);
|
tri::UpdateFlags<SaveMeshType>::FaceClearV(m);
|
||||||
for(fi=m.face.begin();fi!=m.face.end();++fi) if (!fi->IsD()) if (!fi->IsV()) {
|
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if (!fi->IsD()) if (!fi->IsV()) {
|
||||||
vcg::tri::PolygonSupport<SaveMeshType,SaveMeshType>::ExtractPolygon(&*fi,polygon);
|
vcg::tri::PolygonSupport<SaveMeshType,SaveMeshType>::ExtractPolygon(&*fi,polygon);
|
||||||
if(!polygon.empty())
|
if(!polygon.empty())
|
||||||
{
|
|
||||||
fprintf(fpout,"%d ", int(polygon.size()) );
|
|
||||||
for (size_t i=0; i<polygon.size(); i++) fprintf(fpout,"%d ", polygon[i]->Flags() );
|
|
||||||
fprintf(fpout,"\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
|
||||||
{
|
|
||||||
FacePointer fp=&(*fi);
|
|
||||||
if( ! fp->IsD() )
|
|
||||||
{ fprintf(fpout,"3 %d %d %d\n",
|
|
||||||
fp->cV(0)->Flags(), fp->cV(1)->Flags(), fp->cV(2)->Flags() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fclose(fpout);
|
|
||||||
// Recupera i flag originali
|
|
||||||
j=0;
|
|
||||||
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
|
||||||
(*vi).Flags()=FlagV[j++];
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *ErrorMsg(int error)
|
|
||||||
{
|
{
|
||||||
static std::vector<std::string> off_error_msg;
|
fprintf(fpout,"%d ", int(polygon.size()) );
|
||||||
if(off_error_msg.empty())
|
for (size_t i=0; i<polygon.size(); i++) fprintf(fpout,"%d ", polygon[i]->Flags() );
|
||||||
{
|
fprintf(fpout,"\n");
|
||||||
off_error_msg.resize(2 );
|
|
||||||
off_error_msg[0]="No errors";
|
|
||||||
off_error_msg[1]="Can't open file";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(error>1 || error<0) return "Unknown error";
|
|
||||||
else return off_error_msg[error].c_str();
|
|
||||||
}
|
}
|
||||||
/*
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
|
||||||
|
{
|
||||||
|
if( ! fi->IsD() )
|
||||||
|
{
|
||||||
|
if( tri::HasPerFaceColor(m) && (mask & io::Mask::IOM_FACECOLOR) )
|
||||||
|
fprintf(fpout,"3 %d %d %d %i %i %i\n", fi->cV(0)->Flags(), fi->cV(1)->Flags(), fi->cV(2)->Flags(), fi->C()[0],fi->C()[1],fi->C()[2] );
|
||||||
|
else
|
||||||
|
fprintf(fpout,"3 %d %d %d\n", fi->cV(0)->Flags(), fi->cV(1)->Flags(), fi->cV(2)->Flags() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fclose(fpout);
|
||||||
|
// Recupera i flag originali
|
||||||
|
j=0;
|
||||||
|
for(vi=m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
|
(*vi).Flags()=FlagV[j++];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *ErrorMsg(int error)
|
||||||
|
{
|
||||||
|
static std::vector<std::string> off_error_msg;
|
||||||
|
if(off_error_msg.empty())
|
||||||
|
{
|
||||||
|
off_error_msg.resize(2 );
|
||||||
|
off_error_msg[0]="No errors";
|
||||||
|
off_error_msg[1]="Can't open file";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(error>1 || error<0) return "Unknown error";
|
||||||
|
else return off_error_msg[error].c_str();
|
||||||
|
}
|
||||||
|
/*
|
||||||
returns mask of capability one define with what are the saveable information of the format.
|
returns mask of capability one define with what are the saveable information of the format.
|
||||||
*/
|
*/
|
||||||
static int GetExportMaskCapability()
|
static int GetExportMaskCapability()
|
||||||
{
|
{
|
||||||
int capability = 0;
|
int capability = 0;
|
||||||
capability |= vcg::tri::io::Mask::IOM_VERTCOORD;
|
capability |= vcg::tri::io::Mask::IOM_VERTCOORD;
|
||||||
capability |= vcg::tri::io::Mask::IOM_VERTCOLOR;
|
capability |= vcg::tri::io::Mask::IOM_VERTCOLOR;
|
||||||
capability |= vcg::tri::io::Mask::IOM_VERTTEXCOORD;
|
capability |= vcg::tri::io::Mask::IOM_VERTTEXCOORD;
|
||||||
capability |= vcg::tri::io::Mask::IOM_FACEINDEX;
|
capability |= vcg::tri::io::Mask::IOM_FACEINDEX;
|
||||||
capability |= vcg::tri::io::Mask::IOM_BITPOLYGONAL;
|
capability |= vcg::tri::io::Mask::IOM_FACECOLOR;
|
||||||
return capability;
|
capability |= vcg::tri::io::Mask::IOM_BITPOLYGONAL;
|
||||||
}
|
return capability;
|
||||||
|
}
|
||||||
|
|
||||||
}; // end class
|
}; // end class
|
||||||
} // end namespace tri
|
} // end namespace tri
|
||||||
} // end namespace io
|
} // end namespace io
|
||||||
} // end namespace vcg
|
} // end namespace vcg
|
||||||
//@}
|
//@}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue