ImageCache.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Image/ImageCache.H"
00039
00040 #include "Util/Assert.H"
00041 #include "Image/MathOps.H"
00042 #include "Image/ColorOps.H"
00043 #include "Image/Pixels.H"
00044 #include "Image/PixelsInst.H"
00045
00046
00047
00048
00049 template <class T>
00050 ImageCache<T>::ImageCache(uint maxSize)
00051 : itsMaxSize(maxSize)
00052 {}
00053
00054
00055 template <class T>
00056 ImageCache<T>::~ImageCache()
00057 {}
00058
00059
00060 template <class T>
00061 void ImageCache<T>::setMaxSize(const uint maxSize)
00062 {
00063 itsMaxSize = maxSize;
00064
00065 popOffOld();
00066 }
00067
00068
00069 template <class T>
00070 uint ImageCache<T>::getMaxSize() const
00071 { return itsMaxSize; }
00072
00073
00074 template <class T>
00075 void ImageCache<T>::push_back(const Image<T>& img)
00076 {
00077 doWhenAdd(img);
00078 itsCache.push_back(img);
00079 popOffOld();
00080 return;
00081 }
00082
00083
00084 template <class T>
00085 void ImageCache<T>::popOffOld()
00086 {
00087
00088 if (itsMaxSize == 0) return;
00089
00090 while (itsCache.size() > itsMaxSize)
00091 pop_front();
00092
00093 return;
00094 }
00095
00096
00097 template <class T>
00098 Image<T> ImageCache<T>::pop_front()
00099 {
00100 ASSERT(!itsCache.empty());
00101 Image<T> ret = itsCache.front();
00102 doWhenRemove(ret);
00103 itsCache.pop_front();
00104 return ret;
00105 }
00106
00107
00108 template <class T>
00109 const Image<T>& ImageCache<T>::back() const
00110 {
00111 ASSERT(!itsCache.empty());
00112 return itsCache.back();
00113 }
00114
00115
00116 template <class T>
00117 const Image<T>& ImageCache<T>::front() const
00118 {
00119 ASSERT(!itsCache.empty());
00120 return itsCache.front();
00121 }
00122
00123
00124 template <class T>
00125 const Image<T>& ImageCache<T>::getImage(const uint lev) const
00126 {
00127 ASSERT(lev < itsCache.size());
00128 return itsCache[lev];
00129 }
00130
00131
00132 template <class T>
00133 const Image<T>& ImageCache<T>::operator[](const uint lev) const
00134 { return getImage(lev); }
00135
00136
00137 template <class T>
00138 uint ImageCache<T>::size() const
00139 { return itsCache.size(); }
00140
00141
00142 template <class T>
00143 bool ImageCache<T>::empty() const
00144 { return itsCache.empty(); }
00145
00146
00147 template <class T>
00148 void ImageCache<T>::clear()
00149 {
00150
00151
00152
00153 while(size()) this->pop_front();
00154 }
00155
00156
00157 template <class T>
00158 void ImageCache<T>::doWhenAdd(const Image<T>& img)
00159 { }
00160
00161
00162 template <class T>
00163 void ImageCache<T>::doWhenRemove(const Image<T>& img)
00164 { }
00165
00166
00167
00168
00169 template <class T>
00170 ImageCacheAvg<T>::ImageCacheAvg()
00171 : ImageCache<T>(0)
00172 {}
00173
00174
00175 template <class T>
00176 ImageCacheAvg<T>::ImageCacheAvg(uint maxSize)
00177 : ImageCache<T>(maxSize)
00178 {}
00179
00180
00181 template <class T>
00182 Image<T> ImageCacheAvg<T>::mean() const
00183 {
00184 return Image<T> (this->itsSumImg / this->itsCache.size());
00185 }
00186
00187
00188 template <class T>
00189 Image<T> ImageCacheAvg<T>::absDiffMean(const Image<T>& img) const
00190 {
00191 return absDiff(mean(), img);
00192 }
00193
00194
00195 template <class T>
00196 Image<T> ImageCacheAvg<T>::clampedDiffMean(const Image<T>& img) const
00197 {
00198 return clampedDiff(img, mean());
00199 }
00200
00201
00202 template <class T>
00203 Image<typename promote_trait<T,float>::TP> ImageCacheAvg<T>::sum() const
00204 {
00205 return itsSumImg;
00206 }
00207
00208
00209 template <class T>
00210 void ImageCacheAvg<T>::doWhenAdd(const Image<T>& img)
00211 {
00212 if (itsSumImg.initialized())
00213 {
00214 ASSERT(itsSumImg.isSameSize(img));
00215 itsSumImg += img;
00216 }
00217 else
00218 {
00219 itsSumImg = img;
00220 }
00221 }
00222
00223
00224 template <class T>
00225 void ImageCacheAvg<T>::doWhenRemove(const Image<T>& img)
00226 {
00227 ASSERT(itsSumImg.initialized());
00228 itsSumImg -= img;
00229 }
00230
00231
00232
00233
00234
00235 template <class T>
00236 ImageCacheMinMax<T>::ImageCacheMinMax()
00237 : ImageCache<T>(0)
00238 {}
00239
00240
00241 template <class T>
00242 ImageCacheMinMax<T>::ImageCacheMinMax(uint maxSize)
00243 : ImageCache<T>(maxSize)
00244 {}
00245
00246
00247 template <class T>
00248 Image<T> ImageCacheMinMax<T>::getMax() const
00249 {
00250 if (this->itsCache.size() == 0) return Image<T>();
00251 typename std::deque< Image<T> >::const_iterator
00252 itr = this->itsCache.begin(), end = this->itsCache.end();
00253 Image<T> ret = *itr++;
00254 while(itr != end) ret = takeMax(ret, *itr++);
00255 return ret;
00256 }
00257
00258
00259 template <class T>
00260 Image<T> ImageCacheMinMax<T>::getMin() const
00261 {
00262 if (this->itsCache.size() == 0) return Image<T>();
00263 typename std::deque< Image<T> >::const_iterator
00264 itr = this->itsCache.begin(), end = this->itsCache.end();
00265 Image<T> ret = *itr++;
00266 while(itr != end) ret = takeMin(ret, *itr++);
00267 return ret;
00268 }
00269
00270
00271 template <class T>
00272 void ImageCacheMinMax<T>::doWhenAdd(const Image<T>& img)
00273 { }
00274
00275
00276 template <class T>
00277 void ImageCacheMinMax<T>::doWhenRemove(const Image<T>& img)
00278 { }
00279
00280
00281
00282
00283
00284 #ifdef INVT_INST_BYTE
00285 PIX_INST(ImageCache, byte);
00286 PIX_INST(ImageCacheAvg, byte);
00287 template class ImageCacheMinMax<byte>;
00288 #endif
00289
00290 #ifdef INVT_INST_INT16
00291 PIX_INST(ImageCache, int16);
00292 PIX_INST(ImageCacheAvg, int16);
00293 template class ImageCacheMinMax<int16>;
00294 #endif
00295
00296 #ifdef INVT_INST_INT32
00297 PIX_INST(ImageCache, int32);
00298 PIX_INST(ImageCacheAvg, int32);
00299 template class ImageCacheMinMax<int32>;
00300 #endif
00301
00302 #ifdef INVT_INST_FLOAT
00303 PIX_INST(ImageCache, float);
00304 PIX_INST(ImageCacheAvg, float);
00305 template class ImageCacheMinMax<float>;
00306 #endif
00307
00308
00309
00310
00311
00312