CudaCutPaste.C

Go to the documentation of this file.
00001 /*!@file CUDA/CudaCutPaste.C Cut+paste operations from/to CudaImage subregions */
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: Rob Peters <rjpeters@klab.caltech.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CUDA/CudaCutPaste.C $
00035 // $Id: CudaCutPaste.C 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #include "CUDA/CudaCutPaste.H"
00039 #include "CUDA/CudaMathOps.H"
00040 #include "CUDA/CudaImage.H"
00041 #include "Image/Pixels.H"
00042 #include "Util/Assert.H"
00043 #include <algorithm>
00044 
00045 // ######################################################################
00046 CudaImage<float> cudaCrop(const CudaImage<float>& src, const Point2D<int>& pt, const Dims& dims,
00047               const bool zerofill)
00048 {
00049 
00050   if (pt == Point2D<int>(0,0) && dims == src.getDims())
00051     return src;
00052 
00053   const int dev = src.getMemoryDevice();
00054   const MemoryPolicy mp = src.getMemoryPolicy();
00055   ASSERT(mp != HOST_MEMORY);
00056   Dims tile = CudaDevices::getDeviceTileSize(dev);
00057 
00058   CudaImage<float> result(dims, NO_INIT,mp,dev);
00059 
00060   if(!zerofill)
00061     {
00062       ASSERT(src.coordsOk(pt));
00063       ASSERT(src.coordsOk(pt.i + dims.w() - 1, pt.j + dims.h() - 1));
00064     }
00065 
00066   int endX = pt.i+dims.w(); int maxX = std::min(endX,src.getWidth());
00067   int endY = pt.j+dims.h(); int maxY = std::min(endY,src.getHeight());
00068   cuda_c_crop(src.getCudaArrayPtr(),result.getCudaArrayPtr(),src.getWidth(),src.getHeight(),pt.i,pt.j,endX,endY,maxX,maxY,tile.w(),tile.h());
00069   return result;
00070 }
00071 
00072 // ######################################################################
00073 CudaImage<float> cudaCrop(const CudaImage<float>& src, const Rectangle& rect, const bool zerofill)
00074 {
00075   return cudaCrop(src,
00076               Point2D<int>(rect.left(), rect.top()),
00077               Dims(rect.width(), rect.height()),
00078               zerofill);
00079 }
00080 
00081 // ######################################################################
00082 CudaImage<float> cudaShiftImage(const CudaImage<float>& src, const float dx, const float dy)
00083 {
00084   // make sure the source image is valid
00085   ASSERT(src.initialized());
00086 
00087   // create and clear the return image
00088   Dims dim(src.getDims());
00089   const int dev = src.getMemoryDevice();
00090   const MemoryPolicy mp = src.getMemoryPolicy();
00091   CudaImage<float> result(dim, ZEROS,mp,dev);
00092   Dims tile = CudaDevices::getDeviceTileSize(dev);
00093   cuda_c_shiftImage(src.getCudaArrayPtr(),result.getCudaArrayPtr(),dim.w(),dim.h(),dx,dy,tile.w(),tile.h());
00094   return result;
00095 }
00096 
00097 
00098 
00099 // ######################################################################
00100 CudaImage<float> cudaShiftClean(const CudaImage<float>& src, const int dx, const int dy,
00101                     const float bgval)
00102 {
00103   // make sure the source image is valid
00104   ASSERT(src.initialized());
00105 
00106   // create and clear the return image
00107   int w = src.getWidth(), h = src.getHeight();
00108   const int dev = src.getMemoryDevice();
00109   const MemoryPolicy mp = src.getMemoryPolicy();
00110   Dims tile = CudaDevices::getDeviceTileSize(dev);
00111 
00112   CudaImage<float> result(w, h, NO_INIT, mp, dev); cudaClear(result,bgval);
00113 
00114   return result;
00115 
00116   // // find range of pixels to copy:
00117   // int startx = std::max(0, -dx), endx = std::min(w - 1, w - 1 - dx);
00118   // if (startx >= w || endx < 0) return retImg; // empty result
00119   // int starty = std::max(0, -dy), endy = std::min(h - 1, h - 1 - dy);
00120   // if (starty >= h || endy < 0) return retImg; // empty result
00121 
00122   // int dstx = std::max(0, std::min(w - 1, dx));
00123   // int dsty = std::max(0, std::min(h - 1, dy));
00124 
00125   // src += startx + starty * w;
00126   // dst += dstx + dsty * w;
00127 
00128   // int skip = w - endx + startx - 1;
00129 
00130   // // do the copy:
00131   // for (int j = starty; j <= endy; j ++)
00132   //   {
00133   //     for (int i = startx; i <= endx; i ++) *dst++ = *src++;
00134 
00135   //     // ready for next row of pixels:
00136   //     src += skip; dst += skip;
00137   //   }
00138 
00139 }
00140 
00141 
00142 
00143 void cudaInplacePaste(CudaImage<float>& dst,
00144                   const CudaImage<float>& img, const Point2D<int>& pos)
00145 {
00146   int w = dst.getWidth(), h = dst.getHeight();
00147   int iw = img.getWidth(), ih=img.getHeight();
00148 
00149   ASSERT(pos.i + iw <= w && pos.j + ih <= h);
00150   const int dev = dst.getMemoryDevice();
00151   Dims tile = CudaDevices::getDeviceTileSize(dev);
00152   cuda_c_inplacePaste(dst.getCudaArrayPtr(),img.getCudaArrayPtr(),w,h,iw,ih,pos.i,pos.j,tile.w(),tile.h());
00153 }
00154 
00155 void cudaInplacePaste(CudaImage<PixRGB<float> >& dst,
00156                       const CudaImage<PixRGB<float> >& img, const Point2D<int>& pos)
00157 {
00158   int w = dst.getWidth(), h = dst.getHeight();
00159   int iw = img.getWidth(), ih=img.getHeight();
00160 
00161   ASSERT(pos.i + iw <= w && pos.j + ih <= h);
00162   const int dev = dst.getMemoryDevice();
00163   Dims tile = CudaDevices::getDeviceTileSize(dev);
00164   cuda_c_inplacePasteRGB((float3_t *)dst.getCudaArrayPtr(),(float3_t *)img.getCudaArrayPtr(),w,h,iw,ih,pos.i,pos.j,tile.w(),tile.h());
00165 }
00166 
00167 
00168 void cudaInplaceOverlay(CudaImage<float>& dst, const CudaImage<float>& img, const Point2D<int>& pos)
00169 {
00170   int w = dst.getWidth(), h = dst.getHeight();
00171   int iw = img.getWidth(), ih=img.getHeight();
00172 
00173   ASSERT(pos.i + iw <= w && pos.j + ih <= h);
00174   const int dev = dst.getMemoryDevice();
00175   Dims tile = CudaDevices::getDeviceTileSize(dev);
00176   cuda_c_inplaceOverlay(dst.getCudaArrayPtr(),img.getCudaArrayPtr(),w,h,iw,ih,pos.i,pos.j,tile.w(),tile.h());
00177 }
00178 
00179 
00180 void cudaInplaceOverlay(CudaImage<PixRGB<float> >&dst, const CudaImage<PixRGB<float> >&img, const Point2D<int>& pos)
00181 {
00182   int w = dst.getWidth(), h = dst.getHeight();
00183   int iw = img.getWidth(), ih=img.getHeight();
00184 
00185   ASSERT(pos.i + iw <= w && pos.j + ih <= h);
00186   const int dev = dst.getMemoryDevice();
00187   Dims tile = CudaDevices::getDeviceTileSize(dev);
00188   cuda_c_inplaceOverlayRGB((float3_t *)dst.getCudaArrayPtr(),(float3_t *)img.getCudaArrayPtr(),w,h,iw,ih,pos.i,pos.j,tile.w(),tile.h());
00189 }
00190 
Generated on Sun May 8 08:04:43 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3