00001 /*! a test for the different neural sim modules */ 00002 ////////////////////////////////////////////////////////////////////////// 00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00004 // University of Southern California (USC) and the iLab at USC. // 00005 // See http://iLab.usc.edu for information about this project. // 00006 ////////////////////////////////////////////////////////////////////////// 00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00009 // in Visual Environments, and Applications'' by Christof Koch and // 00010 // Laurent Itti, California Institute of Technology, 2001 (patent // 00011 // pending; application number 09/912,225 filed July 23, 2001; see // 00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00013 ////////////////////////////////////////////////////////////////////////// 00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00015 // // 00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00017 // redistribute it and/or modify it under the terms of the GNU General // 00018 // Public License as published by the Free Software Foundation; either // 00019 // version 2 of the License, or (at your option) any later version. // 00020 // // 00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00024 // PURPOSE. See the GNU General Public License for more details. // 00025 // // 00026 // You should have received a copy of the GNU General Public License // 00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00029 // Boston, MA 02111-1307 USA. // 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 //modules are registered by just including their header. 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 //main 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 //setup our simulation time 00084 GenericFrameSpec gfs(ifs->peekFrameSpec()); 00085 SimTime time(SimTime::ZERO()), timestepstim(SimTime::HERTZ(gfs.frameRate)), timestepmodel(itsSimTimeStep.getVal()); 00086 00087 //setup one of our SimUnits 00088 double excite(0),inhibit(0); 00089 convertFromString(manager.getExtraArg(0), excite); 00090 convertFromString(manager.getExtraArg(1), inhibit); 00091 00092 //set timestep in model factory components 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 //get the input 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 //input to system 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 /* So things look consistent in everyone's emacs... */ 00171 /* Local Variables: */ 00172 /* indent-tabs-mode: nil */ 00173 /* End: */