00001 /** 00002 \file Robots/LoBot/ui/LoLaserVizFlat.C 00003 00004 This file defines the non-inline member functions of the 00005 lobot::LaserVizFlat class used for visualizing the laser range finder 00006 measurements. 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: mviswana usc edu 00040 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/ui/LoLaserVizFlat.C $ 00041 // $Id: LoLaserVizFlat.C 13037 2010-03-23 01:00:53Z mviswana $ 00042 // 00043 00044 //------------------------------ HEADERS -------------------------------- 00045 00046 // lobot headers 00047 #include "Robots/LoBot/ui/LoLaserVizFlat.H" 00048 #include "Robots/LoBot/config/LoConfigHelpers.H" 00049 #include "Robots/LoBot/misc/LoExcept.H" 00050 00051 #include "Robots/LoBot/util/LoGL.H" 00052 #include "Robots/LoBot/util/LoString.H" 00053 #include "Robots/LoBot/util/range.hh" 00054 #include "Robots/LoBot/util/triple.hh" 00055 00056 // OpenGL headers 00057 #ifdef INVT_HAVE_LIBGLU 00058 #include <GL/glu.h> 00059 #endif 00060 00061 #ifdef INVT_HAVE_LIBGL 00062 #include <GL/gl.h> 00063 #endif 00064 00065 // Standard C++ headers 00066 #include <string> 00067 #include <algorithm> 00068 00069 //----------------------------- NAMESPACE ------------------------------- 00070 00071 namespace lobot { 00072 00073 //-------------------- INITIALIZATION AND CLEAN-UP ---------------------- 00074 00075 LaserVizFlat::LaserVizFlat(const LaserRangeFinder* lrf) 00076 : Drawable("laser_viz_flat", Params::geometry()), 00077 m_lrf(lrf) 00078 { 00079 if (! lrf) 00080 throw misc_error(LASER_RANGE_FINDER_MISSING) ; 00081 } 00082 00083 LaserVizFlat::~LaserVizFlat(){} 00084 00085 //----------------------------- RENDERING ------------------------------- 00086 00087 #if defined(INVT_HAVE_LIBGLU) && defined(INVT_HAVE_LIBGL) 00088 00089 // Helper to convert the max reading into a string 00090 static std::string max_reading_str(int r) 00091 { 00092 return std::string("Max: ") + to_string(r) + " mm" ; 00093 } 00094 00095 // This method draws the latest set of distance measurements from the 00096 // laser range finder. 00097 void LaserVizFlat::render_me() 00098 { 00099 const range<int> A = m_lrf->get_angular_range() ; 00100 const int M = std::max(abs(A.min()), abs(A.max())) ; 00101 const int R = m_lrf->max_reading() ; 00102 00103 glMatrixMode(GL_PROJECTION) ; 00104 glPushMatrix() ; 00105 glLoadIdentity() ; 00106 gluOrtho2D(-M, M, 0, R); 00107 00108 glMatrixMode(GL_MODELVIEW) ; 00109 glPushMatrix() ; 00110 glLoadIdentity() ; 00111 glRotatef(180, 0, 1, 0) ; 00112 00113 glPushAttrib(GL_COLOR_BUFFER_BIT) ; 00114 glBegin(GL_LINE_STRIP) ; 00115 glColor3fv(Params::color().rgb()) ; 00116 glVertex2i(-M, 0) ; 00117 for (int x = A.min(); x <= A.max(); ++x) 00118 { 00119 int y = m_lrf->get_distance(x) ; 00120 if (y < 0) // bad reading 00121 continue ; 00122 glVertex2i(x, y) ; 00123 } 00124 glVertex2i(M, 0) ; 00125 glEnd() ; 00126 glPopAttrib() ; 00127 00128 glMatrixMode(GL_PROJECTION) ; 00129 glPopMatrix() ; 00130 00131 glMatrixMode(GL_MODELVIEW) ; 00132 glPopMatrix() ; 00133 00134 text_view_volume() ; 00135 glColor3f(1, 1, 0) ; 00136 draw_label(3, 12, "LRF") ; 00137 draw_label(3, m_geometry.height - 4, max_reading_str(R).c_str()) ; 00138 restore_view_volume() ; 00139 } 00140 00141 #endif // defined(INVT_HAVE_LIBGLU) && defined(INVT_HAVE_LIBGL) 00142 00143 //-------------------------- KNOB TWIDDLING ----------------------------- 00144 00145 // Retrieve settings from laser_viz_flat section of config file 00146 template<typename T> 00147 static inline T flat_conf(const std::string& key, const T& default_value) 00148 { 00149 return get_conf<T>("laser_viz_flat", key, default_value) ; 00150 } 00151 00152 // For retrieving measurements_color from laser_viz section of config file 00153 static inline triple<int, int, int> 00154 color_conf(const triple<int, int, int>& default_value) 00155 { 00156 return get_conf<int>("laser_viz", "measurements_color", default_value) ; 00157 } 00158 00159 // Parameters initialization 00160 LaserVizFlat::Params::Params() 00161 : m_geometry(flat_conf<std::string>("geometry", "0 480 480 80")), 00162 m_color(color_conf(make_triple(0, 128, 128))) 00163 {} 00164 00165 // Parameters clean-up 00166 LaserVizFlat::Params::~Params(){} 00167 00168 //----------------------------------------------------------------------- 00169 00170 } // end of namespace encapsulating this file's definitions 00171 00172 /* So things look consistent in everyone's emacs... */ 00173 /* Local Variables: */ 00174 /* indent-tabs-mode: nil */ 00175 /* End: */