FCWriteCache.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @file FCWriteCache.cpp
  3. * @author Erik Rodner
  4. * @date 11/15/2007
  5. */
  6. #include <iostream>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include "vislearning/features/simplefeatures/FCWriteCache.h"
  10. #include "vislearning/baselib/Globals.h"
  11. using namespace OBJREC;
  12. using namespace std;
  13. using namespace NICE;
  14. FCWriteCache::FCWriteCache( const Config * conf,
  15. FeatureFactory *_ff ) :
  16. FeatureFactory ( conf ), ff(_ff)
  17. {
  18. cachedir = conf->gS("cache", "root");
  19. cachemode = Globals::getCacheMode ( conf->gS("cache", "mode", "cat") );
  20. }
  21. FCWriteCache::~FCWriteCache()
  22. {
  23. }
  24. int FCWriteCache::convert ( const NICE::Image & img, NICE::Vector & vec )
  25. {
  26. int ret = ff->convert ( img, vec );
  27. std::string filename = Globals::getCacheFilename( cachedir, cachemode );
  28. std::string filename_feat = filename + ".feature";
  29. struct stat dummy;
  30. if ( stat ( filename_feat.c_str(), &dummy ) < 0 )
  31. {
  32. fprintf (stderr, "FCWriteCache: writing to %s\n", filename_feat.c_str());
  33. ofstream ofs ( filename_feat.c_str(), ios::out);
  34. if ( !ofs.good() )
  35. {
  36. fprintf (stderr, "FCWriteCache: unable to write to file %s\n",
  37. filename_feat.c_str() );
  38. exit(-1);
  39. }
  40. ofs << vec;
  41. ofs.close();
  42. } else {
  43. fprintf (stderr, "FCWriteCache: feature file %s exists !\n", filename_feat.c_str());
  44. }
  45. return ret;
  46. }