app-IZNeuron-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 #include "Component/ModelManager.H"
00033 #include "Component/ModelOptionDef.H"
00034 #include "Image/Image.H"
00035 #include "Image/Layout.H"
00036 #include "Image/DrawOps.H"
00037 #include "Raster/GenericFrame.H"
00038 #include "Raster/Raster.H"
00039 #include "Media/FrameSeries.H"
00040 #include "Util/StringConversions.H"
00041
00042 #include <cstdio>
00043 #include <cstdlib>
00044 #include <cstring>
00045
00046 #ifdef INVT_USE_CPPOX//we need c++ 0X features for this to work
00047
00048 #include "ModelNeuron/SimStructureOpts.H"
00049 #include "ModelNeuron/SimUnit.H"
00050 #include "ModelNeuron/PlotBuffer.H"
00051 #include "ModelNeuron/NeuralSimUtils.H"
00052
00053
00054 #include "ModelNeuron/LowPass.H"
00055 #include "ModelNeuron/LowpassNeuron.H"
00056 #include "ModelNeuron/Rectify.H"
00057 #include "ModelNeuron/IZNeuron.H"
00058 #include "ModelNeuron/Circuits.H"
00059
00060
00061
00062 int submain(const int argc, const char** argv)
00063 {
00064 ModelManager manager("SimUnit Test");
00065 OModelParam<uint> itsDepth(&OPT_SCProbeDepth, &manager);
00066 OModelParam<bool> itsDisplayOutput(&OPT_SCUseDisplayOutput, &manager);
00067 OModelParam<SimTime> itsSimTimeStep(&OPT_SCSimTimeStep, &manager);
00068
00069 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00070 manager.addSubComponent(ofs);
00071
00072 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00073 manager.addSubComponent(ifs);
00074
00075 if (manager.parseCommandLine(argc, argv,
00076 "<excite strength> <inhibit strenth> "
00077 "<comp module> <decoder>", 4, 4) == false)
00078 return 1;
00079
00080 manager.start();
00081 ifs->startStream();
00082
00083
00084 GenericFrameSpec gfs(ifs->peekFrameSpec());
00085 SimTime time(SimTime::ZERO()), timestepstim(SimTime::HERTZ(gfs.frameRate)), timestepmodel(itsSimTimeStep.getVal());
00086
00087
00088 double excite(0),inhibit(0);
00089 convertFromString(manager.getExtraArg(0), excite);
00090 convertFromString(manager.getExtraArg(1), inhibit);
00091
00092
00093 nsu::setParameter(SimUnit::Factory::instance(), timestepmodel);
00094 nsu::setParameter(NeuralDecoder::Factory::instance(), timestepmodel);
00095
00096 SimUnit* iz = SimUnit::Factory::instance().create(manager.getExtraArg(2));
00097 NeuralDecoder* nd = NeuralDecoder::Factory::instance().create(manager.getExtraArg(3));
00098
00099 iz->setDecoderPost(*nd);
00100
00101 PlotBuffer pb;
00102 pb.setSamplingRate(timestepstim);
00103
00104 while (true)
00105 {
00106
00107 const FrameState is = ifs->updateNext();
00108 if (is == FRAME_COMPLETE)
00109 break;
00110
00111 GenericFrame input = ifs->readFrame();
00112 if (!input.initialized())
00113 break;
00114
00115 time += timestepstim;
00116 LINFO("Time: %3.10f",time.msecs());
00117
00118
00119 Image<double> img = input.asFloat();
00120 double inp = img.getVal(0,0);
00121
00122 iz->input(excite * inp);
00123 iz->input(-1.0 * inhibit * inp);
00124
00125 iz->evolve(time);
00126 pb.push(*iz, 0, itsDepth.getVal(), itsDisplayOutput.getVal());
00127 }
00128
00129 LINFO("Simulation complete - Drawing");
00130
00131 if (ofs->becameVoid())
00132 {
00133 LINFO("quitting because output stream was closed or became void");
00134 return 0;
00135 }
00136
00137 ofs->updateNext();
00138 Layout<PixRGB<byte> > oimage = pb.draw(false, 640, pb.getTotal()*150);
00139 ofs->writeRgbLayout(oimage, "output");
00140
00141 if (ofs->shouldWait())
00142 Raster::waitForKey();
00143
00144 delete iz;
00145 delete nd;
00146
00147 return 0;
00148 }
00149 #else
00150 int submain(const int argc, const char** argv) {return 0; };
00151 #endif
00152
00153 int main(const int argc, const char **argv)
00154 {
00155 try
00156 {
00157 return submain(argc, argv);
00158 }
00159 catch (...)
00160 {
00161 REPORT_CURRENT_EXCEPTION;
00162 }
00163
00164 return 1;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173