#include #include "core/basics/StringTools.h" #include "vislearning/baselib/Globals.h" #include "core/basics/ossettings.h" #include #include #include using namespace OBJREC; using namespace NICE; using namespace std; std::string Globals::currentImgFN = ""; void Globals::setCurrentImgFN ( const std::string & imgfn ) { currentImgFN = imgfn; } std::string Globals::getCurrentImgFN ( ) { return currentImgFN; } std::string Globals::getCacheFilename ( const std::string & root, int cache_mode ) { std::string filename = Globals::getCurrentImgFN(); vector mylistdir; StringTools::split ( filename, FILESEP, mylistdir ); int dirpart = 2; if ( cache_mode == SORT_CATEGORIES_SECONDPART ) { cache_mode = SORT_CATEGORIES; dirpart = 3; } if ( cache_mode == SORT_CATEGORIES ) { if ( mylistdir.size() < 2 ) { cerr << "Globals::getCacheFilename: unable to parse filename " << filename << endl; exit(-1); } std::string name = mylistdir[mylistdir.size()-1]; vector mylist; StringTools::split ( name, '.', mylist ); name = ""; for ( uint k = 0 ; k < mylist.size()-1 ; k++ ) if ( k == 0 ) name = name + mylist[k]; else name = name + "." + mylist[k]; std::string dir = root + FILESEPSTRING + mylistdir[mylistdir.size()-dirpart]; struct stat info; if ( stat (dir.c_str(), &info ) < 0 ) { if ( mkdir(dir.c_str(), 0755) < 0 ) { cerr << "Globals::getCacheFilename: unable to create directory: " << dir << endl; exit(-1); } } std::string id = dir + FILESEPSTRING + name; return id; } else if ( cache_mode == SORT_NONE ) { vector mylist; std::string name = mylistdir[ mylistdir.size() - 1 ]; StringTools::split ( name, '.', mylist ); if ( mylist.size() != 2 ) { cerr << "Globals::getCacheFilename: unable to parse filename " << name << endl; exit(-1); } name = mylist[0]; std::string id = root + FILESEPSTRING + name; return id; } else { fprintf (stderr, "Globals::getCacheFilename: unknown mode\n"); } return ""; } int Globals::getCacheMode ( const std::string & desc ) { if ( desc == "cat" ) { return SORT_CATEGORIES; } else if ( desc == "cat2" ) { return SORT_CATEGORIES_SECONDPART; } else if ( desc == "none" ) { return SORT_NONE; } else { fprintf (stderr, "Globals::getCacheMode: mode unknown >%s<\n", desc.c_str() ); exit(-1); } }