PyramidCache.C

Go to the documentation of this file.
00001 /*!@file Image/PyramidCache.C */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/PyramidCache.C $
00035 // $Id: PyramidCache.C 8199 2007-03-30 17:58:46Z rjpeters $
00036 //
00037 
00038 #ifndef IMAGE_PYRAMIDCACHE_C_DEFINED
00039 #define IMAGE_PYRAMIDCACHE_C_DEFINED
00040 
00041 #include "Image/PyramidCache.H"
00042 
00043 #include "rutz/mutex.h"
00044 
00045 // ######################################################################
00046 template <class T>
00047 PyramidCache<T>::PyramidCache()
00048   :
00049   gaussian5(),
00050   laplacian9()
00051 {}
00052 
00053 // ######################################################################
00054 template <class T>
00055 PyramidCache<T>::Item::Item()
00056   : itsImg(), itsPyr()
00057 {
00058   pthread_mutex_init(&itsLock, NULL);
00059 }
00060 
00061 // ######################################################################
00062 template <class T>
00063 PyramidCache<T>::Item::~Item()
00064 {
00065   pthread_mutex_destroy(&itsLock);
00066 }
00067 
00068 // ######################################################################
00069 template <class T>
00070 bool PyramidCache<T>::Item::beginSet(const Image<T>& img,
00071                                      rutz::mutex_lock_class* l)
00072 {
00073   ASSERT(!l->is_locked());
00074 
00075   rutz::mutex_lock_class l2(&itsLock);
00076 
00077   if (itsPyr.size() != 0 && itsImg.hasSameData(img))
00078     // we already have a pyramid cached for this image, so there is no
00079     // need for the caller to regenerate it:
00080     return false;
00081 
00082   // ok, we don't have a cached pyramid for the given image, so pass
00083   // the lock to the caller and let them regenerate it
00084   l->swap(l2);
00085   ASSERT(l->is_locked());
00086   return true;
00087 }
00088 
00089 // ######################################################################
00090 template <class T>
00091 void PyramidCache<T>::Item::endSet(const Image<T>& img, const ImageSet<T>& pyr,
00092                                    rutz::mutex_lock_class* l)
00093 {
00094   ASSERT(l->is_locked());
00095 
00096   itsImg = img;
00097   itsPyr = pyr;
00098 
00099   // release the lock:
00100   {
00101     rutz::mutex_lock_class l2;
00102     l2.swap(*l);
00103     l2.unlock();
00104   }
00105 
00106   ASSERT(!l->is_locked());
00107 }
00108 
00109 // ######################################################################
00110 template <class T>
00111 const ImageSet<T>* PyramidCache<T>::Item::get(const Image<T>& img) const
00112 {
00113   GVX_MUTEX_LOCK(&itsLock);
00114 
00115   if (itsPyr.size() == 0 || !itsImg.hasSameData(img))
00116     return 0;
00117 
00118   return &itsPyr;
00119 }
00120 
00121 // ######################################################################
00122 // Explicit instantiations:
00123 
00124 template class PyramidCache<PixRGB<byte> >;
00125 template class PyramidCache<PixRGB<float> >;
00126 template class PyramidCache<byte>;
00127 template class PyramidCache<float>;
00128 template class PyramidCache<int>;
00129 
00130 // ######################################################################
00131 /* So things look consistent in everyone's emacs... */
00132 /* Local Variables: */
00133 /* mode: c++ */
00134 /* indent-tabs-mode: nil */
00135 /* End: */
00136 
00137 #endif // IMAGE_PYRAMIDCACHE_C_DEFINED
Generated on Sun May 8 08:40:56 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3