00001 //Test our WTA, SC map etc. 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 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; // suppress debug messages 00053 00054 ModelManager manager("WTA Model Testing Program"); 00055 00056 //hook up our frameseries 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 //hook up an SC module 00064 nub::ref<SupColliculusModule> sc(new SupColliculusModule(manager)); 00065 manager.addSubComponent(sc); 00066 00067 //hook up an SC module 00068 nub::ref<NeuralFieldModule> nf(new NeuralFieldModule(manager)); 00069 manager.addSubComponent(nf); 00070 00071 //parse command line and start manager 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 //simulation time 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 //input to model and evolve 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 //update to next frame 00133 const FrameState os = ofs->updateNext(); 00134 00135 //save output 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 /* So things look consistent in everyone's emacs... */ 00172 /* Local Variables: */ 00173 /* indent-tabs-mode: nil */ 00174 /* End: */