From 0bdd7975b0114fbb547c02bf7a5340ea0ef405e2 Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 15 Apr 2008 10:38:12 +0000 Subject: [PATCH] added suppor of color in OFF format. --- wrap/io_trimesh/export.h | 5 +++- wrap/io_trimesh/export_off.h | 20 +++++++++----- wrap/io_trimesh/import_off.h | 51 ++++++++++++++++-------------------- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/wrap/io_trimesh/export.h b/wrap/io_trimesh/export.h index 8dae43cf..958d27a5 100644 --- a/wrap/io_trimesh/export.h +++ b/wrap/io_trimesh/export.h @@ -25,6 +25,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.6 2006/11/04 14:01:00 granzuglia +fixed bug: &(*filename.end()) ---> &(*filename.rbegin()) + Revision 1.5 2006/07/09 05:32:15 cignoni Uncommented obj export. Now obj saving is enabled by default @@ -106,7 +109,7 @@ static int Save(OpenMeshType &m, const char *filename, const int mask, CallBackP } else if(FileExtension(filename,"off")) { - err = ExporterOFF::Save(m,filename); + err = ExporterOFF::Save(m,filename,mask); LastType()=KT_OFF; } else if(FileExtension(filename,"dxf")) diff --git a/wrap/io_trimesh/export_off.h b/wrap/io_trimesh/export_off.h index 18559d00..5ac51c51 100644 --- a/wrap/io_trimesh/export_off.h +++ b/wrap/io_trimesh/export_off.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.13 2007/11/06 10:58:25 cignoni +Changed the return value to the standard 0 in case of success and notzero for failures + Revision 1.12 2007/03/12 16:40:17 tarini Texture coord name change! "TCoord" and "Texture" are BAD. "TexCoord" is GOOD. @@ -70,8 +73,8 @@ namespace vcg { if( m.HasPerVertexNormal() && (mask & io::Mask::IOM_VERTNORMAL)) fprintf(fpout,"N"); - if( m.HasPerVertexColor() && (mask & io::Mask::IOM_VERTCOLOR)) fprintf(fpout,"C"); - if( m.HasPerVertexTexCoord() && (mask & io::Mask::IOM_VERTTEXCOORD)) fprintf(fpout,"ST"); + 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"); fprintf(fpout,"%d %d 0\n", m.vn, m.fn); // note that as edge number we simply write zero typename SaveMeshType::FaceIterator fi; @@ -88,15 +91,18 @@ namespace vcg { if( ! vp->IsD() ) { // ***** ASCII ***** - fprintf(fpout,"%g %g %g\n" ,vp->P()[0],vp->P()[1],vp->P()[2]); - if( m.HasPerVertexColor() && (mask & io::Mask::IOM_VERTCOLOR) ) - fprintf(fpout,"%d %d %d %d\n",vp->C()[0],vp->C()[1],vp->C()[2],vp->C()[3] ); + fprintf(fpout,"%g %g %g " ,vp->P()[0],vp->P()[1],vp->P()[2]); + 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] ); if( m.HasPerVertexNormal() && (mask & io::Mask::IOM_VERTNORMAL) ) - fprintf(fpout,"%g %g %g\n", vp->N()[0],vp->N()[1],vp->N()[2]); + fprintf(fpout,"%g %g %g ", vp->N()[0],vp->N()[1],vp->N()[2]); if( m.HasPerVertexTexCoord() && (mask & io::Mask::IOM_VERTTEXCOORD) ) - fprintf(fpout,"%g %g\n",vp->T().u(),vp->T().v()); + fprintf(fpout,"%g %g ",vp->T().u(),vp->T().v()); + + fprintf(fpout,"\n"); + vp->UberFlags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato! j++; diff --git a/wrap/io_trimesh/import_off.h b/wrap/io_trimesh/import_off.h index 90707e08..6a3c1a2f 100644 --- a/wrap/io_trimesh/import_off.h +++ b/wrap/io_trimesh/import_off.h @@ -24,6 +24,11 @@ History $Log: not supported by cvs2svn $ +Revision 1.22 2008/03/13 08:48:10 granzuglia +added two missing include files: +1) #include +2) #include + Revision 1.21 2007/12/13 17:57:33 cignoni removed harmless gcc warnings @@ -157,17 +162,9 @@ namespace vcg { // To obtain the loading mask all the file must be parsed // to distinguish between per-vertex and per-face color attribute. - + loadmask=0; MESH_TYPE dummyMesh; - - if (Open(dummyMesh, filename, loadmask) == NoError) - { - dummyMesh.Clear(); - - return true; - } - else - return false; + return (Open(dummyMesh, filename, loadmask,0,true)==NoError); } static int Open(MESH_TYPE &mesh, const char *filename,CallBackPos *cb=0) @@ -184,10 +181,8 @@ namespace vcg * \return the operation result */ static int Open(MESH_TYPE &mesh, const char *filename, int &loadmask, - CallBackPos *cb=0) + CallBackPos *cb=0, bool onlyMaskFlag=false ) { - mesh.Clear(); - std::ifstream stream(filename); if (stream.fail()) return CantOpen; @@ -207,14 +202,10 @@ namespace vcg { for (int u = static_cast(header.rfind("OFF")-1); u>=0; u--) { - if (header[u] == 'C') - isColorDefined = true; - else if (header[u] == 'N') - isNormalDefined = true; - else if (u>0 && header[u-1] == 'S' && header[u] == 'T') - isTexCoordDefined = true; - else if (header[u] == '4') - homogeneousComponents = true; + if (header[u] == 'C') isColorDefined = true; + else if (header[u] == 'N') isNormalDefined = true; + else if (u>0 && header[u-1] == 'S' && header[u] == 'T') isTexCoordDefined = true; + else if (header[u] == '4') homogeneousComponents = true; else if (header[u] == 'n') { TokenizeNextLine(stream, tokens); @@ -230,12 +221,16 @@ namespace vcg loadmask = Mask::IOM_VERTCOORD | Mask::IOM_FACEINDEX; - if (isNormalDefined) - loadmask |= Mask::IOM_VERTNORMAL; + if (isNormalDefined) loadmask |= Mask::IOM_VERTNORMAL; + if (isTexCoordDefined) loadmask |= Mask::IOM_VERTTEXCOORD; + if (isColorDefined) { loadmask |= Mask::IOM_VERTCOLOR;loadmask |= Mask::IOM_FACECOLOR;} - if (isTexCoordDefined) - loadmask |= Mask::IOM_VERTTEXCOORD; + if(onlyMaskFlag) return NoError; + + + mesh.Clear(); + // check on next 2 lines to detect corrupted files if(tokens.size() < 3) return InvalidFile; @@ -320,7 +315,7 @@ namespace vcg loadmask |= Mask::IOM_VERTCOLOR; // Store color components - if (VertexType::HasColor()) + if (tri::HasPerVertexColor(mesh)) { // Read color components @@ -408,7 +403,7 @@ namespace vcg k++; // Store texture coordinates - if (VertexType::HasTexCoord()) + if (tri::HasPerWedgeTexCoord(mesh)) { //...TODO... } @@ -488,7 +483,7 @@ namespace vcg // NOTE: It is assumed that colored face takes exactly one text line // (otherwise it is impossible to parse color information since // color components can vary) - if (isColorDefined) + if (isColorDefined && tri::HasPerFaceColor(mesh)) { size_t color_elements = tokens.size() - vert_per_face-1;