123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #include <iostream>
- #include "core/basics/StringTools.h"
- #include "vislearning/baselib/Globals.h"
- #include "core/basics/ossettings.h"
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- 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<string> 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<string> 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<string> 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);
- }
- }
|