NewLaserDataPainter.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  NewLaserDataPainter.cpp
00003  *
00004  *  (C) 2007 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  *  Additional information:
00008  *  $Id: $
00009  *******************************************************************************/
00010 
00011 #include "NewLaserDataPainter.h"
00012 
00013 //#include "Messages/LaserDataM.h"
00014 //#include "Messages/SceneGraphM.h"
00015 
00016 #include <QtOpenGL>
00017 #include <GL/glut.h>
00018 #include <iostream>
00019 
00020 #define THIS NewLaserDataPainter
00021 
00022 THIS::THIS() : PainterPlugin( )
00023 {
00024     setName ( "2D Laser Data" );
00025     m_FirstScan = true;
00026     m_ScaleFactor = 1000; // input data is in meters, scale it for better visualization
00027 }
00028 
00029 THIS::~THIS()
00030 {
00031 }
00032 
00033 
00034 void THIS::updateData(const sensor_msgs::LaserScan::ConstPtr& scan)
00035 {
00036     if(m_FirstScan)
00037     {
00038         m_FirstScan = false;
00039         m_RangeMax = scan->range_max;
00040         // determine number of datapoints in lrf scan
00041         m_NumLaserPoints = (scan->angle_max - scan->angle_min) / scan->angle_increment;
00042 
00043         // build lookup-table
00044         float alpha = scan->angle_min;
00045         for (unsigned int i = 0; i < m_NumLaserPoints; i++)
00046         {
00047           float x = cos(alpha);
00048           float y = sin(alpha);
00049           BaseLib::Math::Vec3f unitPoint(x, y, 0);
00050           m_UnitLaserDirections.push_back(unitPoint * m_ScaleFactor);
00051           alpha += scan->angle_increment;
00052         }
00053     }
00054 
00055     m_WorldPoints.clear();
00056     m_Ranges.clear();
00057 
00058     // process all data in laser scan
00059     for(unsigned i = 0; i < m_NumLaserPoints; i++)
00060     {
00061         float range = scan->ranges[i];
00062         m_Ranges.push_back(range);
00063         if(range < scan->range_min || range > scan->range_max)
00064         {
00065             continue;
00066         }
00067         m_WorldPoints.push_back( m_UnitLaserDirections.at(i) * range);
00068     }
00069 
00070     requestRedraw();
00071 }
00072 
00073 
00074 void THIS::paint ( float next2DLayer )
00075 {
00076     glPushMatrix();
00077     //  TODO:  BaseLib::Math::Mat4d laserToWorld = m_SceneGraph.getTransformation( lrfId, "World" );
00078 
00079     glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00080     glEnable ( GL_BLEND );
00081 
00082     //Paint dots
00083     for ( unsigned i=0; i < m_WorldPoints.size(); i++ )
00084     {
00085         float t = float ( m_Ranges.at(i) ) / m_RangeMax * 3;
00086         if ( t < 0.0 ) t = 0.0;
00087         if ( t > 1.0 ) t = 1.0;
00088 
00089         glColor4f ( 1.0, t, 0.0, 1.0 );
00090 
00091         glPointSize( 5.0 );
00092         glBegin( GL_POINTS );
00093         glVertex3f( m_WorldPoints.at(i).x, m_WorldPoints.at(i).y, m_WorldPoints.at(i).z );
00094         glEnd();
00095     }
00096 
00097     glPopMatrix();
00098 }
00099 
00100 
00101 #undef THIS


obj_rec_gui
Author(s): AGAS/agas@uni-koblenz.de
autogenerated on Mon Oct 6 2014 02:53:43