diff --git a/src/meshlabplugins/filter_plymc/filter_plymc.cpp b/src/meshlabplugins/filter_plymc/filter_plymc.cpp index 43535b7b9..a9abaefbb 100644 --- a/src/meshlabplugins/filter_plymc/filter_plymc.cpp +++ b/src/meshlabplugins/filter_plymc/filter_plymc.cpp @@ -22,11 +22,10 @@ ****************************************************************************/ #include "filter_plymc.h" -#include #include #include #include -#include "simplemeshprovider.h" +#include using namespace vcg; @@ -123,6 +122,7 @@ bool PlyMCPlugin::applyFilter(QAction *filter, MeshDocument &md, RichParameterSe srand(time(NULL)); tri::PlyMC > pmc; + pmc.MP.setCacheSize(64); tri::PlyMC >::Parameter &p = pmc.p; int subdiv=par.getInt("subdiv"); @@ -169,7 +169,12 @@ bool PlyMCPlugin::applyFilter(QAction *filter, MeshDocument &md, RichParameterSe } } - pmc.Process(cb); + if(pmc.Process(cb)==false) + { + this->errorMessage = pmc.errorMessage; + return false; + } + if(par.getBool("openResult")) { diff --git a/src/meshlabplugins/filter_plymc/filter_plymc.pro b/src/meshlabplugins/filter_plymc/filter_plymc.pro index 77e6872bd..b4f5f2f6a 100644 --- a/src/meshlabplugins/filter_plymc/filter_plymc.pro +++ b/src/meshlabplugins/filter_plymc/filter_plymc.pro @@ -1,9 +1,6 @@ include (../../shared.pri) -HEADERS += filter_plymc.h \ - simplemeshprovider.h \ - $$VCGDIR/vcg/complex/algorithms/local_optimization/tri_edge_collapse.h - +HEADERS += filter_plymc.h SOURCES += filter_plymc.cpp \ $$VCGDIR/wrap/ply/plylib.cpp diff --git a/src/meshlabplugins/filter_plymc/simplemeshprovider.h b/src/meshlabplugins/filter_plymc/simplemeshprovider.h deleted file mode 100644 index 6fdc6ca4b..000000000 --- a/src/meshlabplugins/filter_plymc/simplemeshprovider.h +++ /dev/null @@ -1,207 +0,0 @@ -#ifndef SIMPLEMESHPROVIDER_H -#define SIMPLEMESHPROVIDER_H -#include "../../meshlab/alnParser.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 diff --git a/src/plugins_unsupported/oldplymc/simplemeshprovider.h b/src/plugins_unsupported/oldplymc/simplemeshprovider.h new file mode 100644 index 000000000..8a55846f7 --- /dev/null +++ b/src/plugins_unsupported/oldplymc/simplemeshprovider.h @@ -0,0 +1,205 @@ +#ifndef SIMPLEMESHPROVIDER_H +#define SIMPLEMESHPROVIDER_H +#include "../../meshlab/alnParser.h" +#include +#include +#include +#include +#include + +using namespace std; +using namespace vcg; + +/** + * Very simple class to implement a cache of loaded meshes to avoid reloading an processing of the same mesh multiple times. + * + */ + + +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() {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 vcg::tri::TriMesh< std::vector< SVertex>, std::vector< SFace > > {}; + +#endif // SIMPLEMESHPROVIDER_H