Added managment of face color in saving off files

This commit is contained in:
Paolo Cignoni 2014-10-29 22:24:45 +00:00
parent 54875ffa0a
commit 7364bbdb61
1 changed files with 119 additions and 118 deletions

View File

@ -36,13 +36,13 @@
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;
@ -59,7 +59,6 @@ namespace vcg {
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)) if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTNORMAL))
fprintf(fpout,"N"); fprintf(fpout,"N");
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR)) if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR))
@ -75,7 +74,6 @@ namespace vcg {
polynumber = m.fn; polynumber = m.fn;
fprintf(fpout,"%d %d 0\n", m.vn, polynumber); // note that as edge number we simply write zero fprintf(fpout,"%d %d 0\n", m.vn, polynumber); // note that as edge number we simply write zero
typename SaveMeshType::FaceIterator fi;
//vertices //vertices
int j; int j;
@ -93,7 +91,7 @@ namespace vcg {
if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR) ) if( tri::HasPerVertexColor(m) && (mask & io::Mask::IOM_VERTCOLOR) )
fprintf(fpout,"%d %d %d %d ",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] ); 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::HasPerVertexNormal(m) && (mask & io::Mask::IOM_VERTNORMAL) )
fprintf(fpout,"%g %g %g ", vp->N()[0],vp->N()[1],vp->N()[2]); fprintf(fpout,"%g %g %g ", vp->N()[0],vp->N()[1],vp->N()[2]);
if( tri::HasPerVertexTexCoord(m) && (mask & io::Mask::IOM_VERTTEXCOORD) ) if( tri::HasPerVertexTexCoord(m) && (mask & io::Mask::IOM_VERTTEXCOORD) )
@ -114,7 +112,7 @@ namespace vcg {
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())
{ {
@ -125,12 +123,14 @@ namespace vcg {
} }
} }
else { else {
for(fi=m.face.begin();fi!=m.face.end();++fi) for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
{ {
FacePointer fp=&(*fi); if( ! fi->IsD() )
if( ! fp->IsD() ) {
{ fprintf(fpout,"3 %d %d %d\n", if( tri::HasPerFaceColor(m) && (mask & io::Mask::IOM_FACECOLOR) )
fp->cV(0)->Flags(), fp->cV(1)->Flags(), fp->cV(2)->Flags() ); 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() );
} }
} }
} }
@ -168,13 +168,14 @@ namespace vcg {
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_FACECOLOR;
capability |= vcg::tri::io::Mask::IOM_BITPOLYGONAL; capability |= vcg::tri::io::Mask::IOM_BITPOLYGONAL;
return capability; 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