LocustModel.C

Go to the documentation of this file.
00001 /**
00002    \file  Robots/LoBot/lgmd/LocustModel.C
00003    \brief Abstract base class for different locust models.
00004 */
00005 
00006 // //////////////////////////////////////////////////////////////////// //
00007 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00008 // by the University of Southern California (USC) and the iLab at USC.  //
00009 // See http://iLab.usc.edu for information about this project.          //
00010 // //////////////////////////////////////////////////////////////////// //
00011 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00012 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00013 // in Visual Environments, and Applications'' by Christof Koch and      //
00014 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00015 // pending; application number 09/912,225 filed July 23, 2001; see      //
00016 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00017 // //////////////////////////////////////////////////////////////////// //
00018 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00019 //                                                                      //
00020 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00021 // redistribute it and/or modify it under the terms of the GNU General  //
00022 // Public License as published by the Free Software Foundation; either  //
00023 // version 2 of the License, or (at your option) any later version.     //
00024 //                                                                      //
00025 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00026 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00027 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00028 // PURPOSE.  See the GNU General Public License for more details.       //
00029 //                                                                      //
00030 // You should have received a copy of the GNU General Public License    //
00031 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00032 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00033 // Boston, MA 02111-1307 USA.                                           //
00034 // //////////////////////////////////////////////////////////////////// //
00035 //
00036 // Primary maintainer for this file: mviswana usc edu
00037 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/lgmd/LocustModel.C $
00038 // $Id: LocustModel.C 13183 2010-04-08 07:17:49Z mviswana $
00039 //
00040 
00041 //------------------------------ HEADERS --------------------------------
00042 
00043 // lobot headers
00044 #include "Robots/LoBot/lgmd/LocustModel.H"
00045 #include "Robots/LoBot/config/LoConfigHelpers.H"
00046 #include "Robots/LoBot/misc/LoExcept.H"
00047 #include "Robots/LoBot/util/LoGL.H"
00048 
00049 // OpenGL headers
00050 #ifdef INVT_HAVE_LIBGLU
00051 #include <GL/glu.h>
00052 #endif
00053 
00054 #ifdef INVT_HAVE_LIBGL
00055 #include <GL/gl.h>
00056 #endif
00057 
00058 // Standard C++ headers
00059 #include <iomanip>
00060 #include <sstream>
00061 
00062 //----------------------------- NAMESPACE -------------------------------
00063 
00064 namespace lobot {
00065 
00066 //-------------------------- INITIALIZATION -----------------------------
00067 
00068 LocustModel::LocustModel(const LocustModel::InitParams& p)
00069    : Drawable(p.name, p.geometry),
00070      m_lgmd(0), m_range(p.spike_range),
00071      m_source(p.source), m_direction(p.direction),
00072      m_rect(p.rect), m_lrf_range(p.lrf_range),
00073      m_distance(-1), m_tti(-1)
00074 {
00075    // DEVNOTE: Ought to be okay to use this variable without the
00076    // visualization mutex because the visualization and other threads
00077    // have probably not yet been created at this point. Even if they are
00078    // up, they're probably waiting for the main thread to signal that the
00079    // application has been fully initialized...
00080    m_spikes.resize(p.geometry.width) ;
00081 }
00082 
00083 LocustModel::InitParams::InitParams()
00084    : spike_range(0, 1), direction(0),
00085      source(0), rect(Rectangle::tlbrI(0, 0, 0, 0)), lrf_range(-119, 135)
00086 {}
00087 
00088 //--------------------- SPIKE RATE VISUALIZATION ------------------------
00089 
00090 void LocustModel::add_spike(float s)
00091 {
00092    viz_lock() ;
00093       m_spikes.pop_front() ;
00094       m_spikes.push_back(s) ;
00095    viz_unlock() ;
00096 }
00097 
00098 #ifdef INVT_HAVE_LIBGLU
00099 
00100 static std::string str(float s)
00101 {
00102    using namespace std ;
00103 
00104    std::ostringstream label ;
00105    label << fixed << setprecision(1) << s << " Hz" ;
00106    return label.str() ;
00107 }
00108 
00109 void LocustModel::render_me()
00110 {
00111    // Make local copy so as to not hold up main thread
00112    viz_lock() ;
00113       std::deque<float> spikes = m_spikes ;
00114    viz_unlock() ;
00115 
00116    // Setup view volume so that x-coordinates match the amount of spike
00117    // history available and y-coordinates match the spike range.
00118    //
00119    // NOTE: We pad the top a little to ensure that the spike trains don't
00120    // obscure the text label drawn on the top left corner of the
00121    // visualization.
00122    glMatrixMode(GL_PROJECTION) ;
00123    glPushMatrix() ;
00124    glLoadIdentity() ;
00125    gluOrtho2D(0, m_geometry.width, 0, 1.25f * m_range.max()) ;
00126 
00127    glMatrixMode(GL_MODELVIEW) ;
00128    glPushMatrix() ;
00129    glLoadIdentity() ;
00130 
00131    // Draw the spike train
00132    glPushAttrib(GL_COLOR_BUFFER_BIT) ;
00133    glBegin(GL_LINE_STRIP) ;
00134       glColor3f(0.15f, 0.85f, 0.60f) ;
00135       for (int x = 0; x < m_geometry.width; ++x)
00136          glVertex2f(x, spikes[x]) ;
00137    glEnd() ;
00138    glPopAttrib() ;
00139 
00140    // Reset view volume for drawing a little "icon" to show the direction
00141    // in which this locust is looking plus its FOV.
00142    glMatrixMode(GL_PROJECTION) ;
00143    glLoadIdentity() ;
00144    gluOrtho2D(-1, 1, -1, 1) ;
00145 
00146    glMatrixMode(GL_MODELVIEW) ;
00147    glLoadIdentity() ;
00148    glTranslatef(0, -0.9f, 0) ;
00149    glRotatef(get_conf("laser_viz", "lrf_direction", 90.0f), 0, 0, 1) ;
00150    glScalef(0.375f, 0.375f, 1) ;
00151 
00152    // Show the locust's viewing direction and FOV
00153    glColor3f(0.75f, 0.45f, 0.05f) ;
00154    glBegin(GL_LINES) ;
00155       glVertex2i(0, 0) ;
00156       glVertex2f(cos(m_direction), sin(m_direction)) ;
00157 
00158       glVertex2i(0, 0) ;
00159       glVertex2f(cos(m_lrf_range.min()), sin(m_lrf_range.min())) ;
00160 
00161       glVertex2i(0, 0) ;
00162       glVertex2f(cos(m_lrf_range.max()), sin(m_lrf_range.max())) ;
00163    glEnd() ;
00164 
00165    // Restore view volume
00166    glMatrixMode(GL_PROJECTION) ;
00167    glPopMatrix() ;
00168    glMatrixMode(GL_MODELVIEW) ;
00169    glPopMatrix() ;
00170 
00171    // Show latest spike rate in top left corner of drawing area
00172    text_view_volume() ;
00173       glColor3f(0, 1, 1) ;
00174       draw_label(3, 12, str(spikes.back()).c_str()) ;
00175    restore_view_volume() ;
00176 }
00177 
00178 #endif
00179 
00180 //----------------------------- CLEAN-UP --------------------------------
00181 
00182 LocustModel::~LocustModel(){}
00183 
00184 //-----------------------------------------------------------------------
00185 
00186 } // end of namespace encapsulating this file's definitions
00187 
00188 /* So things look consistent in everyone's emacs... */
00189 /* Local Variables: */
00190 /* indent-tabs-mode: nil */
00191 /* End: */
Generated on Sun May 8 08:05:55 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3