FrameCounter.C

Go to the documentation of this file.
00001 /*!@file Media/FrameCounter.C frame counter based on a frame range */
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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Media/FrameCounter.C $
00035 // $Id: FrameCounter.C 13569 2010-06-15 22:32:30Z lior $
00036 //
00037 
00038 #ifndef MEDIA_FRAMECOUNTER_C_DEFINED
00039 #define MEDIA_FRAMECOUNTER_C_DEFINED
00040 
00041 #include "Media/FrameCounter.H"
00042 
00043 // ######################################################################
00044 FrameState FrameCounter::updateNext()
00045 {
00046   const int prev = this->current;
00047 
00048   this->bumpCurrent();
00049 
00050   return this->frameStatus(prev);
00051 }
00052 
00053 // ######################################################################
00054 FrameState FrameCounter::frameStatus(const int prev) const
00055 {
00056   if      (current == prev)            return FRAME_SAME;
00057   else if (current == range.getLast()) return FRAME_FINAL;
00058   else if (current >  range.getLast()) return FRAME_COMPLETE;
00059   else                                 return FRAME_NEXT;
00060 }
00061 
00062 // ######################################################################
00063 FrameState FrameCounter::updateByClock(const SimTime& stime)
00064 {
00065   const int prev = this->current;
00066 
00067   // check whether we need to move on to the next frame:
00068   if (stime >= this->nextTime)
00069     {
00070       this->bumpCurrent();
00071 
00072       // compute the time after which we'll move to the next frame:
00073       const size_t num_delays = range.numDelayTimes();
00074       LDEBUG("num_delays: %"ZU, num_delays);
00075       if (num_delays == 1)
00076         {
00077           this->nextTime =
00078             this->startTime
00079             + ((this->current + 1 - range.getFirst())
00080                * range.getDelayTime(0));
00081         }
00082       else if (num_delays > 1)
00083         {
00084           // when we come to the last frame in a variable frame-rate
00085           // series (which has been specified from a .fl file; see
00086           // FrameRange::fromString() for details), we have no way of
00087           // giving a proper "next frame time", so instead we just use
00088           // SimTime::MAX()
00089 
00090           if (size_t(this->current) < range.numDelayTimes())
00091             this->nextTime = range.getDelayTime(this->current);
00092           else
00093             this->nextTime = SimTime::MAX();
00094         }
00095       else
00096         {
00097           LFATAL("FrameRange contains no delay times");
00098         }
00099       LDEBUG("simtime: %.2fms, frame %d will be uploaded at: %.2fms",
00100              stime.msecs(), this->current + 1, this->nextTime.msecs());
00101     }
00102 
00103   return this->frameStatus(prev);
00104 }
00105 
00106 // ######################################################################
00107 FrameState FrameCounter::updateByEvent(const bool new_event)
00108 {
00109   const int prev = this->current;
00110 
00111   if (new_event)
00112     this->bumpCurrent();
00113 
00114   return this->frameStatus(prev);
00115 }
00116 
00117 // ######################################################################
00118 void FrameCounter::bumpCurrent()
00119 {
00120   ASSERT(range.getStep() > 0);
00121 
00122   if (this->current < range.getFirst())
00123     // special case: in our starting condition before anything has
00124     // happened, we set this->current to range.first-1; so in that
00125     // case we don't want to bump up by range.step, but rather just
00126     // set this->current to range.first
00127     this->current = range.getFirst();
00128   else
00129     this->current += range.getStep();
00130 
00131   if (wrap && this->current > range.getLast())
00132     this->current = range.getFirst();
00133 }
00134 
00135 // ######################################################################
00136 bool FrameCounter::setCurrent(int n)
00137 {
00138   if(n < range.getFirst() || n > range.getLast())
00139     return false;
00140 
00141   this->current = n;
00142   return true;
00143 }
00144 
00145 // ######################################################################
00146 /* So things look consistent in everyone's emacs... */
00147 /* Local Variables: */
00148 /* indent-tabs-mode: nil */
00149 /* End: */
00150 
00151 #endif // MEDIA_FRAMECOUNTER_C_DEFINED
Generated on Sun May 8 08:41:00 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3