FCWriteCache.cpp 1.4 KB

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