#ifndef SIMPLEMESHPROVIDER_H #define SIMPLEMESHPROVIDER_H #include #include #include #include #include using namespace std; using namespace vcg; template class MeshCache { class Pair { public: Pair(){used=0;} TriMeshType *M; std::string Name; int used; // 'data' dell'ultimo accesso. si butta fuori quello lru }; std::list MV; public: void clear(); MeshCache() {MaxSize=6;} ~MeshCache() { typename std::list::iterator mi; for(mi=MV.begin();mi!=MV.end();++mi) delete (*mi).M; } // Restituisce true se la mesh e' in cache; // restituisce in ogni caso il puntatore dove sta (o dovrebbe stare) la mesh // Gestione LRU bool Find(std::string &name, TriMeshType * &sm) { typename std::list::iterator mi; typename std::list::iterator oldest; // quello che e' piu' tempo che non viene acceduto. int last; last = std::numeric_limits::max(); oldest = MV.begin(); for(mi=MV.begin();mi!=MV.end();++mi) { if((*mi).usedMaxSize) { sm=(*oldest).M; (*oldest).used=0; (*oldest).Name=name; } else { MV.push_back(Pair()); MV.back().Name=name; MV.back().M=new TriMeshType(); sm=MV.back().M; } return false; } size_t MaxSize; size_t size() const {return MV.size();} }; template class SimpleMeshProvider { std::vector< std::string > meshnames; std::vector TrV; std::vector WV; // vettore con i pesi da applicare alla mesh. std::vector BBV; // vettore con i bbox trasformati delle mesh da scannare. vcg::Box3f fullBBox; MeshCache MC; public: int size() {return meshnames.size();} int getCacheSize() {return MC.MaxSize;} int setCacheSize(size_t newsize) { if(newsize == MC.MaxSize) return MC.MaxSize; if(newsize <= 0) return MC.MaxSize; MC.MaxSize = newsize; return newsize; } bool openALN (const char* alnName) { // vector rmaps; // ALNParser::ParseALN(rmaps, alnName); // for(size_t i=0; i::FileExtension(meshnames[i],"PLY") || tri::io::Importer::FileExtension(meshnames[i],"ply")) { if(!(TrV[i]==Id)) ret=ply::ScanBBox(meshnames[i].c_str(),BBV[i],mt,true,0); else ret=vcg::ply::ScanBBox(meshnames[i].c_str(),BBV[i]); } else { printf("Trying to import a non-ply file %s\n",meshnames[i].c_str());fflush(stdout); TriMeshType m; int retVal=tri::io::Importer::Open(m,meshnames[i].c_str()); ret = (retVal==0); tri::UpdateBounding::Box(m); BBV[i].Import(m.bbox); } if( ! ret) { printf("\n\nwarning:\n file '%s' not found\n",meshnames[i].c_str());fflush(stdout); continue; } fullBBox.Add(BBV[i]); } return true; } }; class SVertex; class SFace; class SUsedTypes: public vcg::UsedTypes < vcg::Use::AsVertexType, vcg::Use::AsFaceType >{}; class SVertex : public Vertex< SUsedTypes, vertex::Coord3f, vertex::Normal3f,vertex::VFAdj, vertex::BitFlags, vertex::Color4b, vertex::Qualityf>{}; class SFace : public Face< SUsedTypes, face::VertexRef, face::Normal3f,face::Qualityf, face::VFAdj, face::BitFlags> {}; class SMesh : public vcg::tri::TriMesh< std::vector< SVertex>, std::vector< SFace > > {}; #endif // SIMPLEMESHPROVIDER_H