diff --git a/wrap/io_trimesh/export_dae.h b/wrap/io_trimesh/export_dae.h index 8f50670a..4db8283e 100644 --- a/wrap/io_trimesh/export_dae.h +++ b/wrap/io_trimesh/export_dae.h @@ -1,3 +1,32 @@ +/**************************************************************************** +* 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_EXPORTERDAE #define __VCGLIB_EXPORTERDAE @@ -151,10 +180,12 @@ private: if(mask & vcg::tri::io::Mask::IOM_VERTCOLOR) arrc.reserve(5 * 4 * m.vert.size()); int nvert = 0; + std::vector VertexInd(m.vert.size()); for(typename SaveMeshType::VertexIterator it = m.vert.begin();it != m.vert.end();++it) { if (!(it->IsD())) { + VertexInd[it-m.vert.begin()]=nvert; arrp.append(QString::number(float(it->P().X())).append(" ").append(QString::number(float(it->P().Y()))).append(" ").append(QString::number(float(it->P().Z()))).append(" ")); //if(mask & vcg::tri::io::Mask::IOM_VERTNORMAL) arrn.append(QString::number(float(it->N().X())).append(" ").append(QString::number(float(it->N().Y()))).append(" ").append(QString::number(float(it->N().Z()))).append(" ")); @@ -165,7 +196,7 @@ private: ++nvert; } } - + assert(nvert==m.vn); QDomText ap = doc.createTextNode(arrp); CreateSource(doc,meshnode,"positions",ap,nvert); @@ -230,7 +261,7 @@ private: { for(unsigned int ii = 0;ii < 3;++ii) { - int ind_v = (*itf).V(ii) - &(m.vert[0]); + int ind_v = VertexInd[(*itf).V(ii) - &(m.vert[0])]; if (triangles_tess == "") triangles_tess = QString::number(ind_v); else triangles_tess.append(" ").append(QString::number(ind_v)); diff --git a/wrap/io_trimesh/export_obj.h b/wrap/io_trimesh/export_obj.h index d3ecf023..0ef45e21 100644 --- a/wrap/io_trimesh/export_obj.h +++ b/wrap/io_trimesh/export_obj.h @@ -25,6 +25,9 @@ History $Log: not supported by cvs2svn $ + Revision 1.5 2006/10/09 19:58:08 cignoni + Added casts to remove warnings + Revision 1.4 2006/09/18 12:14:38 cignoni Removed bug in the creation of the material filename @@ -162,13 +165,11 @@ namespace io { */ static int SaveASCII(SaveMeshType &m, const char * filename, int mask, CallBackPos *cb=0) { - if(m.vert.size() == 0) - return E_NOTVEXTEXVALID; - if(m.face.size() == 0) - return E_NOTFACESVALID; + if(m.vn == 0) return E_NOTVEXTEXVALID; + if(m.fn == 0) return E_NOTFACESVALID; int current = 0; - int max = m.vert.size()+ m.face.size(); + int max = m.vn+ m.fn; std::vector materials; @@ -182,7 +183,7 @@ namespace io { if(fp == NULL)return E_CANTOPENFILE; fprintf(fp,"####\n#\n# OBJ File Generated by Meshlab\n#\n####\n"); - fprintf(fp,"# Object %s\n#\n# Vertices: %d\n# Faces: %d\n#\n####\n",fn.substr(LastSlash+1).c_str(),m.vert.size(),m.face.size()); + fprintf(fp,"# Object %s\n#\n# Vertices: %d\n# Faces: %d\n#\n####\n",fn.substr(LastSlash+1).c_str(),m.vn,m.fn); //library materials if(mask & vcg::tri::io::Mask::IOM_FACECOLOR) @@ -191,10 +192,12 @@ namespace io { //vertexs + normal VertexIterator vi; std::map NormalVertex; + std::vector VertexId(m.vert.size()); int numvert = 0; int value = 1; for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi) if( !(*vi).IsD() ) { + VertexId[vi-m.vert.begin()]=numvert; //saves normal per vertex if(mask & vcg::tri::io::Mask::IOM_VERTNORMAL | mask & vcg::tri::io::Mask::IOM_WEDGNORMAL) { @@ -211,8 +214,11 @@ namespace io { if (cb !=NULL) { if(!(*cb)((100*++current)/max, "writing vertices ")) { fclose(fp); return E_ABORTED;} } + numvert++; } - fprintf(fp,"# %d vertices, %d vertices normals\n\n",m.vert.size(),NormalVertex.size()); + assert(numvert == m.vn); + + fprintf(fp,"# %d vertices, %d vertices normals\n\n",m.vn,NormalVertex.size()); //faces + texture coords FaceIterator fi; @@ -261,7 +267,7 @@ namespace io { { int v = -1; // +1 because Obj file format begins from index = 1 but not from index = 0. - v = GetIndexVertex(m, (*fi).V(k)) + 1;//index of vertex per face + v = VertexId[GetIndexVertex(m, (*fi).V(k))] + 1;//index of vertex per face int vt = -1; if(mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) diff --git a/wrap/io_trimesh/export_off.h b/wrap/io_trimesh/export_off.h index 2ff7ad45..fe7b860d 100644 --- a/wrap/io_trimesh/export_off.h +++ b/wrap/io_trimesh/export_off.h @@ -20,6 +20,11 @@ * for more details. * * * ****************************************************************************/ +/**************************************************************************** + History + +$Log: not supported by cvs2svn $ +****************************************************************************/ /** @name Save in OFF format @@ -62,53 +67,10 @@ namespace vcg { if( m.HasPerVertexColor() && (mask & io::Mask::IOM_VERTCOLOR)) fprintf(fpout,"C"); if( m.HasPerVertexTexture() && (mask & io::Mask::IOM_VERTTEXCOORD)) fprintf(fpout,"ST"); fprintf(fpout,"OFF\n"); - fprintf(fpout,"%d %d 0\n", m.vn, m.fn); + fprintf(fpout,"%d %d 0\n", m.vn, m.fn); // note that as edge number we simply write zero typename SaveMeshType::FaceIterator fi; - // USeless portio of code that try tocomput the exact number of edges. - // OFF usually has a 0 as edge number. - // - //int count_e = 0; - //int boundary_e = 0; - //bool counted=false; - //for(fi=m.face.begin();fi!=m.face.end();++fi) - // (*fi).ClearS(); - - //for(fi=m.face.begin();fi!=m.face.end();fi++) - //{ - // (*fi).SetS(); - // count_e +=3; //assume that we have to increase the number of edges with three - // for(int j=0; j<3; j++) - // { - // if (face::IsBorder(*fi,j)) //If this edge is a border edge - // boundary_e++; // then increase the number of boundary edges - // else if (face::IsManifold(*fi,j)) //If this edge is manifold - // { - // if((*fi).FFp(j)->IsS()) //If the face on the other side of the edge is already selected - // count_e--; // we counted one edge twice - // } - // else //We have a non-manifold edge - // { - // hei.Set(&(*fi), j , fi->V(j)); - // he=hei; - // he.NextF(); - // while (he.f!=hei.f) // so we have to iterated all faces that are connected to this edge - // { - // if (he.f->IsS()){ // if one of the other faces was already visited than this edge was counted already. - // counted=true; - // break; - // } else { he.NextF(); } - // } - // if (counted) { - // count_e--; - // counted=false; - // } - // } - // } - //} - //fprintf(fpout,"%d\n", count_e); - - //vertices + //vertices int j; std::vector FlagV; VertexPointer vp; @@ -116,25 +78,26 @@ namespace vcg { 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() ) - { // ***** ASCII ***** + FlagV.push_back(vp->UberFlags()); // Salva in ogni caso flag del vertice + 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\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] ); - if( m.HasPerVertexNormal() && (mask & io::Mask::IOM_VERTNORMAL) ) - fprintf(fpout,"%g %g %g\n", vp->N()[0],vp->N()[1],vp->N()[2]); + if( m.HasPerVertexNormal() && (mask & io::Mask::IOM_VERTNORMAL) ) + fprintf(fpout,"%g %g %g\n", vp->N()[0],vp->N()[1],vp->N()[2]); - if( m.HasPerVertexTexture() && (mask & io::Mask::IOM_VERTTEXCOORD) ) - fprintf(fpout,"%g %g\n",vp->T().u(),vp->T().v()); - } + if( m.HasPerVertexTexture() && (mask & io::Mask::IOM_VERTTEXCOORD) ) + fprintf(fpout,"%g %g\n",vp->T().u(),vp->T().v()); - vp->UberFlags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato! - j++; + vp->UberFlags()=j; // Trucco! Nascondi nei flags l'indice del vertice non deletato! + j++; + } } + assert(j==m.vn); FacePointer fp; // int vv[3];