ImageSet.H

Go to the documentation of this file.
00001 /*!@file Image/ImageSet.H */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/ImageSet.H $
00035 // $Id: ImageSet.H 12575 2010-01-15 03:36:17Z itti $
00036 //
00037 
00038 #ifndef IMAGESET_H_DEFINED
00039 #define IMAGESET_H_DEFINED
00040 
00041 #include "Image/Image.H"
00042 #include "Util/Assert.H"
00043 
00044 #include <deque>
00045 
00046 // ######################################################################
00047 //! This class implements a set of images, often used as a dyadic pyramid.
00048 template <class T>
00049 class ImageSet
00050 {
00051 public:
00052   //! Construct with a given number of empty images.
00053   inline ImageSet(const uint n = 0);
00054 
00055   //! Construct with a given number of images of the given size.
00056   inline ImageSet(const uint n, const Dims& dims, InitPolicy init = ZEROS);
00057 
00058   // default dtor, copy-ctor and assignment OK
00059 
00060   //! Copy-conversion constructor
00061   template <class TT> inline ImageSet(const ImageSet<TT>& iset);
00062 
00063   //! Converting assignment
00064   template <class TT> inline ImageSet<T>& operator=(const ImageSet<TT>& iset);
00065 
00066   //! Swap contents with another ImageSet
00067   inline void swap(ImageSet<T>& that);
00068 
00069   //! Keep the same number of images, but make all images empty (0-by-0 size).
00070   /*! This returns the ImageSet to a state where isEmpty() is true. */
00071   inline void clear();
00072 
00073   //! Reset to a new number of images, all images will be empty (0-by-0 size).
00074   inline void reset(uint newDepth = 0);
00075 
00076   //! Return number of images in image set.
00077   inline uint size() const;
00078 
00079   //! Get image from a given level.
00080   inline const Image<T>& getImage(const uint lev) const;
00081 
00082   //! Get image from a given level (shorthand for getImage()).
00083   inline const Image<T>& operator[](const uint lev) const;
00084 
00085   //! Get mutable image from a given level.
00086   inline Image<T>& getImageMut(const uint lev);
00087 
00088   //! Get mutable image from a given level (shorthand for getImageMut()).
00089   inline Image<T>& operator[](const uint lev);
00090 
00091   //! push an image to the back of the set
00092   inline void push_back(const Image<T>& img);
00093 
00094   //! push an image to the front of the set
00095   inline void push_front(const Image<T>& img);
00096 
00097   //! return the last image in the set and pop it off
00098   inline Image<T> pop_back();
00099 
00100   //! return the first image in the set and pop it off
00101   inline Image<T> pop_front();
00102 
00103   //! return the last image in the set (without popping it off)
00104   inline Image<T> front() const;
00105 
00106   //! return the first image in the set (without popping it off)
00107   inline Image<T> back() const;
00108 
00109   //! Return true if the pyramid has no non-empty images (width*height > 0).
00110   inline bool isEmpty() const;
00111 
00112   //! Return true if the pyramid has any non-empty images (width*height > 0).
00113   inline bool isNonEmpty() const;
00114 
00115   //! Return a new ImageSet with images in the half-open range [a,b[
00116   inline ImageSet<T> subSet(const uint a, const uint b) const;
00117 
00118 private:
00119   std::deque< Image<T> > itsLevels;
00120 };
00121 
00122 
00123 
00124 // ######################################################################
00125 // ######################################################################
00126 // ##### INLINED FUNCTIONS:
00127 // ######################################################################
00128 // ######################################################################
00129 
00130 // ######################################################################
00131 template <class T> inline
00132 ImageSet<T>::ImageSet(const uint n)
00133   : itsLevels(n)
00134 {}
00135 
00136 // ######################################################################
00137 template <class T> inline
00138 ImageSet<T>::ImageSet(const uint n, const Dims& dims, InitPolicy init)
00139   : itsLevels(n, Image<T>(dims,init))
00140 {}
00141 
00142 // ######################################################################
00143 template <class T> template <class TT> inline
00144 ImageSet<T>::ImageSet(const ImageSet<TT>& iset) : itsLevels()
00145 {
00146   for (uint i = 0; i < iset.size(); ++i)
00147     itsLevels.push_back(Image<T>(iset.getImage(i)));
00148 }
00149 
00150 // ######################################################################
00151 template <class T> template <class TT> inline
00152 ImageSet<T>& ImageSet<T>::operator=(const ImageSet<TT>& iset)
00153 {
00154   itsLevels.clear();
00155   for (uint i = 0; i < iset.size(); ++i)
00156     itsLevels.push_back(Image<T>(iset.getImage(i)));
00157   return *this;
00158 }
00159 
00160 // ######################################################################
00161 template <class T> inline
00162 void ImageSet<T>::swap(ImageSet<T>& that)
00163 {
00164   this->itsLevels.swap(that.itsLevels);
00165 }
00166 
00167 // ######################################################################
00168 template <class T> inline
00169 void ImageSet<T>::clear()
00170 {
00171   // Reset to an empty vector of given size by swapping with a temp vector
00172   std::deque< Image<T> >(itsLevels.size()).swap(itsLevels);
00173 }
00174 
00175 // ######################################################################
00176 template <class T> inline
00177 void ImageSet<T>::reset(uint newDepth)
00178 {
00179   // Reset to an empty vector of given size by swapping with a temp vector
00180   std::deque< Image<T> >(newDepth).swap(itsLevels);
00181 }
00182 
00183 // ######################################################################
00184 template <class T> inline
00185 uint ImageSet<T>::size() const { return itsLevels.size(); }
00186 
00187 // ######################################################################
00188 template <class T> inline
00189 const Image<T>& ImageSet<T>::getImage(const uint lev) const
00190 {
00191   ASSERT(lev < itsLevels.size());
00192   return itsLevels[lev];
00193 }
00194 
00195 // ######################################################################
00196 template <class T> inline
00197 const Image<T>& ImageSet<T>::operator[](const uint lev) const
00198 { return getImage(lev); }
00199 
00200 // ######################################################################
00201 template <class T> inline
00202 Image<T>& ImageSet<T>::getImageMut(const uint lev)
00203 {
00204   ASSERT(lev < itsLevels.size());
00205   return itsLevels[lev];
00206 }
00207 
00208 // ######################################################################
00209 template <class T> inline
00210 Image<T>& ImageSet<T>::operator[](const uint lev)
00211 { return getImageMut(lev); }
00212 
00213 // ######################################################################
00214 template <class T> inline
00215 void ImageSet<T>::push_back(const Image<T>& img)
00216 {
00217   itsLevels.push_back(img);
00218 }
00219 
00220 // ######################################################################
00221 template <class T> inline
00222 void ImageSet<T>::push_front(const Image<T>& img)
00223 {
00224   itsLevels.push_front(img);
00225 }
00226 
00227 // ######################################################################
00228 template <class T> inline
00229 Image<T> ImageSet<T>::pop_back()
00230 {
00231   ASSERT(isNonEmpty());
00232   Image<T> tmp = itsLevels.back();
00233   itsLevels.pop_back();
00234   return tmp;
00235 }
00236 
00237 // ######################################################################
00238 template <class T> inline
00239 Image<T> ImageSet<T>::pop_front()
00240 {
00241   ASSERT(isNonEmpty());
00242   Image<T> tmp = itsLevels.front();
00243   itsLevels.pop_front();
00244   return tmp;
00245 }
00246 
00247 // ######################################################################
00248 template <class T> inline
00249 Image<T> ImageSet<T>::front() const
00250 {
00251   ASSERT(isNonEmpty());
00252   return itsLevels.front();
00253 }
00254 
00255 // ######################################################################
00256 template <class T> inline
00257 Image<T> ImageSet<T>::back() const
00258 {
00259   ASSERT(isNonEmpty());
00260   return itsLevels.back();
00261 }
00262 
00263 // ######################################################################
00264 template <class T> inline
00265 bool ImageSet<T>::isEmpty() const { return !isNonEmpty(); }
00266 
00267 // ######################################################################
00268 template <class T> inline
00269 bool ImageSet<T>::isNonEmpty() const
00270 {
00271   for (uint i = 0; i < itsLevels.size(); ++i)
00272     if (itsLevels[i].initialized()) return true;
00273 
00274   return false;
00275 }
00276 
00277 // ######################################################################
00278 template <class T> inline
00279 ImageSet<T> ImageSet<T>::subSet(const uint a, const uint b) const
00280 {
00281   ASSERT(b >= a);
00282   ASSERT(b <= this->size());
00283 
00284   ImageSet<T> result(b-a);
00285   for (uint i = a; i < b; ++i)
00286     result.itsLevels[i-a] = this->itsLevels[i];
00287 
00288   return result;
00289 }
00290 
00291 #endif // !IMAGESET_H_DEFINED
00292 
00293 // ######################################################################
00294 /* So things look consistent in everyone's emacs... */
00295 /* Local Variables: */
00296 /* indent-tabs-mode: nil */
00297 /* End: */
Generated on Sun May 8 08:40:54 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3