HandControllers.C

Go to the documentation of this file.
00001 /*!@file Neuro/HandControllers.C Hand controllers */
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: Dicky Nauli Sihite <sihite@usc.edu>
00034 // $HeadURL:
00035 // $Id:
00036 //
00037 
00038 #include "Neuro/HandControllers.H"
00039 //#include "Neuro/SaccadeControllers.H"
00040 #include "Neuro/NeuroOpts.H"
00041 #include "Neuro/NeuroSimEvents.H"
00042 #include "Neuro/SpatialMetrics.H"
00043 #include "Component/OptionManager.H"
00044 #include "Psycho/HandTrace.H"
00045 #include "Simulation/SimEventQueue.H"
00046 #include "Util/StringConversions.H"
00047 #include "Util/StringUtil.H"
00048 #include "Util/sformat.H"
00049 
00050 #include <vector>
00051 
00052 // ######################################################################
00053 // ## Stub Hand Controller
00054 // ######################################################################
00055 StubHandController::StubHandController(OptionManager& mgr) :
00056   HandController(mgr, "Stub Hand Controller",
00057                  "StubHandController")
00058 {  }
00059 
00060 // ######################################################################
00061 StubHandController::~StubHandController()
00062 {  }
00063 
00064 
00065 
00066 // ######################################################################
00067 // ## Tracker Hand Controller
00068 // ######################################################################
00069 TrackerHandController::TrackerHandController(OptionManager& mgr) :
00070   HandController(mgr, "Tracker Hand Controller",
00071                     "TrackerHandController"),
00072   SIMCALLBACK_INIT(SimEventClockTick),
00073   itsConfig(&OPT_HandConfig, this),
00074   itsHandTrace(), itsHandSample()
00075 {  }
00076 
00077 // ######################################################################
00078 TrackerHandController::~TrackerHandController()
00079 {  }
00080 
00081 // ######################################################################
00082 void TrackerHandController::start1()
00083 {
00084   // parse our config string and instantiate all our trackers:
00085   std::vector<std::string> tok;
00086   split(itsConfig.getVal(), ",", std::back_inserter(tok));
00087   if (tok.empty()) LFATAL("I cannot run without at least one handtrace file.");
00088 
00089   for (uint i = 0; i < tok.size(); i ++) {
00090     std::vector<std::string> tt;
00091     split(tok[i], ":", std::back_inserter(tt));
00092     if (tt.empty()) LFATAL("Invalid empty eye-tracker filename");
00093     
00094     std::string fname = tt[0];
00095     std::string extras = join(tt.begin() + 1, tt.end(), ":");
00096     
00097     LINFO("Instantiating Tracker %03d with file '%s', extras '%s'",
00098           i, fname.c_str(), extras.c_str());
00099     
00100     // the only extra we support for now is a color:
00101     //PixRGB<byte> color(128, 255, 255); // cyan color
00102     PixRGB<byte> color(255, 255, 128); // light yellow color
00103     if (tt.size() > 1) convertFromString(tt[1], color);
00104     
00105     // instantiate a new HandTrace object:
00106     rutz::shared_ptr<HandTrace> et(new HandTrace(fname, color));
00107     
00108     itsHandTrace.push_back(et);
00109     itsHandSample.push_back(0);
00110   }
00111   
00112   HandController::start1();
00113 }
00114 
00115 // ######################################################################
00116 void TrackerHandController::
00117 onSimEventClockTick(SimEventQueue& q, rutz::shared_ptr<SimEventClockTick>& ect)
00118 {
00119   const SimTime t = q.now();
00120 
00121   // evolve all our babies and post their data:
00122   bool keepgoing = true;
00123   while(keepgoing) { // will go on until no tracker has any new data
00124     keepgoing = false;
00125 
00126     // loop over our trackers:
00127     for (uint i = 0; i < itsHandTrace.size(); i ++) {
00128       if (itsHandTrace[i]->hasData(itsHandSample[i], t)) {
00129         // ok, this warrants that we continue our while() loop:
00130         keepgoing = true;
00131         
00132         // get the next data sample:
00133         rutz::shared_ptr<HandData> data = itsHandTrace[i]->data(itsHandSample[i]);
00134 
00135         LDEBUG("Human hand %03u [%07"ZU"] (%03d, %03d| %03"ZU") at %.1fms",
00136                i, itsHandSample[i], data->getWheel(), data->getAcclBrake(), data->numButton(),
00137                itsHandSample[i] * itsHandTrace[i]->period().msecs());
00138 
00139         // Event posting
00140         q.post(rutz::make_shared
00141                (new SimEventHandTrackerData
00142                 (this, data, i, itsHandTrace[i]->filename(),
00143                  itsHandTrace[i]->color(), itsHandTrace[i]->period())));
00144         
00145         // ready for next eye movement sample:
00146         ++ itsHandSample[i];
00147       }
00148     }
00149   }
00150 }
00151 
00152 // ######################################################################
00153 /* So things look consistent in everyone's emacs... */
00154 /* Local Variables: */
00155 /* mode: c++ */
00156 /* indent-tabs-mode: nil */
00157 /* End: */
Generated on Sun May 8 08:05:24 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3