diff --git a/wrap/io_trimesh/export_ply.h b/wrap/io_trimesh/export_ply.h index 73ed0622..bf8f7669 100644 --- a/wrap/io_trimesh/export_ply.h +++ b/wrap/io_trimesh/export_ply.h @@ -96,7 +96,6 @@ namespace vcg { static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &pi, CallBackPos *cb=0) // V1.0 { FILE * fpout; - int i; const char * hbin = "binary_little_endian"; const char * hasc = "ascii"; const char * h; @@ -127,7 +126,7 @@ namespace vcg { { const char * TFILE = "TextureFile"; - for(i=0; i < static_cast(m.textures.size()); ++i) + for(size_t i=0; i < m.textures.size(); ++i) fprintf(fpout,"comment %s %s\n", TFILE, (const char *)(m.textures[i].c_str()) ); if(m.textures.size()>1 && (HasPerWedgeTexCoord(m) || HasPerVertexTexCoord(m))) multit = true; @@ -211,8 +210,8 @@ namespace vcg { "property float texture_v\n" ); } - for(i=0;i0 && (pi.mask & Mask::IOM_EDGEINDEX) ) fprintf(fpout, @@ -344,7 +347,59 @@ namespace vcg { VertexPointer vp; VertexIterator vi; SimpleTempData indices(m.vert); - + + std::vector > thfv(pi.VertDescriptorVec.size()); + std::vector > thdv(pi.VertDescriptorVec.size()); + std::vector > thiv(pi.VertDescriptorVec.size()); + std::vector > thsv(pi.VertDescriptorVec.size()); + std::vector > thcv(pi.VertDescriptorVec.size()); + std::vector > thuv(pi.VertDescriptorVec.size()); + + for(size_t i=0;i::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_DOUBLE : thdv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_INT : thiv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_SHORT : thsv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_CHAR : thcv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_UCHAR : thuv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + default : assert(0); + } + } + } + std::vector > thff(pi.FaceDescriptorVec.size()); + std::vector > thdf(pi.FaceDescriptorVec.size()); + std::vector > thif(pi.FaceDescriptorVec.size()); + std::vector > thsf(pi.FaceDescriptorVec.size()); + std::vector > thcf(pi.FaceDescriptorVec.size()); + std::vector > thuf(pi.FaceDescriptorVec.size()); + + for(size_t i=0;i::template FindPerFaceAttribute(m,pi.FaceAttrNameVec[i]); break; + case ply::T_DOUBLE : thdf[i] = vcg::tri::Allocator::template FindPerFaceAttribute(m,pi.FaceAttrNameVec[i]); break; + case ply::T_INT : thif[i] = vcg::tri::Allocator::template FindPerFaceAttribute(m,pi.FaceAttrNameVec[i]); break; + case ply::T_SHORT : thsf[i] = vcg::tri::Allocator::template FindPerFaceAttribute(m,pi.FaceAttrNameVec[i]); break; + case ply::T_CHAR : thcf[i] = vcg::tri::Allocator::template FindPerFaceAttribute(m,pi.FaceAttrNameVec[i]); break; + case ply::T_UCHAR : thuf[i] = vcg::tri::Allocator::template FindPerFaceAttribute(m,pi.FaceAttrNameVec[i]); break; + default : assert(0); + } + } + } + + + + for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi){ vp=&(*vi); indices[vi] = j; @@ -381,22 +436,39 @@ namespace vcg { if( HasPerVertexTexCoord(m) && (pi.mask & Mask::IOM_VERTTEXCOORD) ) { - t = float(vp->T().u()); fwrite(&t,sizeof(float),1,fpout); - t = float(vp->T().v()); fwrite(&t,sizeof(float),1,fpout); + t = ScalarType(vp->T().u()); fwrite(&t,sizeof(ScalarType),1,fpout); + t = ScalarType(vp->T().v()); fwrite(&t,sizeof(ScalarType),1,fpout); } - for(i=0;iT().u(),vp->T().v()); - for(i=0;iQ()),sizeof(typename FaceType::ScalarType),1,fpout); - for(i=0;iQ()); - for(i=0;i VPV(pi.vdn); // property descriptor relative al tipo LoadPly_VertexAux - std::vector FPV(pi.fdn); // property descriptor relative al tipo LoadPly_FaceAux - if(pi.vdn>0){ + std::vector VPV(pi.VertDescriptorVec.size()); // property descriptor relative al tipo LoadPly_VertexAux + std::vector FPV(pi.FaceDescriptorVec.size()); // property descriptor relative al tipo LoadPly_FaceAux + if(pi.VertDescriptorVec.size()>0){ // Compute the total size needed to load additional per vertex data. size_t totsz=0; - for(int i=0;i,data)+totsz; - totsz+=pi.VertexData[i].memtypesize(); + totsz+=pi.VertDescriptorVec[i].memtypesize(); if( pf.AddToRead(VPV[i])==-1 ) { pi.status = pf.GetError(); return pi.status; } } if(totsz > MAX_USER_DATA) @@ -564,12 +564,12 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi ) return pi.status; } } - if(pi.fdn>0){ + if(pi.FaceDescriptorVec.size()>0){ size_t totsz=0; - for(int i=0;i MAX_USER_DATA) @@ -583,7 +583,7 @@ static int Open( OpenMeshType &m, const char * filename, PlyInfo &pi ) /* Main Reading Loop */ /**************************************************************/ m.Clear(); - for(int i=0;i3) fi->SetF(2); - for(k=0;kSetF(0); if(qq<(fa.size-4)) fi->SetF(2); - for(k=0;k(bufstr.length()); - for(i=0;i32 && bufstr[i]<125 ) bufclean.push_back(bufstr[i]); char buf2[255]; @@ -1036,8 +1036,7 @@ int LoadCamera(const char * filename) bool found = true; - int i; - for(i=0;i<23;++i) + for(int i=0;i<23;++i) { if( pf.AddToRead(CameraDesc(i))==-1 ) { @@ -1049,7 +1048,7 @@ int LoadCamera(const char * filename) if(!found) return this->pi.status; - for(i=0;i VertDescriptorVec; + /// AttributeName is an array, externally allocated, containing the names of the attributes to be saved (loaded). + /// We assume that AttributeName[], if not empty, is exactly of the same size of VertexdData[] + /// If AttributeName[i] is not empty we use it to retrieve/store the info instead of the offsetted space in the current vertex + std::vector VertAttrNameVec; /// The additional vertex descriptor that a user can specify to load additional per-face non-standard data stored in a ply - PropDescriptor *FaceData; + std::vector FaceDescriptorVec; + std::vector FaceAttrNameVec; /// a string containing the current ply header. Useful for showing it to the user. std::string header;