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 
00039 #include "Neuro/VisualCortexConfigurator.H"
00040 
00041 #include "Beowulf/Beowulf.H"
00042 #include "Channels/RawVisualCortex.H"
00043 #include "Channels/IntegerRawVisualCortex.H"
00044 #include "Channels/ChannelOpts.H"
00045 #include "Channels/ChannelVisitor.H"
00046 #include "Channels/EntropyChannel.H"
00047 #include "Channels/InformationChannel.H"
00048 #include "Channels/InputHandlerThreaded.H"
00049 #include "Channels/MichelsonChannel.H"
00050 #include "Channels/MultiSpectralResidualChannel.H"
00051 #include "Channels/PN03contrastChannel.H"
00052 #include "Channels/ScorrChannel.H"
00053 #include "Channels/SpectralResidualChannel.H"
00054 #include "Channels/TcorrChannel.H"
00055 #include "Channels/VarianceChannel.H"
00056 #include "Component/OptionManager.H"
00057 #include "Neuro/NeuroOpts.H"
00058 #include "Neuro/VisualCortex.H"
00059 #include "Neuro/VisualCortexBeo.H"
00060 #include "Neuro/VisualCortexEyeMvt.H"
00061 #include "Neuro/VisualCortexSurprise.H"
00062 #include "Beowulf/BeowulfOpts.H"
00063 #include "Util/StringUtil.H"
00064 
00065 namespace
00066 {
00067   class ThreadInstaller : public ChannelVisitor
00068   {
00069   public:
00070     ThreadInstaller()
00071     {}
00072 
00073     virtual ~ThreadInstaller()
00074     {}
00075 
00076     virtual void visitChannelBase(ChannelBase& chan)
00077     {
00078       LFATAL("I don't know how to configure channel '%s' for Threaded use",
00079              chan.descriptiveName().c_str());
00080     }
00081 
00082     virtual void visitSingleChannel(SingleChannel& chan)
00083     {
00084       chan.setInputHandler
00085         (rutz::make_shared(new InputHandlerThreaded));
00086     }
00087 
00088     virtual void visitComplexChannel(ComplexChannel& chan)
00089     {
00090       chan.setSubchanVisitor
00091         (rutz::make_shared(new ThreadInstaller));
00092 
00093       
00094       for (uint i = 0; i < chan.numChans(); ++i)
00095         chan.subChan(i)->accept(*this);
00096     }
00097   };
00098 }
00099 
00100 
00101 VisualCortexConfigurator::
00102 VisualCortexConfigurator(OptionManager& mgr,
00103                          const std::string& descrName,
00104                          const std::string& tagName) :
00105   ModelComponent(mgr, descrName, tagName),
00106   itsVCtype(&OPT_VisualCortexType, this),
00107   itsVC(new VisualCortex(mgr)), 
00108   itsBeo()
00109 {
00110   addSubComponent(itsVC);
00111 }
00112 
00113 
00114 VisualCortexConfigurator::~VisualCortexConfigurator()
00115 {  }
00116 
00117 
00118 nub::ref<VisualCortex> VisualCortexConfigurator::getVC() const
00119 { return itsVC; }
00120 
00121 
00122 nub::soft_ref<Beowulf> VisualCortexConfigurator::getBeo() const
00123 { return itsBeo; }
00124 
00125 
00126 void VisualCortexConfigurator::paramChanged(ModelParamBase* const param,
00127                                             const bool valueChanged,
00128                                             ParamClient::ChangeStatus* status)
00129 {
00130   ModelComponent::paramChanged(param, valueChanged, status);
00131 
00132   
00133   if (param == &itsVCtype) {
00134     
00135     LINFO("Configuring VC of type %s", itsVCtype.getVal().c_str());
00136     OptionManager& mgr = this->getManager();
00137 
00138     
00139     
00140     
00141     
00142     
00143     
00144     
00145     LINFO("Resetting VisualCortex...");
00146     removeSubComponent(*itsVC);
00147     itsVC.reset(new VisualCortex(mgr));
00148 
00149     if (itsBeo.isValid()) {
00150       LINFO("Resetting VisualCortex Beowulf...");
00151       removeSubComponent(*itsBeo); itsBeo.reset(NULL);
00152     }
00153 
00154     
00155     std::vector<std::string> tok;
00156     split(itsVCtype.getVal(), ":", std::back_inserter(tok));
00157     bool threaded = false; const std::string vct = tok.back(); tok.pop_back();
00158     for (size_t i = 0; i < tok.size(); ++i)
00159       if (tok[i].compare("Thread") == 0) threaded = true;
00160       else LFATAL("Unknown vc-type modifier: %s", tok[i].c_str());
00161 
00162     
00163 
00164     
00165     if (vct.compare("None") == 0 || vct.compare("Stub") == 0)
00166       itsVC.reset(new VisualCortex(mgr));
00167 
00168     
00169     else if (vct.compare("Std") == 0)
00170       {
00171         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr, "Visual Cortex", "VisualCortex"));
00172         if (threaded) {
00173           vcx->itsVCX->setSubchanVisitor(rutz::make_shared(new ThreadInstaller));
00174           vcx->itsVCX->sortChannelsByNumSubmaps(true);
00175         }
00176         itsVC = vcx;
00177       }
00178     
00179     else if (vct.compare("EyeMvt") == 0)
00180       itsVC.reset(new VisualCortexEyeMvt(mgr));
00181 
00182     
00183     else if (vct.compare("Entrop") == 0) 
00184       {
00185         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr));
00186         vcx->itsVCX->removeAllSubChans(); vcx->itsVCX->hideOption(&OPT_RawVisualCortexChans);
00187         nub::soft_ref<EntropyChannel> channel(new EntropyChannel(mgr));
00188         vcx->itsVCX->addSubChan(channel);
00189         mgr.setOptionValString(&OPT_LevelSpec, "4-4,0-0,4");
00190         itsVC = vcx;
00191       }
00192 
00193     
00194     else if (vct.compare("Variance") == 0)
00195       {
00196         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr));
00197         vcx->itsVCX->removeAllSubChans(); vcx->itsVCX->hideOption(&OPT_RawVisualCortexChans);
00198         nub::soft_ref<VarianceChannel> channel(new VarianceChannel(mgr));
00199         vcx->itsVCX->addSubChan(channel);
00200         mgr.setOptionValString(&OPT_LevelSpec, "4-4,0-0,4");
00201         itsVC = vcx;
00202       }
00203 
00204     
00205     else if (vct.compare("Michelson") == 0)
00206       {
00207         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr));
00208         vcx->itsVCX->removeAllSubChans(); vcx->itsVCX->hideOption(&OPT_RawVisualCortexChans);
00209         nub::soft_ref<MichelsonChannel> channel(new MichelsonChannel(mgr));
00210         vcx->itsVCX->addSubChan(channel);
00211         mgr.setOptionValString(&OPT_LevelSpec, "4-4,0-0,4");
00212         itsVC = vcx;
00213       }
00214 
00215     
00216     else if (vct.compare("Tcorr") == 0)
00217       {
00218         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr));
00219         vcx->itsVCX->removeAllSubChans(); vcx->itsVCX->hideOption(&OPT_RawVisualCortexChans);
00220         nub::soft_ref<TcorrChannel> channel(new TcorrChannel(mgr));
00221         vcx->itsVCX->addSubChan(channel);
00222         mgr.setOptionValString(&OPT_LevelSpec, "4-4,0-0,4");
00223         itsVC = vcx;
00224       }
00225 
00226     
00227     else if (vct.compare("Scorr") == 0)
00228       {
00229         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr));
00230         vcx->itsVCX->removeAllSubChans(); vcx->itsVCX->hideOption(&OPT_RawVisualCortexChans);
00231         nub::soft_ref<ScorrChannel> channel(new ScorrChannel(mgr));
00232         vcx->itsVCX->addSubChan(channel);
00233         mgr.setOptionValString(&OPT_LevelSpec, "4-4,0-0,4");
00234         itsVC = vcx;
00235       }
00236 
00237     
00238     else if (vct.compare("Info") == 0)
00239       {
00240         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr));
00241         vcx->itsVCX->removeAllSubChans(); vcx->itsVCX->hideOption(&OPT_RawVisualCortexChans);
00242         nub::soft_ref<InformationChannel> channel(new InformationChannel(mgr));
00243         vcx->itsVCX->addSubChan(channel);
00244         mgr.setOptionValString(&OPT_LevelSpec, "4-4,0-0,4");
00245         itsVC = vcx;
00246       }
00247 
00248     
00249     else if (vct.compare("PN03contrast") == 0)
00250       {
00251         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr));
00252         vcx->itsVCX->removeAllSubChans(); vcx->itsVCX->hideOption(&OPT_RawVisualCortexChans);
00253         nub::soft_ref<PN03contrastChannel> channel(new PN03contrastChannel(mgr));
00254         vcx->itsVCX->addSubChan(channel);
00255         mgr.setOptionValString(&OPT_LevelSpec, "4-4,0-0,4");
00256         itsVC = vcx;
00257       }
00258 
00259     
00260     else if (vct.compare("SpectralResidual") == 0)
00261       {
00262         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr));
00263         vcx->itsVCX->removeAllSubChans(); vcx->itsVCX->hideOption(&OPT_RawVisualCortexChans);
00264         nub::soft_ref<SpectralResidualChannel> channel(new SpectralResidualChannel(mgr));
00265         vcx->itsVCX->addSubChan(channel);
00266         mgr.setOptionValString(&OPT_LevelSpec, "4-4,0-0,4");
00267         itsVC = vcx;
00268       }
00269 
00270     
00271     else if (vct.compare("MultiSpectralResidual") == 0)
00272       {
00273         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr));
00274         vcx->itsVCX->removeAllSubChans(); vcx->itsVCX->hideOption(&OPT_RawVisualCortexChans);
00275         nub::soft_ref<MultiSpectralResidualChannel> channel(new MultiSpectralResidualChannel(mgr));
00276         vcx->itsVCX->addSubChan(channel);
00277         mgr.setOptionValString(&OPT_LevelSpec, "4-4,0-0,4");
00278         itsVC = vcx;
00279       }
00280 
00281     
00282     else if (vct.compare("Beo") == 0)
00283       {
00284         itsBeo.reset(new Beowulf(mgr, "Visual Cortex Beowulf", "VisualCortexBeowulf", true));
00285         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr, "Visual Cortex", "VisualCortex"));
00286         setupVisualCortexBeo(*(vcx->itsVCX), itsBeo);
00287         itsVC = vcx;
00288       }
00289 
00290     
00291     else if (vct.compare("Surp") == 0)
00292       {
00293         nub::ref<VisualCortexSurprise> vcs(new VisualCortexSurprise(mgr));
00294         nub::ref<VisualCortexStd> vcx(new VisualCortexStd(mgr, "Visual Cortex", "VisualCortex", vcs));
00295         if (threaded) {
00296           vcx->itsVCX->setSubchanVisitor(rutz::make_shared(new ThreadInstaller));
00297           vcx->itsVCX->sortChannelsByNumSubmaps(true);
00298         }
00299         itsVC = vcx;
00300       }
00301 
00302     
00303     else if (vct.compare("Int") == 0)
00304       {
00305         nub::ref<VisualCortexInt> vcx(new VisualCortexInt(mgr, "Visual Cortex", "VisualCortex"));
00306         if (threaded) {
00307           vcx->itsVCX->setSubchanVisitor(rutz::make_shared(new ThreadInstaller));
00308           vcx->itsVCX->sortChannelsByNumSubmaps(true);
00309         }
00310         itsVC = vcx;
00311       }
00312     
00313     else if (vct.compare("Env") == 0)
00314       {
00315         nub::ref<VisualCortexEnv> vcx(new VisualCortexEnv(mgr, "Visual Cortex", "VisualCortex"));
00316         itsVC = vcx;
00317       }
00318     
00319     else
00320       LFATAL("Unknown vc-type: %s", vct.c_str());
00321 
00322     
00323     
00324     
00325     
00326     
00327     
00328     if (itsBeo.isValid())
00329       {
00330         addSubComponent(itsBeo);
00331 
00332         
00333         itsBeo->exportOptions(MC_RECURSE);
00334 
00335         
00336         mgr.setOptionValString(&OPT_BeowulfMaster, "true");
00337       }
00338 
00339     
00340     addSubComponent(itsVC);
00341 
00342     
00343     itsVC->exportOptions(MC_RECURSE);
00344   }
00345 }
00346 
00347 
00348 
00349 
00350 
00351 
00352