LoLaserVizFlat.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
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
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
00066 #include <string>
00067 #include <algorithm>
00068
00069
00070
00071 namespace lobot {
00072
00073
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
00086
00087 #if defined(INVT_HAVE_LIBGLU) && defined(INVT_HAVE_LIBGL)
00088
00089
00090 static std::string max_reading_str(int r)
00091 {
00092 return std::string("Max: ") + to_string(r) + " mm" ;
00093 }
00094
00095
00096
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)
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
00144
00145
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
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
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
00166 LaserVizFlat::Params::~Params(){}
00167
00168
00169
00170 }
00171
00172
00173
00174
00175