00001 #ifndef Impala_Core_ImageSet_CheckSizes_h 00002 #define Impala_Core_ImageSet_CheckSizes_h 00003 00004 #include "Core/ImageSet/Reporter.h" 00005 #include "Core/ImageSet/MakeImageSet.h" 00006 #include "Persistency/ImageSetRepository.h" 00007 00008 namespace Impala 00009 { 00010 namespace Core 00011 { 00012 namespace ImageSet 00013 { 00014 00015 00016 class CheckSizes : public Listener 00017 { 00018 public: 00019 00020 CheckSizes(Reporter* reporter, CmdOptions& options) 00021 { 00022 mReporter = reporter; 00023 mMinWidth = 100; 00024 mMaxWidth = 2000; 00025 mMinHeight = 100; 00026 mMaxHeight = 2000; 00027 mWriteCorrected = false; 00028 mNewSet = 0; 00029 if (options.GetNrArg() != 7) 00030 { 00031 ILOG_ERROR("Need 7 arguments"); 00032 } 00033 else 00034 { 00035 mMinWidth = atol(options.GetArg(2)); 00036 mMaxWidth = atol(options.GetArg(3)); 00037 mMinHeight = atol(options.GetArg(4)); 00038 mMaxHeight = atol(options.GetArg(5)); 00039 mWriteCorrected = atol(options.GetArg(6)) != 0; 00040 } 00041 ILOG_DEBUG("range: width: " << mMinWidth << " - " << mMaxWidth 00042 << ", height: " << mMinHeight << " - " << mMaxHeight); 00043 } 00044 00045 virtual void 00046 HandleNewWalk(ImageSet* is) 00047 { 00048 if (mWriteCorrected) 00049 { 00050 String name = FileNameBase(is->GetSetName()) + ".ok.txt"; 00051 mNewSet = new ImageSet(name); 00052 } 00053 } 00054 00055 virtual void 00056 HandleNewFile(ImageSet* is, int fileId, Array::Array2dVec3UInt8* im) 00057 { 00058 String fileName = is->GetAsPath(fileId); 00059 if (im == 0) 00060 { 00061 ILOG_ERROR("No image " << fileName); 00062 return; 00063 } 00064 bool error = false; 00065 if ((im->CW() < mMinWidth) || (im->CW() > mMaxWidth)) 00066 { 00067 ILOG_ERROR("width " << im->CW() << " out of range: " << fileName); 00068 error = true; 00069 } 00070 if ((im->CH() < mMinHeight) || (im->CH() > mMaxHeight)) 00071 { 00072 ILOG_ERROR("height " << im->CH() << " out of range: " << fileName); 00073 error = true; 00074 } 00075 if (error) 00076 { 00077 return; 00078 } 00079 if (mNewSet) 00080 { 00081 int dirId = is->GetDirIdOfFile(fileId); 00082 mNewSet->AddFile(is->GetFile(fileId), is->GetSection(dirId), 00083 is->GetDir(dirId)); 00084 } 00085 } 00086 00087 virtual void 00088 HandleDoneWalk(ImageSet* is) 00089 { 00090 if (mNewSet) 00091 { 00092 Persistency::ImageSetLocator loc(is->GetLocator(), ""); 00093 Persistency::ImageSetRepository().Add(loc, mNewSet); 00094 } 00095 } 00096 00097 private: 00098 00099 Reporter* mReporter; 00100 int mMinWidth; 00101 int mMaxWidth; 00102 int mMinHeight; 00103 int mMaxHeight; 00104 bool mWriteCorrected; 00105 ImageSet* mNewSet; 00106 00107 ILOG_VAR_DEC; 00108 00109 }; 00110 00111 ILOG_VAR_INIT(CheckSizes, Core.ImageSet); 00112 00113 } // namespace ImageSet 00114 } // namespace Core 00115 } // namespace Impala 00116 00117 #endif