00001 #ifndef Impala_Core_VideoSet_CombineConcepts_h
00002 #define Impala_Core_VideoSet_CombineConcepts_h
00003
00004 #include "Core/Column/AddAssign.h"
00005 #include "Core/Column/MulAssign.h"
00006 #include "Core/Column/DivAssign.h"
00007 #include "Persistency/SimilarityTableSetRepository.h"
00008 #include "Core/VideoSet/Reporter.h"
00009
00010 namespace Impala
00011 {
00012 namespace Core
00013 {
00014 namespace VideoSet
00015 {
00016
00017
00018 class CombineConcepts : public Listener
00019 {
00020 public:
00021 typedef Feature::FeatureDefinition FeatureDefinition;
00022 typedef Table::SimilarityTableSet SimilarityTableSet;
00023 typedef Persistency::SimilarityTableSetLocator SimilarityTableSetLocator;
00024 typedef Persistency::SimilarityTableSetRepository SimilarityTableSetRepository;
00025
00026 CombineConcepts(Reporter* reporter, CmdOptions& options)
00027 {
00028 if (options.GetNrArg() < 7)
00029 {
00030 ILOG_ERROR("Missing argument");
00031 return;
00032 }
00033 mConceptFileName = options.GetArg(2);
00034 mModel = options.GetArg(3);
00035 mResultName = options.GetArg(4);
00036 mCombi = options.GetArg(5);
00037 if ((mCombi != "mul") && (mCombi != "avg"))
00038 {
00039 ILOG_ERROR("Unknown combination method : " << mCombi);
00040 return;
00041 }
00042 for (int i=6 ; i<options.GetNrArg() ; i++)
00043 mFeatureDefs.push_back(options.GetArg(i));
00044 }
00045
00046 virtual void
00047 HandleNewWalk(VideoSet* vs, String walkType)
00048 {
00049 mWalkType = walkType;
00050 }
00051
00052 virtual void
00053 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00054 {
00055 SimilarityTableSetLocator loc(vs->GetLocator(), false, mWalkType,
00056 mConceptFileName, mModel, mFeatureDefs[0],
00057 vs->GetContainer(fileId));
00058 SimilarityTableSet* combinedSet = SimilarityTableSetRepository().Get(loc);
00059 for (int i=1 ; i<mFeatureDefs.size() ; i++)
00060 {
00061 loc.SetFeature(mFeatureDefs[i]);
00062 SimilarityTableSet* simSet = SimilarityTableSetRepository().Get(loc);
00063 for (int t=0 ; t<simSet->NrTables() ; t++)
00064 {
00065 if (mCombi == "mul")
00066 MulAssign(combinedSet->GetSimTable(t)->GetColumn1(),
00067 simSet->GetSimTable(t)->GetColumn1(), 0, -1);
00068 else
00069 AddAssign(combinedSet->GetSimTable(t)->GetColumn1(),
00070 simSet->GetSimTable(t)->GetColumn1(), 0, -1);
00071 }
00072 delete simSet;
00073 }
00074 if (mCombi == "avg")
00075 for (int t=0 ; t<combinedSet->NrTables() ; t++)
00076 DivAssign(combinedSet->GetSimTable(t)->GetColumn1(),
00077 mFeatureDefs.size(), 0, -1);
00078 combinedSet->ComputeRanks(true);
00079
00080 loc.SetFeature(mResultName);
00081 SimilarityTableSetRepository().Add(loc, combinedSet);
00082 delete combinedSet;
00083 }
00084
00085 private:
00086
00087 String mConceptFileName;
00088 String mModel;
00089 String mResultName;
00090 String mCombi;
00091 std::vector<String> mFeatureDefs;
00092 String mWalkType;
00093
00094 ILOG_VAR_DEC;
00095
00096 };
00097
00098 ILOG_VAR_INIT(CombineConcepts, Impala.Core.VideoSet);
00099
00100 }
00101 }
00102 }
00103
00104 #endif