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 if (Link::Mpi::NrProcs() == 8)
00028 {
00029 String feat = options.GetArg(2);
00030 int nr = Link::Mpi::MyId();
00031 String sub = (nr == 0) ? "" : "_sub_" + MakeString(nr);
00032 mDef = Feature::FeatureDefinition(feat + sub);
00033 ILOG_INFO_NODE("indexing feature " << mDef.AsString());
00034 }
00035 else
00036 {
00037 mDef = Feature::FeatureDefinition(options.GetArg(2));
00038 }
00039 mTable = 0;
00040 mKeyframes = 0;
00041 mKeyframeMask = 0;
00042 mWalkType = "unknown";
00043 }
00044
00045 virtual void
00046 HandleNewWalk(VideoSet* vs, String walkType)
00047 {
00048 mWalkType = walkType;
00049 }
00050
00051 virtual void
00052 HandleNewWalk(VideoSet* vs, Keyframes* keyframes, bool* keyframeMask)
00053 {
00054 mKeyframes = keyframes;
00055 mKeyframeMask = keyframeMask;
00056 }
00057
00058 virtual void
00059 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00060 {
00061 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00062 String fName = vs->GetFilePathFeatureData(mWalkType, mDef,
00063 fileId, false, -1, false,
00064 false);
00065 if (fName.empty())
00066 {
00067 return;
00068 }
00069 Feature::FeatureTable tmp(mDef);
00070 Table::Read(&tmp, fName, vs->GetDatabase());
00071 if (mTable == 0)
00072 {
00073 mTable = new Feature::FeatureTable(mDef, 0,
00074 tmp.GetFeatureVectorLength());
00075 }
00076 #else // REPOSITORY_USED
00077 Persistency::FeatureLocator loc(vs->GetLocator(), false, false,
00078 mWalkType, mDef.AsString(),
00079 vs->GetContainerFile(fileId));
00080 FeatureTable* tmp = Persistency::FeatureTableRepository().Get(loc);
00081 if (mTable == 0)
00082 {
00083 mTable = new FeatureTable(mDef, 12000,
00084 tmp->GetFeatureVectorLength());
00085 }
00086 #endif // REPOSITORY_USED
00087 bool* mask = mKeyframeMask;
00088 if (mask)
00089 mask = mKeyframeMask + mKeyframes->GetFirstKeyframeVideo(fileId);
00090 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00091 Table::Select(mTable, &tmp, mask, false);
00092 #else // REPOSITORY_USED
00093 Table::Select(mTable, tmp, mask, false);
00094 delete tmp;
00095 #endif // REPOSITORY_USED
00096 }
00097
00098 virtual void
00099 HandleDoneWalk(VideoSet* vs)
00100 {
00101 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00102 String fName = vs->GetFilePathFeatureIndex(mDef, "", true, false);
00103 if (! fName.empty())
00104 Table::Write(mTable, fName, vs->GetDatabase(), true);
00105 #else // REPOSITORY_USED
00106 Persistency::FeatureLocator loc(vs->GetLocator(), false, true, "",
00107 mDef.AsString(), "");
00108 Persistency::FeatureTableRepository().Add(loc, mTable);
00109 #endif // REPOSITORY_USED
00110 }
00111
00112 private:
00113
00114 Reporter* mReporter;
00115 Feature::FeatureDefinition mDef;
00116 Feature::FeatureTable* mTable;
00117 Keyframes* mKeyframes;
00118 bool* mKeyframeMask;
00119 String mWalkType;
00120
00121 ILOG_VAR_DEC;
00122 };
00123
00124 ILOG_VAR_INIT(IndexFeatures, Impala.Core.VideoSet);
00125
00126 }
00127 }
00128 }
00129
00130 #endif