LoLaserWindowGrid.C

Go to the documentation of this file.
00001 /**
00002    \file Robots/LoBot/ui/LoLaserWindowGrid.C
00003 
00004    \brief This file defines the non-inline member functions of the
00005    lobot::LaserWindowGrid class that is used to draw the LRF measurements
00006    grid.
00007 */
00008 
00009 // //////////////////////////////////////////////////////////////////// //
00010 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00011 // by the University of Southern California (USC) and the iLab at USC.  //
00012 // See http://iLab.usc.edu for information about this project.          //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00015 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00016 // in Visual Environments, and Applications'' by Christof Koch and      //
00017 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00018 // pending; application number 09/912,225 filed July 23, 2001; see      //
00019 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00020 // //////////////////////////////////////////////////////////////////// //
00021 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00024 // redistribute it and/or modify it under the terms of the GNU General  //
00025 // Public License as published by the Free Software Foundation; either  //
00026 // version 2 of the License, or (at your option) any later version.     //
00027 //                                                                      //
00028 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00029 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00030 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00031 // PURPOSE.  See the GNU General Public License for more details.       //
00032 //                                                                      //
00033 // You should have received a copy of the GNU General Public License    //
00034 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00035 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00036 // Boston, MA 02111-1307 USA.                                           //
00037 // //////////////////////////////////////////////////////////////////// //
00038 //
00039 // Primary maintainer for this file: Manu Viswanathan <mviswana at usc dot edu>
00040 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/ui/LoLaserWindowGrid.C $
00041 // $Id: LoLaserWindowGrid.C 11191 2009-05-16 19:11:59Z mviswana $
00042 //
00043 
00044 //---------------------- ALTERNATIVE DEFINITION -------------------------
00045 
00046 // In case OpenGL is missing...
00047 #ifndef INVT_HAVE_LIBGL
00048 
00049 #include "Robots/LoBot/ui/LoLaserWindowGrid.H"
00050 #include "Robots/LoBot/misc/LoExcept.H"
00051 
00052 namespace lobot {
00053 
00054 LaserWindowGrid::my_factory LaserWindowGrid::register_me("grid") ;
00055 
00056 LaserWindowGrid::LaserWindowGrid()
00057    : base()
00058 {
00059    throw missing_libs(MISSING_OPENGL) ;
00060 }
00061 
00062 // Empty API
00063 void LaserWindowGrid::render() const {}
00064 
00065 LaserWindowGrid::~LaserWindowGrid(){}
00066 
00067 }
00068 
00069 #else // OpenGL available ==> the real McCoy
00070 
00071 //------------------------------ HEADERS --------------------------------
00072 
00073 // lobot headers
00074 #include "Robots/LoBot/ui/LoLaserWindowGrid.H"
00075 
00076 // OpenGL headers
00077 #include <GL/gl.h>
00078 
00079 //----------------------------- NAMESPACE -------------------------------
00080 
00081 namespace lobot {
00082 
00083 //----------------------- FACTORY REGISTRATION --------------------------
00084 
00085 LaserWindowGrid::my_factory LaserWindowGrid::register_me("grid") ;
00086 
00087 //-------------------------- INITIALIZATION -----------------------------
00088 
00089 // Constructor
00090 LaserWindowGrid::LaserWindowGrid()
00091    : base()
00092 {}
00093 
00094 //------------------------- DRAWING THE GRID ----------------------------
00095 
00096 // This function object draws the grid lines corresponding to a given
00097 // marking interval, taking care to only draw the grid lines when they
00098 // are actually active (as determined by the current zoom level and the
00099 // marking's zoom range).
00100 class draw_grid_lines {
00101    float zoom_level, max ;
00102 public:
00103    draw_grid_lines(float zoom_level, float max) ;
00104    void operator()(const LaserWindowGrid::Marking&) const ;
00105 } ;
00106 
00107 draw_grid_lines::draw_grid_lines(float Z, float M)
00108    : zoom_level(Z), max(M)
00109 {}
00110 
00111 void draw_grid_lines::operator()(const LaserWindowGrid::Marking& M) const
00112 {
00113    if (! M.third.in(zoom_level)) // current zoom level out of marking's
00114       return ;                   // zoom range
00115 
00116   glColor3fv(M.second.rgb()) ;
00117   for (float i = M.first; i <= max; i += M.first) {
00118       glVertex2f(i,  max) ;
00119       glVertex2f(i, -max) ;
00120       glVertex2f(-max, i) ;
00121       glVertex2f( max, i) ;
00122       glVertex2f(-i,  max) ;
00123       glVertex2f(-i, -max) ;
00124       glVertex2f(-max, -i) ;
00125       glVertex2f( max, -i) ;
00126   }
00127 }
00128 
00129 // Draw the grid using the marking specifications
00130 void LaserWindowGrid::render() const
00131 {
00132    if (! m_canvas)
00133       return ;
00134 
00135    glPushAttrib(GL_COLOR_BUFFER_BIT) ;
00136       glBegin(GL_LINES) ;
00137          std::for_each(m_markings.begin(), m_markings.end(),
00138                        draw_grid_lines(m_canvas->zoom_level(), m_max)) ;
00139       glEnd() ;
00140       base::draw_main_axes() ;
00141    glPopAttrib() ;
00142 }
00143 
00144 //----------------------------- CLEAN-UP --------------------------------
00145 
00146 LaserWindowGrid::~LaserWindowGrid()
00147 {}
00148 
00149 //-----------------------------------------------------------------------
00150 
00151 } // end of namespace encapsulating this file's definitions
00152 
00153 #endif // INVT_HAVE_LIBGL
00154 
00155 /* So things look consistent in everyone's emacs... */
00156 /* Local Variables: */
00157 /* indent-tabs-mode: nil */
00158 /* End: */
Generated on Sun May 8 08:05:56 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3