app-WTA-test.C
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 #include "Component/ModelManager.H"
00035 #include "Channels/InputFrame.H"
00036 #include "Image/Image.H"
00037 #include "Media/FrameSeries.H"
00038 #include "Raster/GenericFrame.H"
00039 #include "Raster/Raster.H"
00040 #include "Transport/FrameInfo.H"
00041 #include "Util/Pause.H"
00042 #include "Util/csignals.H"
00043
00044 #ifdef INVT_USE_CPPOX//we need c++ 0X features for this to work
00045 #include "ModelNeuron/SupColliculusModule.H"
00046 #include "ModelNeuron/NeuralFieldModule.H"
00047
00048 int submain(const int argc, const char** argv)
00049 {
00050 volatile int signum = 0;
00051 catchsignals(&signum);
00052 MYLOGVERB = LOG_INFO;
00053
00054 ModelManager manager("WTA Model Testing Program");
00055
00056
00057 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00058 manager.addSubComponent(ofs);
00059
00060 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00061 manager.addSubComponent(ifs);
00062
00063
00064 nub::ref<SupColliculusModule> sc(new SupColliculusModule(manager));
00065 manager.addSubComponent(sc);
00066
00067
00068 nub::ref<NeuralFieldModule> nf(new NeuralFieldModule(manager));
00069 manager.addSubComponent(nf);
00070
00071
00072 if (manager.parseCommandLine(argc, argv, "NF or SC", 1, 1) == false)
00073 return(1);
00074
00075 if (manager.getExtraArg(0).compare("NF") == 0)
00076 manager.removeSubComponent(sc);
00077 else if (manager.getExtraArg(0).compare("SC") == 0)
00078 manager.removeSubComponent(nf);
00079 else
00080 LFATAL("No such type");
00081
00082 manager.start();
00083
00084 ifs->startStream();
00085
00086 int c = 0;
00087 PauseWaiter p;
00088
00089
00090 SimTime timestep = SimTime::MSECS(1000/ifs->peekFrameSpec().frameRate);
00091 SimTime time = SimTime::ZERO();
00092
00093 while (true)
00094 {
00095 if (signum != 0)
00096 {
00097 LINFO("quitting because %s was caught", signame(signum));
00098 return -1;
00099 }
00100
00101 if (ofs->becameVoid())
00102 {
00103 LINFO("quitting because output stream was closed or became void");
00104 return 0;
00105 }
00106
00107 if (p.checkPause())
00108 continue;
00109
00110 const FrameState is = ifs->updateNext();
00111 if (is == FRAME_COMPLETE)
00112 break;
00113
00114 GenericFrame input = ifs->readFrame();
00115 if (!input.initialized())
00116 break;
00117
00118
00119 time += timestep;
00120 if (manager.getExtraArg(0).compare("NF") == 0)
00121 {
00122 nf->setInput(input.asFloat(), 0);
00123 nf->update(time);
00124 }
00125 else
00126 {
00127 sc->setInput(input.asFloat(), 0);
00128 sc->update(time);
00129 }
00130 LINFO("Time: %3.2f", time.msecs());
00131
00132
00133 const FrameState os = ofs->updateNext();
00134
00135
00136 ofs->writeFrame(input, "input frame");
00137 if (manager.getExtraArg(0).compare("NF") == 0)
00138 ofs->writeRgbLayout(nf->getDisplay(), "NF Simulation");
00139 else
00140 ofs->writeRgbLayout(sc->getDisplay(), "SC Simulation");
00141
00142 if (os == FRAME_FINAL)
00143 break;
00144
00145 LDEBUG("frame %d", c++);
00146
00147 if (ifs->shouldWait() || ofs->shouldWait())
00148 Raster::waitForKey();
00149 }
00150
00151 return 0;
00152 }
00153 #else
00154 int submain(const int argc, const char** argv) {return 0; };
00155 #endif
00156
00157 int main(const int argc, const char **argv)
00158 {
00159 try
00160 {
00161 return submain(argc, argv);
00162 }
00163 catch (...)
00164 {
00165 REPORT_CURRENT_EXCEPTION;
00166 }
00167 return 1;
00168 }
00169
00170
00171
00172
00173
00174