00001 #ifndef Impala_Core_VideoSet_IndexFeatures_h
00002 #define Impala_Core_VideoSet_IndexFeatures_h
00003
00004 #include "Persistency/FeatureTableRepository.h"
00005 #include "Core/Feature/FeatureTable.h"
00006 #include "Core/VideoSet/Reporter.h"
00007 #include "Core/VideoSet/Keyframes.h"
00008 #include "Core/Table/Select.h"
00009 #include "Core/Table/Write.h"
00010
00011 namespace Impala
00012 {
00013 namespace Core
00014 {
00015 namespace VideoSet
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 mKeyframes = 0;
00030 mKeyframeMask = 0;
00031 mWalkType = "unknown";
00032 }
00033
00034 virtual void
00035 HandleNewWalk(VideoSet* vs, String walkType)
00036 {
00037 mWalkType = walkType;
00038 }
00039
00040 virtual void
00041 HandleNewWalk(VideoSet* vs, Keyframes* keyframes, bool* keyframeMask)
00042 {
00043 mKeyframes = keyframes;
00044 mKeyframeMask = keyframeMask;
00045 }
00046
00047 virtual void
00048 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00049 {
00050 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00051 String fName = vs->GetFilePathFeatureData(mWalkType, mDef,
00052 fileId, false, -1, false,
00053 false);
00054 if (fName.empty())
00055 {
00056 return;
00057 }
00058 Feature::FeatureTable tmp(mDef);
00059 Table::Read(&tmp, fName, vs->GetDatabase());
00060 if (mTable == 0)
00061 {
00062 mTable = new Feature::FeatureTable(mDef, 0,
00063 tmp.GetFeatureVectorLength());
00064 }
00065 #else // REPOSITORY_USED
00066 Persistency::FeatureLocator loc(vs->GetLocator(), false, false,
00067 mWalkType, mDef.AsString(),
00068 vs->GetContainerFile(fileId));
00069 FeatureTable* tmp = Persistency::FeatureTableRepository().Get(loc);
00070 if (mTable == 0)
00071 {
00072 mTable = new FeatureTable(mDef, 12000,
00073 tmp->GetFeatureVectorLength());
00074 }
00075 #endif // REPOSITORY_USED
00076 bool* mask = mKeyframeMask;
00077 if (mask)
00078 mask = mKeyframeMask + mKeyframes->GetFirstKeyframeVideo(fileId);
00079 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00080 Table::Select(mTable, &tmp, mask, false);
00081 #else // REPOSITORY_USED
00082 Table::Select(mTable, tmp, mask, false);
00083 delete tmp;
00084 #endif // REPOSITORY_USED
00085 }
00086
00087 virtual void
00088 HandleDoneWalk(VideoSet* vs)
00089 {
00090 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00091 String fName = vs->GetFilePathFeatureIndex(mDef, "", true, false);
00092 if (! fName.empty())
00093 Table::Write(mTable, fName, vs->GetDatabase(), true);
00094 #else // REPOSITORY_USED
00095 Persistency::FeatureLocator loc(vs->GetLocator(), false, true, "",
00096 mDef.AsString(), "");
00097 Persistency::FeatureTableRepository().Add(loc, mTable);
00098 #endif // REPOSITORY_USED
00099 }
00100
00101 private:
00102
00103 Reporter* mReporter;
00104 Feature::FeatureDefinition mDef;
00105 Feature::FeatureTable* mTable;
00106 Keyframes* mKeyframes;
00107 bool* mKeyframeMask;
00108 String mWalkType;
00109
00110 };
00111
00112 }
00113 }
00114 }
00115
00116 #endif