HandControllers.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Neuro/HandControllers.H"
00039
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
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
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
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
00101
00102 PixRGB<byte> color(255, 255, 128);
00103 if (tt.size() > 1) convertFromString(tt[1], color);
00104
00105
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
00122 bool keepgoing = true;
00123 while(keepgoing) {
00124 keepgoing = false;
00125
00126
00127 for (uint i = 0; i < itsHandTrace.size(); i ++) {
00128 if (itsHandTrace[i]->hasData(itsHandSample[i], t)) {
00129
00130 keepgoing = true;
00131
00132
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
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
00146 ++ itsHandSample[i];
00147 }
00148 }
00149 }
00150 }
00151
00152
00153
00154
00155
00156
00157