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