00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef __VCGLIB_IMPORT_VMI
00036 #define __VCGLIB_IMPORT_VMI
00037
00038 #include <vcg/simplex/vertex/component_ocf.h>
00039 #include <vcg/simplex/face/component_ocf.h>
00040 #include <wrap/io_trimesh/io_mask.h>
00041 #include <wrap/callback.h>
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 namespace vcg {
00056 namespace tri {
00057 namespace io {
00058
00059 template <int N> struct DummyType{ char placeholder[N]; };
00060
00061
00062
00065 template <class MeshType, class A, class T>
00066 struct Der:public T{
00067 typedef typename std::set<typename MeshType::PointerToAttribute >::iterator HWIte;
00068
00069 template <int VoF>
00070 static void AddAttrib(MeshType &m, const char * name, unsigned int s, void * data){
00071 switch(VoF)
00072 {
00073 case 0: if(s == sizeof(A)){
00074 typename MeshType::template PerVertexAttributeHandle<A> h = vcg::tri::Allocator<MeshType>:: template AddPerVertexAttribute<A>(m,name);
00075 for(unsigned int i = 0; i < m.vert.size(); ++i)
00076 memcpy(&h[i], (void*) &((A*)data)[i],sizeof(A));
00077 }
00078 else
00079 T::template AddAttrib<0>(m,name,s,data);
00080 break;
00081 case 1: if(s == sizeof(A)){
00082 typename MeshType::template PerFaceAttributeHandle<A> h = vcg::tri::Allocator<MeshType>:: template AddPerFaceAttribute<A>(m,name);
00083 for(unsigned int i = 0; i < m.face.size(); ++i)
00084 memcpy(&h[i], (void*) &((A*)data)[i],sizeof(A));
00085 }
00086 else
00087 T::template AddAttrib<0>(m,name,s,data);
00088 break;
00089 case 2:
00090 if(s == sizeof(A)){
00091 typename MeshType::template PerMeshAttributeHandle<A> h = vcg::tri::Allocator<MeshType>:: template AddPerMeshAttribute<A>(m,name);
00092 memcpy(&h(), (void*) ((A*)data),sizeof(A));
00093 }
00094 else
00095 T::template AddAttrib<2>(m,name,s,data);
00096 break;
00097
00098 default:break;
00099 }
00100 }
00101 };
00102
00105 template <class MeshType, class A, class T>
00106 struct DerK:public T{
00107 typedef typename std::set<typename MeshType::PointerToAttribute >::iterator HWIte;
00108 template <int VoF>
00109 static void AddAttrib(MeshType &m, const char * name, unsigned int s, void * data){
00110 switch(VoF){
00111 case 0:
00112 if(s == sizeof(A)){
00113 typename MeshType::template PerVertexAttributeHandle<A> h = vcg::tri::Allocator<MeshType>::template AddPerVertexAttribute<A>(m,name);
00114 for(unsigned int i = 0; i < m.vert.size(); ++i)
00115 memcpy((void*) &(h[i]), (void*) &((A*)data)[i],sizeof(A));
00116 }
00117 else
00118 if(s < sizeof(A)){
00119
00120 int padd = sizeof(A) - s;
00121 typename MeshType::template PerVertexAttributeHandle<A> h = vcg::tri::Allocator<MeshType>::template AddPerVertexAttribute<A>(m,name);
00122 for(unsigned int i = 0; i < m.vert.size(); ++i){
00123 char * dest = &((char*)(&h[i]))[0];
00124 memcpy( (void *)dest , (void*) &((A*)data)[i],s);
00125 }
00126 typename MeshType::PointerToAttribute pa;
00127 pa._name = std::string(name);
00128 HWIte res = m.vert_attr.find(pa);
00129 pa = *res;
00130 m.vert_attr.erase(res);
00131 pa._padding = padd;
00132 std::pair<HWIte,bool > new_pa = m.vert_attr.insert(pa);
00133 assert(new_pa.second);
00134 }
00135 else
00136 T::template AddAttrib<0>(m,name,s,data);
00137 break;
00138 case 1:
00139 if(s == sizeof(A)){
00140 typename MeshType::template PerVertexAttributeHandle<A> h = vcg::tri::Allocator<MeshType>::template AddPerVertexAttribute<A>(m,name);
00141 for(unsigned int i = 0; i < m.vert.size(); ++i)
00142 memcpy((void*) &(h[i]), (void*) &((A*)data)[i],sizeof(A));
00143 }
00144 else
00145 if(s < sizeof(A)){
00146
00147 int padd = sizeof(A) - s;
00148 typename MeshType::template PerFaceAttributeHandle<A> h = vcg::tri::Allocator<MeshType>::template AddPerFaceAttribute<A>(m,name);
00149 for(unsigned int i = 0; i < m.face.size(); ++i){
00150 char * dest = &((char*)(&h[i]))[0];
00151 memcpy( (void *)dest , (void*) &((A*)data)[i],s);
00152 }
00153 typename MeshType::PointerToAttribute pa;
00154 pa._name = std::string(name);
00155 HWIte res = m.face_attr.find(pa);
00156 pa = *res;
00157 m.face_attr.erase(res);
00158 pa._padding = padd;
00159 std::pair<HWIte,bool > new_pa = m.face_attr.insert(pa);
00160 assert(new_pa.second);
00161 }
00162 else
00163 T::template AddAttrib<1>(m,name,s,data);
00164 break;
00165 case 2:
00166 if(s == sizeof(A)){
00167 typename MeshType::template PerMeshAttributeHandle<A> h = vcg::tri::Allocator<MeshType>::template AddPerMeshAttribute<A>(m,name);
00168 memcpy((void*)&h(), (void*)((A*)data),sizeof(A));
00169 }
00170 else
00171 if(s < sizeof(A)){
00172
00173 int padd = sizeof(A) - s;
00174 typename MeshType::template PerMeshAttributeHandle<A> h = vcg::tri::Allocator<MeshType>::template AddPerMeshAttribute<A>(m,name);
00175 char * dest = & ((char*)(&h()))[0];
00176 memcpy( (void *)dest , (void*)((A*)data),s);
00177
00178 typename MeshType::PointerToAttribute pa;
00179 pa._name = std::string(name);
00180 HWIte res = m.mesh_attr.find(pa);
00181 pa = *res;
00182 m.mesh_attr.erase(res);
00183 pa._padding = padd;
00184 std::pair<HWIte,bool > new_pa = m.mesh_attr.insert(pa);
00185 assert(new_pa.second);
00186 }
00187 else
00188 T::template AddAttrib<2>(m,name,s,data);
00189 break;
00190 default: assert(0);break;
00191 }
00192 }
00193 };
00194
00198 template <class MeshType> struct K {
00199 template <int VoF>
00200 static void AddAttrib(MeshType &, const char * , unsigned int , void * ){
00201
00202 assert(0);
00203 }
00204 };
00205
00206 template <class MeshType, class B0 > struct K0 : public DerK< MeshType, B0, K<MeshType> > {};
00207 template <class MeshType, class B0, class B1 > struct K1 : public DerK< MeshType, B1, K0<MeshType, B0> > {};
00208 template <class MeshType, class B0, class B1, class B2 > struct K2 : public DerK< MeshType, B2, K1<MeshType, B0, B1> > {};
00209 template <class MeshType, class B0, class B1, class B2,class B3> struct K3 : public DerK< MeshType, B3, K2<MeshType, B0, B1, B2> > {};
00210 template <class MeshType, class B0, class B1, class B2,class B3,class B4> struct K4 : public DerK< MeshType, B4, K3<MeshType, B0, B1, B2, B3> > {};
00211 template <class MeshType, class B0, class B1, class B2,class B3,class B4,class B5> struct K5 : public DerK< MeshType, B5, K4<MeshType, B0, B1, B2, B3, B4> > {};
00212 template <class MeshType, class B0, class B1, class B2,class B3,class B4,class B5,class B6> struct K6 : public DerK< MeshType, B6, K5<MeshType, B0, B1, B2, B3, B4, B5> > {};
00213 template <class MeshType, class B0, class B1, class B2,class B3,class B4,class B5,class B6,class B7> struct K7 : public DerK< MeshType, B7, K6<MeshType, B0, B1, B2, B3, B4, B5, B6> > {};
00214 template <class MeshType, class B0, class B1, class B2,class B3,class B4,class B5,class B6,class B7,class B8> struct K8 : public DerK< MeshType, B8, K7<MeshType, B0, B1, B2, B3, B4, B5, B6, B7> > {};
00215 template <class MeshType, class B0, class B1, class B2,class B3,class B4,class B5,class B6,class B7,class B8,class B9> struct K9 : public DerK< MeshType, B9, K8<MeshType, B0, B1, B2, B3, B4, B5, B6, B7, B8> > {};
00216 template <class MeshType, class B0, class B1, class B2,class B3,class B4,class B5,class B6,class B7,class B8,class B9,class B10> struct K10 : public DerK< MeshType, B10, K9<MeshType, B0, B1, B2, B3, B4, B5, B6, B7, B8, B9> > {};
00217 template <class MeshType, class B0, class B1, class B2,class B3,class B4,class B5,class B6,class B7,class B8,class B9,class B10,class B11> struct K11 : public DerK< MeshType, B11, K10<MeshType, B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B11 > > {};
00218 template <class MeshType, class B0, class B1, class B2,class B3,class B4,class B5,class B6,class B7,class B8,class B9,class B10,class B11,class B12>struct K12 : public DerK< MeshType, B12, K11<MeshType, B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B11, B12 > > {};
00219
00220 template <class MeshType, class A0,
00221 class B0 = DummyType<1048576>,
00222 class B1 = DummyType<2048>,
00223 class B2 = DummyType<1024>,
00224 class B3 = DummyType<512>,
00225 class B4 = DummyType<256>,
00226 class B5 = DummyType<128>,
00227 class B6 = DummyType<64>,
00228 class B7 = DummyType<32>,
00229 class B8 = DummyType<16>,
00230 class B9 = DummyType<8>,
00231 class B10 = DummyType<4>,
00232 class B11 = DummyType<2>,
00233 class B12 = DummyType<1>
00234 > struct C0 : public DerK< MeshType, A0, K12<MeshType, B0, B1, B2, B3, B4,B5,B6,B7,B8,B9,B10,B11,B12> > {};
00235
00236 template <class MeshType, class A0, class A1> struct C1 : public Der< MeshType, A1, C0<MeshType, A0> > {};
00237 template <class MeshType, class A0, class A1, class A2> struct C2 : public Der< MeshType, A2, C1<MeshType, A0, A1> > {};
00238 template <class MeshType, class A0, class A1, class A2,class A3> struct C3 : public Der< MeshType, A3, C2<MeshType, A0, A1, A2> > {};
00239 template <class MeshType, class A0, class A1, class A2,class A3,class A4> struct AttrAll : public Der< MeshType, A4, C3<MeshType, A0, A1, A2, A3> > {};
00240
00241
00242
00243 template <class OpenMeshType,class A0 = long, class A1 = double, class A2 = int,class A3 = short, class A4 = char >
00244 class ImporterVMI: public AttrAll<OpenMeshType,A0,A1,A2,A3,A4>
00245 {
00246
00247 static void ReadString(FILE * f,std::string & out){
00248 unsigned int l; fread(&l,4,1,f);
00249 char * buf = new char[l+1];
00250 fread(buf,1,l,f);buf[l]='\0';
00251 out = std::string(buf);
00252 delete [] buf;
00253 }
00254
00255 static void ReadInt(FILE *f, unsigned int & i){ fread(&i,1,4,f);}
00256 static void ReadFloat(FILE *f, float & v){ fread(&v,1,sizeof(float),f);}
00257
00258
00259 static int LoadVertexOcfMask( FILE * f){
00260 int mask =0;
00261 std::string s;
00262
00263
00264 ReadString(f,s);
00265 if( s == std::string("HAS_VERTEX_QUALITY_OCF")) mask |= Mask::IOM_VERTQUALITY;
00266
00267
00268 ReadString(f,s);
00269 if( s == std::string("HAS_VERTEX_COLOR_OCF")) mask |= Mask::IOM_VERTCOLOR;
00270
00271
00272 ReadString(f,s);
00273 if( s == std::string("HAS_VERTEX_NORMAL_OCF")) mask |= Mask::IOM_VERTNORMAL;
00274
00275
00276 ReadString(f,s);
00277
00278
00279
00280 ReadString(f,s);
00281 if( s == std::string("HAS_VERTEX_TEXCOORD_OCF")) mask |= Mask::IOM_VERTTEXCOORD;
00282
00283
00284 ReadString(f,s);
00285
00286
00287
00288 ReadString(f,s);
00289
00290
00292 ReadString(f,s);
00293
00294
00295
00296 ReadString(f,s);
00297 if( s == std::string("HAS_VERTEX_RADIUS_OCF")) mask |= Mask::IOM_VERTRADIUS;
00298
00299 return mask;
00300 }
00301
00302 template <typename MeshType, typename CONT>
00303 struct LoadVertexOcf{
00304 LoadVertexOcf(FILE* ,const CONT & ){
00305
00306 }
00307 };
00308
00309
00310
00311 template <typename MeshType>
00312 struct
00313 LoadVertexOcf<MeshType,vertex::vector_ocf<typename OpenMeshType::VertexType> >{
00314 typedef typename OpenMeshType::VertexType VertexType;
00315 LoadVertexOcf( FILE * f, vertex::vector_ocf<typename OpenMeshType::VertexType> & vert){
00316 std::string s;
00317
00318
00319 ReadString(f,s);
00320 if( s == std::string("HAS_VERTEX_QUALITY_OCF")) {
00321 vert.EnableQuality();
00322 fread((void*)&vert.QV[0],sizeof(typename VertexType::QualityType),vert.size(),f);
00323 }
00324
00325
00326 ReadString(f,s);
00327 if( s == std::string("HAS_VERTEX_COLOR_OCF")) {
00328 vert.EnableColor();
00329 fread((void*)&vert.CV[0],sizeof(typename VertexType::ColorType),vert.size(),f);
00330 }
00331
00332
00333 ReadString(f,s);
00334 if( s == std::string("HAS_VERTEX_NORMAL_OCF")) {
00335 vert.EnableNormal();
00336 fread((void*)&vert.NV[0],sizeof(typename VertexType::NormalType),vert.size(),f);
00337 }
00338
00339
00340 ReadString(f,s);
00341 if( s == std::string("HAS_VERTEX_MARK_OCF")) {
00342 vert.EnableMark();
00343 fread((void*)&vert.MV[0],sizeof(typename VertexType::MarkType),vert.size(),f);
00344 }
00345
00346
00347 ReadString(f,s);
00348 if( s == std::string("HAS_VERTEX_TEXCOORD_OCF")) {
00349 vert.EnableTexCoord();
00350 fread((void*)&vert.TV[0],sizeof(typename VertexType::TexCoordType),vert.size(),f);
00351 }
00352
00353
00354 ReadString(f,s);
00355 if( s == std::string("HAS_VERTEX_VFADJACENCY_OCF")) {
00356 vert.EnableVFAdjacency();
00357 fread((void*)&vert.AV[0],sizeof(typename vertex::vector_ocf<VertexType>::VFAdjType),vert.size(),f);
00358 }
00359
00360
00361 ReadString(f,s);
00362 if( s == std::string("HAS_VERTEX_CURVATURE_OCF")) {
00363 vert.EnableCurvature();
00364 fread((void*)&vert.CuV[0],sizeof(typename VertexType::CurvatureType),vert.size(),f);
00365 }
00366
00367
00368 ReadString(f,s);
00369 if( s == std::string("HAS_VERTEX_CURVATUREDIR_OCF")) {
00370 vert.EnableCurvatureDir();
00371 fread((void*)&vert.CuDV[0],sizeof(typename VertexType::CurvatureDirType),vert.size(),f);
00372 }
00373
00374
00375 ReadString(f,s);
00376 if( s == std::string("HAS_VERTEX_RADIUS_OCF")) {
00377 vert.EnableRadius();
00378 fread((void*)&vert.RadiusV[0],sizeof(typename VertexType::RadiusType),vert.size(),f);
00379 }
00380
00381 }
00382 };
00383
00384 template <typename MeshType, typename CONT>
00385 struct LoadFaceOcf{
00386 LoadFaceOcf(FILE * , const CONT & ){
00387
00388 }
00389 };
00390
00391
00392 static int LoadFaceOcfMask( FILE * f){
00393 int mask=0;
00394 std::string s;
00395
00396
00397 ReadString(f,s);
00398 if( s == std::string("HAS_FACE_QUALITY_OCF")) mask |= Mask::IOM_FACEQUALITY;
00399
00400
00401 ReadString(f,s);
00402 if( s == std::string("HAS_FACE_COLOR_OCF")) mask |= Mask::IOM_FACECOLOR;
00403
00404
00405 ReadString(f,s);
00406 if( s == std::string("HAS_FACE_NORMAL_OCF")) mask |= Mask::IOM_FACENORMAL;
00407
00409 ReadString(f,s);
00410
00411
00412
00413 ReadString(f,s);
00414 if( s == std::string("HAS_FACE_WEDGETEXCOORD_OCF")) mask |= Mask::IOM_WEDGTEXCOORD;
00415
00416
00417
00418 ReadString(f,s);
00419
00420
00421
00422 ReadString(f,s);
00423
00424
00425
00426 ReadString(f,s);
00427 if( s == std::string("HAS_FACE_WEDGECOLOR_OCF")) mask |= Mask::IOM_WEDGCOLOR;
00428
00429
00430 ReadString(f,s);
00431 if( s == std::string("HAS_FACE_WEDGENORMAL_OCF")) mask |= Mask::IOM_WEDGNORMAL;
00432 return mask;
00433 }
00434
00435
00436
00437 template <typename MeshType>
00438 struct LoadFaceOcf< MeshType, face::vector_ocf<typename OpenMeshType::FaceType> >{
00439 typedef typename OpenMeshType::FaceType FaceType;
00440 LoadFaceOcf( FILE * f, face::vector_ocf<FaceType> & face){
00441 std::string s;
00442
00443
00444 ReadString(f,s);
00445 if( s == std::string("HAS_FACE_QUALITY_OCF")) {
00446 face.EnableQuality();
00447 fread((void*)&face.QV[0],sizeof(typename FaceType::QualityType),face.size(),f);
00448 }
00449
00450
00451 ReadString(f,s);
00452 if( s == std::string("HAS_FACE_COLOR_OCF")) {
00453 face.EnableColor();
00454 fread((void*)&face.CV[0],sizeof(typename FaceType::ColorType),face.size(),f);
00455 }
00456
00457
00458 ReadString(f,s);
00459 if( s == std::string("HAS_FACE_NORMAL_OCF")) {
00460 face.EnableNormal();
00461 fread((void*)&face.NV[0],sizeof(typename FaceType::NormalType),face.size(),f);
00462 }
00463
00464
00465 ReadString(f,s);
00466 if( s == std::string("HAS_FACE_MARK_OCF")) {
00467 face.EnableMark();
00468 fread((void*)&face.MV[0],sizeof(typename FaceType::MarkType),face.size(),f);
00469 }
00470
00471
00472 ReadString(f,s);
00473 if( s == std::string("HAS_FACE_WEDGETEXCOORD_OCF")) {
00474 face.EnableWedgeTex();
00475 fread((void*)&face.WTV[0],sizeof(typename FaceType::WedgeTexCoordType),face.size(),f);
00476 }
00477
00478
00479
00480 ReadString(f,s);
00481 if( s == std::string("HAS_FACE_FFADJACENCY_OCF")) {
00482 face.EnableFFAdjacency();
00483 fread((void*)&face.AF[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size(),f);
00484 }
00485
00486
00487 ReadString(f,s);
00488 if( s == std::string("HAS_FACE_VFADJACENCY_OCF")) {
00489 face.EnableVFAdjacency();
00490 fread((void*)&face.AV[0],sizeof(typename face::vector_ocf<FaceType>::AdjTypePack),face.size(),f);
00491 }
00492
00493
00494 ReadString(f,s);
00495 if( s == std::string("HAS_FACE_WEDGECOLOR_OCF")) {
00496 face.EnableWedgeColor();
00497 fread((void*)&face.WCV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeColorTypePack),face.size(),f);
00498 }
00499
00500
00501 ReadString(f,s);
00502 if( s == std::string("HAS_FACE_WEDGENORMAL_OCF")) {
00503 face.EnableWedgeNormal();
00504 fread((void*)&face.WNV[0],sizeof(typename face::vector_ocf<FaceType>::WedgeNormalTypePack),face.size(),f);
00505 }
00506 }
00507 };
00508
00509 static int FaceMaskBitFromString(std::string s){
00510 if( s.find("Color",0) != std::string::npos ) return Mask::IOM_FACECOLOR; else
00511 if( s.find("BitFlags",0) != std::string::npos ) return Mask::IOM_FACEFLAGS; else
00512 if( s.find("VertexRef",0) != std::string::npos ) return Mask::IOM_FACEINDEX; else
00513 if( s.find("Normal",0) != std::string::npos ) return Mask::IOM_FACENORMAL; else
00514 if( s.find("Quality",0) != std::string::npos ) return Mask::IOM_FACEQUALITY; else
00515 if( s.find("Quality",0) != std::string::npos ) return Mask::IOM_FACEQUALITY; else
00516 if( s.find("WedgeColor",0) != std::string::npos ) return Mask::IOM_WEDGCOLOR; else
00517 if( s.find("WedgeNormal",0) != std::string::npos ) return Mask::IOM_WEDGNORMAL; else
00518 if( s.find("WedgeTexCoord",0) != std::string::npos) return Mask::IOM_WEDGTEXCOORD; else
00519 return 0;
00520 }
00521 static int VertexMaskBitFromString(std::string s){
00522 if( s.find("Color",0) != std::string::npos ) return Mask::IOM_VERTCOLOR; else
00523 if( s.find("Coord",0) != std::string::npos ) return Mask::IOM_VERTCOORD; else
00524 if( s.find("BitFlags",0) != std::string::npos ) return Mask::IOM_VERTFLAGS; else
00525 if( s.find("Quality",0) != std::string::npos ) return Mask::IOM_VERTQUALITY; else
00526 if( s.find("Normal",0) != std::string::npos ) return Mask::IOM_VERTNORMAL; else
00527 if( s.find("TexCoord",0) != std::string::npos ) return Mask::IOM_VERTTEXCOORD; else
00528 if( s.find("Radius",0) != std::string::npos ) return Mask::IOM_VERTRADIUS; else
00529 return 0;
00530 }
00531
00532
00533 static FILE *& F(){static FILE * f; return f;}
00534
00535
00536 static void * Malloc(unsigned int n){ return (n)?malloc(n):0;}
00537 static void Free(void * ptr){ if(ptr) free (ptr);}
00538
00539
00540 typedef typename OpenMeshType::FaceType FaceType;
00541 typedef typename OpenMeshType::FaceContainer FaceContainer;
00542 typedef typename OpenMeshType::FaceIterator FaceIterator;
00543
00544 typedef typename OpenMeshType::VertContainer VertContainer;
00545 typedef typename OpenMeshType::VertexIterator VertexIterator;
00546 typedef typename OpenMeshType::VertexType VertexType;
00547
00548 public:
00549 enum VMIErrorCodes {
00550 VMI_NO_ERROR = 0,
00551 VMI_INCOMPATIBLE_VERTEX_TYPE,
00552 VMI_INCOMPATIBLE_FACE_TYPE,
00553 VMI_FAILED_OPEN
00554 };
00555
00561 static const char* ErrorMsg(int message_code)
00562 {
00563 static const char* error_msg[] =
00564 {
00565 "No errors",
00566 "The file has a incompatible vertex signature",
00567 "The file has a incompatible Face signature",
00568 "General failure of the file opening"
00569 };
00570
00571 if(message_code>4 || message_code<0)
00572 return "Unknown error";
00573 else
00574 return error_msg[message_code];
00575 };
00576
00577
00578
00579
00580
00581 static bool GetHeader( std::vector<std::string>& fnameV,
00582 std::vector<std::string>& fnameF,
00583 unsigned int & vertSize,
00584 unsigned int &faceSize,
00585 vcg::Box3f & bbox,
00586 int & mask){
00587 std::string name;
00588 unsigned int nameFsize,nameVsize,i;
00589
00590 ReadString(F(),name); ReadInt(F(),nameFsize);
00591
00592 for(i=0; i < nameFsize; ++i)
00593 {ReadString(F(), name);fnameF.push_back( name );mask |= FaceMaskBitFromString(name);}
00594 mask |= LoadFaceOcfMask(F());
00595
00596 ReadString(F(),name); ReadInt(F() , faceSize);
00597 ReadString(F(), name); ReadInt(F(),nameVsize);
00598
00599 for(i=0; i < nameVsize; ++i)
00600 {ReadString(F(), name) ;fnameV.push_back( name);mask |= VertexMaskBitFromString(name);}
00601 mask |= LoadVertexOcfMask(F());
00602
00603 ReadString(F(),name); ReadInt(F(),vertSize);
00604
00605 ReadString(F(),name);
00606 float float_value;
00607 for(unsigned int i =0; i < 2; ++i){ReadFloat(F(),float_value); bbox.min[i]=float_value;}
00608 for(unsigned int i =0; i < 2; ++i){ReadFloat(F(),float_value); bbox.max[i]=float_value;}
00609
00610 ReadString(F(),name);
00611 assert(strstr( name.c_str(),"end_header")!=NULL);
00612 return true;
00613 }
00614
00615
00616 static bool GetHeader(const char * filename,std::vector<std::string>& nameV, std::vector<std::string>& nameF, unsigned int & vertSize, unsigned int &faceSize,vcg::Box3f & bbox,int & mask){
00617 F() = fopen(filename,"rb");
00618 return GetHeader(nameV, nameF, vertSize, faceSize,bbox,mask);
00619 fclose(F());
00620 }
00621
00622 public:
00623 static bool LoadMask(const char * f, int & mask){
00624 std::vector<std::string> nameV;
00625 std::vector<std::string> nameF;
00626 unsigned int vertSize, faceSize;
00627 vcg::Box3f bbox;
00628 GetHeader(f,nameV,nameF,vertSize, faceSize, bbox, mask);
00629 return true;
00630 }
00631
00632 static int Open(OpenMeshType &m, const char * filename, int & mask,CallBackPos * = 0 ){
00633
00634 typedef typename OpenMeshType::VertexType VertexType;
00635 typedef typename OpenMeshType::FaceType FaceType;
00636 typename OpenMeshType::FaceIterator fi;
00637 typename OpenMeshType::VertexIterator vi;
00638 F() = fopen(filename,"rb");
00639 if(!F()) return VMI_FAILED_OPEN;
00640 std::vector<std::string> nameF,nameV,fnameF,fnameV;
00641 unsigned int vertSize,faceSize;
00642
00643
00644 vcg::Box3f lbbox;
00645 GetHeader(fnameV, fnameF, vertSize, faceSize,lbbox,mask);
00646 m.bbox.Import(lbbox);
00647
00648 OpenMeshType::FaceType::Name(nameF);
00649 OpenMeshType::VertexType::Name(nameV);
00650
00651
00652 if(fnameV != nameV) return VMI_INCOMPATIBLE_VERTEX_TYPE;
00653 if(fnameF != nameF) return VMI_INCOMPATIBLE_FACE_TYPE;
00654
00655 int offsetV=0,offsetF=0;
00656
00657 if(vertSize!=0)
00658
00659 fread(&offsetV,sizeof( int),1,F());
00660
00661 if(faceSize!=0)
00662
00663 fread(&offsetF,sizeof( int),1,F());
00664
00665
00666 fread(&m.shot,sizeof(Shot<typename OpenMeshType::ScalarType>),1,F());
00667 fread(&m.vn,sizeof(int),1,F());
00668 fread(&m.fn,sizeof(int),1,F());
00669 fread(&m.imark,sizeof(int),1,F());
00670 fread(&m.bbox,sizeof(Box3<typename OpenMeshType::ScalarType>),1,F());
00671 fread(&m.C(),sizeof(Color4b),1,F());
00672
00673
00674
00675 m.vert.resize(vertSize);
00676
00677
00678 size_t read = 0;
00679
00680 if(vertSize>0){
00681 read=fread((void*)& m.vert[0],sizeof(VertexType),vertSize,F());
00682 assert(ferror(F())==0);
00683 assert(read==vertSize);
00684 LoadVertexOcf<OpenMeshType,VertContainer>(F(),m.vert);
00685 }
00686
00687 read = 0;
00688 m.face.resize(faceSize);
00689 if(faceSize>0){
00690
00691 read = fread((void*)& m.face[0],sizeof(FaceType),faceSize,F());
00692 assert(ferror(F())==0);
00693 assert(!feof(F()));
00694 assert(read==faceSize);
00695 LoadFaceOcf<OpenMeshType,FaceContainer>(F(),m.face);
00696 }
00697
00698
00699
00700 std::string _string,_trash;
00701 unsigned int n,sz;
00702
00703 ReadString(F(),_trash); ReadInt(F(),n);
00704
00705 for(size_t ia = 0 ; ia < n; ++ia){
00706 ReadString(F(),_trash); ReadString(F(),_string);
00707 ReadString(F(),_trash); ReadInt(F(),sz);
00708
00709 void * data = Malloc(sz*m.vert.size());
00710 fread(data,sz,m.vert.size(),F());
00711 AttrAll<OpenMeshType,A0,A1,A2,A3,A4>::template AddAttrib<0>(m,_string.c_str(),sz,data);
00712 Free(data);
00713 }
00714
00715
00716 ReadString(F(),_trash); ReadInt(F(),n);
00717 for(size_t ia = 0 ; ia < n; ++ia){
00718 ReadString(F(),_trash); ReadString(F(),_string);
00719 ReadString(F(),_trash); ReadInt(F(),sz);
00720 void * data = Malloc(sz*m.face.size());
00721 fread(data,sz,m.face.size(),F());
00722 AttrAll<OpenMeshType,A0,A1,A2,A3,A4>::template AddAttrib<1>(m,_string.c_str(),sz,data);
00723 Free(data);
00724 }
00725
00726
00727 ReadString(F(),_trash); ReadInt(F(),n);
00728 for(unsigned int ia = 0 ; ia < n; ++ia){
00729 ReadString(F(),_trash); ReadString(F(),_string);
00730 ReadString(F(),_trash); ReadInt(F(),sz);
00731 void * data = Malloc(sz);
00732 fread(data,1,sz,F());
00733 AttrAll<OpenMeshType,A0,A1,A2,A3,A4>::template AddAttrib<2>(m,_string.c_str(),sz,data);
00734 Free(data);
00735 }
00736
00737 if(FaceType::HasVFAdjacency())
00738 for(vi = m.vert.begin(); vi != m.vert.end(); ++vi){
00739 (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0];
00740 (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0];
00741 (*vi).VFp() = (*vi).VFp()-(FaceType*)offsetF+ &m.face[0];
00742 }
00743
00744 if(FaceType::HasVertexRef())
00745 for(fi = m.face.begin(); fi != m.face.end(); ++fi){
00746 (*fi).V(0) = (*fi).V(0)-(VertexType*)offsetV+ &m.vert[0];
00747 (*fi).V(1) = (*fi).V(1)-(VertexType*)offsetV+ &m.vert[0];
00748 (*fi).V(2) = (*fi).V(2)-(VertexType*)offsetV+ &m.vert[0];
00749 }
00750
00751 if(FaceType::HasFFAdjacency())
00752 for(fi = m.face.begin(); fi != m.face.end(); ++fi){
00753 (*fi).FFp(0) = (*fi).FFp(0)-(FaceType*)offsetF+ &m.face[0];
00754 (*fi).FFp(1) = (*fi).FFp(1)-(FaceType*)offsetF+ &m.face[0];
00755 (*fi).FFp(2) = (*fi).FFp(2)-(FaceType*)offsetF+ &m.face[0];
00756 }
00757
00758 if(FaceType::HasVFAdjacency())
00759 for(fi = m.face.begin(); fi != m.face.end(); ++fi){
00760 (*fi).VFp(0) = (*fi).VFp(0)-(FaceType*)offsetF+ &m.face[0];
00761 (*fi).VFp(1) = (*fi).VFp(1)-(FaceType*)offsetF+ &m.face[0];
00762 (*fi).VFp(2) = (*fi).VFp(2)-(FaceType*)offsetF+ &m.face[0];
00763 }
00764
00765 fclose(F());
00766 return VMI_NO_ERROR;
00767 }
00768
00769 };
00770
00771
00772 }
00773 }
00774 }
00775
00776 #endif