DisplayController.C

Go to the documentation of this file.
00001 /*!@file Psycho/DisplayController.C */
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: David Berg <dberg@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Psycho/DisplayController.C $
00035 
00036 #include "Psycho/DisplayController.H"
00037 
00038 // ######################################################################
00039 DisplayController::DisplayController() : itsDisplay(), itsBuffer(),
00040                                          itsLog(), isPaused(false),
00041                                          isDone(false), isRexReady(false),
00042                                          isVideoStream(), itsFrameCount(0),
00043                                          itsBackgroundFrame(), itsRexImage(),
00044                                          itsPauser(), itsFuncMap()
00045 {
00046 }
00047 
00048 // ######################################################################
00049 DisplayController::~DisplayController()
00050 {
00051 }
00052 
00053 // ######################################################################
00054 void DisplayController::setDisplay(nub::soft_ref<PsychoDisplay> d)
00055 {
00056   itsDisplay = d;
00057 }
00058 
00059 // ######################################################################
00060 void DisplayController::setBuffer(rutz::shared_ptr<SharedBuffer<RexData*> > buff)
00061 {
00062   itsBuffer = buff;
00063 }
00064 
00065 // ######################################################################
00066 void DisplayController::setEventLog(nub::soft_ref<EventLog> log)
00067 {
00068   itsLog = log;
00069 }
00070 
00071 // ######################################################################
00072 void DisplayController::pushEvent(const std::string& msg, const bool& useLinfo)
00073 {
00074   if (itsLog.isValid())
00075     itsLog->pushEvent(msg);
00076 
00077   if (useLinfo)
00078     LINFO(msg.c_str());
00079 }
00080 
00081 // ######################################################################
00082 void DisplayController::pause(bool pausestate)
00083 {
00084   isPaused = pausestate;
00085   if (itsDisplay->hasYUVoverlay())
00086     itsDisplay->destroyYUVoverlay();
00087   if (!isPaused)
00088     itsPauser.post();
00089   itsFrameCount = 0;
00090 }
00091 
00092 // ######################################################################
00093 void DisplayController::setBackground(const GenericFrame& gf,
00094                                       const int framenum)
00095 {
00096   //if we don't already have an overlay, set one up
00097   if (!itsDisplay->hasYUVoverlay())
00098     itsDisplay->createVideoOverlay(VIDFMT_YUV420P,gf.getWidth(),
00099                                    gf.getHeight());
00100 
00101   //get our frame as a video, converting as necessary
00102   VideoFrame vid = gf.asVideo();
00103 
00104   //are we in video streaming mode or what?
00105   if (gf.nativeType() == GenericFrame::VIDEO)
00106     {
00107       //this means the caller is in control and we display now.
00108       isVideoStream = true;
00109       if (isRexReady)
00110         {
00111           isRexReady=false;
00112           overlayVideo(itsRexImage, vid, PixRGB<byte>(1,1,1), framenum);
00113         }
00114       else
00115         itsDisplay->displayVideoOverlay(vid, framenum, SDLdisplay::NEXT_VSYNC);
00116     }
00117   else
00118     {
00119       //this means rex is in control, we display when it says so
00120       isVideoStream = false;
00121       //save a copy for later, will be used by draw()
00122       itsBackgroundFrame = VideoFrame::deepCopyOf(vid);
00123     }
00124   itsFrameCount = framenum;
00125 }
00126 
00127 // ######################################################################
00128 void DisplayController::start()
00129 {
00130   if ( !itsBuffer.is_valid() ||  !itsDisplay.isValid())
00131     LFATAL("I need a buffer and a display to start");
00132   isDone = false;
00133 
00134 }
00135 
00136 // ######################################################################
00137 void DisplayController::stop()
00138 {
00139   pause(false);
00140 
00141   if (itsDisplay->hasYUVoverlay())
00142     itsDisplay->destroyYUVoverlay();
00143 
00144   isDone = true;
00145   itsBuffer->stopWaiting();
00146 }
00147 
00148 // ######################################################################
00149 void DisplayController::run()
00150 {
00151   //loop until someone tells us to quite or the buffer returns NULL data
00152   while (!isDone)
00153     {
00154       //check to see if someone told us to pause;
00155       if (isPaused)
00156         {
00157           itsPauser.wait();
00158         }
00159 
00160       //start popping data off of the queue, waiting if no data
00161       RexData* d = itsBuffer->pop();
00162 
00163       //if our buffer is returning empty data lets exit
00164       if (d->buflen == 0)
00165         {
00166           isDone = true;
00167           delete d;
00168           break;
00169         }
00170 
00171       //!once we have the data look up the function in our map, calling it
00172       (this->*itsFuncMap[d->status])(d->buffer);
00173 
00174       //!delete the data as we are done with it
00175       delete d;
00176     }
00177 }
00178 
00179 // ######################################################################
00180 const char* DisplayController::jobType() const
00181 {
00182   return "DisplayController";
00183 }
00184 
00185 // ######################################################################
00186 int DisplayController::priority() const
00187 {
00188   return 0;
00189 }
00190 
00191 // ######################################################################
00192 void DisplayController::draw(const byte* parameters)
00193 {
00194   //if we are in video streaming mode just flip the ready flag
00195   if (isVideoStream)
00196     isRexReady = true;
00197   else
00198     {
00199       VideoFrame tmp = itsBackgroundFrame;
00200       overlayVideo(itsRexImage, tmp, PixRGB<byte>(1,1,1), itsFrameCount);
00201       itsFrameCount++;
00202     }
00203 }
00204 
00205 // ######################################################################
00206 void DisplayController::drawCircle(const byte* parameters)
00207 {
00208 
00209 }
00210 
00211 // ######################################################################
00212 void DisplayController::clearScreen(const byte* parameters)
00213 {
00214   itsDisplay->displayVideoOverlay(itsBackgroundFrame, itsFrameCount,
00215                                   SDLdisplay::NEXT_VSYNC);
00216   itsFrameCount++;
00217 }
00218 
00219 // ######################################################################
00220 /* So things look consistent in everyone's emacs... */
00221 /* Local Variables: */
00222 /* indent-tabs-mode: nil */
00223 /* End: */
00224 
00225 
Generated on Sun May 8 08:41:12 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3