test-ModelManagerQt.cpp

Go to the documentation of this file.
00001 /*! @file Qt/test-ModelManagerQt.cpp test Qt interface for a more interactive alternative to command line configs */
00002 
00003 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Qt/test-ModelManagerQt.cpp $
00004 // $Id: test-ModelManagerQt.cpp 10993 2009-03-06 06:05:33Z itti $
00005 
00006 #include "Component/ModelManager.H"
00007 #include "Qt/ui/ModelManagerControl.h"
00008 #include "Neuro/StdBrain.H"
00009 #include "Neuro/VisualCortexConfigurator.H"
00010 #include "QtUtil/Util.H"
00011 #include "Simulation/SimEventQueueConfigurator.H"
00012 #include "Component/JobServerConfigurator.H"
00013 #include "Media/SimFrameSeries.H"
00014 #include "Neuro/NeuroOpts.H"
00015 
00016 #include <qapplication.h>
00017 #include <qthread.h>
00018 #include <unistd.h>
00019 
00020 class ModelRun : public QThread {
00021 public:
00022   ModelRun(ModelManager *mgr_, nub::ref<SimEventQueueConfigurator> seqc_, bool *dorun_) :
00023     QThread(), mgr(mgr_), seqc(seqc_), dorun(dorun_)
00024   { }
00025 
00026   virtual void run() {
00027     while(true) {
00028       // wait until ready to start
00029       if (*dorun == false) { usleep(50000); continue; }
00030 
00031       // let's do it!
00032       mgr->start();
00033       nub::ref<SimEventQueue> q = seqc->getQ();
00034 
00035       // run until all data has been processed:
00036       SimStatus status = SIM_CONTINUE;
00037       while (status == SIM_CONTINUE && *dorun == true) status = q->evolve();
00038 
00039       // print final memory allocation stats
00040       LINFO("Simulation terminated.");
00041 
00042       // stop all our ModelComponents
00043       mgr->stop();
00044     }
00045   }
00046 
00047 private:
00048   ModelManager *mgr;
00049   nub::ref<SimEventQueueConfigurator> seqc;
00050   bool *dorun;
00051 };
00052 
00053 int main( int argc, const char ** argv )
00054 {
00055   // instantiate a model manager:
00056   ModelManager mgr( "model manager" );
00057 
00058   // instantiate our various ModelComponents:
00059   nub::ref<JobServerConfigurator> jsc(new JobServerConfigurator(mgr));
00060   mgr.addSubComponent(jsc);
00061 
00062   nub::ref<SimEventQueueConfigurator> seqc(new SimEventQueueConfigurator(mgr));
00063   mgr.addSubComponent(seqc);
00064 
00065   // NOTE: make sure you register your OutputFrameSeries with the
00066   // manager before you do your InputFrameSeries, to ensure that
00067   // outputs for the current frame get saved before the next input
00068   // frame is loaded.
00069   nub::ref<SimOutputFrameSeries> ofs(new SimOutputFrameSeries(mgr));
00070   mgr.addSubComponent(ofs);
00071 
00072   nub::ref<SimInputFrameSeries> ifs(new SimInputFrameSeries(mgr));
00073   mgr.addSubComponent(ifs);
00074 
00075   nub::ref<StdBrain> brain(new StdBrain(mgr));
00076   mgr.addSubComponent(brain);
00077 
00078   // Request a bunch of option aliases (shortcuts to lists of options):
00079   REQUEST_OPTIONALIAS_NEURO(mgr);
00080 
00081   // Parse command-line:
00082   if (mgr.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00083   // NOTE: change this so that it brings up alert box and config dialog
00084 
00085   // get our thread going:
00086   bool dorun = false;
00087   ModelRun mr(&mgr, seqc, &dorun);
00088   mr.start();
00089 
00090   // show the configuration dialog
00091   QApplication a( argc, argv2qt( argc, argv ) );
00092   ModelManagerControl mmc;
00093   mmc.init( mgr, &dorun );
00094   mmc.show();
00095   a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
00096   a.exec();
00097 
00098   return 0;
00099 }
Generated on Sun May 8 08:05:33 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3