bug in importvmi::loadmask when loading from memory.

General cleanup of useless parameters [by way of Fabio Ganovelli]
This commit is contained in:
granzuglia 2013-09-23 11:07:30 +00:00
parent e3a8a50bc5
commit ce4b264dfd
2 changed files with 256 additions and 242 deletions

View File

@ -72,39 +72,39 @@ namespace io {
static unsigned int & pos(){static unsigned int p = 0; return p;} static unsigned int & pos(){static unsigned int p = 0; return p;}
static int fwrite_sim(const void * , size_t size, size_t count, FILE * ){ pos() += size * count;return size * count; } static int fwrite_sim(const void * , size_t size, size_t count){ pos() += size * count;return size * count; }
static int fwrite_mem(const void *src , size_t size, size_t count, FILE * ){ memcpy(&Out_mem()[pos()],src,size*count); pos() += size * count;return size * count; } static int fwrite_mem(const void *src , size_t size, size_t count ){ memcpy(&Out_mem()[pos()],src,size*count); pos() += size * count;return size * count; }
static int WriteOut(const void * src, size_t size, size_t count, FILE *f){ static int WriteOut(const void * src, size_t size, size_t count){
switch(Out_mode()){ switch(Out_mode()){
case 0: return fwrite_sim(src, size,count, f ); break; case 0: return fwrite_sim(src, size,count); break;
case 1: return fwrite_mem(src, size,count, f ); break; case 1: return fwrite_mem(src, size,count); break;
case 2: return fwrite(src, size,count, f ); break; case 2: return fwrite(src, size,count, F() ); break;
} }
} }
static void WriteString(FILE *f,const char * in) { unsigned int l = strlen(in); WriteOut(&l,4,1,f); WriteOut(in,1,l,f);} static void WriteString( const char * in) { unsigned int l = strlen(in); WriteOut(&l,4,1 ); WriteOut(in,1,l );}
static void WriteInt(FILE *f,const unsigned int i) { WriteOut(&i,1,4,f);} static void WriteInt (const unsigned int i) { WriteOut(&i,1,4 );}
static void WriteFloat(FILE *f,const float v) { WriteOut(&v,1,sizeof(float),f);} static void WriteFloat( const float v) { WriteOut(&v,1,sizeof(float) );}
/* save Ocf Vertex Components */ /* save Ocf Vertex Components */
template <typename OpenMeshType,typename CONT> template <typename OpenMeshType,typename CONT>
struct SaveVertexOcf{ struct SaveVertexOcf{
SaveVertexOcf(FILE*f, const CONT & /*vert*/, bool only_header){ SaveVertexOcf( const CONT & /*vert*/, bool only_header){
// do nothing, it is a std::vector // do nothing, it is a std::vector
if(only_header){ if(only_header){
WriteString(f,"NOT_HAS_VERTEX_QUALITY_OCF"); WriteString( "NOT_HAS_VERTEX_QUALITY_OCF");
WriteString(f,"NOT_HAS_VERTEX_COLOR_OCF"); WriteString( "NOT_HAS_VERTEX_COLOR_OCF");
WriteString(f,"NOT_HAS_VERTEX_NORMAL_OCF"); WriteString( "NOT_HAS_VERTEX_NORMAL_OCF");
WriteString(f,"NOT_HAS_VERTEX_MARK_OCF"); WriteString( "NOT_HAS_VERTEX_MARK_OCF");
WriteString(f,"NOT_HAS_VERTEX_TEXCOORD_OCF"); WriteString( "NOT_HAS_VERTEX_TEXCOORD_OCF");
WriteString(f,"NOT_HAS_VERTEX_VFADJACENCY_OCF"); WriteString( "NOT_HAS_VERTEX_VFADJACENCY_OCF");
WriteString(f,"NOT_HAS_VERTEX_CURVATURE_OCF"); WriteString( "NOT_HAS_VERTEX_CURVATURE_OCF");
WriteString(f,"NOT_HAS_VERTEX_CURVATUREDIR_OCF"); WriteString( "NOT_HAS_VERTEX_CURVATUREDIR_OCF");
WriteString(f,"NOT_HAS_VERTEX_RADIUS_OCF"); WriteString( "NOT_HAS_VERTEX_RADIUS_OCF");
} }
} }
}; };
@ -113,52 +113,52 @@ namespace io {
template <typename MeshType> template <typename MeshType>
struct SaveVertexOcf<MeshType, vertex::vector_ocf<typename MeshType::VertexType> >{ struct SaveVertexOcf<MeshType, vertex::vector_ocf<typename MeshType::VertexType> >{
typedef typename MeshType::VertexType VertexType; typedef typename MeshType::VertexType VertexType;
SaveVertexOcf(FILE * f,const vertex::vector_ocf<VertexType> & vert, bool only_header){ SaveVertexOcf( const vertex::vector_ocf<VertexType> & vert, bool only_header){
if( VertexType::HasQualityOcf() && vert.IsQualityEnabled()){ if( VertexType::HasQualityOcf() && vert.IsQualityEnabled()){
WriteString(f,"HAS_VERTEX_QUALITY_OCF"); WriteString( "HAS_VERTEX_QUALITY_OCF");
if(!only_header) WriteOut(&vert.QV[0],sizeof(typename VertexType::QualityType),vert.size(),f); if(!only_header) WriteOut(&vert.QV[0],sizeof(typename VertexType::QualityType),vert.size() );
}else WriteString(f,"NOT_HAS_VERTEX_QUALITY_OCF"); }else WriteString( "NOT_HAS_VERTEX_QUALITY_OCF");
if( VertexType::HasColorOcf() && vert.IsColorEnabled()){ if( VertexType::HasColorOcf() && vert.IsColorEnabled()){
WriteString(f,"HAS_VERTEX_COLOR_OCF"); WriteString( "HAS_VERTEX_COLOR_OCF");
if(!only_header) WriteOut(&vert.CV[0],sizeof(typename VertexType::ColorType),vert.size(),f); if(!only_header) WriteOut(&vert.CV[0],sizeof(typename VertexType::ColorType),vert.size() );
}else WriteString(f,"NOT_HAS_VERTEX_COLOR_OCF"); }else WriteString( "NOT_HAS_VERTEX_COLOR_OCF");
if( VertexType::HasNormalOcf() && vert.IsNormalEnabled()){ if( VertexType::HasNormalOcf() && vert.IsNormalEnabled()){
WriteString(f,"HAS_VERTEX_NORMAL_OCF"); WriteString( "HAS_VERTEX_NORMAL_OCF");
if(!only_header) WriteOut(&vert.NV[0],sizeof(typename VertexType::NormalType),vert.size(),f); if(!only_header) WriteOut(&vert.NV[0],sizeof(typename VertexType::NormalType),vert.size() );
}else WriteString(f,"NOT_HAS_VERTEX_NORMAL_OCF"); }else WriteString( "NOT_HAS_VERTEX_NORMAL_OCF");
if( VertexType::HasMarkOcf() && vert.IsMarkEnabled()){ if( VertexType::HasMarkOcf() && vert.IsMarkEnabled()){
WriteString(f,"HAS_VERTEX_MARK_OCF"); WriteString( "HAS_VERTEX_MARK_OCF");
if(!only_header) WriteOut(&vert.MV[0],sizeof(typename VertexType::MarkType),vert.size(),f); if(!only_header) WriteOut(&vert.MV[0],sizeof(typename VertexType::MarkType),vert.size() );
}else WriteString(f,"NOT_HAS_VERTEX_MARK_OCF"); }else WriteString( "NOT_HAS_VERTEX_MARK_OCF");
if( VertexType::HasTexCoordOcf() && vert.IsTexCoordEnabled()){ if( VertexType::HasTexCoordOcf() && vert.IsTexCoordEnabled()){
WriteString(f,"HAS_VERTEX_TEXCOORD_OCF"); WriteString( "HAS_VERTEX_TEXCOORD_OCF");
if(!only_header) WriteOut(&vert.TV[0],sizeof(typename VertexType::TexCoordType),vert.size(),f); if(!only_header) WriteOut(&vert.TV[0],sizeof(typename VertexType::TexCoordType),vert.size() );
}else WriteString(f,"NOT_HAS_VERTEX_TEXCOORD_OCF"); }else WriteString( "NOT_HAS_VERTEX_TEXCOORD_OCF");
if( VertexType::HasVFAdjacencyOcf() && vert.IsVFAdjacencyEnabled()){ if( VertexType::HasVFAdjacencyOcf() && vert.IsVFAdjacencyEnabled()){
WriteString(f,"HAS_VERTEX_VFADJACENCY_OCF"); WriteString( "HAS_VERTEX_VFADJACENCY_OCF");
if(!only_header) WriteOut(&vert.AV[0],sizeof(typename vertex::vector_ocf<VertexType>::VFAdjType),vert.size(),f); if(!only_header) WriteOut(&vert.AV[0],sizeof(typename vertex::vector_ocf<VertexType>::VFAdjType),vert.size() );
}else WriteString(f,"NOT_HAS_VERTEX_VFADJACENCY_OCF"); }else WriteString( "NOT_HAS_VERTEX_VFADJACENCY_OCF");
if( VertexType::HasCurvatureOcf() && vert.IsCurvatureEnabled()){ if( VertexType::HasCurvatureOcf() && vert.IsCurvatureEnabled()){
WriteString(f,"HAS_VERTEX_CURVATURE_OCF"); WriteString( "HAS_VERTEX_CURVATURE_OCF");
if(!only_header) WriteOut(&vert.CuV[0],sizeof(typename VertexType::CurvatureType),vert.size(),f); if(!only_header) WriteOut(&vert.CuV[0],sizeof(typename VertexType::CurvatureType),vert.size() );
}else WriteString(f,"NOT_HAS_VERTEX_CURVATURE_OCF"); }else WriteString( "NOT_HAS_VERTEX_CURVATURE_OCF");
if( VertexType::HasCurvatureDirOcf() && vert.IsCurvatureDirEnabled()){ if( VertexType::HasCurvatureDirOcf() && vert.IsCurvatureDirEnabled()){
WriteString(f,"HAS_VERTEX_CURVATUREDIR_OCF"); WriteString( "HAS_VERTEX_CURVATUREDIR_OCF");
if(!only_header) WriteOut(&vert.CuDV[0],sizeof(typename VertexType::CurvatureDirType),vert.size(),f); if(!only_header) WriteOut(&vert.CuDV[0],sizeof(typename VertexType::CurvatureDirType),vert.size() );
}else WriteString(f,"NOT_HAS_VERTEX_CURVATUREDIR_OCF"); }else WriteString( "NOT_HAS_VERTEX_CURVATUREDIR_OCF");
if( VertexType::HasRadiusOcf() && vert.IsRadiusEnabled()){ if( VertexType::HasRadiusOcf() && vert.IsRadiusEnabled()){
WriteString(f,"HAS_VERTEX_RADIUS_OCF"); WriteString( "HAS_VERTEX_RADIUS_OCF");
if(!only_header) WriteOut(&vert.RadiusV[0],sizeof(typename VertexType::RadiusType),vert.size(),f); if(!only_header) WriteOut(&vert.RadiusV[0],sizeof(typename VertexType::RadiusType),vert.size() );
}else WriteString(f,"NOT_HAS_VERTEX_RADIUS_OCF"); }else WriteString( "NOT_HAS_VERTEX_RADIUS_OCF");
} }
}; };
@ -167,18 +167,18 @@ namespace io {
/* save Ocf Face Components */ /* save Ocf Face Components */
template <typename MeshType,typename CONT> template <typename MeshType,typename CONT>
struct SaveFaceOcf{ struct SaveFaceOcf{
SaveFaceOcf(FILE * f,const CONT & /*face*/, bool only_header){ SaveFaceOcf( const CONT & /*face*/, bool only_header){
// it is a std::vector // it is a std::vector
if(only_header){ if(only_header){
WriteString(f,"NOT_HAS_FACE_QUALITY_OCF"); WriteString( "NOT_HAS_FACE_QUALITY_OCF");
WriteString(f,"NOT_HAS_FACE_COLOR_OCF"); WriteString( "NOT_HAS_FACE_COLOR_OCF");
WriteString(f,"NOT_HAS_FACE_NORMAL_OCF"); WriteString( "NOT_HAS_FACE_NORMAL_OCF");
WriteString(f,"NOT_HAS_FACE_MARK_OCF"); WriteString( "NOT_HAS_FACE_MARK_OCF");
WriteString(f,"NOT_HAS_FACE_WEDGETEXCOORD_OCF"); WriteString( "NOT_HAS_FACE_WEDGETEXCOORD_OCF");
WriteString(f,"NOT_HAS_FACE_FFADJACENCY_OCF"); WriteString( "NOT_HAS_FACE_FFADJACENCY_OCF");
WriteString(f,"NOT_HAS_FACE_VFADJACENCY_OCF"); WriteString( "NOT_HAS_FACE_VFADJACENCY_OCF");
WriteString(f,"NOT_HAS_FACE_WEDGECOLOR_OCF"); WriteString( "NOT_HAS_FACE_WEDGECOLOR_OCF");
WriteString(f,"NOT_HAS_FACE_WEDGENORMAL_OCF"); WriteString( "NOT_HAS_FACE_WEDGENORMAL_OCF");
} }
} }
}; };
@ -187,52 +187,52 @@ namespace io {
template <typename MeshType> template <typename MeshType>
struct SaveFaceOcf< MeshType, face::vector_ocf<typename MeshType::FaceType> >{ struct SaveFaceOcf< MeshType, face::vector_ocf<typename MeshType::FaceType> >{
typedef typename MeshType::FaceType FaceType; typedef typename MeshType::FaceType FaceType;
SaveFaceOcf(FILE * f,const face::vector_ocf<FaceType> & face, bool only_header){ SaveFaceOcf( const face::vector_ocf<FaceType> & face, bool only_header){
if( FaceType::HasFaceQualityOcf() && face.IsQualityEnabled()){ if( FaceType::HasQualityOcf() && face.IsQualityEnabled()){
WriteString(f,"HAS_FACE_QUALITY_OCF"); WriteString( "HAS_FACE_QUALITY_OCF");
if(!only_header) WriteOut(&face.QV[0],sizeof(typename FaceType::QualityType),face.size(),f); if(!only_header) WriteOut(&face.QV[0],sizeof(typename FaceType::QualityType),face.size() );
}else WriteString(f,"NOT_HAS_FACE_QUALITY_OCF"); }else WriteString( "NOT_HAS_FACE_QUALITY_OCF");
if( FaceType::HasFaceColorOcf() && face.IsColorEnabled()){ if( FaceType::HasColorOcf() && face.IsColorEnabled()){
WriteString(f,"HAS_FACE_COLOR_OCF"); WriteString( "HAS_FACE_COLOR_OCF");
if(!only_header) WriteOut(&face.CV[0],sizeof(typename FaceType::ColorType),face.size(),f); if(!only_header) WriteOut(&face.CV[0],sizeof(typename FaceType::ColorType),face.size() );
}else WriteString(f,"NOT_HAS_FACE_COLOR_OCF"); }else WriteString( "NOT_HAS_FACE_COLOR_OCF");
if( FaceType::HasFaceNormalOcf() && face.IsNormalEnabled()){ if( FaceType::HasNormalOcf() && face.IsNormalEnabled()){
WriteString(f,"HAS_FACE_NORMAL_OCF"); WriteString( "HAS_FACE_NORMAL_OCF");
if(!only_header) WriteOut(&face.NV[0],sizeof(typename FaceType::NormalType),face.size(),f); if(!only_header) WriteOut(&face.NV[0],sizeof(typename FaceType::NormalType),face.size() );
}else WriteString(f,"NOT_HAS_FACE_NORMAL_OCF"); }else WriteString( "NOT_HAS_FACE_NORMAL_OCF");
if( FaceType::HasFaceMarkOcf() && face.IsMarkEnabled()){ if( FaceType::HasMarkOcf() && face.IsMarkEnabled()){
WriteString(f,"HAS_FACE_MARK_OCF"); WriteString( "HAS_FACE_MARK_OCF");
if(!only_header) WriteOut(&face.MV[0],sizeof(typename FaceType::MarkType),face.size(),f); if(!only_header) WriteOut(&face.MV[0],sizeof(typename FaceType::MarkType),face.size() );
}else WriteString(f,"NOT_HAS_FACE_MARK_OCF"); }else WriteString( "NOT_HAS_FACE_MARK_OCF");
if( FaceType::HasWedgeTexCoordOcf() && face.IsWedgeTexEnabled()){ if( FaceType::HasWedgeTexCoordOcf() && face.IsWedgeTexCoordEnabled()){
WriteString(f,"HAS_FACE_WEDGETEXCOORD_OCF"); WriteString( "HAS_FACE_WEDGETEXCOORD_OCF");
if(!only_header) WriteOut(&face.WTV[0],sizeof(typename FaceType::WedgeTexCoordType),face.size(),f); if(!only_header) WriteOut(&face.WTV[0],sizeof(typename FaceType::WedgeTexCoordType),face.size() );
}else WriteString(f,"NOT_HAS_FACE_WEDGETEXCOORD_OCF"); }else WriteString( "NOT_HAS_FACE_WEDGETEXCOORD_OCF");
if( FaceType::HasFFAdjacencyOcf() && face.IsFFAdjacencyEnabled()){ if( FaceType::HasFFAdjacencyOcf() && face.IsFFAdjacencyEnabled()){
WriteString(f,"HAS_FACE_FFADJACENCY_OCF"); WriteString( "HAS_FACE_FFADJACENCY_OCF");
if(!only_header) WriteOut(&face.AF[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size(),f); if(!only_header) WriteOut(&face.AF[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size() );
}else WriteString(f,"NOT_HAS_FACE_FFADJACENCY_OCF"); }else WriteString( "NOT_HAS_FACE_FFADJACENCY_OCF");
if( FaceType::HasVFAdjacencyOcf() && face.IsVFAdjacencyEnabled()){ if( FaceType::HasVFAdjacencyOcf() && face.IsVFAdjacencyEnabled()){
WriteString(f,"HAS_FACE_VFADJACENCY_OCF"); WriteString( "HAS_FACE_VFADJACENCY_OCF");
if(!only_header) WriteOut(&face.AV[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size(),f); if(!only_header) WriteOut(&face.AV[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size() );
}else WriteString(f,"NOT_HAS_FACE_VFADJACENCY_OCF"); }else WriteString( "NOT_HAS_FACE_VFADJACENCY_OCF");
if( FaceType::HasWedgeColorOcf() && face.IsWedgeColorEnabled()){ if( FaceType::HasWedgeColorOcf() && face.IsWedgeColorEnabled()){
WriteString(f,"HAS_FACE_WEDGECOLOR_OCF"); WriteString( "HAS_FACE_WEDGECOLOR_OCF");
if(!only_header) WriteOut(&face.WCV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeColorTypePack),face.size(),f); if(!only_header) WriteOut(&face.WCV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeColorTypePack),face.size() );
}else WriteString(f,"NOT_HAS_FACE_WEDGECOLOR_OCF"); }else WriteString( "NOT_HAS_FACE_WEDGECOLOR_OCF");
if( FaceType::HasWedgeNormalOcf() && face.IsWedgeNormalEnabled()){ if( FaceType::HasWedgeNormalOcf() && face.IsWedgeNormalEnabled()){
WriteString(f,"HAS_FACE_WEDGENORMAL_OCF"); WriteString( "HAS_FACE_WEDGENORMAL_OCF");
if(!only_header) WriteOut(&face.WNV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeNormalTypePack),face.size(),f); if(!only_header) WriteOut(&face.WNV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeNormalTypePack),face.size() );
}else WriteString(f,"NOT_HAS_FACE_WEDGENORMAL_OCF"); }else WriteString( "NOT_HAS_FACE_WEDGENORMAL_OCF");
} }
}; };
@ -287,65 +287,65 @@ namespace io {
faceSize = m.face.size(); faceSize = m.face.size();
/* write header */ /* write header */
WriteString(F(),"FACE_TYPE"); WriteString( "FACE_TYPE");
WriteInt(F(),nameF.size()); WriteInt( nameF.size());
for(i=0; i < nameF.size(); ++i) WriteString(F(),nameF[i].c_str()); for(i=0; i < nameF.size(); ++i) WriteString( nameF[i].c_str());
SaveFaceOcf<SaveMeshType,FaceContainer>(F(),m.face,true); SaveFaceOcf<SaveMeshType,FaceContainer>( m.face,true);
WriteString(F(),"SIZE_VECTOR_FACES"); WriteString( "SIZE_VECTOR_FACES");
WriteInt(F(), faceSize ); WriteInt( faceSize );
WriteString(F(),"VERTEX_TYPE"); WriteString( "VERTEX_TYPE");
WriteInt(F(),nameV.size()); WriteInt( nameV.size());
for(i=0; i < nameV.size(); ++i) WriteString(F(),nameV[i].c_str()); for(i=0; i < nameV.size(); ++i) WriteString( nameV[i].c_str());
SaveVertexOcf<SaveMeshType,VertContainer>(F(),m.vert,true); SaveVertexOcf<SaveMeshType,VertContainer>( m.vert,true);
WriteString(F(),"SIZE_VECTOR_VERTS"); WriteString( "SIZE_VECTOR_VERTS");
WriteInt(F(),vertSize); WriteInt( vertSize);
WriteString(F(),"BOUNDING_BOX"); WriteString( "BOUNDING_BOX");
float float_value; float float_value;
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.min[i]; WriteFloat(F(),float_value);} for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.min[i]; WriteFloat( float_value);}
for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.max[i]; WriteFloat(F(),float_value);} for(unsigned int i =0; i < 2; ++i){float_value = m.bbox.max[i]; WriteFloat( float_value);}
WriteString(F(),"end_header"); WriteString( "end_header");
/* end header */ /* end header */
if(vertSize!=0){ if(vertSize!=0){
void * offsetV = (void*) &m.vert[0]; void * offsetV = (void*) &m.vert[0];
/* write the address of the first vertex */ /* write the address of the first vertex */
WriteOut(&offsetV,sizeof(void *),1,F()); WriteOut(&offsetV,sizeof(void *),1 );
} }
if(faceSize!=0){ if(faceSize!=0){
void * offsetF= (void*)&m.face[0]; void * offsetF= (void*)&m.face[0];
/* write the address of the first face */ /* write the address of the first face */
WriteOut(&offsetF,sizeof( void *),1,F()); WriteOut(&offsetF,sizeof( void *),1 );
} }
/* save the object mesh */ /* save the object mesh */
WriteOut(&m.shot,sizeof(Shot<typename SaveMeshType::ScalarType>),1,F()); WriteOut(&m.shot,sizeof(Shot<typename SaveMeshType::ScalarType>),1 );
WriteOut(&m.vn,sizeof(int),1,F()); WriteOut(&m.vn,sizeof(int),1 );
WriteOut(&m.fn,sizeof(int),1,F()); WriteOut(&m.fn,sizeof(int),1 );
WriteOut(&m.imark,sizeof(int),1,F()); WriteOut(&m.imark,sizeof(int),1 );
WriteOut(&m.bbox,sizeof(Box3<typename SaveMeshType::ScalarType>),1,F()); WriteOut(&m.bbox,sizeof(Box3<typename SaveMeshType::ScalarType>),1 );
WriteOut(&m.C(),sizeof(Color4b),1,F()); WriteOut(&m.C(),sizeof(Color4b),1 );
unsigned int written; unsigned int written;
if(vertSize!=0){ if(vertSize!=0){
/* save the vertices */ /* save the vertices */
written = WriteOut((void*)&m.vert[0],sizeof(typename SaveMeshType::VertexType),m.vert.size(),F()); written = WriteOut((void*)&m.vert[0],sizeof(typename SaveMeshType::VertexType),m.vert.size() );
SaveVertexOcf<SaveMeshType,VertContainer>(F(),m.vert,false); SaveVertexOcf<SaveMeshType,VertContainer>( m.vert,false);
} }
if(faceSize!=0){ if(faceSize!=0){
/* save the faces */ /* save the faces */
written = WriteOut((void*)&m.face[0],sizeof(typename SaveMeshType::FaceType),faceSize,F()); written = WriteOut((void*)&m.face[0],sizeof(typename SaveMeshType::FaceType),faceSize );
SaveFaceOcf<SaveMeshType,FaceContainer>(F(),m.face,false); SaveFaceOcf<SaveMeshType,FaceContainer>( m.face,false);
} }
@ -361,19 +361,19 @@ namespace io {
unsigned int n_named_attr = 0; unsigned int n_named_attr = 0;
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty(); for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
WriteString(F(),"N_PER_VERTEX_ATTRIBUTES"); WriteInt (F(),n_named_attr); WriteString( "N_PER_VERTEX_ATTRIBUTES"); WriteInt ( n_named_attr);
for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai) for(ai = m.vert_attr.begin(); ai != m.vert_attr.end(); ++ai)
if(!(*ai)._name.empty()) if(!(*ai)._name.empty())
{ {
STDBv * stdb = (STDBv *) (*ai)._handle; STDBv * stdb = (STDBv *) (*ai)._handle;
WriteString(F(),"PER_VERTEX_ATTR_NAME"); WriteString( "PER_VERTEX_ATTR_NAME");
WriteString(F(),(*ai)._name.c_str() ); WriteString( (*ai)._name.c_str() );
WriteString(F(),"PER_VERTEX_ATTR_SIZE"); WriteString( "PER_VERTEX_ATTR_SIZE");
WriteInt(F(),stdb->SizeOf()); WriteInt( stdb->SizeOf());
WriteOut(stdb->DataBegin(),m.vert.size(),stdb->SizeOf(),F()); WriteOut(stdb->DataBegin(),m.vert.size(),stdb->SizeOf() );
} }
} }
@ -383,21 +383,21 @@ namespace io {
unsigned int n_named_attr = 0; unsigned int n_named_attr = 0;
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty(); for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
WriteString(F(),"N_PER_FACE_ATTRIBUTES"); WriteString( "N_PER_FACE_ATTRIBUTES");
WriteInt (F(),n_named_attr); WriteInt ( n_named_attr);
for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai) for(ai = m.face_attr.begin(); ai != m.face_attr.end(); ++ai)
if(!(*ai)._name.empty()) if(!(*ai)._name.empty())
{ {
STDBf * stdb = (STDBf *) (*ai)._handle; STDBf * stdb = (STDBf *) (*ai)._handle;
WriteString(F(),"PER_FACE_ATTR_NAME"); WriteString( "PER_FACE_ATTR_NAME");
WriteString(F(),(*ai)._name.c_str()); WriteString( (*ai)._name.c_str());
WriteString(F(),"PER_FACE_ATTR_SIZE"); WriteString( "PER_FACE_ATTR_SIZE");
WriteInt(F(),stdb->SizeOf()); WriteInt( stdb->SizeOf());
WriteOut(stdb->DataBegin(),m.face.size(),stdb->SizeOf(),F()); WriteOut(stdb->DataBegin(),m.face.size(),stdb->SizeOf() );
} }
} }
@ -406,19 +406,19 @@ namespace io {
typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai; typename std::set< typename SaveMeshType::PointerToAttribute>::const_iterator ai;
unsigned int n_named_attr = 0; unsigned int n_named_attr = 0;
for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty(); for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai) n_named_attr+=!(*ai)._name.empty();
WriteString(F(),"N_PER_MESH_ATTRIBUTES"); WriteInt(F(),n_named_attr); WriteString( "N_PER_MESH_ATTRIBUTES"); WriteInt( n_named_attr);
for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai) for(ai = m.mesh_attr.begin(); ai != m.mesh_attr.end(); ++ai)
if(!(*ai)._name.empty()) if(!(*ai)._name.empty())
{ {
SimpleTempDataBase * handle = (SimpleTempDataBase *) (*ai)._handle ; SimpleTempDataBase * handle = (SimpleTempDataBase *) (*ai)._handle ;
WriteString(F(),"PER_MESH_ATTR_NAME"); WriteString( "PER_MESH_ATTR_NAME");
WriteString(F(),(*ai)._name.c_str()); WriteString( (*ai)._name.c_str());
WriteString(F(),"PER_MESH_ATTR_SIZE"); WriteString( "PER_MESH_ATTR_SIZE");
WriteInt(F(),handle->SizeOf()); WriteInt( handle->SizeOf());
WriteOut(handle->DataBegin(),1,handle->SizeOf(),F()); WriteOut(handle->DataBegin(),1,handle->SizeOf() );
} }
} }

