00001 #ifndef Impala_Core_ImageSet_Reporter_h
00002 #define Impala_Core_ImageSet_Reporter_h
00003
00004 #include "Basis/CmdOptions.h"
00005 #include "Basis/Timer.h"
00006 #include "Core/ImageSet/Listener.h"
00007 #include "Core/ImageSet/ImageSet.h"
00008
00009 namespace Impala
00010 {
00011 namespace Core
00012 {
00013 namespace ImageSet
00014 {
00015
00016
00024 class Reporter : public Listener
00025 {
00026 public:
00027
00028 Reporter(Reporter* master)
00029 {
00030 mMaster = master;
00031 CmdOptions& options = CmdOptions::GetInstance();
00032 mReport = options.GetInt("report");
00033 mNrDone = 0;
00034 mReportArray = true;
00035 }
00036
00037 virtual void
00038 HandleNewWalk(ImageSet* is)
00039 {
00040 if (mMaster)
00041 ILOG_DEBUG(".. new walk");
00042 }
00043
00044 virtual void
00045 HandleNewWalk(ImageSet* is, int nrBookmarks)
00046 {
00047 if (mMaster)
00048 ILOG_DEBUG(".. new walk, nrBookmarks = " << nrBookmarks);
00049 mNrBookmarks = nrBookmarks;
00050 }
00051
00052 virtual void
00053 HandleNewDir(ImageSet* is, int dirId)
00054 {
00055 if (mMaster)
00056 ILOG_DEBUG(".. new dir id = " << dirId);
00057 }
00058
00059 virtual void
00060 HandleDoneDir(ImageSet* is, int dirId)
00061 {
00062 if (mMaster)
00063 ILOG_DEBUG(".. done dir id = " << dirId);
00064 }
00065
00066 virtual void
00067 HandleNewFile(ImageSet* is, int fileId, Array::Array2dVec3UInt8* im)
00068 {
00069 if (mMaster)
00070 ILOG_DEBUG(".. new file id = " << fileId);
00071 if (mMaster)
00072 {
00073 mMaster->AllDoneFile();
00074 return;
00075 }
00076 mDoPrint = false;
00077 mNrDone++;
00078 if ((mReport > 0) && (mNrDone % mReport == 0))
00079 mDoPrint = true;
00080 if (mDoPrint)
00081 {
00082 int nrFiles = is->NrFiles();
00083 int perc = (int) (((double) fileId / (double) nrFiles) * 100);
00084 ILOG_INFO("-- file " << fileId << " of " << nrFiles
00085 << " (at " << perc << "%); did " << mNrDone);
00086 }
00087 Array::ArraySystem::Instance().MarkMemoryUsage(false);
00088 }
00089
00090 virtual void
00091 HandleNewFile(ImageSet* is, int fileId, Array::Array2dVec3UInt8* im,
00092 Geometry::Rectangle rect, String anno)
00093 {
00094 if (mMaster)
00095 ILOG_DEBUG(".. new file id = " << fileId);
00096 if (mMaster)
00097 {
00098 mMaster->AllDoneFile();
00099 return;
00100 }
00101 mDoPrint = false;
00102 mNrDone++;
00103 if ((mReport > 0) && (mNrDone % mReport == 0))
00104 mDoPrint = true;
00105 if (mDoPrint)
00106 {
00107 int nrFiles = mNrBookmarks;
00108 int perc = (int) (((double)mNrDone / (double)nrFiles) * 100);
00109 ILOG_INFO("-- file " << mNrDone << " of " << nrFiles
00110 << " (at " << perc << "%)");
00111 }
00112 Array::ArraySystem::Instance().MarkMemoryUsage(false);
00113 }
00114
00115 virtual void
00116 HandleDoneWalk(ImageSet* is)
00117 {
00118 if (mMaster)
00119 ILOG_DEBUG(".. done walk");
00120 }
00121
00122 virtual void
00123 HandleDoneWalk(ImageSet* is, int nrBookmarks)
00124 {
00125 if (mMaster)
00126 ILOG_DEBUG(".. done walk, nrBookmarks = " << nrBookmarks);
00127 }
00128
00129 void
00130 SetReportArray(bool flag)
00131 {
00132 mReportArray = flag;
00133 }
00134
00135 void
00136 FinalReport()
00137 {
00138 ILOG_INFO("DONE time total=" << mTimerTotal.SplitTime()
00139 << " error=" << ILOG_ERROR_COUNT);
00140 }
00141
00142 bool
00143 DoPrint()
00144 {
00145 return mDoPrint;
00146 }
00147
00148 private:
00149
00150 void
00151 AllDoneFile()
00152 {
00153 if (mReportArray)
00154 Array::ArraySystem::Instance().CheckMemoryUsageSinceMark(false);
00155 if (mDoPrint)
00156 {
00157 ILOG_INFO("++ avg time=" << mTimerReport.SplitTimeStr(mReport)
00158 << " total=" << mTimerTotal.SplitTimeStr()
00159 << " error=" << ILOG_ERROR_COUNT);
00160 mTimerReport.Start();
00161 }
00162 }
00163
00164 Reporter* mMaster;
00165 int mReport;
00166 int mNrDone;
00167 bool mReportArray;
00168 Timer mTimerTotal;
00169 Timer mTimerReport;
00170 bool mDoPrint;
00171 int mNrBookmarks;
00172
00173 ILOG_VAR_DEC;
00174 };
00175
00176 ILOG_VAR_INIT(Reporter, Impala.Core.ImageSet);
00177
00178 }
00179 }
00180 }
00181
00182 #endif