SimulationViewer.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/SimulationViewer.H"
00039 #include "Component/OptionManager.H"
00040 #include "Neuro/NeuroOpts.H"
00041 #include "Neuro/NeuroSimEvents.H"
00042 #include "Media/MediaSimEvents.H"
00043 #include "Simulation/SimEventQueue.H"
00044
00045
00046
00047
00048 SimulationViewer::SimulationViewer(OptionManager& mgr,
00049 const std::string& descrName,
00050 const std::string& tagName) :
00051 SimModule(mgr, descrName, tagName),
00052 SIMCALLBACK_INIT(SimEventSceneDescription),
00053 SIMCALLBACK_INIT(SimEventObjectDescription),
00054 itsDisplayInterp(&OPT_SVdisplayInterp, this),
00055 itsMapFactor(&OPT_SVdisplayMapFactor, this),
00056 itsMapType(&OPT_SVdisplayMapType, this)
00057 { }
00058
00059
00060 SimulationViewer::~SimulationViewer()
00061 { }
00062
00063
00064 void SimulationViewer::
00065 onSimEventSceneDescription(SimEventQueue& q, rutz::shared_ptr<SimEventSceneDescription>& e)
00066 {
00067 LINFO("Scene is: %s ", e->getSceneData()->description.c_str());
00068 }
00069
00070
00071 void SimulationViewer::
00072 onSimEventObjectDescription(SimEventQueue& q, rutz::shared_ptr<SimEventObjectDescription>& e)
00073 {
00074 LINFO("Object is: %s id %i", e->getObjData()->description.c_str(), e->getObjData()->id);
00075 }
00076
00077
00078 Image<float> SimulationViewer::getMap(SimEventQueue& q,
00079 const bool warn) const
00080 {
00081 const float fac = itsMapFactor.getVal();
00082 const std::string typ = itsMapType.getVal();
00083 Image<float> ret;
00084
00085 if (typ.compare("SM") == 0)
00086 {
00087 if (SeC<SimEventSaliencyMapOutput> e =
00088 q.check<SimEventSaliencyMapOutput>(this, SEQ_ANY))
00089 ret = e->sm(fac);
00090 else if (warn) LERROR("Could not get a Saliency Map!");
00091 }
00092 else if (typ.compare("TRM") == 0)
00093 {
00094 if (SeC<SimEventTaskRelevanceMapOutput> e =
00095 q.check<SimEventTaskRelevanceMapOutput>(this, SEQ_ANY))
00096 ret = e->trm(fac);
00097 else if (warn) LERROR("Could not get a Task Relevance Map!");
00098 }
00099 else if (typ.compare("AGM") == 0)
00100 {
00101 if (SeC<SimEventAttentionGuidanceMapOutput> e =
00102 q.check<SimEventAttentionGuidanceMapOutput>(this, SEQ_ANY))
00103 ret = e->agm(fac);
00104 else if (warn) LERROR("Could not get an Attention Guidance Map!");
00105 }
00106 else if (typ.compare("VCO") == 0)
00107 {
00108 if (SeC<SimEventVisualCortexOutput> e =
00109 q.check<SimEventVisualCortexOutput>(this, SEQ_ANY))
00110 ret = e->vco(fac);
00111 else if (warn) LERROR("Could not get a Visual Cortex Output Map!");
00112 }
00113 else LFATAL("Unknown desired map type '%s'", typ.c_str());
00114
00115
00116 ret = inverseMap(ret);
00117
00118 return ret;
00119 }
00120
00121
00122
00123
00124 SimulationViewerAdapter::SimulationViewerAdapter(OptionManager& mgr,
00125 const std::string& descrName,
00126 const std::string& tagName) :
00127 SimulationViewer(mgr, descrName, tagName),
00128 SIMCALLBACK_INIT(SimEventRetinaImage),
00129 SIMCALLBACK_INIT(SimEventWTAwinner),
00130 itsInverseRetinal(&OPT_SVInverseTransform, this),
00131 itsInput(),
00132 itsCurrFOA(WTAwinner::NONE()),
00133 itsPrevFOA(WTAwinner::NONE()),
00134 itsTransform(new SpaceVariantModule(mgr))
00135 {
00136 addSubComponent(itsTransform);
00137 }
00138
00139
00140 void SimulationViewerAdapter::reset1()
00141 {
00142 itsInput.freeMem();
00143 itsCurrFOA = WTAwinner::NONE();
00144 itsPrevFOA = WTAwinner::NONE();
00145 itsTransform->clear();
00146
00147
00148 SimulationViewer::reset1();
00149 }
00150
00151
00152 void SimulationViewerAdapter::
00153 onSimEventRetinaImage(SimEventQueue& q, rutz::shared_ptr<SimEventRetinaImage>& e)
00154 {
00155
00156 itsInput = e->frame().colorByte();
00157
00158
00159 if (e->getRetTransform().is_valid() && e->getMapTransform().is_valid())
00160 {
00161
00162 itsTransform->setTransform(e->getRetTransform());
00163 itsTransform->setMapTransform(e->getMapTransform());
00164
00165
00166 if (itsInverseRetinal.getVal())
00167 itsInput = itsTransform->inverseTransform(itsInput);
00168 }
00169
00170 doEventRetinaImage(q, e);
00171 }
00172
00173
00174 void SimulationViewerAdapter::
00175 onSimEventWTAwinner(SimEventQueue& q, rutz::shared_ptr<SimEventWTAwinner>& e)
00176 {
00177 itsPrevFOA = itsCurrFOA;
00178 itsCurrFOA = e->winner();
00179 if (itsCurrFOA.isValid())
00180 {
00181 fromRetinal(itsCurrFOA.p);
00182 fromRetinalMap(itsCurrFOA.smpos);
00183 }
00184 doEventWTAwinner(q, e);
00185 }
00186
00187
00188 Image<float> SimulationViewerAdapter::inverseMap(const Image<float>& map_image) const
00189 {
00190 Image<float> map = map_image;
00191
00192
00193 if (itsTransform->validTransforms() && itsInverseRetinal.getVal())
00194 map = itsTransform->inverseMap(map);
00195 return map;
00196 }
00197
00198
00199 Image<float> SimulationViewerAdapter::inverseRetinal(const Image<float>& ret_image) const
00200 {
00201 Image<float> ret = ret_image;
00202
00203
00204 if (itsTransform->validTransforms() && itsInverseRetinal.getVal())
00205 ret = itsTransform->inverseTransform(ret);
00206 return ret;
00207 }
00208
00209
00210 void SimulationViewerAdapter::toRetinal(Point2D<int>& point) const
00211 {
00212 if (itsTransform->validTransforms())
00213 itsTransform->toSvCoords(point);
00214 }
00215
00216
00217 void SimulationViewerAdapter::fromRetinal(Point2D<int>& point) const
00218 {
00219 if (itsTransform->validTransforms() && itsInverseRetinal.getVal())
00220 itsTransform->fromSvCoords(point);
00221 }
00222
00223
00224 void SimulationViewerAdapter::fromRetinalMap(Point2D<int>& point) const
00225 {
00226 if (itsTransform->validTransforms() && itsInverseRetinal.getVal())
00227 itsTransform->fromSvCoordsMap(point);
00228 }
00229
00230
00231
00232
00233
00234