diff --git a/wrap/io_trimesh/import_vmi.h b/wrap/io_trimesh/import_vmi.h index 05aa06d3..f67b6802 100644 --- a/wrap/io_trimesh/import_vmi.h +++ b/wrap/io_trimesh/import_vmi.h @@ -38,15 +38,15 @@ #include #include /* - VMI VCG Mesh Image. - The vmi image file consists of a header containing the description of the vertex and face type, - the length of vectors containing vertices of faces and the memory image of the object mesh as it is when - 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. - 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 + VMI VCG Mesh Image. + The vmi image file consists of a header containing the description of the vertex and face type, + the length of vectors containing vertices of faces and the memory image of the object mesh as it is when + 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. + 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 */ @@ -54,193 +54,193 @@ namespace vcg { namespace tri { namespace io { - template struct DummyType{ char placeholder[N]; }; + template struct DummyType{ char placeholder[N]; }; - /* ------------------------- derivation chain for the vertex attribute ---------------------------*/ + /* ------------------------- derivation chain for the vertex attribute ---------------------------*/ - /** this class is for testing only the equality with the type optionally provided by the user when calling Open - */ - template - struct Der:public T{ - typedef typename std::set::iterator HWIte; + /** this class is for testing only the equality with the type optionally provided by the user when calling Open + */ + template + struct Der:public T{ + typedef typename std::set::iterator HWIte; - template - static void AddAttrib(MeshType &m, const char * name, unsigned int s, void * data){ - switch(VoF) - { - case 0: 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) - memcpy(&h[i], (void*) &((A*)data)[i],sizeof(A)); // we don't want the type conversion - } - else - T::template AddAttrib<0>(m,name,s,data); - break; - case 1: if(s == sizeof(A)){ - typename MeshType::template PerFaceAttributeHandle h = vcg::tri::Allocator:: template AddPerFaceAttribute(m,name); - for(unsigned int i = 0; i < m.face.size(); ++i) - memcpy(&h[i], (void*) &((A*)data)[i],sizeof(A)); // we don't want the type conversion - } - else - T::template AddAttrib<0>(m,name,s,data); - break; - 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 - } - else - T::template AddAttrib<2>(m,name,s,data); - break; + template + static void AddAttrib(MeshType &m, const char * name, unsigned int s, void * data){ + switch(VoF) + { + case 0: 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) + memcpy(&h[i], (void*) &((A*)data)[i],sizeof(A)); // we don't want the type conversion + } + else + T::template AddAttrib<0>(m,name,s,data); + break; + case 1: if(s == sizeof(A)){ + typename MeshType::template PerFaceAttributeHandle h = vcg::tri::Allocator:: template AddPerFaceAttribute(m,name); + for(unsigned int i = 0; i < m.face.size(); ++i) + memcpy(&h[i], (void*) &((A*)data)[i],sizeof(A)); // we don't want the type conversion + } + else + T::template AddAttrib<0>(m,name,s,data); + break; + 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 + } + else + T::template AddAttrib<2>(m,name,s,data); + break; - default:break; - } - } - }; + default:break; + } + } + }; - /** this class is for testing the list of increasing size types until one is larger than the size of the unknown type - */ - template - struct DerK:public T{ - typedef typename std::set::iterator HWIte; - template - static void AddAttrib(MeshType &m, const char * name, unsigned int s, void * data){ - switch(VoF){ - case 0: - 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) - memcpy((void*) &(h[i]), (void*) &((A*)data)[i],sizeof(A)); // we don't want the type conversion - } - else - if(s < sizeof(A)){ - // padding - int padd = sizeof(A) - s; - typename MeshType::template PerVertexAttributeHandle h = vcg::tri::Allocator::template AddPerVertexAttribute(m,name); - for(unsigned int i = 0; i < m.vert.size(); ++i){ - char * dest = &((char*)(&h[i]))[0]; - memcpy( (void *)dest , (void*) &((A*)data)[i],s); // we don't want the type conversion - } - typename MeshType::PointerToAttribute pa; - pa._name = std::string(name); - HWIte res = m.vert_attr.find(pa); - pa = *res; - m.vert_attr.erase(res); - pa._padding = padd; - std::pair new_pa = m.vert_attr.insert(pa); - assert(new_pa.second); - } - else - T::template AddAttrib<0>(m,name,s,data); - break; - 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) - memcpy((void*) &(h[i]), (void*) &((A*)data)[i],sizeof(A)); // we don't want the type conversion - } - else - if(s < sizeof(A)){ - // padding - int padd = sizeof(A) - s; - typename MeshType::template PerFaceAttributeHandle h = vcg::tri::Allocator::template AddPerFaceAttribute(m,name); - for(unsigned int i = 0; i < m.face.size(); ++i){ - char * dest = &((char*)(&h[i]))[0]; - memcpy( (void *)dest , (void*) &((A*)data)[i],s); // we don't want the type conversion - } - typename MeshType::PointerToAttribute pa; - pa._name = std::string(name); - HWIte res = m.face_attr.find(pa); - pa = *res; - m.face_attr.erase(res); - pa._padding = padd; - std::pair new_pa = m.face_attr.insert(pa); - assert(new_pa.second); - } - else - T::template AddAttrib<1>(m,name,s,data); - break; - case 2: - if(s == sizeof(A)){ - typename MeshType::template PerMeshAttributeHandle h = vcg::tri::Allocator::template AddPerMeshAttribute(m,name); - memcpy((void*)&h(), (void*)((A*)data),sizeof(A)); // we don't want the type conversion - } - else - if(s < sizeof(A)){ - // padding - int padd = sizeof(A) - s; - 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 + /** this class is for testing the list of increasing size types until one is larger than the size of the unknown type + */ + template + struct DerK:public T{ + typedef typename std::set::iterator HWIte; + template + static void AddAttrib(MeshType &m, const char * name, unsigned int s, void * data){ + switch(VoF){ + case 0: + 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) + memcpy((void*) &(h[i]), (void*) &((A*)data)[i],sizeof(A)); // we don't want the type conversion + } + else + if(s < sizeof(A)){ + // padding + int padd = sizeof(A) - s; + typename MeshType::template PerVertexAttributeHandle h = vcg::tri::Allocator::template AddPerVertexAttribute(m,name); + for(unsigned int i = 0; i < m.vert.size(); ++i){ + char * dest = &((char*)(&h[i]))[0]; + memcpy( (void *)dest , (void*) &((A*)data)[i],s); // we don't want the type conversion + } + typename MeshType::PointerToAttribute pa; + pa._name = std::string(name); + HWIte res = m.vert_attr.find(pa); + pa = *res; + m.vert_attr.erase(res); + pa._padding = padd; + std::pair new_pa = m.vert_attr.insert(pa); + assert(new_pa.second); + } + else + T::template AddAttrib<0>(m,name,s,data); + break; + 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) + memcpy((void*) &(h[i]), (void*) &((A*)data)[i],sizeof(A)); // we don't want the type conversion + } + else + if(s < sizeof(A)){ + // padding + int padd = sizeof(A) - s; + typename MeshType::template PerFaceAttributeHandle h = vcg::tri::Allocator::template AddPerFaceAttribute(m,name); + for(unsigned int i = 0; i < m.face.size(); ++i){ + char * dest = &((char*)(&h[i]))[0]; + memcpy( (void *)dest , (void*) &((A*)data)[i],s); // we don't want the type conversion + } + typename MeshType::PointerToAttribute pa; + pa._name = std::string(name); + HWIte res = m.face_attr.find(pa); + pa = *res; + m.face_attr.erase(res); + pa._padding = padd; + std::pair new_pa = m.face_attr.insert(pa); + assert(new_pa.second); + } + else + T::template AddAttrib<1>(m,name,s,data); + break; + case 2: + if(s == sizeof(A)){ + typename MeshType::template PerMeshAttributeHandle h = vcg::tri::Allocator::template AddPerMeshAttribute(m,name); + memcpy((void*)&h(), (void*)((A*)data),sizeof(A)); // we don't want the type conversion + } + else + if(s < sizeof(A)){ + // padding + int padd = sizeof(A) - s; + 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); - pa = *res; - m.mesh_attr.erase(res); - pa._padding = padd; - std::pair new_pa = m.mesh_attr.insert(pa); - assert(new_pa.second); - } - else - T::template AddAttrib<2>(m,name,s,data); - break; - default: assert(0);break; - } - } - }; + typename MeshType::PointerToAttribute pa; + pa._name = std::string(name); + HWIte res = m.mesh_attr.find(pa); + pa = *res; + m.mesh_attr.erase(res); + pa._padding = padd; + std::pair new_pa = m.mesh_attr.insert(pa); + assert(new_pa.second); + } + else + T::template AddAttrib<2>(m,name,s,data); + break; + default: assert(0);break; + } + } + }; - /** - This is the templated derivation chain - */ - template struct K { - template - 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); - } - }; + /** + This is the templated derivation chain + */ + template struct K { + template + 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); + } + }; - template struct K0 : public DerK< MeshType, B0, K > {}; - template struct K1 : public DerK< MeshType, B1, K0 > {}; - template struct K2 : public DerK< MeshType, B2, K1 > {}; - template struct K3 : public DerK< MeshType, B3, K2 > {}; - template struct K4 : public DerK< MeshType, B4, K3 > {}; - template struct K5 : public DerK< MeshType, B5, K4 > {}; - template struct K6 : public DerK< MeshType, B6, K5 > {}; - template struct K7 : public DerK< MeshType, B7, K6 > {}; - template struct K8 : public DerK< MeshType, B8, K7 > {}; - template struct K9 : public DerK< MeshType, B9, K8 > {}; - template struct K10 : public DerK< MeshType, B10, K9 > {}; - template struct K11 : public DerK< MeshType, B11, K10 > {}; - template struct K12 : public DerK< MeshType, B12, K11 > {}; + template struct K0 : public DerK< MeshType, B0, K > {}; + template struct K1 : public DerK< MeshType, B1, K0 > {}; + template struct K2 : public DerK< MeshType, B2, K1 > {}; + template struct K3 : public DerK< MeshType, B3, K2 > {}; + template struct K4 : public DerK< MeshType, B4, K3 > {}; + template struct K5 : public DerK< MeshType, B5, K4 > {}; + template struct K6 : public DerK< MeshType, B6, K5 > {}; + template struct K7 : public DerK< MeshType, B7, K6 > {}; + template struct K8 : public DerK< MeshType, B8, K7 > {}; + template struct K9 : public DerK< MeshType, B9, K8 > {}; + template struct K10 : public DerK< MeshType, B10, K9 > {}; + 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 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> - > struct C0 : public DerK< MeshType, A0, K12 > {}; + template , + class B1 = DummyType<2048>, + class B2 = DummyType<1024>, + class B3 = DummyType<512>, + 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> + > struct C0 : public DerK< MeshType, A0, K12 > {}; - template struct C1 : public Der< MeshType, A1, C0 > {}; - template struct C2 : public Der< MeshType, A2, C1 > {}; - template struct C3 : public Der< MeshType, A3, C2 > {}; - template struct AttrAll : public Der< MeshType, A4, C3 > {}; + template struct C1 : public Der< MeshType, A1, C0 > {}; + template struct C2 : public Der< MeshType, A2, C1 > {}; + template struct C3 : public Der< MeshType, A3, C2 > {}; + template struct AttrAll : public Der< MeshType, A4, C3 > {}; - template - class ImporterVMI: public AttrAll - { + template + class ImporterVMI: public AttrAll + { static void ReadString(std::string & out){ unsigned int l; Read(&l,4,1); @@ -254,9 +254,9 @@ namespace io { static void ReadFloat( float & v){ Read(&v,1,sizeof(float));} - static int LoadVertexOcfMask( ){ - int mask =0; - std::string s; + static int LoadVertexOcfMask( ){ + int mask =0; + std::string s; // vertex quality ReadString( s); @@ -310,7 +310,7 @@ namespace io { struct LoadVertexOcf >{ typedef typename OpenMeshType::VertexType VertexType; - LoadVertexOcf( FILE * f, vertex::vector_ocf & vert){ + LoadVertexOcf( FILE * /*f*/, vertex::vector_ocf & vert){ std::string s; // vertex quality @@ -504,52 +504,52 @@ namespace io { } }; - static int FaceMaskBitFromString(std::string s){ - if( s.find("Color",0) != std::string::npos ) return Mask::IOM_FACECOLOR; else - if( s.find("BitFlags",0) != std::string::npos ) return Mask::IOM_FACEFLAGS; else - if( s.find("VertexRef",0) != std::string::npos ) return Mask::IOM_FACEINDEX; else - if( s.find("Normal",0) != std::string::npos ) return Mask::IOM_FACENORMAL; else - if( s.find("Quality",0) != std::string::npos ) return Mask::IOM_FACEQUALITY; else - if( s.find("Quality",0) != std::string::npos ) return Mask::IOM_FACEQUALITY; else - if( s.find("WedgeColor",0) != std::string::npos ) return Mask::IOM_WEDGCOLOR; else - if( s.find("WedgeNormal",0) != std::string::npos ) return Mask::IOM_WEDGNORMAL; else - if( s.find("WedgeTexCoord",0) != std::string::npos) return Mask::IOM_WEDGTEXCOORD; else - return 0; - } - static int VertexMaskBitFromString(std::string s){ - if( s.find("Color",0) != std::string::npos ) return Mask::IOM_VERTCOLOR; else - if( s.find("Coord",0) != std::string::npos ) return Mask::IOM_VERTCOORD; else - if( s.find("BitFlags",0) != std::string::npos ) return Mask::IOM_VERTFLAGS; else - if( s.find("Quality",0) != std::string::npos ) return Mask::IOM_VERTQUALITY; else - if( s.find("Normal",0) != std::string::npos ) return Mask::IOM_VERTNORMAL; else - if( s.find("TexCoord",0) != std::string::npos ) return Mask::IOM_VERTTEXCOORD; else - if( s.find("Radius",0) != std::string::npos ) return Mask::IOM_VERTRADIUS; else - return 0; - } + static int FaceMaskBitFromString(std::string s){ + if( s.find("Color",0) != std::string::npos ) return Mask::IOM_FACECOLOR; else + if( s.find("BitFlags",0) != std::string::npos ) return Mask::IOM_FACEFLAGS; else + if( s.find("VertexRef",0) != std::string::npos ) return Mask::IOM_FACEINDEX; else + if( s.find("Normal",0) != std::string::npos ) return Mask::IOM_FACENORMAL; else + if( s.find("Quality",0) != std::string::npos ) return Mask::IOM_FACEQUALITY; else + if( s.find("Quality",0) != std::string::npos ) return Mask::IOM_FACEQUALITY; else + if( s.find("WedgeColor",0) != std::string::npos ) return Mask::IOM_WEDGCOLOR; else + if( s.find("WedgeNormal",0) != std::string::npos ) return Mask::IOM_WEDGNORMAL; else + if( s.find("WedgeTexCoord",0) != std::string::npos) return Mask::IOM_WEDGTEXCOORD; else + return 0; + } + static int VertexMaskBitFromString(std::string s){ + if( s.find("Color",0) != std::string::npos ) return Mask::IOM_VERTCOLOR; else + if( s.find("Coord",0) != std::string::npos ) return Mask::IOM_VERTCOORD; else + if( s.find("BitFlags",0) != std::string::npos ) return Mask::IOM_VERTFLAGS; else + if( s.find("Quality",0) != std::string::npos ) return Mask::IOM_VERTQUALITY; else + if( s.find("Normal",0) != std::string::npos ) return Mask::IOM_VERTNORMAL; else + if( s.find("TexCoord",0) != std::string::npos ) return Mask::IOM_VERTTEXCOORD; else + if( s.find("Radius",0) != std::string::npos ) return Mask::IOM_VERTRADIUS; else + return 0; + } - static FILE *& F(){static FILE * f; return f;} + 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);} + static void * Malloc(unsigned int n){ return (n)?malloc(n):0;} + static void Free(void * ptr){ if(ptr) free (ptr);} - typedef typename OpenMeshType::FaceType FaceType; - typedef typename OpenMeshType::FaceContainer FaceContainer; - typedef typename OpenMeshType::FaceIterator FaceIterator; + typedef typename OpenMeshType::FaceType FaceType; + typedef typename OpenMeshType::FaceContainer FaceContainer; + typedef typename OpenMeshType::FaceIterator FaceIterator; - typedef typename OpenMeshType::VertContainer VertContainer; - typedef typename OpenMeshType::VertexIterator VertexIterator; - typedef typename OpenMeshType::VertexType VertexType; + typedef typename OpenMeshType::VertContainer VertContainer; + typedef typename OpenMeshType::VertexIterator VertexIterator; + typedef typename OpenMeshType::VertexType VertexType; - public: - enum VMIErrorCodes { - VMI_NO_ERROR = 0, - VMI_INCOMPATIBLE_VERTEX_TYPE, - VMI_INCOMPATIBLE_FACE_TYPE, - VMI_FAILED_OPEN - }; + public: + enum VMIErrorCodes { + VMI_NO_ERROR = 0, + VMI_INCOMPATIBLE_VERTEX_TYPE, + VMI_INCOMPATIBLE_FACE_TYPE, + VMI_FAILED_OPEN + }; /*! * Standard call for knowing the meaning of an error code @@ -572,52 +572,52 @@ namespace io { return error_msg[message_code]; }; - /* Read the info about the mesh. Note: in the header the bounding box is always written/readed - 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, - unsigned int &faceSize, - vcg::Box3f & bbox, - int & mask){ - std::string name; - unsigned int nameFsize,nameVsize,i; + /* Read the info about the mesh. Note: in the header the bounding box is always written/readed + 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, + unsigned int &faceSize, + vcg::Box3f & bbox, + int & mask){ + std::string name; + unsigned int nameFsize,nameVsize,i; - ReadString( name); ReadInt( nameFsize); + ReadString( name); ReadInt( nameFsize); - for(i=0; i < nameFsize; ++i) - {ReadString( name);fnameF.push_back( name );mask |= FaceMaskBitFromString(name);} - mask |= LoadFaceOcfMask(); + 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); + ReadString( name); ReadInt( faceSize); + ReadString( name); ReadInt( nameVsize); - for(i=0; i < nameVsize; ++i) - {ReadString( name) ;fnameV.push_back( name);mask |= VertexMaskBitFromString(name);} - mask |= LoadVertexOcfMask(); + for(i=0; i < nameVsize; ++i) + {ReadString( name) ;fnameV.push_back( name);mask |= VertexMaskBitFromString(name);} + mask |= LoadVertexOcfMask(); ReadString( name); ReadInt( vertSize); - ReadString( name); - float float_value; - for(unsigned int i =0; i < 2; ++i){ReadFloat( float_value); bbox.min[i]=float_value;} - for(unsigned int i =0; i < 2; ++i){ReadFloat( float_value); bbox.max[i]=float_value;} + ReadString( name); + float float_value; + for(unsigned int i =0; i < 2; ++i){ReadFloat( float_value); bbox.min[i]=float_value;} + for(unsigned int i =0; i < 2; ++i){ReadFloat( float_value); bbox.max[i]=float_value;} - ReadString( name); - assert(strstr( name.c_str(),"end_header")!=NULL); - return true; - } + ReadString( name); + assert(strstr( name.c_str(),"end_header")!=NULL); + return true; + } - 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; - } + 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 const char * & In_mem(){static const char * in_mem; return in_mem;} @@ -639,28 +639,28 @@ namespace io { } - static bool LoadMask(const char * f, int & mask){ - std::vector nameV; - std::vector nameF; - unsigned int vertSize, faceSize; - vcg::Box3f bbox; - F() = fopen(f,"rb"); - In_mode() = 1; - GetHeader(nameV,nameF,vertSize, faceSize, bbox, mask); - return true; - } + static bool LoadMask(const char * f, int & mask){ + std::vector nameV; + std::vector nameF; + unsigned int vertSize, faceSize; + vcg::Box3f bbox; + F() = fopen(f,"rb"); + In_mode() = 1; + GetHeader(nameV,nameF,vertSize, faceSize, bbox, mask); + return true; + } - static bool LoadMaskFromMem( const char * ptr, int & mask){ - std::vector nameV; - std::vector nameF; - unsigned int vertSize, faceSize; - vcg::Box3f bbox; - In_mode() = 0; - pos() = 0; - In_mem() = ptr; - GetHeader(nameV,nameF,vertSize, faceSize, bbox, mask); - return true; - } + static bool LoadMaskFromMem( const char * ptr, int & mask){ + std::vector nameV; + std::vector nameF; + unsigned int vertSize, faceSize; + vcg::Box3f bbox; + In_mode() = 0; + pos() = 0; + In_mem() = ptr; + GetHeader(nameV,nameF,vertSize, faceSize, bbox, mask); + return true; + } static int Open(OpenMeshType &m, const char * filename, int & mask,CallBackPos * /*cb*/ = 0 ) { In_mode() = 1; @@ -685,8 +685,8 @@ namespace io { typename OpenMeshType::FaceIterator fi; typename OpenMeshType::VertexIterator vi; - std::vector nameF,nameV,fnameF,fnameV; - unsigned int vertSize,faceSize; + std::vector nameF,nameV,fnameF,fnameV; + unsigned int vertSize,faceSize; /* read the header */ vcg::Box3f lbbox; @@ -702,13 +702,13 @@ namespace io { void * offsetV = 0,*offsetF = 0; - if(vertSize!=0) - /* read the address of the first vertex */ - Read(&offsetV,sizeof( void *),1 ); + if(vertSize!=0) + /* read the address of the first vertex */ + Read(&offsetV,sizeof( void *),1 ); - if(faceSize!=0) - /* read the address of the first face */ - Read(&offsetF,sizeof( void *),1 ); + if(faceSize!=0) + /* read the address of the first face */ + Read(&offsetF,sizeof( void *),1 ); /* read the object mesh */ Read(&m.shot,sizeof(Shot),1 ); @@ -719,35 +719,35 @@ namespace io { Read(&m.C(),sizeof(Color4b),1 ); - /* resize the vector of vertices */ - m.vert.resize(vertSize); + /* resize the vector of vertices */ + m.vert.resize(vertSize); - size_t read = 0; - /* load the vertices */ - if(vertSize>0){ - read=Read((void*)& m.vert[0],sizeof(VertexType),vertSize ); - LoadVertexOcf(F(),m.vert); - } + size_t read = 0; + /* load the vertices */ + if(vertSize>0){ + read=Read((void*)& m.vert[0],sizeof(VertexType),vertSize ); + LoadVertexOcf(F(),m.vert); + } - read = 0; - m.face.resize(faceSize); - if(faceSize>0){ - /* load the faces */ - read = Read((void*)& m.face[0],sizeof(FaceType),faceSize ); - LoadFaceOcf(m.face); - } + read = 0; + m.face.resize(faceSize); + if(faceSize>0){ + /* load the faces */ + 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; + /* load the per vertex attributes */ + std::string _string,_trash; + unsigned int n,sz; - ReadString( _trash); ReadInt( n); + ReadString( _trash); ReadInt( n); - for(size_t ia = 0 ; ia < n; ++ia){ - ReadString(_trash); ReadString(_string); - ReadString(_trash); ReadInt(sz); + for(size_t ia = 0 ; ia < n; ++ia){ + ReadString(_trash); ReadString(_string); + ReadString(_trash); ReadInt(sz); void * data = Malloc(sz*m.vert.size()); Read(data,sz,m.vert.size()); @@ -755,56 +755,56 @@ namespace io { Free(data); } - /* load the per face attributes */ - ReadString(_trash); ReadInt( n); - 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() ); - AttrAll::template AddAttrib<1>(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){ + ReadString(_trash); ReadString( _string); + ReadString(_trash); ReadInt( sz); + void * data = Malloc(sz*m.face.size()); + Read(data,sz,m.face.size() ); + AttrAll::template AddAttrib<1>(m,_string.c_str(),sz,data); + Free(data); + } - /* load the per mesh attributes */ - ReadString( _trash); ReadInt( n); - for(unsigned int ia = 0 ; ia < n; ++ia){ - ReadString( _trash); ReadString( _string); - ReadString( _trash); ReadInt( sz); - void * data = Malloc(sz); - Read(data,1,sz ); - AttrAll::template AddAttrib<2>(m,_string.c_str(),sz,data); - Free(data); - } + /* load the per mesh attributes */ + ReadString( _trash); ReadInt( n); + for(unsigned int ia = 0 ; ia < n; ++ia){ + ReadString( _trash); ReadString( _string); + ReadString( _trash); ReadInt( sz); + void * data = Malloc(sz); + Read(data,1,sz ); + AttrAll::template AddAttrib<2>(m,_string.c_str(),sz,data); + Free(data); + } - if(!m.face.empty()){ - if(FaceVectorHasVFAdjacency(m.face)) - for(vi = m.vert.begin(); vi != m.vert.end(); ++vi){ - (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0]; - (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0]; - (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0]; - } + if(!m.face.empty()){ + if(FaceVectorHasVFAdjacency(m.face)) + for(vi = m.vert.begin(); vi != m.vert.end(); ++vi){ + (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0]; + (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0]; + (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0]; + } - 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(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)) - 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]; - (*fi).FFp(2) = (*fi).FFp(2)-(FaceType*)offsetF+ &m.face[0]; - } + 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]; + (*fi).FFp(2) = (*fi).FFp(2)-(FaceType*)offsetF+ &m.face[0]; + } - } + } - return VMI_NO_ERROR; // zero is the standard (!) code of success - } + return VMI_NO_ERROR; // zero is the standard (!) code of success + } - }; // end class + }; // end class } // end Namespace tri