LoLaserMain.C

Go to the documentation of this file.
00001 /**
00002    \file Robots/LoBot/LoLaserMain.C
00003 
00004    \brief Testing the Hokuyo laser range finder.
00005 
00006    This program implements a simple GUI to help visualize the distance
00007    measurements made by lobot's Hokuyo laser range finder.
00008 */
00009 
00010 // //////////////////////////////////////////////////////////////////// //
00011 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00012 // by the University of Southern California (USC) and the iLab at USC.  //
00013 // See http://iLab.usc.edu for information about this project.          //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00016 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00017 // in Visual Environments, and Applications'' by Christof Koch and      //
00018 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00019 // pending; application number 09/912,225 filed July 23, 2001; see      //
00020 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00021 // //////////////////////////////////////////////////////////////////// //
00022 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00023 //                                                                      //
00024 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00025 // redistribute it and/or modify it under the terms of the GNU General  //
00026 // Public License as published by the Free Software Foundation; either  //
00027 // version 2 of the License, or (at your option) any later version.     //
00028 //                                                                      //
00029 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00030 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00031 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00032 // PURPOSE.  See the GNU General Public License for more details.       //
00033 //                                                                      //
00034 // You should have received a copy of the GNU General Public License    //
00035 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00036 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00037 // Boston, MA 02111-1307 USA.                                           //
00038 // //////////////////////////////////////////////////////////////////// //
00039 //
00040 // Primary maintainer for this file: Manu Viswanathan <mviswana at usc dot edu>
00041 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/LoLaserMain.C $
00042 // $Id: LoLaserMain.C 13905 2010-09-09 21:38:44Z mviswana $
00043 //
00044 
00045 //--------------------------- LIBRARY CHECK -----------------------------
00046 
00047 #ifndef INVT_HAVE_LIBGLUT
00048 
00049 #include "Util/log.H"
00050 
00051 int main()
00052 {
00053    LERROR("Sorry, this program needs the OpenGL and GLUT libraries.") ;
00054    return 1 ;
00055 }
00056 
00057 #else
00058 
00059 //------------------------------ HEADERS --------------------------------
00060 
00061 // lobot headers
00062 #include "Robots/LoBot/ui/LoLaserWindow.H"
00063 
00064 #include "Robots/LoBot/config/LoConfig.H"
00065 #include "Robots/LoBot/config/LoCommonOpts.H"
00066 
00067 #include "Robots/LoBot/misc/LoExcept.H"
00068 
00069 // INVT model component support
00070 #include "Component/ModelManager.H"
00071 #include "Component/ModelParam.H"
00072 
00073 // INVT utilities
00074 #include "Util/log.H"
00075 
00076 // OpenGL headers
00077 #include <GL/glut.h>
00078 
00079 //------------------------ APPLICATION OBJECT ---------------------------
00080 
00081 // The following class wraps around the ModelManager and associated
00082 // objects, providing a neatly encapsulated API for the main program.
00083 namespace lobot {
00084 
00085 struct LoApp {
00086    LoApp(int argc, const char* argv[]) ;
00087    void run() ;
00088    ~LoApp() ;
00089 
00090 private:
00091    // We use the INVT model manager mostly for processing command line
00092    // arguments.
00093    ModelManager m_model_manager ;
00094 
00095    // Various command line options specific to this program.
00096    //
00097    // NOTE: There's only one! The --config-file option allows users to
00098    // specify the name of a file containing various settings. All
00099    // customization of this program's behaviour is achieved via this
00100    // settings file.
00101    OModelParam<std::string> m_cf_option ; // --config-file
00102 
00103    // Accessing command line arguments and config file settings
00104    std::string config_file() const {return m_cf_option.getVal() ;}
00105 
00106    // Initialization
00107    void init_glut(int* argc, char* argv[]) ;
00108    void parse_command_line(int argc, const char* argv[]) ;
00109 } ;
00110 
00111 } // end of namespace encapsulating above class definition
00112 
00113 //------------------------------- MAIN ----------------------------------
00114 
00115 int main(int argc, const char* argv[])
00116 {
00117    MYLOGVERB = LOG_ERR ; // minimize INVT's incessant chatter
00118    try
00119    {
00120       lobot::LoApp app(argc, argv) ;
00121       app.run() ;
00122    }
00123    catch (lobot::uhoh& e)
00124    {
00125       LERROR("%s", e.what()) ;
00126       return e.code() ;
00127    }
00128    catch (std::exception& e)
00129    {
00130       LERROR("%s", e.what()) ;
00131       return 255 ;
00132    }
00133    return 0 ;
00134 }
00135 
00136 //----------------------------- NAMESPACE -------------------------------
00137 
00138 namespace lobot {
00139 
00140 //----------------------------- APP INIT --------------------------------
00141 
00142 // Setup INVT model manager and GLUT and process command line options
00143 LoApp::LoApp(int argc, const char* argv[])
00144    : m_model_manager("lolaser"),
00145      m_cf_option(& OPT_ConfigFile, & m_model_manager)
00146 {
00147    init_glut(& argc, const_cast<char**>(argv)) ;
00148    parse_command_line(argc, argv) ;
00149 }
00150 
00151 void LoApp::init_glut(int* argc, char* argv[])
00152 {
00153    glutInit(argc, argv) ;
00154    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE) ;
00155 }
00156 
00157 void LoApp::parse_command_line(int argc, const char* argv[])
00158 {
00159    std::string default_config_file = getenv("HOME") ;
00160    default_config_file += "/.lolaserrc" ;
00161    m_model_manager.setOptionValString(& OPT_ConfigFile,
00162                                       default_config_file.c_str()) ;
00163 
00164    if (! m_model_manager.parseCommandLine(argc, argv, "", 0, 0))
00165       throw customization_error(BAD_OPTION) ;
00166 }
00167 
00168 //----------------------------- MAIN LOOP -------------------------------
00169 
00170 // Application object's run method (aka main loop)
00171 void LoApp::run()
00172 {
00173    try
00174    {
00175       m_model_manager.start() ;
00176       Configuration::load(config_file()) ;
00177       //Configuration::dump() ;
00178       m_model_manager.stop() ; // GLUT's main loop will prevent proper clean-up
00179    }
00180    catch (customization_error& e) // this is not fatal
00181    {
00182       LERROR("%s", e.what()) ; // simply report error and move on
00183    }
00184 
00185    LaserWindow::create("Hokuyo LRF Tester") ;
00186    glutMainLoop() ;
00187 }
00188 
00189 //--------------------------- APP CLEAN-UP ------------------------------
00190 
00191 LoApp::~LoApp(){}
00192 
00193 //------------------------------ HELPERS --------------------------------
00194 
00195 } // namespace lobot encapsulating application object and its helpers
00196 
00197 //-----------------------------------------------------------------------
00198 
00199 #endif // #ifndef INVT_HAVE_LIBGLUT
00200 
00201 /* So things look consistent in everyone's emacs... */
00202 /* Local Variables: */
00203 /* indent-tabs-mode: nil */
00204 /* End: */
Generated on Sun May 8 08:41:30 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3