test-beoGrab-master.C

Go to the documentation of this file.
00001 /*!@file Parallel/test-beoGrab-master.C Test frame grabbing and X display */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Parallel/test-beoGrab-master.C $
00035 // $Id: test-beoGrab-master.C 6431 2006-04-06 20:38:04Z rjpeters $
00036 //
00037 
00038 #include "Image/Image.H"
00039 #include "Image/Pixels.H"
00040 #include "Util/Types.H"
00041 #include "Beowulf/Beowulf.H"
00042 #include "Component/ModelManager.H"
00043 #include "GUI/XWinManaged.H"
00044 #include "Util/log.H"
00045 
00046 #include <cstdio>
00047 #include <cstdlib>
00048 #include <cstring>
00049 
00050 /*! This simple executable tests video frame grabbing through the
00051   video4linux driver (see V4Lgrabber.H) or the IEEE1394 (firewire)
00052   grabber (see IEEE1394grabber.H). Selection of the grabber type is
00053   made via the --fg-type=XX command-line option. */
00054 int main(const int argc, const char **argv)
00055 {
00056   // instantiate a model manager:
00057   ModelManager manager("Beo Frame Grabber Tester Master");
00058 
00059   // Instantiate our various ModelComponents:
00060 
00061   nub::soft_ref<Beowulf>
00062     beo(new Beowulf(manager, "Beowulf Master", "BeowulfMaster", true));
00063   manager.addSubComponent(beo);
00064 
00065   // Parse command-line:
00066   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00067 
00068   TCPmessage rmsg;      // buffer to receive messages from nodes
00069   TCPmessage smsg;      // buffer to send messages to nodes
00070 
00071   // let's get all our ModelComponent instances started:
00072   manager.start();
00073 
00074   // get ready for main loop:
00075   XWinManaged* winA = 0;
00076   XWinManaged* winB = 0;
00077   XWinManaged* winC = 0;
00078   XWinManaged* winE = 0;
00079   CloseButtonListener listener;
00080 
00081   smsg.addInt32(1);
00082 
00083   // kick all of the slave nodes into action:
00084   for (int rnode = 0; rnode < beo->getNbSlaves(); ++rnode)
00085     beo->send(rnode,smsg);
00086 
00087   int32 rframe = 0, raction = 0;
00088 
00089   while(1)
00090   {
00091     int rnode = 0;
00092     if (rnode < beo->getNbSlaves()
00093         && beo->receive(rnode, rmsg, rframe, raction, 5))
00094       {
00095         Image< PixRGB<byte> > ima = rmsg.getElementColByteIma();
00096 
00097         const std::string info = rmsg.getElementString();
00098         LINFO("received info: '%s'", info.c_str());
00099 
00100         if (winA == 0)
00101           {
00102             winA = new XWinManaged(ima, beo->nodeName(rnode));
00103             listener.add(winA);
00104           }
00105         else
00106           winA->drawImage(ima);
00107 
00108         beo->send(rnode,smsg);
00109       }
00110     rmsg.reset(rframe, raction);
00111 
00112     rnode++;
00113     if (rnode < beo->getNbSlaves()
00114         && beo->receive(rnode, rmsg, rframe, raction, 5))
00115       {
00116         Image< PixRGB<byte> > ima = rmsg.getElementColByteIma();
00117 
00118         const std::string info = rmsg.getElementString();
00119         LINFO("received info: '%s'", info.c_str());
00120 
00121         if (winB == 0)
00122           {
00123             winB = new XWinManaged(ima, beo->nodeName(rnode));
00124             listener.add(winB);
00125           }
00126         else
00127           winB->drawImage(ima);
00128 
00129         beo->send(rnode,smsg);
00130       }
00131     rmsg.reset(rframe, raction);
00132 
00133     rnode++;
00134     if (rnode < beo->getNbSlaves()
00135         && beo->receive(rnode, rmsg, rframe, raction, 5))
00136       {
00137         Image< PixRGB<byte> > ima = rmsg.getElementColByteIma();
00138 
00139         const std::string info = rmsg.getElementString();
00140         LINFO("received info: '%s'", info.c_str());
00141 
00142         if (winC == 0)
00143           {
00144             winC = new XWinManaged(ima, beo->nodeName(rnode));
00145             listener.add(winC);
00146           }
00147         else
00148           winC->drawImage(ima);
00149 
00150         beo->send(rnode,smsg);
00151       }
00152     rmsg.reset(rframe, raction);
00153 
00154     rnode++;
00155     if (rnode < beo->getNbSlaves()
00156         && beo->receive(rnode, rmsg, rframe, raction, 5))
00157       {
00158         Image< PixRGB<byte> > ima = rmsg.getElementColByteIma();
00159 
00160         const std::string info = rmsg.getElementString();
00161         LINFO("received info: '%s'", info.c_str());
00162 
00163         if (winE == 0)
00164           {
00165             winE = new XWinManaged(ima, beo->nodeName(rnode));
00166             listener.add(winE);
00167           }
00168         else
00169           winE->drawImage(ima);
00170 
00171         beo->send(rnode,smsg);
00172       }
00173     rmsg.reset(rframe, raction);
00174 
00175     if (listener.pressedAnyCloseButton())
00176       break;
00177   }
00178 
00179   delete winA;
00180   delete winB;
00181   delete winC;
00182   delete winE;
00183 
00184   // stop all our ModelComponents
00185   manager.stop();
00186 
00187   // all done!
00188   return 0;
00189 }
00190 
00191 // ######################################################################
00192 /* So things look consistent in everyone's emacs... */
00193 /* Local Variables: */
00194 /* indent-tabs-mode: nil */
00195 /* End: */
Generated on Sun May 8 08:05:30 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3