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/VisualCortex.H"
00039
00040 #include "Channels/ChannelOpts.H"
00041 #include "Channels/RawVisualCortex.H"
00042 #include "Channels/IntegerRawVisualCortex.H"
00043 #include "Channels/ChannelFacets.H"
00044 #include "Component/GlobalOpts.H"
00045 #include "Component/OptionManager.H"
00046 #include "Component/ParamMap.H"
00047 #include "Image/ColorOps.H"
00048 #include "Image/MathOps.H"
00049 #include "Image/Pixels.H"
00050 #include "Image/PyramidOps.H"
00051 #include "Image/ShapeOps.H"
00052 #include "Image/Transforms.H"
00053 #include "Media/MediaSimEvents.H"
00054 #include "Neuro/EnvVisualCortex.H"
00055 #include "Neuro/NeuroOpts.H"
00056 #include "Neuro/NeuroSimEvents.H"
00057 #include "Neuro/WTAwinner.H"
00058 #include "Simulation/SimEventQueue.H"
00059 #include "Transport/FrameInfo.H"
00060 #include "Transport/FrameOstream.H"
00061 #include "Util/sformat.H"
00062 #include "rutz/mutex.h"
00063 #include "rutz/trace.h"
00064
00065 #include <algorithm>
00066 #include <cctype>
00067 #include <cstdio>
00068 #include <vector>
00069
00070
00071
00072 VisualCortex::VisualCortex(OptionManager& mgr,
00073 const std::string& descrName,
00074 const std::string& tag) :
00075 SimModule(mgr, descrName, tag)
00076 {
00077 GVX_TRACE(__PRETTY_FUNCTION__);
00078 }
00079
00080
00081 VisualCortex::~VisualCortex()
00082 {
00083 GVX_TRACE(__PRETTY_FUNCTION__);
00084 }
00085
00086
00087
00088 VisualCortexStd::VisualCortexStd(OptionManager& mgr,
00089 const std::string& descrName,
00090 const std::string& tag) :
00091 VisualCortex(mgr, descrName, tag),
00092 SIMCALLBACK_INIT(SimEventRetinaImage),
00093 SIMCALLBACK_INIT(SimEventSaveOutput),
00094 SIMREQHANDLER_INIT(SimReqVCXfeatures),
00095 SIMREQHANDLER_INIT(SimReqVCXmaps),
00096 SIMREQHANDLER_INIT(SimReqVCXchanVis),
00097 itsVCX(new RawVisualCortex(mgr))
00098 {
00099 GVX_TRACE(__PRETTY_FUNCTION__);
00100 addSubComponent(itsVCX);
00101 }
00102
00103
00104 VisualCortexStd::VisualCortexStd(OptionManager& mgr,
00105 const std::string& descrName,
00106 const std::string& tag, nub::ref<RawVisualCortex> vcx) :
00107 VisualCortex(mgr, descrName, tag),
00108 SIMCALLBACK_INIT(SimEventRetinaImage),
00109 SIMCALLBACK_INIT(SimEventSaveOutput),
00110 SIMREQHANDLER_INIT(SimReqVCXfeatures),
00111 SIMREQHANDLER_INIT(SimReqVCXmaps),
00112 SIMREQHANDLER_INIT(SimReqVCXchanVis),
00113 itsVCX(vcx)
00114 {
00115 GVX_TRACE(__PRETTY_FUNCTION__);
00116 addSubComponent(itsVCX);
00117 }
00118
00119
00120 VisualCortexStd::~VisualCortexStd()
00121 {
00122 GVX_TRACE(__PRETTY_FUNCTION__);
00123 }
00124
00125
00126 void VisualCortexStd::onSimEventRetinaImage(SimEventQueue& q, rutz::shared_ptr<SimEventRetinaImage>& e)
00127 {
00128
00129 itsVCX->input(e->frame());
00130
00131
00132 q.post(rutz::make_shared(new SimEventVisualCortexOutput(this, itsVCX->getOutput())));
00133 }
00134
00135
00136 void VisualCortexStd::handleSimReqVCXfeatures(SimEventQueue& q, rutz::shared_ptr<SimReqVCXfeatures>& r)
00137 {
00138 itsVCX->getFeatures(r->loc(), r->features());
00139 }
00140
00141
00142 void VisualCortexStd::handleSimReqVCXmaps(SimEventQueue& q, rutz::shared_ptr<SimReqVCXmaps>& r)
00143 {
00144 r->populateChannelMaps(itsVCX.get());
00145 }
00146
00147
00148 void VisualCortexStd::handleSimReqVCXchanVis(SimEventQueue& q, rutz::shared_ptr<SimReqVCXchanVis>& r)
00149 {
00150 LINFO("Triggering visitor %s", r->toString().c_str());
00151 r->preProcessing(itsVCX.get());
00152 itsVCX->accept(*(r->visitor()));
00153 r->postProcessing(itsVCX.get());
00154 }
00155
00156
00157 void VisualCortexStd::onSimEventSaveOutput(SimEventQueue& q, rutz::shared_ptr<SimEventSaveOutput>& e)
00158 {
00159
00160
00161 nub::ref<FrameOstream> ofs = dynamic_cast<const SimModuleSaveInfo&>(e->sinfo()).ofs;
00162
00163 itsVCX->saveResults(ofs);
00164 }
00165
00166
00167
00168 VisualCortexInt::VisualCortexInt(OptionManager& mgr,
00169 const std::string& descrName,
00170 const std::string& tag) :
00171 VisualCortex(mgr, descrName, tag),
00172 SIMCALLBACK_INIT(SimEventRetinaImage),
00173 SIMCALLBACK_INIT(SimEventSaveOutput),
00174 SIMREQHANDLER_INIT(SimReqVCXfeatures),
00175 SIMREQHANDLER_INIT(SimReqVCXmaps),
00176 SIMREQHANDLER_INIT(SimReqVCXchanVis),
00177 itsIME(new IntegerMathEngine(mgr)),
00178 itsVCX(new IntegerRawVisualCortex(mgr, itsIME))
00179 {
00180 GVX_TRACE(__PRETTY_FUNCTION__);
00181 addSubComponent(itsIME);
00182 addSubComponent(itsVCX);
00183
00184
00185 mgr.setOptionValString(&OPT_MaxNormType, "Maxnorm");
00186 mgr.setOptionValString(&OPT_DirectionChannelLowThresh, "0");
00187 mgr.setOptionValString(&OPT_IntChannelScaleBits, "16");
00188 mgr.setOptionValString(&OPT_IntMathLowPass5, "lp5optim");
00189 mgr.setOptionValString(&OPT_IntMathLowPass9, "lp9optim");
00190 mgr.setOptionValString(&OPT_RawVisualCortexOutputFactor, "1.0e-12");
00191 }
00192
00193
00194 VisualCortexInt::VisualCortexInt(OptionManager& mgr,
00195 const std::string& descrName,
00196 const std::string& tag, nub::ref<IntegerMathEngine> ime,
00197 nub::ref<IntegerRawVisualCortex> vcx) :
00198 VisualCortex(mgr, descrName, tag),
00199 SIMCALLBACK_INIT(SimEventRetinaImage),
00200 SIMCALLBACK_INIT(SimEventSaveOutput),
00201 SIMREQHANDLER_INIT(SimReqVCXfeatures),
00202 SIMREQHANDLER_INIT(SimReqVCXmaps),
00203 SIMREQHANDLER_INIT(SimReqVCXchanVis),
00204 itsIME(ime),
00205 itsVCX(vcx),
00206 itsPcache()
00207 {
00208 GVX_TRACE(__PRETTY_FUNCTION__);
00209 addSubComponent(itsIME);
00210 addSubComponent(itsVCX);
00211
00212
00213 mgr.setOptionValString(&OPT_MaxNormType, "Maxnorm");
00214 mgr.setOptionValString(&OPT_DirectionChannelLowThresh, "0");
00215 mgr.setOptionValString(&OPT_IntChannelScaleBits, "16");
00216 mgr.setOptionValString(&OPT_IntMathLowPass5, "lp5optim");
00217 mgr.setOptionValString(&OPT_IntMathLowPass9, "lp9optim");
00218 mgr.setOptionValString(&OPT_RawVisualCortexOutputFactor, "1.0e-12");
00219 }
00220
00221
00222 VisualCortexInt::~VisualCortexInt()
00223 {
00224 GVX_TRACE(__PRETTY_FUNCTION__);
00225 }
00226
00227
00228 void VisualCortexInt::onSimEventRetinaImage(SimEventQueue& q, rutz::shared_ptr<SimEventRetinaImage>& e)
00229 {
00230
00231 IntegerInput inp = IntegerInput::fromRgb(e->frame().colorByte(), itsIME->getNbits());
00232 itsVCX->inputInt(inp, q.now(), &itsPcache);
00233
00234
00235 Image<float> fout = itsVCX->getOutput();
00236 q.post(rutz::make_shared(new SimEventVisualCortexOutput(this, fout)));
00237 }
00238
00239
00240 void VisualCortexInt::handleSimReqVCXfeatures(SimEventQueue& q, rutz::shared_ptr<SimReqVCXfeatures>& r)
00241 {
00242 itsVCX->getFeatures(r->loc(), r->features());
00243 }
00244
00245
00246 void VisualCortexInt::handleSimReqVCXmaps(SimEventQueue& q, rutz::shared_ptr<SimReqVCXmaps>& r)
00247 {
00248 r->populateChannelMaps(itsVCX.get());
00249 }
00250
00251
00252 void VisualCortexInt::handleSimReqVCXchanVis(SimEventQueue& q, rutz::shared_ptr<SimReqVCXchanVis>& r)
00253 {
00254 LFATAL("Not supported yet...");
00255
00256
00257
00258
00259
00260 }
00261
00262
00263 void VisualCortexInt::onSimEventSaveOutput(SimEventQueue& q, rutz::shared_ptr<SimEventSaveOutput>& e)
00264 {
00265
00266
00267 nub::ref<FrameOstream> ofs = dynamic_cast<const SimModuleSaveInfo&>(e->sinfo()).ofs;
00268
00269 itsVCX->saveResults(ofs);
00270 }
00271
00272
00273
00274 VisualCortexEnv::VisualCortexEnv(OptionManager& mgr,
00275 const std::string& descrName,
00276 const std::string& tag) :
00277 VisualCortex(mgr, descrName, tag),
00278 SIMCALLBACK_INIT(SimEventRetinaImage),
00279 SIMCALLBACK_INIT(SimEventSaveOutput),
00280 SIMREQHANDLER_INIT(SimReqVCXfeatures),
00281 SIMREQHANDLER_INIT(SimReqVCXmaps),
00282 SIMREQHANDLER_INIT(SimReqVCXchanVis),
00283 itsVCX(new EnvVisualCortexFloat(mgr))
00284 {
00285 GVX_TRACE(__PRETTY_FUNCTION__);
00286 addSubComponent(itsVCX);
00287 }
00288
00289
00290 VisualCortexEnv::~VisualCortexEnv()
00291 {
00292 GVX_TRACE(__PRETTY_FUNCTION__);
00293 }
00294
00295
00296 void VisualCortexEnv::onSimEventRetinaImage(SimEventQueue& q, rutz::shared_ptr<SimEventRetinaImage>& e)
00297 {
00298
00299 itsVCX->input(e->frame().colorByte());
00300
00301
00302 q.post(rutz::make_shared(new SimEventVisualCortexOutput(this, itsVCX->getVCXmap())));
00303 }
00304
00305
00306 void VisualCortexEnv::handleSimReqVCXfeatures(SimEventQueue& q, rutz::shared_ptr<SimReqVCXfeatures>& r)
00307 {
00308 LFATAL("Not supported yet...");
00309
00310
00311
00312 }
00313
00314
00315 void VisualCortexEnv::handleSimReqVCXmaps(SimEventQueue& q, rutz::shared_ptr<SimReqVCXmaps>& r)
00316 {
00317 r->populateChannelMaps(itsVCX.get());
00318 }
00319
00320
00321 void VisualCortexEnv::handleSimReqVCXchanVis(SimEventQueue& q, rutz::shared_ptr<SimReqVCXchanVis>& r)
00322 {
00323 LFATAL("Not supported yet...");
00324
00325
00326
00327
00328
00329 }
00330
00331
00332 void VisualCortexEnv::onSimEventSaveOutput(SimEventQueue& q, rutz::shared_ptr<SimEventSaveOutput>& e)
00333 {
00334
00335
00336 nub::ref<FrameOstream> ofs = dynamic_cast<const SimModuleSaveInfo&>(e->sinfo()).ofs;
00337
00338
00339
00340 }
00341
00342
00343
00344
00345
00346