CudaFramework.C

Go to the documentation of this file.
00001 /*!@file CUDA/CudaFramework.C  Framework for specifying layout of images  */
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:
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/CUDA/CudaFramework.C $
00035 // $Id: CudaFramework.C 12962 2010-03-06 02:13:53Z irock $
00036 //
00037 
00038 #include "CudaFramework.H"
00039 #include <stdio.h>
00040 #include <stdlib.h>
00041 #include <string.h>
00042 #include <pthread.h>
00043 #include <errno.h>
00044 #include <GL/glew.h>
00045 #include <cuda_gl_interop.h>
00046 #include "CUDA/CudaImage.H"
00047 #include "CUDA/CudaImageSet.H"
00048 #include "Image/Pixels.H"
00049 #include "Image/MathOps.H"
00050 #if defined(__APPLE__) || defined(MACOSX)
00051 #include <GLUT/glut.h>
00052 #else
00053 #include <GL/glut.h>
00054 #endif
00055 #include "CudaImageDisplay.h"
00056 #include <unistd.h>
00057 #include "Raster/Raster.H"
00058 #include "Raster/PngWriter.H"
00059 #include "CUDA/CudaCutPaste.H"
00060 #include "Component/ModelManager.H"
00061 #include "CUDA/CudaSaliency.H"
00062 #include "Image/SimpleFont.H"
00063 #include "Image/DrawOps.H"
00064 #include "Raster/Raster.H"
00065 #include "Raster/GenericFrame.H"
00066 #include "Media/FrameSeries.H"
00067 #include "CUDA/CudaDrawOps.H"
00068 #include "CUDA/CudaShapeOps.H"
00069 
00070 
00071 // ######################################################################
00072 CudaFramework::CudaFramework()
00073 {
00074   canvasModified = true;
00075 }
00076 
00077 
00078 // ######################################################################
00079 CudaFramework::~CudaFramework()
00080 {
00081 }
00082 
00083 
00084 // ######################################################################
00085 int CudaFramework::getW()
00086 {
00087   return w;
00088 }
00089 
00090 
00091 // ######################################################################
00092 int CudaFramework::getH()
00093 {
00094   return h;
00095 }
00096 
00097 
00098 // ######################################################################
00099 int CudaFramework::getCanvasW()
00100 {
00101   return canvas_image.getWidth();
00102 }
00103 
00104 
00105 // ######################################################################
00106 int CudaFramework::getCanvasH()
00107 {
00108   return canvas_image.getHeight();
00109 }
00110 
00111 
00112 // ######################################################################
00113 CudaImage<PixRGB<float> >& CudaFramework::getCanvas()
00114 {
00115   return canvas_image;
00116 }
00117 
00118 
00119 // ######################################################################
00120 Point2D<int> CudaFramework::getPoint(int index)
00121 {
00122   return point_list[index];
00123 }
00124 
00125 // ######################################################################
00126 int CudaFramework::getDev()
00127 {
00128   return dev1;
00129 }
00130 
00131 
00132 // ######################################################################
00133 MemoryPolicy CudaFramework::getMP()
00134 {
00135   return mp1;
00136 }
00137 
00138 
00139 // ######################################################################
00140 int CudaFramework::getLockAtt()
00141 {
00142 return  pthread_mutex_trylock(&canvas_lock);
00143 }
00144 
00145 
00146 // ######################################################################
00147 bool CudaFramework::getCanvasModified()
00148 {
00149   return canvasModified;
00150 }
00151 
00152 
00153 // ######################################################################
00154 void CudaFramework::setMutexDestroy()
00155 {
00156  pthread_mutex_destroy(&canvas_lock);
00157 }
00158 
00159 
00160 // ######################################################################
00161 void CudaFramework::setMutexUnlock()
00162 {
00163  pthread_mutex_unlock(&canvas_lock);
00164 }
00165 
00166 
00167 // ######################################################################
00168 void CudaFramework::setCanvasModified(bool new_state)
00169 {
00170   canvasModified = new_state;
00171 }
00172 
00173 
00174 // ######################################################################
00175 void CudaFramework::setPoint(int index,Point2D<int> pt)
00176 {
00177   point_list[index] = pt;
00178 }
00179 
00180 
00181 // ######################################################################
00182 void CudaFramework::setDev(int dev)
00183 {
00184   dev1 = dev;
00185 }
00186 
00187 
00188 // ######################################################################
00189 void CudaFramework::setMP(MemoryPolicy mp)
00190 {
00191   mp1 = mp;
00192 }
00193 
00194 
00195 // ######################################################################
00196 void CudaFramework::setW(int W)
00197 {
00198   w = W;
00199 }
00200 
00201 
00202 // ######################################################################
00203 void CudaFramework::setH(int H)
00204 {
00205   h = H;
00206 }
00207 
00208 
00209 // ######################################################################
00210 void CudaFramework::updateCanvas(int index, CudaImage<PixRGB<float> > &src)
00211 {
00212   pthread_mutex_lock(&canvas_lock);
00213   cudaInplacePaste(canvas_image,src,point_list[index]);
00214   canvasModified=true;
00215   pthread_mutex_unlock(&canvas_lock);
00216 }
00217 
00218 
00219 // ######################################################################
00220 void CudaFramework::startFramework(int W,int H,int dev,MemoryPolicy mp)
00221 {
00222   //Initialise
00223   w = W;
00224   h = H;
00225   dev1 = dev;
00226   mp1 = mp;
00227   canvas_image  = CudaImage<PixRGB<float> >(w,h,ZEROS, mp1, dev1);
00228   pthread_mutex_init(&canvas_lock, 0);
00229 }
00230 
00231 // ######################################################################
00232 void CudaFramework::drawRectangle_centrepoint(Point2D<int> max_point, const PixRGB<float> color,const int w,const int h, const int rad)
00233 { //Centering around max point
00234   pthread_mutex_lock(&canvas_lock);
00235   Point2D<int> centre_point;
00236 
00237   centre_point.i = max_point.i - w/2;
00238   centre_point.j = max_point.j - h/2;
00239   if(centre_point.i <0 )
00240     centre_point.i = 0;
00241   if(centre_point.j <0 )
00242     centre_point.j = 0;
00243 
00244   cudaDrawRect(canvas_image,Rectangle::Rectangle(centre_point,(Dims::Dims(w,h))),color,rad);
00245   canvasModified=true;
00246   pthread_mutex_unlock(&canvas_lock);
00247 
00248 }
00249 // ######################################################################
00250 void CudaFramework::drawRectangle_topleftpoint(Point2D<int> max_point, const PixRGB<float> color,const int w,const int h, const int rad)
00251 { //Centering around max point
00252   pthread_mutex_lock(&canvas_lock);
00253   cudaDrawRect(canvas_image,Rectangle::Rectangle(max_point,(Dims::Dims(w,h))),color,rad);
00254   canvasModified=true;
00255   pthread_mutex_unlock(&canvas_lock);
00256 
00257 }
00258 // ######################################################################
00259 
00260 void CudaFramework::setText(const char* text,Point2D<int> text_coord,const PixRGB<float> color,const PixRGB<float> bgcolor,const SimpleFont& f,bool transparent_background)
00261 {
00262   pthread_mutex_lock(&canvas_lock);
00263   writeText(text_patch,Point2D<int>(0,0),text,color,bgcolor,f,transparent_background);
00264   text_patch_cuda = CudaImage<PixRGB<float> >(text_patch,mp1,dev1);
00265   cudaInplacePaste(canvas_image,text_patch_cuda,text_coord);
00266   canvasModified=true;
00267   pthread_mutex_unlock(&canvas_lock);
00268 }
00269 
00270 //######################################################################
00271 void CudaFramework::initTextLayer(int w,int h)
00272 {
00273   text_patch = Image<PixRGB<float> >(w,h,NO_INIT);
00274 }
00275 //######################################################################
Generated on Sun May 8 08:04:43 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3