View File

@ -242,56 +242,56 @@ namespace io {
class ImporterVMI: public AttrAll<OpenMeshType,A0,A1,A2,A3,A4> class ImporterVMI: public AttrAll<OpenMeshType,A0,A1,A2,A3,A4>
{ {
static void ReadString(FILE * f,std::string & out){ static void ReadString(std::string & out){
unsigned int l; Read(&l,4,1,f); unsigned int l; Read(&l,4,1);
char * buf = new char[l+1]; char * buf = new char[l+1];
Read(buf,1,l,f);buf[l]='\0'; Read(buf,1,l);buf[l]='\0';
out = std::string(buf); out = std::string(buf);
delete [] buf; delete [] buf;
} }
static void ReadInt(FILE *f, unsigned int & i){ Read(&i,1,4,f);} static void ReadInt( unsigned int & i){ Read(&i,1,4);}
static void ReadFloat(FILE *f, float & v){ Read(&v,1,sizeof(float),f);} static void ReadFloat( float & v){ Read(&v,1,sizeof(float));}
static int LoadVertexOcfMask( FILE * f){ static int LoadVertexOcfMask( ){
int mask =0; int mask =0;
std::string s; std::string s;
// vertex quality // vertex quality
ReadString(f,s); 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 // vertex color
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_COLOR_OCF")) mask |= Mask::IOM_VERTCOLOR; if( s == std::string("HAS_VERTEX_COLOR_OCF")) mask |= Mask::IOM_VERTCOLOR;
// vertex normal // vertex normal
ReadString(f,s); 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 // vertex mark
ReadString(f,s); ReadString( s);
//if( s == std::string("HAS_VERTEX_MARK_OCF")) mask |= //if( s == std::string("HAS_VERTEX_MARK_OCF")) mask |=
// vertex texcoord // vertex texcoord
ReadString(f,s); 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 // vertex-face adjacency
ReadString(f,s); ReadString( s);
//if( s == std::string("HAS_VERTEX_VFADJACENCY_OCF")) mask |= //if( s == std::string("HAS_VERTEX_VFADJACENCY_OCF")) mask |=
// vertex curvature // vertex curvature
ReadString(f,s); ReadString( s);
//if( s == std::string("HAS_VERTEX_CURVATURE_OCF")) mask |= //if( s == std::string("HAS_VERTEX_CURVATURE_OCF")) mask |=
//// vertex curvature dir //// vertex curvature dir
ReadString(f,s); ReadString( s);
//if( s == std::string("HAS_VERTEX_CURVATUREDIR_OCF")) mask |= //if( s == std::string("HAS_VERTEX_CURVATUREDIR_OCF")) mask |=
// vertex radius // vertex radius
ReadString(f,s); 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;
@ -314,66 +314,66 @@ namespace io {
std::string s; std::string s;
// vertex quality // vertex quality
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_QUALITY_OCF")) { if( s == std::string("HAS_VERTEX_QUALITY_OCF")) {
vert.EnableQuality(); vert.EnableQuality();
Read((void*)&vert.QV[0],sizeof(typename VertexType::QualityType),vert.size(),f); Read((void*)&vert.QV[0],sizeof(typename VertexType::QualityType),vert.size() );
} }
// vertex color // vertex color
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_COLOR_OCF")) { if( s == std::string("HAS_VERTEX_COLOR_OCF")) {
vert.EnableColor(); vert.EnableColor();
Read((void*)&vert.CV[0],sizeof(typename VertexType::ColorType),vert.size(),f); Read((void*)&vert.CV[0],sizeof(typename VertexType::ColorType),vert.size() );
} }
// vertex normal // vertex normal
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_NORMAL_OCF")) { if( s == std::string("HAS_VERTEX_NORMAL_OCF")) {
vert.EnableNormal(); vert.EnableNormal();
Read((void*)&vert.NV[0],sizeof(typename VertexType::NormalType),vert.size(),f); Read((void*)&vert.NV[0],sizeof(typename VertexType::NormalType),vert.size() );
} }
// vertex mark // vertex mark
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_MARK_OCF")) { if( s == std::string("HAS_VERTEX_MARK_OCF")) {
vert.EnableMark(); vert.EnableMark();
Read((void*)&vert.MV[0],sizeof(typename VertexType::MarkType),vert.size(),f); Read((void*)&vert.MV[0],sizeof(typename VertexType::MarkType),vert.size() );
} }
// vertex texcoord // vertex texcoord
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_TEXCOORD_OCF")) { if( s == std::string("HAS_VERTEX_TEXCOORD_OCF")) {
vert.EnableTexCoord(); vert.EnableTexCoord();
Read((void*)&vert.TV[0],sizeof(typename VertexType::TexCoordType),vert.size(),f); Read((void*)&vert.TV[0],sizeof(typename VertexType::TexCoordType),vert.size() );
} }
// vertex-face adjacency // vertex-face adjacency
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_VFADJACENCY_OCF")) { if( s == std::string("HAS_VERTEX_VFADJACENCY_OCF")) {
vert.EnableVFAdjacency(); vert.EnableVFAdjacency();
Read((void*)&vert.AV[0],sizeof(typename vertex::vector_ocf<VertexType>::VFAdjType),vert.size(),f); Read((void*)&vert.AV[0],sizeof(typename vertex::vector_ocf<VertexType>::VFAdjType),vert.size() );
} }
// vertex curvature // vertex curvature
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_CURVATURE_OCF")) { if( s == std::string("HAS_VERTEX_CURVATURE_OCF")) {
vert.EnableCurvature(); vert.EnableCurvature();
Read((void*)&vert.CuV[0],sizeof(typename VertexType::CurvatureType),vert.size(),f); Read((void*)&vert.CuV[0],sizeof(typename VertexType::CurvatureType),vert.size() );
} }
// vertex curvature dir // vertex curvature dir
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_CURVATUREDIR_OCF")) { if( s == std::string("HAS_VERTEX_CURVATUREDIR_OCF")) {
vert.EnableCurvatureDir(); vert.EnableCurvatureDir();
Read((void*)&vert.CuDV[0],sizeof(typename VertexType::CurvatureDirType),vert.size(),f); Read((void*)&vert.CuDV[0],sizeof(typename VertexType::CurvatureDirType),vert.size() );
} }
// vertex radius // vertex radius
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_VERTEX_RADIUS_OCF")) { if( s == std::string("HAS_VERTEX_RADIUS_OCF")) {
vert.EnableRadius(); vert.EnableRadius();
Read((void*)&vert.RadiusV[0],sizeof(typename VertexType::RadiusType),vert.size(),f); Read((void*)&vert.RadiusV[0],sizeof(typename VertexType::RadiusType),vert.size() );
} }
} }
@ -381,51 +381,51 @@ namespace io {
template <typename MeshType, typename CONT> template <typename MeshType, typename CONT>
struct LoadFaceOcf{ struct LoadFaceOcf{
LoadFaceOcf(FILE * /* f */ , const CONT & /* face */){ LoadFaceOcf(const CONT & /* face */){
// do nothing, it is a std::vector // do nothing, it is a std::vector
} }
}; };
static int LoadFaceOcfMask( FILE * f){ static int LoadFaceOcfMask( ){
int mask=0; int mask=0;
std::string s; std::string s;
// face quality // face quality
ReadString(f,s); 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 // face color
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_COLOR_OCF")) mask |= Mask::IOM_FACECOLOR; if( s == std::string("HAS_FACE_COLOR_OCF")) mask |= Mask::IOM_FACECOLOR;
// face normal // face normal
ReadString(f,s); 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 //// face mark
ReadString(f,s); ReadString( s);
//if( s == std::string("HAS_FACE_MARK_OCF")) mask |= //if( s == std::string("HAS_FACE_MARK_OCF")) mask |=
// face wedgetexcoord // face wedgetexcoord
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_WEDGETEXCOORD_OCF")) mask |= Mask::IOM_WEDGTEXCOORD; if( s == std::string("HAS_FACE_WEDGETEXCOORD_OCF")) mask |= Mask::IOM_WEDGTEXCOORD;
// face-face adjacency // face-face adjacency
ReadString(f,s); ReadString( s);
// if( s == std::string("HAS_FACE_FFADJACENCY_OCF")) mask |= */ // if( s == std::string("HAS_FACE_FFADJACENCY_OCF")) mask |= */
// vertex-face adjacency // vertex-face adjacency
ReadString(f,s); ReadString( s);
//if( s == std::string("HAS_FACE_VFADJACENCY_OCF")) mask |= //if( s == std::string("HAS_FACE_VFADJACENCY_OCF")) mask |=
// face WedgeColor // face WedgeColor
ReadString(f,s); 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 // face WedgeNormal
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_WEDGENORMAL_OCF")) mask |= Mask::IOM_WEDGNORMAL; if( s == std::string("HAS_FACE_WEDGENORMAL_OCF")) mask |= Mask::IOM_WEDGNORMAL;
return mask; return mask;
} }
@ -435,71 +435,71 @@ namespace io {
template <typename MeshType> template <typename MeshType>
struct LoadFaceOcf< MeshType, face::vector_ocf<typename OpenMeshType::FaceType> >{ struct LoadFaceOcf< MeshType, face::vector_ocf<typename OpenMeshType::FaceType> >{
typedef typename OpenMeshType::FaceType FaceType; typedef typename OpenMeshType::FaceType FaceType;
LoadFaceOcf( FILE * f, face::vector_ocf<FaceType> & face){ LoadFaceOcf( face::vector_ocf<FaceType> & face){
std::string s; std::string s;
// face quality // face quality
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_QUALITY_OCF")) { if( s == std::string("HAS_FACE_QUALITY_OCF")) {
face.EnableQuality(); face.EnableQuality();
Read((void*)&face.QV[0],sizeof(typename FaceType::QualityType),face.size(),f); Read((void*)&face.QV[0],sizeof(typename FaceType::QualityType),face.size() );
} }
// face color // face color
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_COLOR_OCF")) { if( s == std::string("HAS_FACE_COLOR_OCF")) {
face.EnableColor(); face.EnableColor();
Read((void*)&face.CV[0],sizeof(typename FaceType::ColorType),face.size(),f); Read((void*)&face.CV[0],sizeof(typename FaceType::ColorType),face.size() );
} }
// face normal // face normal
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_NORMAL_OCF")) { if( s == std::string("HAS_FACE_NORMAL_OCF")) {
face.EnableNormal(); face.EnableNormal();
Read((void*)&face.NV[0],sizeof(typename FaceType::NormalType),face.size(),f); Read((void*)&face.NV[0],sizeof(typename FaceType::NormalType),face.size() );
} }
// face mark // face mark
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_MARK_OCF")) { if( s == std::string("HAS_FACE_MARK_OCF")) {
face.EnableMark(); face.EnableMark();
Read((void*)&face.MV[0],sizeof(typename FaceType::MarkType),face.size(),f); Read((void*)&face.MV[0],sizeof(typename FaceType::MarkType),face.size() );
} }
// face wedgetexcoord // face wedgetexcoord
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_WEDGETEXCOORD_OCF")) { if( s == std::string("HAS_FACE_WEDGETEXCOORD_OCF")) {
face.EnableWedgeTexCoord(); face.EnableWedgeTexCoord();
Read((void*)&face.WTV[0],sizeof(typename FaceType::WedgeTexCoordType),face.size(),f); Read((void*)&face.WTV[0],sizeof(typename FaceType::WedgeTexCoordType),face.size() );
} }
// face-face adjacency // face-face adjacency
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_FFADJACENCY_OCF")) { if( s == std::string("HAS_FACE_FFADJACENCY_OCF")) {
face.EnableFFAdjacency(); face.EnableFFAdjacency();
Read((void*)&face.AF[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size(),f); Read((void*)&face.AF[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size() );
} }
// vertex-face adjacency // vertex-face adjacency
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_VFADJACENCY_OCF")) { if( s == std::string("HAS_FACE_VFADJACENCY_OCF")) {
face.EnableVFAdjacency(); face.EnableVFAdjacency();
Read((void*)&face.AV[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size(),f); Read((void*)&face.AV[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size() );
} }
// face WedgeColor // face WedgeColor
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_WEDGECOLOR_OCF")) { if( s == std::string("HAS_FACE_WEDGECOLOR_OCF")) {
face.EnableWedgeColor(); face.EnableWedgeColor();
Read((void*)&face.WCV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeColorTypePack),face.size(),f); Read((void*)&face.WCV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeColorTypePack),face.size() );
} }
// face WedgeNormal // face WedgeNormal
ReadString(f,s); ReadString( s);
if( s == std::string("HAS_FACE_WEDGENORMAL_OCF")) { if( s == std::string("HAS_FACE_WEDGENORMAL_OCF")) {
face.EnableWedgeNormal(); face.EnableWedgeNormal();
Read((void*)&face.WNV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeNormalTypePack),face.size(),f); Read((void*)&face.WNV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeNormalTypePack),face.size() );
} }
} }
}; };
@ -585,28 +585,28 @@ namespace io {
std::string name; std::string name;
unsigned int nameFsize,nameVsize,i; unsigned int nameFsize,nameVsize,i;
ReadString(F(),name); ReadInt(F(),nameFsize); ReadString( name); ReadInt( nameFsize);
for(i=0; i < nameFsize; ++i) for(i=0; i < nameFsize; ++i)
{ReadString(F(), name);fnameF.push_back( name );mask |= FaceMaskBitFromString(name);} {ReadString( name);fnameF.push_back( name );mask |= FaceMaskBitFromString(name);}
mask |= LoadFaceOcfMask(F()); mask |= LoadFaceOcfMask();
ReadString(F(),name); ReadInt(F() , faceSize); ReadString( name); ReadInt( faceSize);
ReadString(F(), name); ReadInt(F(),nameVsize); ReadString( name); ReadInt( nameVsize);
for(i=0; i < nameVsize; ++i) for(i=0; i < nameVsize; ++i)
{ReadString(F(), name) ;fnameV.push_back( name);mask |= VertexMaskBitFromString(name);} {ReadString( name) ;fnameV.push_back( name);mask |= VertexMaskBitFromString(name);}
mask |= LoadVertexOcfMask(F()); mask |= LoadVertexOcfMask();
ReadString(F(),name); ReadString( name);
ReadInt(F(),vertSize); ReadInt( vertSize);
ReadString(F(),name); ReadString( name);
float float_value; float float_value;
for(unsigned int i =0; i < 2; ++i){ReadFloat(F(),float_value); bbox.min[i]=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(F(),float_value); bbox.max[i]=float_value;} for(unsigned int i =0; i < 2; ++i){ReadFloat( float_value); bbox.max[i]=float_value;}
ReadString(F(),name); ReadString( name);
assert(strstr( name.c_str(),"end_header")!=NULL); assert(strstr( name.c_str(),"end_header")!=NULL);
return true; return true;
} }
@ -625,14 +625,14 @@ namespace io {
static unsigned int & pos(){static unsigned int p = 0; return p;} static unsigned int & pos(){static unsigned int p = 0; return p;}
static int Read_sim(const void * , size_t size, size_t count, FILE * ){ pos() += size * count;return size * count; } static int Read_sim(const void * , size_t size, size_t count ){ pos() += size * count;return size * count; }
static int Read_mem( void *dst , size_t size, size_t count, FILE * ){ memcpy(dst,&In_mem()[pos()],size*count); pos() += size * count;return size * count; } static int Read_mem( void *dst , size_t size, size_t count ){ memcpy(dst,&In_mem()[pos()],size*count); pos() += size * count;return size * count; }
static int Read( void * dst, size_t size, size_t count, FILE *f){ static int Read( void * dst, size_t size, size_t count){
switch(In_mode()){ switch(In_mode()){
case 0: return Read_mem(dst, size,count, f ); break; case 0: return Read_mem(dst, size,count ); break;
case 1: return fread(dst, size,count, f ); break; case 1: return fread(dst, size,count, F() ); break;
} }
assert(0); assert(0);
return 0; return 0;
@ -644,7 +644,21 @@ namespace io {
std::vector<std::string> nameF; std::vector<std::string> nameF;
unsigned int vertSize, faceSize; unsigned int vertSize, faceSize;
vcg::Box3f bbox; vcg::Box3f bbox;
GetHeader(f,nameV,nameF,vertSize, faceSize, bbox, mask); 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<std::string> nameV;
std::vector<std::string> 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; return true;
} }
@ -690,19 +704,19 @@ namespace io {
if(vertSize!=0) if(vertSize!=0)
/* read the address of the first vertex */ /* read the address of the first vertex */
Read(&offsetV,sizeof( void *),1,F()); Read(&offsetV,sizeof( void *),1 );
if(faceSize!=0) if(faceSize!=0)
/* read the address of the first face */ /* read the address of the first face */
Read(&offsetF,sizeof( void *),1,F()); Read(&offsetF,sizeof( void *),1 );
/* read the object mesh */ /* read the object mesh */
Read(&m.shot,sizeof(Shot<typename OpenMeshType::ScalarType>),1,F()); Read(&m.shot,sizeof(Shot<typename OpenMeshType::ScalarType>),1 );
Read(&m.vn,sizeof(int),1,F()); Read(&m.vn,sizeof(int),1 );
Read(&m.fn,sizeof(int),1,F()); Read(&m.fn,sizeof(int),1 );
Read(&m.imark,sizeof(int),1,F()); Read(&m.imark,sizeof(int),1 );
Read(&m.bbox,sizeof(Box3<typename OpenMeshType::ScalarType>),1,F()); Read(&m.bbox,sizeof(Box3<typename OpenMeshType::ScalarType>),1 );
Read(&m.C(),sizeof(Color4b),1,F()); Read(&m.C(),sizeof(Color4b),1 );
/* resize the vector of vertices */ /* resize the vector of vertices */
@ -712,7 +726,7 @@ namespace io {
size_t read = 0; size_t read = 0;
/* load the vertices */ /* load the vertices */
if(vertSize>0){ if(vertSize>0){
read=Read((void*)& m.vert[0],sizeof(VertexType),vertSize,F()); read=Read((void*)& m.vert[0],sizeof(VertexType),vertSize );
LoadVertexOcf<OpenMeshType,VertContainer>(F(),m.vert); LoadVertexOcf<OpenMeshType,VertContainer>(F(),m.vert);
} }
@ -720,8 +734,8 @@ namespace io {
m.face.resize(faceSize); m.face.resize(faceSize);
if(faceSize>0){ if(faceSize>0){
/* load the faces */ /* load the faces */
read = Read((void*)& m.face[0],sizeof(FaceType),faceSize,F()); read = Read((void*)& m.face[0],sizeof(FaceType),faceSize );
LoadFaceOcf<OpenMeshType,FaceContainer>(F(),m.face); LoadFaceOcf<OpenMeshType,FaceContainer>(m.face);
} }
@ -729,36 +743,36 @@ namespace io {
std::string _string,_trash; std::string _string,_trash;
unsigned int n,sz; unsigned int n,sz;
ReadString(F(),_trash); ReadInt(F(),n); ReadString( _trash); ReadInt( n);
for(size_t ia = 0 ; ia < n; ++ia){ for(size_t ia = 0 ; ia < n; ++ia){
ReadString(F(),_trash); ReadString(F(),_string); ReadString(_trash); ReadString(_string);
ReadString(F(),_trash); ReadInt(F(),sz); ReadString(_trash); ReadInt(sz);
void * data = Malloc(sz*m.vert.size()); void * data = Malloc(sz*m.vert.size());
Read(data,sz,m.vert.size(),F()); Read(data,sz,m.vert.size());
AttrAll<OpenMeshType,A0,A1,A2,A3,A4>::template AddAttrib<0>(m,_string.c_str(),sz,data); AttrAll<OpenMeshType,A0,A1,A2,A3,A4>::template AddAttrib<0>(m,_string.c_str(),sz,data);
Free(data); Free(data);
} }
/* load the per face attributes */ /* load the per face attributes */
ReadString(F(),_trash); ReadInt(F(),n); ReadString(_trash); ReadInt( n);
for(size_t ia = 0 ; ia < n; ++ia){ for(size_t ia = 0 ; ia < n; ++ia){
ReadString(F(),_trash); ReadString(F(),_string); ReadString(_trash); ReadString( _string);
ReadString(F(),_trash); ReadInt(F(),sz); ReadString(_trash); ReadInt( sz);
void * data = Malloc(sz*m.face.size()); void * data = Malloc(sz*m.face.size());
Read(data,sz,m.face.size(),F()); Read(data,sz,m.face.size() );
AttrAll<OpenMeshType,A0,A1,A2,A3,A4>::template AddAttrib<1>(m,_string.c_str(),sz,data); AttrAll<OpenMeshType,A0,A1,A2,A3,A4>::template AddAttrib<1>(m,_string.c_str(),sz,data);
Free(data); Free(data);
} }
/* load the per mesh attributes */ /* load the per mesh attributes */
ReadString(F(),_trash); ReadInt(F(),n); ReadString( _trash); ReadInt( n);
for(unsigned int ia = 0 ; ia < n; ++ia){ for(unsigned int ia = 0 ; ia < n; ++ia){
ReadString(F(),_trash); ReadString(F(),_string); ReadString( _trash); ReadString( _string);
ReadString(F(),_trash); ReadInt(F(),sz); ReadString( _trash); ReadInt( sz);
void * data = Malloc(sz); void * data = Malloc(sz);
Read(data,1,sz,F()); Read(data,1,sz );
AttrAll<OpenMeshType,A0,A1,A2,A3,A4>::template AddAttrib<2>(m,_string.c_str(),sz,data); AttrAll<OpenMeshType,A0,A1,A2,A3,A4>::template AddAttrib<2>(m,_string.c_str(),sz,data);
Free(data); Free(data);
} }