00001 /*!@file Psycho/PsychoDisplay.H Display psychophysics stimuli */ 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; 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/Psycho/PsychoDisplay.H $ 00035 // $Id: PsychoDisplay.H 14176 2010-10-28 04:28:19Z ilink $ 00036 // 00037 00038 #ifndef PSYCHODISPLAY_H_DEFINED 00039 #define PSYCHODISPLAY_H_DEFINED 00040 00041 #ifdef HAVE_SDL_SDL_H 00042 00043 #include "GUI/SDLdisplay.H" 00044 00045 class EyeTracker; 00046 00047 //! for drawing clouds of dots 00048 typedef struct{ 00049 int x; 00050 int y; 00051 int coherent; 00052 int age; 00053 int dx; 00054 int dy; 00055 } DOT; 00056 00057 //! Class fo do various psychophysics displays 00058 /*! This class is to facilitate the display of various psychophysics 00059 stimuli, with an initial emphasis on playing movies at a controlled 00060 framerate. Programs using this class, such as psycho-movie.C, should 00061 run as root if SCHED_FIFO scheduling is required (and I highly 00062 recommend it, as it will make timing reliable). The class uses the 00063 SDLdisplay class to do the displays, and PsychoDisplay derives from 00064 SDLdisplay. See GUI/SDLdisplay.H for basic SDL info. */ 00065 00066 class PsychoDisplay : public SDLdisplay 00067 { 00068 public: 00069 // ###################################################################### 00070 /*! @name Constructors, destructor and initialization */ 00071 //@{ 00072 00073 //! Constructor 00074 PsychoDisplay(OptionManager& mgr, 00075 const std::string& descrName = "Psycho Display", 00076 const std::string& tagName = "PsychoDisplay"); 00077 00078 //! Destructor 00079 ~PsychoDisplay(); 00080 00081 //! Optionally we may work in conjunction with an EyeTracker 00082 void setEyeTracker(nub::soft_ref<EyeTracker> e); 00083 00084 //!Set the size of the fixation point 00085 void setFixationSize(const int size); 00086 //@} 00087 00088 // ###################################################################### 00089 /*! @name Display and interaction functions */ 00090 //@{ 00091 00092 //! Clear screen using our default grey 00093 void clearScreen(const bool vsync = true); 00094 00095 //! display a circle 00096 /*! @param x horizontal position of center of cross, or -1 to have 00097 it at the center of the screen 00098 @param y vertical position of center of cross, or -1 to have 00099 it at the center of the screen 00100 @param radius radius of the circle 00101 @param ringwidth width of the ring 00102 @param color of the circle 00103 @param vsync will attempt to sync with vertical blanking if true */ 00104 void displayCircle(const int x = -1, const int y = -1, 00105 const int radius = 10, 00106 const PixRGB<byte> color = PixRGB<byte>(255,255,255), 00107 const bool vsync = true); 00108 00109 //! display a filled circle 00110 /*! @param x horizontal position of center of cross, or -1 to have 00111 it at the center of the screen 00112 @param y vertical position of center of cross, or -1 to have 00113 it at the center of the screen 00114 @param radius radius of the circle 00115 @param ringwidth width of the ring 00116 @param color of the circle 00117 @param vsync will attempt to sync with vertical blanking if true */ 00118 void displayFilledCircle(const int x = -1, const int y = -1, 00119 const int radius = 10, 00120 const PixRGB<byte> color = PixRGB<byte>(255,255,255), 00121 const bool vsync = true); 00122 00123 void displayFilledCircleBlink(const int x = -1, const int y = -1, 00124 const int radius = 10, 00125 const PixRGB<byte> color = PixRGB<byte>(255,255,255), 00126 const int iter = 5, const int delay = 2); 00127 00128 //! display a fixation image icon 00129 /*! @param image icon that replaces fixation cross 00130 @param x horizontal position of center of cross, or -1 to have 00131 it at the center of the screen 00132 @param y vertical position of center of cross, or -1 to have 00133 it at the center of the screen 00134 @param vsync will attempt to sync with vertical blanking if true */ 00135 void displayFixationIcon(const Image< PixRGB<byte> >& image, 00136 const int x = -1, const int y = -1, 00137 const bool vsync = true); 00138 00139 //! blink a fixation image icon 00140 /*! @param image icon that replaces fixation cross 00141 @param iter number of times we should blink the cross 00142 @param delay blink duration, in frames as per our frame 00143 duration ModelParam */ 00144 void displayFixationIconBlink(const Image< PixRGB<byte> >& image, 00145 const int x = -1, const int y = -1, 00146 const int iter = 5, const int delay = 2); 00147 00148 //! display a fixation cross 00149 /*! @param x horizontal position of center of cross, or -1 to have 00150 it at the center of the screen 00151 @param y vertical position of center of cross, or -1 to have 00152 it at the center of the screen 00153 @param vsync will attempt to sync with vertical blanking if true */ 00154 void displayFixation(const int x = -1, const int y = -1, 00155 const bool vsync = true); 00156 00157 //! blink a fixation cross 00158 /*! @param iter number of times we should blink the cross 00159 @param delay blink duration, in frames as per our frame 00160 duration ModelParam */ 00161 void displayFixationBlink(const int x = -1, const int y = -1, 00162 const int iter = 5, const int delay = 2); 00163 00164 //! display a fixation red dot 00165 /*! @param x horizontal position of center of dot, or -1 to have 00166 it at the center of the screen 00167 @param y vertical position of center of cross, or -1 to have 00168 it at the center of the screen 00169 @param color RGB to specifiy the color 00170 @param vsync will attempt to sync with vertical blanking if true */ 00171 void displayColorDotFixation(const int x = -1, const int y = -1, 00172 const PixRGB<byte> color = PixRGB<byte>(255,255,255), 00173 const bool vsync = true); 00174 00175 //! blink a fixation color dot 00176 /*! @param iter number of times we should blink the cross 00177 @param delay blink duration, in frames as per our frame 00178 duration ModelParam */ 00179 void displayColorDotFixationBlink(const int x = -1, 00180 const int y = -1, 00181 const int iter = 5, 00182 const int delay = 2, 00183 const PixRGB<byte> color = PixRGB<byte>(255,255,255)); 00184 00185 //! display a fixation red dot 00186 /*! @param x horizontal position of center of dot, or -1 to have 00187 it at the center of the screen 00188 @param y vertical position of center of cross, or -1 to have 00189 it at the center of the screen 00190 @param vsync will attempt to sync with vertical blanking if true */ 00191 void displayRedDotFixation(const int x = -1, const int y = -1, 00192 const bool vsync = true); 00193 00194 //! display a fixation white dot 00195 /*! @param x horizontal position of center of dot, or -1 to have 00196 it at the center of the screen 00197 @param y vertical position of center of cross, or -1 to have 00198 it at the center of the screen 00199 @param vsync will attempt to sync with vertical blanking if true */ 00200 void displayWhiteDotFixation(const int x = -1, const int y = -1, 00201 const bool vsync = true); 00202 00203 //! blink a fixation red dot 00204 /*! @param iter number of times we should blink the cross 00205 @param delay blink duration, in frames as per our frame 00206 duration ModelParam */ 00207 void displayRedDotFixationBlink(const int x = -1, 00208 const int y = -1, 00209 const int iter = 5, 00210 const int delay = 2); 00211 00212 void displayRedDotFixationBlink(Image< PixRGB<byte> > img, 00213 const int x = -1, 00214 const int y = -1, 00215 const int iter = 5, 00216 const int delay = 2); 00217 00218 //! display a static low-level 5-point ISCAN calibration array 00219 void displayISCANcalib(); 00220 00221 //! display a bunch of eye-tracker calibration dots 00222 /*! Caution: calling this function will lead to a fatal error if 00223 setEyeTracker() has not been called previously with a valid 00224 EyeTracker. */ 00225 void displayEyeTrackerCalibration(const int nptshoriz = 7, 00226 const int nptsvertic = 5, 00227 const int timefactor = 1, 00228 const bool mouserespond = false); 00229 00230 00231 //!display a dot moving on a bacground image 00232 void displayMovingDotBackground(SDL_Surface *img, 00233 const int startX = 320, 00234 const int startY = 240, 00235 const int endX = 320, 00236 const int endY = 100, 00237 const float speed = 10.0, 00238 const PixRGB<byte> color = PixRGB<byte>(255,255,255)); 00239 00240 //!string together many dot animations 00241 void displayMovingDotTrain(const Image< PixRGB<byte> >& img, 00242 int location[][2], 00243 int num_loc, 00244 float speed[], 00245 int stay[], 00246 const PixRGB<byte> color = PixRGB<byte>(255,255,255)); 00247 00248 //! display a square that moves along the path in different speed each time 00249 /*! @param location points that segment path. The first index is point 00250 and the second index is the x or y position of the point 00251 @param num_loc number of locations specified 00252 @param speed pixels/frame. If more than one speed is specified, then 00253 it displays the same path with differnt speed 00254 @param num_speed number of speeds specified */ 00255 void displaySmoothPursuitGroupCalibration(int location[][2], 00256 int num_loc, float speed[], int num_speed); 00257 00258 //! display a square moving from start point to end point for 00259 // eye-tracker calibration by smooth pursuit 00260 /*! @param startX x position of the starting point 00261 @param startY y position of the starting point 00262 @param endX x position of the end point 00263 @param endY y position of the end point 00264 @param speed pixels/secs */ 00265 void displaySmoothPursuitCalibration(const int startX = 10, const int startY = 10, 00266 const int endX = 500, const int endY = 500, const float speed = 10.0, uint color = 0); 00267 00268 //! display a square moving along the path with different speed from transition location 00269 // to location, and stay different duration at each transition point 00270 /*! @param location transition points that segment path. The first index is point 00271 and the second index is the x or y position of the point 00272 @param num_loc number of transition points specified 00273 @param speed pixels/frame. It specify the speed from each transition point to point 00274 @param stay number of frames to stay 00275 */ 00276 void displaySmoothPursuitFancyTrace(int location[][2], int num_loc, float speed[], int stay[], uint color); 00277 00278 //! display a cloud of dots 00279 void drawCloud(DOT *clouds, const int numDots = -1, 00280 const Uint8 r = 0xff, const Uint8 g = 0xff, 00281 const Uint8 b = 0xff, const bool vsync = true); 00282 00283 //! display a cloud of dots 00284 void drawClouds(DOT *newClouds, DOT *oldClouds, const int numDots = -1, 00285 const Uint8 r = 0xff, const Uint8 g = 0xff, 00286 const Uint8 b = 0xff, const bool vsync = true); 00287 00288 //! show a text message using our default colors 00289 //! show a text message 00290 /*! @param ind ind=0 displays the text in the middle of screen, ind =1 displays the text on top or the screen 00291 and ind = -1 displays the message at the buttom of the display, ind=-2 for random placement of the message 00292 */ 00293 void displayText(const std::string& msg, const bool vsync = true , int ind = 0 , const int fontsize = 10); 00294 00295 void displayText(const std::string& msg, const Point2D<int>& p , const PixRGB<byte> txtcol ,const PixRGB<byte> bgcol , const bool vsync=true) ; 00296 00297 void displayRandomText(const int stringlength = 8, const int fontsize = 6, const bool vsync = true, int ind = 0); 00298 00299 //! display a 5x5 grid of random numbers 00300 /*! This is flashed after every trial and subject is asked to report 00301 the number that appeared at the target location.*/ 00302 int displayNumbers(const int targetRow = -1, 00303 const int targetCol = -1, const bool vsync = true); 00304 00305 int drawPoint(const Point2D<int> thePoint); 00306 00307 int drawPointColor(const Point2D<int> thePoint,PixRGB<byte> color); 00308 00309 int drawCalibPoint(const Point2D<int> thePoint); 00310 00311 // ###################################################################### 00312 /*! @name Access functions */ 00313 //@{ 00314 00315 //! Get background grey value 00316 PixRGB<byte> getGrey() const; 00317 00318 //! change background color 00319 void changeBackgroundColor(PixRGB<byte> c); 00320 00321 00322 //@} 00323 00324 protected: 00325 00326 //! Get our background grey as Uint32 color (for use with SDL) 00327 Uint32 getGreyUint32() const; 00328 00329 //! Get our black as Uint32 color (for use with SDL) 00330 Uint32 getBlackUint32() const; 00331 00332 //! Get our white as Uint32 color (for use with SDL) 00333 Uint32 getWhiteUint32() const; 00334 00335 OModelParam<PixRGB<byte> > itsBackgroundColor; //!< background grey color 00336 OModelParam<PixRGB<byte> > itsTextColor; //!< text foreground color 00337 OModelParam<PixRGB<byte> > itsBlack; //!< "black" color 00338 OModelParam<PixRGB<byte> > itsWhite; //!< "white" color 00339 OModelParam<std::string> itsFixationIcon; //!< image icon for fixation 00340 00341 NModelParam<int> itsFixSiz; //!< size of fixation cross 00342 NModelParam<int> itsFixThick; //!< thickness of fixation cross 00343 00344 private: 00345 nub::soft_ref<EyeTracker> itsEyeTracker; 00346 }; 00347 00348 #endif // HAVE_SDL_SDL_H 00349 00350 #endif 00351 00352 // ###################################################################### 00353 /* So things look consistent in everyone's emacs... */ 00354 /* Local Variables: */ 00355 /* indent-tabs-mode: nil */ 00356 /* End: */