diff --git a/wrap/io_trimesh/import_vmi.h b/wrap/io_trimesh/import_vmi.h index 00f42599..05aa06d3 100644 --- a/wrap/io_trimesh/import_vmi.h +++ b/wrap/io_trimesh/import_vmi.h @@ -8,7 +8,7 @@ * \ * * All rights reserved. * * * -* This program is Free software; you can redistribute it and/or modify * +* 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. * @@ -28,7 +28,7 @@ Revision 1.1 2007/02/14 01:20:37 ganovelli working draft of VCG Mesh Image importer and exporter. Does not consider optional attributes. The mesh atributes are only vn and fn (no bbox, texture coordiantes) - + ****************************************************************************/ @@ -44,7 +44,7 @@ passed to the function Save(SaveMeshType m) NOTE: THIS IS NOT A FILE FORMAT. IT IS ONLY USEFUL FOR DUMPING MESH IMAGES FOR DEBUG PURPOSE. Example of use: say you are running a time consuming mesh processing and you want to save intermediate - state, but no file format support all the attributes you need in your vertex/face type. + state, but no file format support all the attributes you need in your vertex/face type. NOTE2: At the present if you add members to your TriMesh these will NOT be saved. More precisely, this file and import_vmi must be updated to reflect changes in vcg/complex/trimesh/base.h @@ -84,7 +84,7 @@ namespace io { else T::template AddAttrib<0>(m,name,s,data); break; - case 2: + case 2: if(s == sizeof(A)){ typename MeshType::template PerMeshAttributeHandle h = vcg::tri::Allocator:: template AddPerMeshAttribute(m,name); memcpy(&h(), (void*) ((A*)data),sizeof(A)); // we don't want the type conversion @@ -131,9 +131,9 @@ namespace io { assert(new_pa.second); } else - T::template AddAttrib<0>(m,name,s,data); + T::template AddAttrib<0>(m,name,s,data); break; - case 1: + case 1: if(s == sizeof(A)){ typename MeshType::template PerVertexAttributeHandle h = vcg::tri::Allocator::template AddPerVertexAttribute(m,name); for(unsigned int i = 0; i < m.vert.size(); ++i) @@ -158,7 +158,7 @@ namespace io { assert(new_pa.second); } else - T::template AddAttrib<1>(m,name,s,data); + T::template AddAttrib<1>(m,name,s,data); break; case 2: if(s == sizeof(A)){ @@ -172,7 +172,7 @@ namespace io { typename MeshType::template PerMeshAttributeHandle h = vcg::tri::Allocator::template AddPerMeshAttribute(m,name); char * dest = & ((char*)(&h()))[0]; memcpy( (void *)dest , (void*)((A*)data),s); // we don't want the type conversion - + typename MeshType::PointerToAttribute pa; pa._name = std::string(name); HWIte res = m.mesh_attr.find(pa); @@ -183,7 +183,7 @@ namespace io { assert(new_pa.second); } else - T::template AddAttrib<2>(m,name,s,data); + T::template AddAttrib<2>(m,name,s,data); break; default: assert(0);break; } @@ -195,9 +195,9 @@ namespace io { */ template struct K { template - static void AddAttrib(MeshType &/*m*/, const char * /*name*/, unsigned int /*s*/, void * /*data*/){ + static void AddAttrib(MeshType &/*m*/, const char * /*name*/, unsigned int /*s*/, void * /*data*/){ // if yohu got this your attribute is larger than 1048576. Honestly... - assert(0); + assert(0); } }; @@ -215,20 +215,20 @@ namespace io { template struct K11 : public DerK< MeshType, B11, K10 > {}; template struct K12 : public DerK< MeshType, B12, K11 > {}; - template , class B1 = DummyType<2048>, class B2 = DummyType<1024>, class B3 = DummyType<512>, - class B4 = DummyType<256>, + class B4 = DummyType<256>, class B5 = DummyType<128>, class B6 = DummyType<64>, - class B7 = DummyType<32>, - class B8 = DummyType<16>, - class B9 = DummyType<8>, - class B10 = DummyType<4>, - class B11 = DummyType<2>, - class B12 = DummyType<1> + class B7 = DummyType<32>, + class B8 = DummyType<16>, + class B9 = DummyType<8>, + class B10 = DummyType<4>, + class B11 = DummyType<2>, + class B12 = DummyType<1> > struct C0 : public DerK< MeshType, A0, K12 > {}; template struct C1 : public Der< MeshType, A1, C0 > {}; @@ -238,29 +238,29 @@ namespace io { - template + template class ImporterVMI: public AttrAll { - - static void ReadString(std::string & out){ + + static void ReadString(std::string & out){ unsigned int l; Read(&l,4,1); - char * buf = new char[l+1]; + char * buf = new char[l+1]; Read(buf,1,l);buf[l]='\0'; - out = std::string(buf); - delete [] buf; - } - + out = std::string(buf); + delete [] buf; + } + static void ReadInt( unsigned int & i){ Read(&i,1,4);} static void ReadFloat( float & v){ Read(&v,1,sizeof(float));} - - static int LoadVertexOcfMask( ){ + + static int LoadVertexOcfMask( ){ int mask =0; - std::string s; + std::string s; // vertex quality ReadString( s); - if( s == std::string("HAS_VERTEX_QUALITY_OCF")) mask |= Mask::IOM_VERTQUALITY; + if( s == std::string("HAS_VERTEX_QUALITY_OCF")) mask |= Mask::IOM_VERTQUALITY; // vertex color ReadString( s); @@ -268,33 +268,33 @@ namespace io { // vertex normal ReadString( s); - if( s == std::string("HAS_VERTEX_NORMAL_OCF")) mask |= Mask::IOM_VERTNORMAL; + if( s == std::string("HAS_VERTEX_NORMAL_OCF")) mask |= Mask::IOM_VERTNORMAL; // vertex mark ReadString( s); - //if( s == std::string("HAS_VERTEX_MARK_OCF")) mask |= + //if( s == std::string("HAS_VERTEX_MARK_OCF")) mask |= // vertex texcoord ReadString( s); - if( s == std::string("HAS_VERTEX_TEXCOORD_OCF")) mask |= Mask::IOM_VERTTEXCOORD; + if( s == std::string("HAS_VERTEX_TEXCOORD_OCF")) mask |= Mask::IOM_VERTTEXCOORD; // vertex-face adjacency ReadString( s); - //if( s == std::string("HAS_VERTEX_VFADJACENCY_OCF")) mask |= + //if( s == std::string("HAS_VERTEX_VFADJACENCY_OCF")) mask |= // vertex curvature ReadString( s); - //if( s == std::string("HAS_VERTEX_CURVATURE_OCF")) mask |= + //if( s == std::string("HAS_VERTEX_CURVATURE_OCF")) mask |= //// vertex curvature dir ReadString( s); - //if( s == std::string("HAS_VERTEX_CURVATUREDIR_OCF")) mask |= + //if( s == std::string("HAS_VERTEX_CURVATUREDIR_OCF")) mask |= // vertex radius ReadString( s); - if( s == std::string("HAS_VERTEX_RADIUS_OCF")) mask |= Mask::IOM_VERTRADIUS; + if( s == std::string("HAS_VERTEX_RADIUS_OCF")) mask |= Mask::IOM_VERTRADIUS; - return mask; + return mask; } template @@ -309,7 +309,7 @@ namespace io { template struct LoadVertexOcf >{ - typedef typename OpenMeshType::VertexType VertexType; + typedef typename OpenMeshType::VertexType VertexType; LoadVertexOcf( FILE * f, vertex::vector_ocf & vert){ std::string s; @@ -385,15 +385,15 @@ namespace io { // do nothing, it is a std::vector } }; - - + + static int LoadFaceOcfMask( ){ int mask=0; std::string s; // face quality ReadString( s); - if( s == std::string("HAS_FACE_QUALITY_OCF")) mask |= Mask::IOM_FACEQUALITY; + if( s == std::string("HAS_FACE_QUALITY_OCF")) mask |= Mask::IOM_FACEQUALITY; // face color ReadString( s); @@ -401,11 +401,11 @@ namespace io { // face normal ReadString( s); - if( s == std::string("HAS_FACE_NORMAL_OCF")) mask |= Mask::IOM_FACENORMAL; + if( s == std::string("HAS_FACE_NORMAL_OCF")) mask |= Mask::IOM_FACENORMAL; //// face mark ReadString( s); - //if( s == std::string("HAS_FACE_MARK_OCF")) mask |= + //if( s == std::string("HAS_FACE_MARK_OCF")) mask |= // face wedgetexcoord ReadString( s); @@ -418,23 +418,23 @@ namespace io { // vertex-face adjacency ReadString( s); - //if( s == std::string("HAS_FACE_VFADJACENCY_OCF")) mask |= + //if( s == std::string("HAS_FACE_VFADJACENCY_OCF")) mask |= // face WedgeColor ReadString( s); - if( s == std::string("HAS_FACE_WEDGECOLOR_OCF")) mask |= Mask::IOM_WEDGCOLOR; + if( s == std::string("HAS_FACE_WEDGECOLOR_OCF")) mask |= Mask::IOM_WEDGCOLOR; // face WedgeNormal ReadString( s); - if( s == std::string("HAS_FACE_WEDGENORMAL_OCF")) mask |= Mask::IOM_WEDGNORMAL; - return mask; + if( s == std::string("HAS_FACE_WEDGENORMAL_OCF")) mask |= Mask::IOM_WEDGNORMAL; + return mask; } - + /* partial specialization for vector_ocf */ template struct LoadFaceOcf< MeshType, face::vector_ocf >{ - typedef typename OpenMeshType::FaceType FaceType; + typedef typename OpenMeshType::FaceType FaceType; LoadFaceOcf( face::vector_ocf & face){ std::string s; @@ -530,7 +530,7 @@ namespace io { static FILE *& F(){static FILE * f; return f;} - + static void * Malloc(unsigned int n){ return (n)?malloc(n):0;} static void Free(void * ptr){ if(ptr) free (ptr);} @@ -544,7 +544,7 @@ namespace io { typedef typename OpenMeshType::VertexType VertexType; public: - enum VMIErrorCodes { + enum VMIErrorCodes { VMI_NO_ERROR = 0, VMI_INCOMPATIBLE_VERTEX_TYPE, VMI_INCOMPATIBLE_FACE_TYPE, @@ -576,9 +576,9 @@ namespace io { as a vcg::Box3f, even if the scalar type is not float. The bounding box of the mesh will be set properly on loading. */ - static bool GetHeader( std::vector& fnameV, - std::vector& fnameF, - unsigned int & vertSize, + static bool GetHeader( std::vector& fnameV, + std::vector& fnameF, + unsigned int & vertSize, unsigned int &faceSize, vcg::Box3f & bbox, int & mask){ @@ -587,14 +587,14 @@ namespace io { ReadString( name); ReadInt( nameFsize); - for(i=0; i < nameFsize; ++i) + for(i=0; i < nameFsize; ++i) {ReadString( name);fnameF.push_back( name );mask |= FaceMaskBitFromString(name);} mask |= LoadFaceOcfMask(); ReadString( name); ReadInt( faceSize); ReadString( name); ReadInt( nameVsize); - for(i=0; i < nameVsize; ++i) + for(i=0; i < nameVsize; ++i) {ReadString( name) ;fnameV.push_back( name);mask |= VertexMaskBitFromString(name);} mask |= LoadVertexOcfMask(); @@ -612,15 +612,15 @@ namespace io { } - static bool GetHeader(const char * filename,std::vector& nameV, std::vector& nameF, unsigned int & vertSize, unsigned int &faceSize,vcg::Box3f & bbox,int & mask){ + static bool GetHeader(const char * filename,std::vector& nameV, std::vector& nameF, unsigned int & vertSize, unsigned int &faceSize,vcg::Box3f & bbox,int & mask){ F() = fopen(filename,"rb"); bool res = GetHeader(nameV, nameF, vertSize, faceSize,bbox,mask); fclose(F()); return res; } - public: - static char * & In_mem(){static char * in_mem; return in_mem;} + public: + static const char * & In_mem(){static const char * in_mem; return in_mem;} static unsigned int & In_mode(){static unsigned int in_mode = 0; return in_mode;} @@ -639,10 +639,10 @@ namespace io { } - static bool LoadMask(const char * f, int & mask){ + static bool LoadMask(const char * f, int & mask){ std::vector nameV; std::vector nameF; - unsigned int vertSize, faceSize; + unsigned int vertSize, faceSize; vcg::Box3f bbox; F() = fopen(f,"rb"); In_mode() = 1; @@ -681,36 +681,36 @@ namespace io { static int Deserialize(OpenMeshType &m, int & mask) { typedef typename OpenMeshType::VertexType VertexType; - typedef typename OpenMeshType::FaceType FaceType; - typename OpenMeshType::FaceIterator fi; - typename OpenMeshType::VertexIterator vi; + typedef typename OpenMeshType::FaceType FaceType; + typename OpenMeshType::FaceIterator fi; + typename OpenMeshType::VertexIterator vi; std::vector nameF,nameV,fnameF,fnameV; unsigned int vertSize,faceSize; - /* read the header */ + /* read the header */ vcg::Box3f lbbox; GetHeader(fnameV, fnameF, vertSize, faceSize,lbbox,mask); m.bbox.Import(lbbox); - /* read the mesh type */ - OpenMeshType::FaceType::Name(nameF); - OpenMeshType::VertexType::Name(nameV); + /* read the mesh type */ + OpenMeshType::FaceType::Name(nameF); + OpenMeshType::VertexType::Name(nameV); - /* check if the type is the very same, otherwise return */ + /* check if the type is the very same, otherwise return */ if(fnameV != nameV) return VMI_INCOMPATIBLE_VERTEX_TYPE; if(fnameF != nameF) return VMI_INCOMPATIBLE_FACE_TYPE; - void * offsetV = 0,*offsetF = 0; + void * offsetV = 0,*offsetF = 0; if(vertSize!=0) /* read the address of the first vertex */ - Read(&offsetV,sizeof( void *),1 ); + Read(&offsetV,sizeof( void *),1 ); if(faceSize!=0) /* read the address of the first face */ - Read(&offsetF,sizeof( void *),1 ); + Read(&offsetF,sizeof( void *),1 ); - /* read the object mesh */ + /* read the object mesh */ Read(&m.shot,sizeof(Shot),1 ); Read(&m.vn,sizeof(int),1 ); Read(&m.fn,sizeof(int),1 ); @@ -723,10 +723,10 @@ namespace io { m.vert.resize(vertSize); - size_t read = 0; + size_t read = 0; /* load the vertices */ if(vertSize>0){ - read=Read((void*)& m.vert[0],sizeof(VertexType),vertSize ); + read=Read((void*)& m.vert[0],sizeof(VertexType),vertSize ); LoadVertexOcf(F(),m.vert); } @@ -734,34 +734,34 @@ namespace io { m.face.resize(faceSize); if(faceSize>0){ /* load the faces */ - read = Read((void*)& m.face[0],sizeof(FaceType),faceSize ); - LoadFaceOcf(m.face); + read = Read((void*)& m.face[0],sizeof(FaceType),faceSize ); + LoadFaceOcf(m.face); } - + /* load the per vertex attributes */ std::string _string,_trash; unsigned int n,sz; - + ReadString( _trash); ReadInt( n); - for(size_t ia = 0 ; ia < n; ++ia){ + for(size_t ia = 0 ; ia < n; ++ia){ ReadString(_trash); ReadString(_string); ReadString(_trash); ReadInt(sz); - void * data = Malloc(sz*m.vert.size()); + void * data = Malloc(sz*m.vert.size()); Read(data,sz,m.vert.size()); - AttrAll::template AddAttrib<0>(m,_string.c_str(),sz,data); - Free(data); - } + AttrAll::template AddAttrib<0>(m,_string.c_str(),sz,data); + Free(data); + } /* load the per face attributes */ ReadString(_trash); ReadInt( n); - for(size_t ia = 0 ; ia < n; ++ia){ + for(size_t ia = 0 ; ia < n; ++ia){ ReadString(_trash); ReadString( _string); ReadString(_trash); ReadInt( sz); void * data = Malloc(sz*m.face.size()); - Read(data,sz,m.face.size() ); + Read(data,sz,m.face.size() ); AttrAll::template AddAttrib<1>(m,_string.c_str(),sz,data); Free(data); } @@ -772,7 +772,7 @@ namespace io { ReadString( _trash); ReadString( _string); ReadString( _trash); ReadInt( sz); void * data = Malloc(sz); - Read(data,1,sz ); + Read(data,1,sz ); AttrAll::template AddAttrib<2>(m,_string.c_str(),sz,data); Free(data); } @@ -785,14 +785,14 @@ namespace io { (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0]; } - if(FaceVectorHasFVAdjacency(m.face)) + if(FaceVectorHasFVAdjacency(m.face)) for(fi = m.face.begin(); fi != m.face.end(); ++fi){ (*fi).V(0) = (*fi).V(0)-(VertexType*)offsetV+ &m.vert[0]; (*fi).V(1) = (*fi).V(1)-(VertexType*)offsetV+ &m.vert[0]; (*fi).V(2) = (*fi).V(2)-(VertexType*)offsetV+ &m.vert[0]; } - if(FaceVectorHasFFAdjacency(m.face)) + if(FaceVectorHasFFAdjacency(m.face)) for(fi = m.face.begin(); fi != m.face.end(); ++fi){ (*fi).FFp(0) = (*fi).FFp(0)-(FaceType*)offsetF+ &m.face[0]; (*fi).FFp(1) = (*fi).FFp(1)-(FaceType*)offsetF+ &m.face[0]; @@ -801,8 +801,8 @@ namespace io { } - return VMI_NO_ERROR; // zero is the standard (!) code of success - } + return VMI_NO_ERROR; // zero is the standard (!) code of success + } }; // end class