CudaPyrBuilder.C

Go to the documentation of this file.
00001 /*!@file CUDA/CudaPyrBuilder.C Classes for building CUDA based dyadic pyramids */
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/CudaPyrBuilder.C $
00035 // $Id: CudaPyrBuilder.C 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #include "CUDA/CudaPyrBuilder.H"
00039 
00040 #include "CUDA/CudaImage.H"
00041 #include "CUDA/CudaImageSet.H"
00042 #include "CUDA/CudaCutPaste.H"
00043 #include "Image/Pixels.H"
00044 #include "CUDA/CudaPyramidCache.H"
00045 #include "CUDA/CudaPyramidOps.H"
00046 #include "rutz/trace.h"
00047 
00048 
00049 // ######################################################################
00050 // ##### PyrBuilder functions:
00051 // ######################################################################
00052 
00053 // ######################################################################
00054 template <class T>
00055 CudaPyrBuilder<T>::CudaPyrBuilder()
00056 {
00057 
00058 }
00059 
00060 // ######################################################################
00061 template <class T>
00062 CudaPyrBuilder<T>::~CudaPyrBuilder()
00063 {
00064 
00065 }
00066 
00067 // ######################################################################
00068 template <class T>
00069 void CudaPyrBuilder<T>::reset()
00070 {
00071 
00072 }
00073 
00074 
00075 // ######################################################################
00076 // ##### ReichardtPyrBuilder Functions:
00077 // ######################################################################
00078 template <class T> CudaReichardtPyrBuilder<T>::CudaReichardtPyrBuilder() :
00079   CudaPyrBuilder<T>()
00080 {
00081 }
00082 
00083 template <class T> CudaReichardtPyrBuilder<T>::CudaReichardtPyrBuilder(const float dx,
00084                                             const float dy,
00085                                             const PyramidType typ,
00086                                             const float gabor_theta,
00087                                             const float intens) :
00088   CudaPyrBuilder<T>(), itsDX(dx), itsDY(dy), itsPtype(typ),
00089   itsGaborAngle(gabor_theta), itsGaborIntens(intens)
00090 {
00091 
00092 }
00093 
00094 template <class T> CudaImageSet<T> CudaReichardtPyrBuilder<T>::build(const CudaImage<T>& image,
00095                                           const int firstlevel,
00096                                           const int depth,
00097                                           CudaPyramidCache<T>* cache)
00098 {
00099   const CudaImageSet<T>* const cached =
00100     (cache != 0 && itsPtype == Gaussian5)
00101     ? cache->gaussian5.get(image) // may be null if there is no cached pyramid
00102     : 0;
00103 
00104   // create a pyramid with the input image
00105   CudaImageSet<T> upyr =
00106     cached != 0
00107     ? *cached
00108     : cudaBuildPyrGeneric(image, firstlevel, depth, itsPtype,
00109                       itsGaborAngle, itsGaborIntens);
00110   // create an empty pyramid
00111   CudaImageSet<T> spyr(depth);
00112 
00113   // fill the empty pyramid with the shifted version
00114   for (int i = firstlevel; i < depth; ++i)
00115     spyr[i] = cudaShiftImage(upyr[i], itsDX, itsDY);
00116 
00117   // store both pyramids in the deques
00118   unshifted.push_back(upyr);
00119   shifted.push_back(spyr);
00120 
00121   CudaImageSet<T> result(depth);
00122 
00123   // so, it's our first time? Pretend the pyramid before this was
00124   // the same as the current one ...
00125   if (unshifted.size() == 1)
00126     {
00127       unshifted.push_back(upyr);
00128       shifted.push_back(spyr);
00129     }
00130 
00131   // need to pop off old pyramid?
00132   if (unshifted.size() == 3)
00133     {
00134       unshifted.pop_front();
00135       shifted.pop_front();
00136     }
00137 
00138   // compute the Reichardt maps
00139   for (int i = firstlevel; i < depth; ++i)
00140     {
00141       result[i] =
00142         (unshifted.back()[i] * shifted.front()[i]) -
00143         (unshifted.front()[i] * shifted.back()[i]);
00144     }
00145 
00146   return result;
00147 }
00148 
00149 // ######################################################################
00150 template <class T> CudaReichardtPyrBuilder<T>* CudaReichardtPyrBuilder<T>::clone() const
00151 {
00152   return new CudaReichardtPyrBuilder<T>(*this);
00153 }
00154 
00155 // ######################################################################
00156 template <class T> void CudaReichardtPyrBuilder<T>::reset()
00157 {
00158   shifted.clear();
00159   unshifted.clear();
00160 }
00161 
00162 // ######################################################################
00163 // ##### Instantiations
00164 // ######################################################################
00165 
00166 #define INSTANTIATE(T) \
00167 template class CudaPyrBuilder< T >; \
00168 template class CudaReichardtPyrBuilder< T >; \
00169 
00170 INSTANTIATE(float);
Generated on Sun May 8 08:40:36 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3