parallel-color-search.C

00001 /*!@file AppPsycho/parallel-color-search.c Psychophysics main application for indexing experiment */
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 //
00035 // 2008-4-24 16:14:27Z nnoori $
00036 //written by Nader Noori
00037 
00038 //
00039 #ifndef INVT_HAVE_LIBSDL_IMAGE
00040 
00041 #include <cstdio>
00042 int main()
00043 {
00044         fprintf(stderr, "The SDL_image library must be installed to use this program\n");
00045         return 1;
00046 }
00047 
00048 #else
00049 
00050 
00051 
00052 /*
00053 Attention: SDL_image is needed for linking
00054 
00055 */
00056 
00057 #include "Component/ModelManager.H"
00058 #include "Image/Image.H"
00059 #include "Psycho/PsychoDisplay.H"
00060 #include "Psycho/EyeTrackerConfigurator.H"
00061 #include "Psycho/EyeTracker.H"
00062 #include "Psycho/PsychoOpts.H"
00063 #include "Component/EventLog.H"
00064 #include "Component/ComponentOpts.H"
00065 #include "Raster/Raster.H"
00066 #include "Util/MathFunctions.H"
00067 #include "Util/Types.H"
00068 #include <iostream>
00069 #include <fstream>
00070 #include <SDL/SDL.h>
00071 #include <SDL/SDL_image.h>
00072 #include <stdio.h>
00073 #include <stdlib.h>
00074 #include <map>
00075 #include <time.h>
00076 #include <sstream>
00077 #include "basic-graphics.H"
00078 #include "AppPsycho/psycho-skin-mapgenerator.h"
00079 
00080 
00081  using namespace std;
00082 
00083 SDL_Surface* drawTheBoard(Matrix& bmap,map<int,Uint32>& colorMap , uint w , uint h ){
00084 
00085         SDL_Surface* surface = getABlankSurface(w,h) ;
00086         uint nr = (uint)bmap.getNumOfRows() ;
00087         uint nc = (uint) bmap.getNumOfColumns() ;
00088         uint pw = w / ( 2* nc +1);
00089         uint ph = h / (2 * nr +1) ;
00090         uint offX = (w - pw*(2*nc-1))/2 ;
00091         uint offY = (h - ph*(2*nr-1))/2 ;
00092         for( uint r = 0 ; r < nr ; r++){
00093                 for( uint c = 0 ; c < nc ; c++){
00094                         fillRectangle(surface,colorMap[bmap.get(r,c)],offX+ (2*c )*pw,offY+ (2*r)*ph  ,pw,ph) ;
00095 
00096                 }
00097         }
00098         return surface ;
00099 }
00100 
00101 extern "C" int main(int argc, char* argv[] ){
00102 
00103         ModelManager manager("Psycho Skin");
00104         nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00105 
00106         MYLOGVERB = LOG_INFO;  // suppress debug messages
00107 
00108         manager.addSubComponent(d);
00109         nub::soft_ref<EventLog> el(new EventLog(manager));
00110         manager.addSubComponent(el);
00111         d->setEventLog(el);
00112         // Parse command-line:
00113         if (manager.parseCommandLine(argc, argv,"<logfilename>", 1 , 3)==false)
00114                 return(1);
00115         manager.setOptionValString(&OPT_EventLogFileName,manager.getExtraArg(2).c_str() );
00116         manager.start();
00117 
00118         SDL_Rect offset;
00119         SDL_Rect targetOffset ;
00120         targetOffset.x = (d->getWidth()-(d->getWidth())/10)/2 ;;
00121         targetOffset.y = (d->getHeight() - (d->getHeight())/10)/2 ;
00122         offset.x = 0 ;
00123         offset.y = 0 ;
00124         int k = -1 ;
00125         map<int,Uint32>* cm = new map<int , Uint32>() ;
00126         for( int i = 1 ; i <=10; i++){
00127                         (*cm)[i] = d->getUint32color(PixRGB<byte>(0, 255-12.5*i, 0));
00128                 }
00129 
00130         do{
00131                 d->clearScreen() ;
00132                 srand ( time(NULL) );
00133                 uint displacement = rand()%220 + 35 ;
00134                 Matrix* bm = getARandomMap(30,30,5) ;
00135                 Matrix* tm = getARandomMap(1,2,2) ;
00136                 tm->set(0,0,12);
00137                 tm->set(0,1,13);
00138                 (*cm)[11] = d->getUint32color(PixRGB<byte>(displacement,20,displacement)) ;
00139                 (*cm)[12] = d->getUint32color(PixRGB<byte>(displacement,20,0)) ;
00140                 (*cm)[13] = d->getUint32color(PixRGB<byte>(0,20,displacement)) ;
00141 
00142                 SDL_Surface* target = drawTheBoard(*tm,*cm,(d->getWidth())/10,(d->getHeight())/10) ;
00143 
00144                 uint distractorNum = rand()%15 ;
00145 
00146                 for(uint i = 0 ; i < distractorNum ; i++){
00147                         (*bm).set(rand()%(bm->getNumOfRows())+1,rand() % bm->getNumOfColumns()+1,11) ;
00148                 }
00149                 int targetFlag = rand()%3 ;
00150                 switch( targetFlag ){
00151                         case 0 : (*bm).set(rand()%(bm->getNumOfRows())+1,rand() % bm->getNumOfColumns()+1,12) ; break ;
00152                         case 1 : (*bm).set(rand()%(bm->getNumOfRows())+1,rand() % bm->getNumOfColumns()+1,13) ; break ;
00153                         default : break ;
00154                 }
00155 
00156                 SDL_Surface* board = drawTheBoard(*bm,*cm,d->getWidth(),d->getHeight());
00157 
00158                 d->pushEvent("started showing target image");
00159                 d->displaySDLSurfacePatch( target , &targetOffset ,NULL , -2,false, true);
00160                 d->waitFrames(5);
00161                 d->clearScreen();
00162                 /*we let's delay showing the board after the target*/
00163                 d->pushEvent("started showing blink");
00164                 d->displayFixationBlink(-1, -1, 3, 2);
00165                 d->pushEvent("displaying the test image");
00166                 d->displaySDLSurfacePatch(board , &offset,NULL , -2,false, true);
00167 
00168                 delete bm ;
00169                 delete tm ;
00170                 k = d->waitForKey() ;
00171                 dumpSurface(board) ;
00172                 dumpSurface(target);
00173 
00174         }while(k!=32);
00175         delete cm ;
00176         manager.stop();
00177         return 0 ;
00178 }
00179 
00180 
00181 #endif // INVT_HAVE_LIBSDL_IMAGE
00182 
00183 
Generated on Sun May 8 08:40:39 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3