CudaImageSet.H

Go to the documentation of this file.
00001 /*!@file CUDA/CudaImageSet.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/CUDA/CudaImageSet.H $
00035 // $Id: CudaImageSet.H 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #ifndef CUDAIMAGESET_H_DEFINED
00039 #define CUDAIMAGESET_H_DEFINED
00040 
00041 #include "CUDA/CudaImage.H"
00042 #include "Image/ImageSet.H"
00043 #include "Image/Pixels.H"
00044 #include "Util/Assert.H"
00045 
00046 #include <deque>
00047 
00048 // ######################################################################
00049 //! This class implements a set of images, often used as a dyadic pyramid.
00050 template <class T>
00051 class CudaImageSet
00052 {
00053 public:
00054   //! Construct with a given number of empty images.
00055   inline CudaImageSet(const uint n=0);
00056 
00057   //! Construct with a given number of images of the given size.
00058   inline CudaImageSet(const uint n, const Dims& dims, const MemoryPolicy mp, const int dev);
00059 
00060   //! Construct with a given number of images, size and type of initialization
00061   inline CudaImageSet(const uint n, const Dims& dims, const InitPolicy init, const MemoryPolicy mp, const int dev);
00062 
00063   inline CudaImageSet(const ImageSet<T>& cp, const MemoryPolicy mp, const int dev);
00064 
00065   // default desructor OK
00066 
00067   //! Copy Constructor
00068   inline CudaImageSet(const CudaImageSet<T>& cp);
00069 
00070   //! Copy Constructor with different memory location
00071   inline CudaImageSet(const CudaImageSet<T>& cp, const MemoryPolicy mp, const int dev);
00072 
00073   //! Swap contents with another ImageSet
00074   inline void swap(CudaImageSet<T>& that);
00075 
00076   //! Keep the same number of images, but make all images empty (0-by-0 size).
00077   /*! This returns the ImageSet to a state where isEmpty() is true. */
00078   inline void clear();
00079 
00080   //! Reset to a new number of images, all images will be empty (0-by-0 size).
00081   inline void reset(uint newDepth = 0);
00082 
00083   //! Return number of images in image set.
00084   inline uint size() const;
00085 
00086   //! Get image from a given level.
00087   inline const CudaImage<T>& getImage(const uint lev) const;
00088 
00089   //! Get image from a given level (shorthand for getImage()).
00090   inline const CudaImage<T>& operator[](const uint lev) const;
00091 
00092   //! Get mutable image from a given level.
00093   inline CudaImage<T>& getImageMut(const uint lev);
00094 
00095   //! Get mutable image from a given level (shorthand for getImageMut()).
00096   inline CudaImage<T>& operator[](const uint lev);
00097 
00098   //! push an image to the back of the set
00099   inline void push_back(CudaImage<T>& img);
00100 
00101   //! push an image to the front of the set
00102   inline void push_front(CudaImage<T>& img);
00103 
00104   //! return the last image in the set and pop it off
00105   inline CudaImage<T> pop_back();
00106 
00107   //! return the first image in the set and pop it off
00108   inline CudaImage<T> pop_front();
00109 
00110   //! return the last image in the set (without popping it off)
00111   inline CudaImage<T> front() const;
00112 
00113   //! return the first image in the set (without popping it off)
00114   inline CudaImage<T> back() const;
00115 
00116   //! Return true if the pyramid has no non-empty images (width*height > 0).
00117   inline bool isEmpty() const;
00118 
00119   //! Return true if the pyramid has any non-empty images (width*height > 0).
00120   inline bool isNonEmpty() const;
00121 
00122   //! Return a new ImageSet with images in the half-open range [a,b[
00123   inline CudaImageSet<T> subSet(const uint a, const uint b) const;
00124 
00125 private:
00126   std::deque< CudaImage<T> > itsLevels;
00127 };
00128 
00129 
00130 
00131 // ######################################################################
00132 // ######################################################################
00133 // ##### INLINED FUNCTIONS:
00134 // ######################################################################
00135 // ######################################################################
00136 
00137 // ######################################################################
00138 template <class T> inline
00139 CudaImageSet<T>::CudaImageSet(const uint n)
00140   : itsLevels(n, CudaImage<T>())
00141 {}
00142 
00143 // ######################################################################
00144 template <class T> inline
00145 CudaImageSet<T>::CudaImageSet(const uint n, const Dims& dims, const MemoryPolicy mp, const int dev)
00146 : itsLevels(n, CudaImage<T>(dims,mp,dev))
00147 {}
00148 
00149 // ######################################################################
00150 template <class T> inline
00151 CudaImageSet<T>::CudaImageSet(const ImageSet<T>& cp, const MemoryPolicy mp, const int dev)
00152   : itsLevels(cp.size())
00153 {
00154   for (uint i = 0; i < cp.size(); ++i)
00155     this->itsLevels[i] = CudaImage<T>(cp[i],mp,dev);
00156 }
00157 
00158 
00159 // ######################################################################
00160 template <class T> inline
00161 CudaImageSet<T>::CudaImageSet(const uint n, const Dims& dims, const InitPolicy init, const MemoryPolicy mp, const int dev)
00162 : itsLevels(n, CudaImage<T>(dims,init,mp,dev))
00163 {}
00164 
00165 // ######################################################################
00166 template <class T> inline
00167 CudaImageSet<T>::CudaImageSet(const CudaImageSet<T>& cp)
00168 : itsLevels(cp.size())
00169 {
00170   for (uint i = 0; i < cp.size(); ++i)
00171     this->itsLevels[i] = CudaImage<T>(cp.itsLevels[i]);
00172 }
00173 
00174 // ######################################################################
00175 template <class T> inline
00176 CudaImageSet<T>::CudaImageSet(const CudaImageSet<T>& cp, const MemoryPolicy mp, const int dev)
00177 : itsLevels(cp.size())
00178 {
00179   for (uint i = 0; i < cp.size(); ++i)
00180     this->itsLevels[i] = CudaImage<T>(cp.itsLevels[i],mp,dev);
00181 }
00182 
00183 // ######################################################################
00184 template <class T> inline
00185 void CudaImageSet<T>::swap(CudaImageSet<T>& that)
00186 {
00187   this->itsLevels.swap(that.itsLevels);
00188 }
00189 
00190 // ######################################################################
00191 template <class T> inline
00192 void CudaImageSet<T>::clear()
00193 {
00194   // Reset to an empty vector of given size by swapping with a temp vector
00195   std::deque< CudaImage<T> >(itsLevels.size()).swap(itsLevels);
00196 }
00197 
00198 // ######################################################################
00199 template <class T> inline
00200 void CudaImageSet<T>::reset(uint newDepth)
00201 {
00202   // Reset to an empty vector of given size by swapping with a temp vector
00203   std::deque< CudaImage<T> >(newDepth).swap(itsLevels);
00204 }
00205 
00206 // ######################################################################
00207 template <class T> inline
00208 uint CudaImageSet<T>::size() const { return itsLevels.size(); }
00209 
00210 // ######################################################################
00211 template <class T> inline
00212 const CudaImage<T>& CudaImageSet<T>::getImage(const uint lev) const
00213 {
00214   ASSERT(lev < itsLevels.size());
00215   return itsLevels[lev];
00216 }
00217 
00218 // ######################################################################
00219 template <class T> inline
00220 const CudaImage<T>& CudaImageSet<T>::operator[](const uint lev) const
00221 { return getImage(lev); }
00222 
00223 // ######################################################################
00224 template <class T> inline
00225 CudaImage<T>& CudaImageSet<T>::getImageMut(const uint lev)
00226 {
00227   ASSERT(lev < itsLevels.size());
00228   return itsLevels[lev];
00229 }
00230 
00231 // ######################################################################
00232 template <class T> inline
00233 CudaImage<T>& CudaImageSet<T>::operator[](const uint lev)
00234 { return getImageMut(lev); }
00235 
00236 // ######################################################################
00237 template <class T> inline
00238 void CudaImageSet<T>::push_back(CudaImage<T>& img)
00239 {
00240   itsLevels.push_back(img);
00241 }
00242 
00243 // ######################################################################
00244 template <class T> inline
00245 void CudaImageSet<T>::push_front(CudaImage<T>& img)
00246 {
00247   itsLevels.push_front(img);
00248 }
00249 
00250 // ######################################################################
00251 template <class T> inline
00252 CudaImage<T> CudaImageSet<T>::pop_back()
00253 {
00254   ASSERT(isNonEmpty());
00255   CudaImage<T> tmp = itsLevels.back();
00256   itsLevels.pop_back();
00257   return tmp;
00258 }
00259 
00260 // ######################################################################
00261 template <class T> inline
00262 CudaImage<T> CudaImageSet<T>::pop_front()
00263 {
00264   ASSERT(isNonEmpty());
00265   CudaImage<T> tmp = itsLevels.front();
00266   itsLevels.pop_front();
00267   return tmp;
00268 }
00269 
00270 // ######################################################################
00271 template <class T> inline
00272 CudaImage<T> CudaImageSet<T>::front() const
00273 {
00274   ASSERT(isNonEmpty());
00275   return itsLevels.front();
00276 }
00277 
00278 // ######################################################################
00279 template <class T> inline
00280 CudaImage<T> CudaImageSet<T>::back() const
00281 {
00282   ASSERT(isNonEmpty());
00283   return itsLevels.back();
00284 }
00285 
00286 // ######################################################################
00287 template <class T> inline
00288 bool CudaImageSet<T>::isEmpty() const { return !isNonEmpty(); }
00289 
00290 // ######################################################################
00291 template <class T> inline
00292 bool CudaImageSet<T>::isNonEmpty() const
00293 {
00294   for (uint i = 0; i < itsLevels.size(); ++i)
00295     if (itsLevels[i].initialized()) return true;
00296 
00297   return false;
00298 }
00299 
00300 // ######################################################################
00301 template <class T> inline
00302 CudaImageSet<T> CudaImageSet<T>::subSet(const uint a, const uint b) const
00303 {
00304   ASSERT(b >= a);
00305   ASSERT(b <= this->size());
00306 
00307   CudaImageSet<T> result(b-a);
00308   for (uint i = a; i < b; ++i)
00309     result.itsLevels[i-a] = this->itsLevels[i];
00310 
00311   return result;
00312 }
00313 
00314 // Explicit Instantiations
00315 
00316 template class CudaImageSet<float>;
00317 
00318 #endif // !CUDAIMAGESET_H_DEFINED
00319 
00320 // ######################################################################
00321 /* So things look consistent in everyone's emacs... */
00322 /* Local Variables: */
00323 /* indent-tabs-mode: nil */
00324 /* End: */
Generated on Sun May 8 08:04:43 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3