00001 #ifndef Impala_Core_ImageSet_ClusterFeatures_h
00002 #define Impala_Core_ImageSet_ClusterFeatures_h
00003
00004 #include "Core/Feature/ClusterorFactory.h"
00005 #include "Core/Feature/Computor.h"
00006 #include "Core/ImageSet/Reporter.h"
00007
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace ImageSet
00013 {
00014
00015
00016 class ClusterFeatures : public Listener
00017 {
00018 public:
00019
00020 typedef Feature::Computor Computor;
00021 typedef Feature::Clusteror Clusteror;
00022 typedef Feature::FeatureTable FeatureTable;
00023
00024 ClusterFeatures(Computor* computor, String clusteror, Reporter* reporter,
00025 CmdOptions& options)
00026 {
00027 mReporter = reporter;
00028 mComputor = computor;
00029
00030 if (options.GetNrArg() < 7)
00031 ILOG_ERROR("missing argument");
00032 String mode = options.GetArg(4);
00033 int nrWantedClusters = atoi(options.GetArg(5));
00034 int nrSamplesAtime = atoi(options.GetArg(6));
00035 ILOG_INFO("mode = " << mode << ", wanted = " << nrWantedClusters <<
00036 ", samplesAtime = " << nrSamplesAtime);
00037
00038 mComputor->MakeRegionFeatureTableSet();
00039
00040 for (int p=0 ; p<mComputor->GetNrPixelFeatureSets() ; p++)
00041 {
00042 for (int r=0 ; r<mComputor->GetNrRegionFeatureSets() ; r++)
00043 {
00044
00045 int minElemsInCluster = 2;
00046 Feature::ClusterorFactory::Instance().Construct
00047 (mClusterors, p, r, nrWantedClusters, nrSamplesAtime,
00048 minElemsInCluster, clusteror, options);
00049 }
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 }
00068
00069 virtual void
00070 HandleNewFile(ImageSet* is, int fileId, Array::Array2dVec3UInt8* im)
00071 {
00072 ILOG_DEBUG("new file " << fileId);
00073 Quid quid = is->GetQuidImage(fileId);
00074
00075 mComputor->ComputeRegionFeatures(im, quid);
00076
00077 for (int p=0 ; p<mComputor->GetNrPixelFeatureSets() ; p++)
00078 {
00079 for (int r=0 ; r<mComputor->GetNrRegionFeatureSets() ; r++)
00080 {
00081 FeatureTable* tab = mComputor->GetRegionFeatureTable(p, r);
00082 for (int clustID=0 ; clustID<mClusterors.size() ; clustID++)
00083 {
00084 if (mClusterors[clustID]->GetPixelFeatureSet() == p
00085 && mClusterors[clustID]->GetRegionFeatureSet() == r)
00086 {
00087 mClusterors[clustID]->Cluster(tab);
00088 }
00089 }
00090 }
00091 }
00092
00093 mComputor->GetRegionFeatureTableSet()->SetEmpty();
00094
00095
00096 bool allDone = true;
00097 for (int i=0 ; i<mClusterors.size() ; i++)
00098 {
00099 if (mReporter->DoPrint())
00100 mClusterors[i]->PrintStatus();
00101 allDone = allDone && mClusterors[i]->HadEnough();
00102 }
00103 if (allDone)
00104 {
00105 ILOG_INFO("all clusterors had enough");
00106 HandleDoneWalk(is);
00107 ILOG_INFO("had enough, bye");
00108 exit(0);
00109 }
00110 ILOG_DEBUG("done file " << fileId);
00111 }
00112
00113 virtual void
00114 HandleDoneWalk(ImageSet* is)
00115 {
00116 ILOG_INFO("Done Walk");
00117 for (int i=0 ; i<mClusterors.size() ; i++)
00118 mClusterors[i]->FinishBuffer();
00119 std::cout << std::endl;
00120
00121 for (int i=0 ; i<mClusterors.size() ; i++)
00122 {
00123 Clusteror* c = mClusterors[i];
00124 FeatureTable* tab = mComputor->MakeProtoFeatureTable
00125 (c->GetPixelFeatureSet(), c->GetRegionFeatureSet(),
00126 c->GetClusterType(), c->GetClusterVal());
00127 c->Clusters2FeatureTable(tab);
00128 }
00129
00130 mComputor->WriteProtoFeatureTableSet(is);
00131 }
00132
00133 private:
00134
00135 Reporter* mReporter;
00136 Feature::Computor* mComputor;
00137 std::vector<Clusteror*> mClusterors;
00138
00139 ILOG_VAR_DEC;
00140
00141 };
00142
00143 ILOG_VAR_INIT(ClusterFeatures, Impala.Core.ImageSet);
00144
00145 }
00146 }
00147 }
00148
00149 #endif