00001 #ifndef Impala_Core_VideoSet_ConcatFeatures_h
00002 #define Impala_Core_VideoSet_ConcatFeatures_h
00003
00004 #include "Persistency/FeatureTableSetRepository.h"
00005 #include "Core/Feature/FeatureTableSet.h"
00006 #include "Core/VideoSet/Reporter.h"
00007 #include "Core/Table/Write.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace VideoSet
00014 {
00015
00016
00017 class ConcatFeatures : public Listener
00018 {
00019 public:
00020 typedef Feature::FeatureList FeatureList;
00021 typedef Feature::FeatureDefinition FeatureDefinition;
00022 typedef Feature::FeatureTable FeatureTable;
00023 typedef Feature::FeatureTableSet FeatureTableSet;
00024
00025 ConcatFeatures(Reporter* reporter, CmdOptions& options)
00026 {
00027 mReporter = reporter;
00028 if (FileNameExt(options.GetArg(2)) == "txt")
00029 {
00030 mSrcFileName = options.GetArg(2);
00031 mSrcDefs = mSrcFileName;
00032 mResultDef = FeatureDefinition(FileNameBase(mSrcFileName));
00033 ILOG_INFO("resultDef = " << mResultDef.AsString());
00034 }
00035 else
00036 {
00037 mResultDef = FeatureDefinition(options.GetArg(2));
00038 mSrcDefs = options.GetArg(3);
00039 for (int i=4 ; i<options.GetNrArg() ; i++)
00040 mSrcDefs += ";" + options.GetArg(i);
00041 }
00042 mWalkType = "unknown";
00043 mIsPartial = false;
00044 }
00045
00046 virtual void
00047 HandleNewWalkPartial(VideoSet* vs, int startFrame, int stepSize,
00048 int numberFrames)
00049 {
00050 mIsPartial = true;
00051 mNumberFrames = numberFrames;
00052 }
00053
00054 virtual void
00055 HandleNewWalk(VideoSet* vs, String walkType)
00056 {
00057 mWalkType = walkType;
00058 }
00059
00060 virtual void
00061 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00062 {
00063 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00064 std::vector<String> defList;
00065 if (!mSrcFileName.empty())
00066 {
00067 String filePath;
00068 Util::Database* db;
00069 if (StringStartsWith(mSrcFileName, ".."))
00070 {
00071 db = &Util::Database::GetInstance();
00072 filePath = db->GetFilePath(mSrcFileName, false, false);
00073 }
00074 else
00075 {
00076 filePath = vs->GetFilePathFeatureData(mWalkType, mSrcFileName,
00077 fileId, mIsPartial,
00078 0, false, false);
00079 db = vs->GetDatabase();
00080 }
00081 Util::DatabaseReadString(std::back_inserter(defList), filePath,
00082 db, true);
00083 mSrcDefs = defList[0];
00084 for (int i=1 ; i<defList.size() ; i++)
00085 mSrcDefs += ";" + defList[i];
00086 ILOG_DEBUG("mSrcDefs = " << mSrcDefs);
00087 }
00088
00089 FeatureTableSet* fSet = FeatureTableSet::MakeFromFile
00090 (mWalkType, false, mSrcDefs, vs, fileId, mIsPartial, mNumberFrames);
00091 #else // REPOSITORY_USED
00092 Persistency::FeatureLocator loc(vs->GetLocator(), false, false,
00093 mWalkType, mSrcDefs,
00094 vs->GetContainerFile(fileId));
00095 if (mIsPartial)
00096 loc.SetNumberFrames(mNumberFrames);
00097 FeatureTableSet* fSet =
00098 Persistency::FeatureTableSetRepository().Get(loc);
00099 #endif // REPOSITORY_USED
00100 if (fSet == 0)
00101 return;
00102
00103 FeatureTable* res;
00104 String resName = mResultDef.AsString();
00105 if (resName == "vissem_proto_annotation_nrScales_2_nrRects_130" ||
00106 resName == "vissemgabor_proto_annotation_nrScales_2_nrRects_130")
00107 {
00108 ILOG_INFO("Using VissemHack to get original order in vector");
00109 res = fSet->ConcatTablesVissemHack(mResultDef);
00110 }
00111 else
00112 {
00113 res = fSet->ConcatTables(mResultDef);
00114 }
00115
00116 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00117 String fName = vs->GetFilePathFeatureData
00118 (mWalkType, mResultDef, fileId, false, -1, true, false);
00119 if ((res != 0) && (!fName.empty()))
00120 {
00121 Table::Write(res, fName, vs->GetDatabase(), true);
00122 }
00123 #else // REPOSITORY_USED
00124 if (res != 0)
00125 {
00126 loc.SetFeatureDef(mResultDef);
00127 loc.SetNumberFrames(0);
00128 Persistency::FeatureTableRepository().Add(loc, res);
00129 }
00130 #endif // REPOSITORY_USED
00131 fSet->Delete();
00132 delete fSet;
00133 delete res;
00134 }
00135
00136 private:
00137
00138 Reporter* mReporter;
00139 FeatureDefinition mResultDef;
00140 String mSrcDefs;
00141 String mSrcFileName;
00142 String mWalkType;
00143 bool mIsPartial;
00144 int mNumberFrames;
00145
00146 ILOG_VAR_DEC;
00147
00148 };
00149
00150 ILOG_VAR_INIT(ConcatFeatures, Impala.Core.VideoSet);
00151
00152 }
00153 }
00154 }
00155
00156 #endif