00001 #ifndef Impala_Core_ImageSet_IndexFeatures_h
00002 #define Impala_Core_ImageSet_IndexFeatures_h
00003
00004 #include "Persistency/FeatureTableRepository.h"
00005 #include "Core/Feature/FeatureTable.h"
00006 #include "Core/ImageSet/Reporter.h"
00007 #include "Core/Table/Append.h"
00008 #include "Core/Table/Write.h"
00009 #include "Core/Feature/DumpFeatureTableHistogram.h"
00010
00011 namespace Impala
00012 {
00013 namespace Core
00014 {
00015 namespace ImageSet
00016 {
00017
00018
00019 class IndexFeatures : public Listener
00020 {
00021 public:
00022 typedef Feature::FeatureTable FeatureTable;
00023
00024 IndexFeatures(Reporter* reporter, CmdOptions& options)
00025 {
00026 mReporter = reporter;
00027 mDef = Feature::FeatureDefinition(options.GetArg(2));
00028 mTable = 0;
00029 }
00030
00031 virtual void
00032 HandleDoneDir(ImageSet* is, int dirId)
00033 {
00034 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00035 String fName = is->GetFilePathFeatureData(mDef, dirId, false, -1,
00036 false, false);
00037 if (fName.empty())
00038 {
00039 return;
00040 }
00041 FeatureTable tmp(mDef);
00042 Table::Read(&tmp, fName, is->GetDatabase());
00043 if (mTable == 0)
00044 {
00045 mTable = new FeatureTable(mDef, 12000, tmp.GetFeatureVectorLength());
00046 }
00047 Table::Append(mTable, &tmp);
00048 #else // REPOSITORY_USED
00049 Persistency::FeatureLocator loc(is->GetLocator(), false, false, "",
00050 mDef.AsString(),
00051 is->GetContainerDir(dirId));
00052 FeatureTable* tmp = Persistency::FeatureTableRepository().Get(loc);
00053 if (mTable == 0)
00054 {
00055 mTable = new FeatureTable(mDef, 12000,
00056 tmp->GetFeatureVectorLength());
00057 }
00058 Table::Append(mTable, tmp);
00059 delete tmp;
00060 #endif // REPOSITORY_USED
00061 }
00062
00063 virtual void
00064 HandleDoneWalk(ImageSet* is)
00065 {
00066 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00067 String fName = is->GetFilePathFeatureIndex(mDef, "", true, false);
00068 if (!fName.empty())
00069 Table::Write(mTable, fName, is->GetDatabase(), true);
00070 #else // REPOSITORY_USED
00071 Persistency::FeatureLocator loc(is->GetLocator(), false, true, "",
00072 mDef.AsString(), "");
00073 Persistency::FeatureTableRepository().Add(loc, mTable);
00074 #endif // REPOSITORY_USED
00075 }
00076
00077 private:
00078
00079 Reporter* mReporter;
00080 Feature::FeatureDefinition mDef;
00081 Feature::FeatureTable* mTable;
00082
00083 };
00084
00085 }
00086 }
00087 }
00088
00089 #endif