00001 #ifndef Impala_Core_ImageSet_ProtoSimilarityEval_h
00002 #define Impala_Core_ImageSet_ProtoSimilarityEval_h
00003
00004 #include "Persistency/FeatureTableRepository.h"
00005 #include "Core/ImageSet/Reporter.h"
00006 #include "Core/Feature/Computor.h"
00007
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace ImageSet
00013 {
00014
00015
00016 class ProtoSimilarityEval : public Listener
00017 {
00018 public:
00019
00020 ProtoSimilarityEval(Feature::Computor* computor, Reporter* reporter,
00021 CmdOptions& options)
00022 {
00023 mReporter = reporter;
00024 mComputor = computor;
00025 if (options.GetNrArg() < 5)
00026 ILOG_ERROR("Need more arguments");
00027 String protoSet = options.GetArg(2);
00028 if (protoSet == "nil")
00029 protoSet = "";
00030 String maskSet = options.GetArg(3);
00031 if (maskSet == "nil")
00032 maskSet = "";
00033 int maxNr = atol(options.GetArg(4));
00034 mComputor->ReadPrototypes(protoSet, maskSet, maxNr);
00035 }
00036
00037 virtual void
00038 HandleNewFile(ImageSet* is, int fileId, Array::Array2dVec3UInt8* im)
00039 {
00040 Quid quid = is->GetQuidImage(fileId);
00041 mComputor->ComputeFeatures(im, quid);
00042 }
00043
00044 virtual void
00045 HandleDoneDir(ImageSet* is, int dirId)
00046 {
00047 bool binary = true;
00048 Feature::FeatureTableSet* tableSet = mComputor->GetFeatureTableSet();
00049 Persistency::FeatureLocator loc(is->GetLocator(), false, false, "",
00050 "empty", is->GetContainerDir(dirId));
00051 for (int i=0 ; i<tableSet->Size() ; i++)
00052 {
00053 Feature::FeatureDefinition def = tableSet->GetFeatureDefinition(i);
00054 def = mComputor->ExtendFeatureDefinition(def);
00055 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00056 String fName = is->GetFilePathFeatureData(def, dirId, false,
00057 0, true, false);
00058 if (!fName.empty())
00059 {
00060 Table::Write(tableSet->GetTable(i), fName, is->GetDatabase(),
00061 binary);
00062 }
00063 #else // REPOSITORY_USED
00064 loc.SetFeatureDef(def);
00065 Persistency::FeatureTableRepository().Add(loc,
00066 tableSet->GetTable(i));
00067 #endif // REPOSITORY_USED
00068 tableSet->GetTable(i)->SetSize(0);
00069 }
00070 String mask = mComputor->GetMaskSetBase();
00071 if (!mask.empty())
00072 {
00073 #ifndef REPOSITORY_USED
00074 String fName = is->GetFilePathFeatureData(mask + ".txt", dirId,
00075 false, 0, true, false);
00076 if (!fName.empty())
00077 mComputor->WriteFeatureDefinitions(fName, is->GetDatabase());
00078 #else // REPOSITORY_USED
00079 loc.SetFeatureString(mask + ".txt");
00080 mComputor->WriteFeatureDefinitions(loc);
00081 #endif // REPOSITORY_USED
00082 }
00083 }
00084
00085 private:
00086
00087 Reporter* mReporter;
00088 Feature::Computor* mComputor;
00089
00090 ILOG_VAR_DEC;
00091
00092 };
00093
00094 ILOG_VAR_INIT(ProtoSimilarityEval, Impala.Core.ImageSet);
00095
00096 }
00097 }
00098 }
00099
00100 #endif