00001 /*!@file Media/FrameCounter.H 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.H $ 00035 // $Id: FrameCounter.H 13569 2010-06-15 22:32:30Z lior $ 00036 // 00037 00038 #ifndef MEDIA_FRAMECOUNTER_H_DEFINED 00039 #define MEDIA_FRAMECOUNTER_H_DEFINED 00040 00041 #include "Media/FrameRange.H" 00042 #include "Media/FrameState.H" 00043 #include "Util/Assert.H" 00044 #include "Util/log.H" 00045 00046 //! Frame counting based on a given FrameRange 00047 class FrameCounter { 00048 public: 00049 00050 //! Default constructor (first=last=0, delay=0.0) 00051 inline FrameCounter(const FrameRange& rng, bool w=false) : 00052 range(rng), 00053 current(-1), 00054 nextTime(SimTime::ZERO()), 00055 startTime(SimTime::ZERO()), 00056 wrap(w) 00057 {} 00058 00059 //! Reset frame and time counters 00060 void reset(const FrameRange& rng, bool update_start_time, bool w = false) 00061 { 00062 range = rng; 00063 current = range.getFirst()-1; 00064 nextTime = startTime; 00065 wrap = w; 00066 00067 if (update_start_time) 00068 { 00069 ASSERT(rng.numDelayTimes() > 0); 00070 this->setStartTime(rng.getDelayTime(0)); 00071 } 00072 } 00073 00074 //! Get the current frame number 00075 int currentFrame() const 00076 { 00077 // if current < first, then it means that we haven't yet started 00078 // counting, so just return the number of what the first frame 00079 // will be once we do start 00080 return current < range.getFirst() ? range.getFirst() : current; 00081 } 00082 00083 //! Set the time at which we start incrementing frames 00084 void setStartTime(const SimTime& t) { startTime = t; nextTime = t; } 00085 00086 //! Update our frame counter for the given simtime and new-event status. 00087 /*! If we are in event-triggered mode, then the counter is advanced 00088 if new_event is true; if we are NOT in event-triggered mode, 00089 then the counter is advanced if sufficient time has passed since 00090 our previous frame. */ 00091 FrameState update(const SimTime& stime, 00092 const bool new_event = false) 00093 { 00094 if (!range.isEventTriggered()) 00095 { 00096 return this->updateByClock(stime); 00097 } 00098 else 00099 { 00100 return this->updateByEvent(new_event); 00101 } 00102 } 00103 00104 //! Just increment the frame counter by one. 00105 FrameState updateNext(); 00106 00107 //! Try to force the counter to the given value 00108 /*! If the given value is outside of the frame range, return false. */ 00109 bool setCurrent(int n); 00110 00111 private: 00112 // return the proper status for the 'current' frame number, given 00113 // the previous frame number 00114 FrameState frameStatus(const int prev) const; 00115 00116 FrameState updateByClock(const SimTime& stime); 00117 00118 FrameState updateByEvent(const bool new_event); 00119 00120 void bumpCurrent(); 00121 00122 FrameRange range; 00123 int current; //!< current frame number 00124 SimTime nextTime; //!< time at which we'll move to the next frame 00125 SimTime startTime; //!< time at which we start counting frames 00126 bool wrap; //!< go to the beginning of the frame if the end is reached 00127 }; 00128 00129 // ###################################################################### 00130 /* So things look consistent in everyone's emacs... */ 00131 /* Local Variables: */ 00132 /* indent-tabs-mode: nil */ 00133 /* End: */ 00134 00135 #endif // MEDIA_FRAMECOUNTER_H_DEFINED