#ifndef SIMPLEMESHPROVIDER_H #define SIMPLEMESHPROVIDER_H #include "../../meshlab/alnParser.h" #include #include #include #include #include /* * A mesh provider class has the simpler role of passing the set of meshes to be merged to the surface reconstrcution algorithm. * The only reason for this abstraction is that, plymc can work in a out-of-core way and the loading of the needed range maps can be optimized with a high level caching system. */ template class MinimalMeshProvider { private: std::vector< std::string > nameVec; std::vector< TriMeshType * > meshVec; std::vector trVec; std::vector weightVec; // weight tot be applied to each mesh. vcg::Box3f fullBBox; public: bool Find(const std::string &name, TriMeshType * &sm) { for(int i=0;i 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() {MeshCacheSize=6;} ~MeshCache() { typename std::list::iterator mi; for(mi=MV.begin();mi!=MV.end();++mi) delete (*mi).M; } /** * @brief Find load a mesh form the cache if it is in or from the disk otherwise * @param name what mesh to find * @param sm the pointer loaded mesh * @return true if the mesh was already in cache * */ bool Find(const 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).usedMeshCacheSize) { 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 MeshCacheSize; size_t size() const {return MV.size();} }; template class SimpleMeshProvider { private: std::vector< std::string > meshnames; std::vector TrV; std::vector WV; // weight tot be applied to each mesh. std::vector BBV; // bbox of the transformed meshes.. vcg::Box3f fullBBox; MeshCache MC; public: int size() {return meshnames.size();} int getCacheSize() {return MC.MeshCacheSize;} int setCacheSize(size_t newsize) { if(newsize == MC.MeshCacheSize) return MC.MeshCacheSize; if(newsize <= 0) return MC.MeshCacheSize; MC.MeshCacheSize = 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")) { ret=ply::ScanBBox(meshnames[i].c_str(),BBV[i],TrV[i],true,0); } else { printf("Trying to import a non-ply file %s\n",meshnames[i].c_str());fflush(stdout); TriMeshType m; ret = (tri::io::Importer::Open(m,meshnames[i].c_str()) == tri::io::Importer::E_NOERROR); tri::UpdatePosition::Matrix(m,TrV[i]); 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 tri::TriMesh< std::vector< SVertex>, std::vector< SFace > > {}; } #endif // SIMPLEMESHPROVIDER_H