00001 /*!@file Image/DrawOps.C functions for drawing on images 00002 */ 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2002 // 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; filed July 23, 2001, following provisional applications // 00013 // No. 60/274,674 filed March 8, 2001 and 60/288,724 filed May 4, 2001).// 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: Dirk Walther <walther@caltech.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CUDA/CudaDrawOps.C $ 00035 // $Id: CudaDrawOps.C 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 #include "CUDA/CudaDrawOps.H" 00039 #include "CUDA/CudaImage.H" 00040 #include "Image/Rectangle.H" 00041 #include "CUDA/cudadefs.h" 00042 #include "Util/Assert.H" 00043 #include "Util/sformat.H" 00044 #include "rutz/trace.h" 00045 #include <cmath> 00046 00047 00048 void cudaDrawFilledRect(CudaImage<float> &dst, const Rectangle& r, const float color) 00049 { 00050 ASSERT(dst.initialized()); 00051 const MemoryPolicy mp = dst.getMemoryPolicy(); 00052 int dev = dst.getMemoryDevice(); 00053 const int w=dst.getWidth(); 00054 const int h=dst.getHeight(); 00055 ASSERT(mp != HOST_MEMORY); 00056 Dims tile = CudaDevices::getDeviceTileSize1D(dev); 00057 int tile_width, tile_height; 00058 tile_width = tile_height = 1; 00059 if(r.width() > r.height()) 00060 tile_width = tile.sz(); 00061 else 00062 tile_height = tile.sz(); 00063 cuda_c_drawFilledRect(dst.getCudaArrayPtr(),r.top(),r.left(),r.bottomI(),r.rightI(),color,w,h,tile_width,tile_height); 00064 } 00065 00066 void cudaDrawFilledRect(CudaImage<PixRGB<float> > &dst, const Rectangle& r, const PixRGB<float> color) 00067 { 00068 ASSERT(dst.initialized()); 00069 00070 const MemoryPolicy mp = dst.getMemoryPolicy(); 00071 int dev = dst.getMemoryDevice(); 00072 const int w=dst.getWidth(); 00073 const int h=dst.getHeight(); 00074 ASSERT(mp != HOST_MEMORY); 00075 Dims tile = CudaDevices::getDeviceTileSize1D(dev); 00076 int tile_width, tile_height; 00077 tile_width = tile_height = 1; 00078 if(r.width() > r.height()) 00079 tile_width = tile.sz(); 00080 else 00081 tile_height = tile.sz(); 00082 cuda_c_drawFilledRectRGB((float3_t *) dst.getCudaArrayPtr(),r.top(),r.left(),r.bottomI(),r.rightI(),(float3_t *)&color,w,h,tile_width,tile_height); 00083 00084 } 00085 00086 00087 00088 // ###################################################################### 00089 template <class T> void cudaDrawRect(CudaImage<T>& dst, const Rectangle& r, const T color, const int rad) 00090 { 00091 ASSERT(dst.initialized()); 00092 ASSERT(r.isValid()); 00093 ASSERT(dst.rectangleOk(r)); 00094 00095 int w=dst.getWidth(); 00096 int h=dst.getHeight(); 00097 int topB,topE,botB,botE,leftB,leftE,rightB,rightE; 00098 00099 topB = std::max(r.top()-rad,0); 00100 topE = std::min(r.top()+rad,h-1); 00101 botB = std::max(r.bottomI()-rad,0); 00102 botE = std::min(r.bottomI()+rad,h-1); 00103 leftB = std::max(r.left()-rad,0); 00104 leftE = std::min(r.left()+rad,w-1); 00105 rightB = std::max(r.rightI()-rad,0); 00106 rightE = std::min(r.rightI()+rad,w-1); 00107 // Top Line 00108 cudaDrawFilledRect(dst,Rectangle::tlbrI(topB,r.left(),topE,r.rightI()),color); 00109 // Bottom Line 00110 cudaDrawFilledRect(dst,Rectangle::tlbrI(botB,r.left(),botE,r.rightI()),color); 00111 // Left Line 00112 cudaDrawFilledRect(dst,Rectangle::tlbrI(topB,leftB,botE,leftE),color); 00113 // Right Line 00114 cudaDrawFilledRect(dst,Rectangle::tlbrI(topB,rightB,botE,rightE),color); 00115 00116 } 00117 00118 template void cudaDrawRect(CudaImage<PixRGB<float> >& dst, const Rectangle& r, const PixRGB<float> color, const int rad); 00119 template void cudaDrawRect(CudaImage<float>& dst, const Rectangle& r, const float color, const int rad); 00120 00121 // ###################################################################### 00122 /* So things look consistent in everyone's emacs... */ 00123 /* Local Variables: */ 00124 /* indent-tabs-mode: nil */ 00125 /* End: */