HandTrace.H

Go to the documentation of this file.
00001 /*!@file Psycho/HandTrace.H A hand movement trace on a steering wheel */
00002 // //////////////////////////////////////////////////////////////////// //
00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00004 // by the University of Southern California (USC) and the iLab at USC.  //
00005 // See http://iLab.usc.edu for information about this project.          //
00006 // //////////////////////////////////////////////////////////////////// //
00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00009 // in Visual Environments, and Applications'' by Christof Koch and      //
00010 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00011 // pending; application number 09/912,225 filed July 23, 2001; see      //
00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00015 //                                                                      //
00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00017 // redistribute it and/or modify it under the terms of the GNU General  //
00018 // Public License as published by the Free Software Foundation; either  //
00019 // version 2 of the License, or (at your option) any later version.     //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00024 // PURPOSE.  See the GNU General Public License for more details.       //
00025 //                                                                      //
00026 // You should have received a copy of the GNU General Public License    //
00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00029 // Boston, MA 02111-1307 USA.                                           //
00030 // //////////////////////////////////////////////////////////////////// //
00031 //
00032 // Primary maintainer for this file: Dicky Nauli Sihite <sihite@usc.edu>
00033 // $HeadURL: 
00034 // #Id:
00035 
00036 #ifndef PSYCHO_HANDTRACE_H_DEFINED
00037 #define PSYCHO_HANDTRACE_H_DEFINED
00038 
00039 #include "Image/Pixels.H"
00040 #include "Psycho/HandData.H"
00041 #include "Util/SimTime.H"
00042 #include "rutz/shared_ptr.h"
00043 #include "Component/ParamMap.H"
00044 
00045 #include <string>
00046 #include <vector>
00047 
00048 
00049 //! A hand movement trace
00050 /*! This class encapsulates a simple hand movement trace and provides
00051   I/O functions. */
00052 class HandTrace {
00053   /*! Public functions, please see how to call these below the class */
00054 public:
00055   // ######################################################################
00056   /*! @name Constructors, destructor and initialization */
00057 
00058   //! Constructor from a file on disk, use given display color
00059   HandTrace(const std::string& filename, const PixRGB<byte>& color);
00060 
00061   //! Destructor
00062   ~HandTrace();
00063 
00064   // ######################################################################
00065   /*! @name Data access functions */
00066 
00067   //! Did sample of given index happen before given time?
00068   /*! Typically one would keep incrementing the index until we return
00069     false here, at which point it would be time to increment the
00070     time. Note that we will always return false after the index gets
00071     past all available samples in the trace. */
00072   bool hasData(const size_t index, const SimTime& t) const;
00073 
00074   //! Do we have a sample for the given index?
00075   /*! This will return true as long as the index is not past the
00076     available amount of data. */
00077   bool hasData(const size_t index) const;
00078 
00079   //! Get the data for a given index
00080   /*! Note that this will throw a fatal error if we don't have data
00081     for that index; so be sure to check with hasData() first. */
00082   rutz::shared_ptr<HandData> data(const size_t index) const;
00083 
00084   //We need to be able to export the RawExtraData as well and pass it through...
00085 
00086   //! Get our display color
00087   PixRGB<byte> color() const;
00088 
00089   //! Get number of available (non-trash) samples
00090   size_t size() const;
00091   //! Get number of parsed events (if any)
00092   size_t numEvents() const;
00093   
00094   // ######################################################################
00095   /*! @name Metadata access functions */
00096 
00097   //! Get sampling period
00098   SimTime period() const;
00099 
00100   //! Get filename, with extension if any
00101   std::string filename() const;
00102 
00103   //! Get filename, without extension if any
00104   std::string basename() const;
00105   
00106 private:
00107   // forbid assignment and copy-construction:
00108   HandTrace& operator=(const HandTrace& e);
00109   HandTrace(const HandTrace& e);
00110 
00111   // add data from an unformatted line
00112   bool pushData(const std::string line);
00113   bool isEventField(const std::string &field) const;
00114 
00115   //! To add/remove special field
00116   std::string special(std::string field) const;
00117   std::string unspecial(std::string field) const;
00118 
00119   // ## variables #########################################################
00120   std::string itsFilename;
00121   PixRGB<byte> itsColor;
00122   SimTime itsPeriod;
00123   size_t itsTrash;
00124   uint itsNumEvents;
00125 
00126   std::vector<std::string> itsFields;
00127 
00128   int nativeX, nativeY;
00129   // for internal use only!
00130   struct RawHandData {
00131     int x,y;
00132     std::vector<bool> b;
00133     int mx,my,nmx,nmy;
00134     bool mlb, mmb, mrb;
00135     std::string kbch;
00136     rutz::shared_ptr<ParamMap> extraData; // may be NULL if no extra data
00137   };
00138   std::vector<RawHandData> itsData;
00139   std::vector<rutz::shared_ptr<ParamMap> > itsEvents;
00140 };
00141 
00142 // ######################################################################
00143 // ## Inline functions (public)
00144 // ######################################################################
00145 inline bool HandTrace::hasData(const size_t index, const SimTime& t) const {
00146   return ( index < itsData.size() && itsPeriod * int(index) < t ); }
00147 
00148 // ######################################################################
00149 inline bool HandTrace::hasData(const size_t index) const {
00150   return ( index < itsData.size() ); }
00151 
00152 // ######################################################################
00153 inline rutz::shared_ptr<HandData> HandTrace::data(const size_t index) const {
00154   if (index >= itsData.size()) LFATAL("Index past end of trace");
00155   rutz::shared_ptr<HandData> ret;
00156   //ret.reset(new HandData(itsData[index].x, itsData[index].y, itsData[index].b));
00157   ret.reset(new HandData(itsData[index].kbch.c_str(),
00158                          itsData[index].mx, itsData[index].my,
00159                          itsData[index].nmx, itsData[index].nmy,
00160                          itsData[index].mlb, itsData[index].mmb,
00161                          itsData[index].mrb,
00162                          itsData[index].x, itsData[index].y, itsData[index].b));
00163   return ret; }
00164 
00165 // ######################################################################
00166 inline PixRGB<byte> HandTrace::color() const {
00167   return itsColor; }
00168 
00169 // ######################################################################
00170 inline size_t HandTrace::size() const {
00171   return itsData.size(); }
00172 
00173 // ######################################################################
00174 inline size_t HandTrace::numEvents() const {
00175   return itsNumEvents; }
00176 
00177 // ######################################################################
00178 inline SimTime HandTrace::period() const {
00179   return itsPeriod; }
00180 
00181 // ######################################################################
00182 inline std::string HandTrace::filename() const {
00183   return itsFilename; } // return filename with extension if exist
00184  
00185 // ######################################################################
00186 inline std::string HandTrace::basename() const { // trace filename to extension
00187   size_t idx = itsFilename.rfind('.');
00188   if (idx != itsFilename.npos) return itsFilename.substr(0, idx);
00189   return itsFilename; } // no extension filename?
00190 
00191 
00192 
00193 // ######################################################################
00194 /* So things look consistent in everyone's emacs... */
00195 /* Local Variables: */
00196 /* mode: c++ */
00197 /* indent-tabs-mode: nil */
00198 /* End: */
00199 
00200 #endif // PSYCHO_HANDTRACE_H_DEFINED
Generated on Sun May 8 08:41:13 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3