RGBDepthPainter.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  RGBDepthPainter.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 "RGBDepthPainter.h"
00012 
00013 #include "Workers/Math/Math.h"
00014 #include "Messages/SceneGraphM.h"
00015 
00016 #include "Architecture/Config/Config.h"
00017 
00018 #include <QtOpenGL>
00019 #include <GL/glut.h>
00020 
00021 #define THIS RGBDepthPainter
00022 
00023 THIS::THIS() : PainterPlugin( )
00024 {
00025   setName ( "RGB Depth Data" );
00026 }
00027 
00028 
00029 THIS::~THIS()
00030 {
00031 }
00032 
00033 
00034 void THIS::processMessage ( Message* newMessage )
00035 {
00036   PainterPlugin::processMessage ( newMessage );
00037   switch ( newMessage->getType() )
00038   {
00039 
00040     case MessageTypes::RGB_DEPTH_M:
00041     {
00042       RGBDepthM* message = Message::castTo<RGBDepthM> ( newMessage );
00043       if ( message )
00044       {
00045         m_Rows = message->getRows();
00046         m_Columns = message->getColumns();
00047 
00048         if(!Config::getBool("Kinect.bCreate3DMap"))
00049         {
00050           // Don't store old depth data
00051           m_Points.clear();
00052           m_ValidRobotToWorld.clear();
00053           m_RgbImage.clear();
00054         }
00055 
00056         m_Points.push_back(message->getPoints());
00057 
00058         if(message->getRgbImage())
00059         {
00060           m_RgbImageAvailable = true;
00061           m_RgbImage.push_back(*message->getRgbImage());
00062         }
00063         else
00064         {
00065           m_RgbImageAvailable = false;
00066         }
00067 
00068         m_ValidRobotToWorld.push_back(message->getSceneGraph().getTransformation( "Robot", "World" ));
00069 
00070         requestRedraw();
00071       }
00072       break;
00073     }
00074 
00075   default:
00076     break;
00077 
00078   }
00079 }
00080 
00081 void THIS::paint ( float next2DLayer )
00082 {
00083 
00084 
00085 
00086 
00087   for(unsigned int i=0;i<m_Points.size();++i)
00088   {
00089     glPushMatrix();
00090 
00091     /* Transform points from robot to world coordinates */
00092     GLdouble glMatrix[16];
00093     m_ValidRobotToWorld.at(i).toColumnMajor ( glMatrix );
00094     glMultMatrixd ( glMatrix );
00095 
00096     /* Draw points with corresponding color */
00097 
00098     glPointSize ( 1.0 );
00099     glBegin( GL_POINTS );
00100 
00101     for(unsigned int y=0; y<m_Rows;++y)
00102     {
00103       for(unsigned int x=0; x<m_Columns;++x)
00104       {
00105         /* Color values have range [0..1] */
00106         if(m_RgbImageAvailable)
00107         {
00108           glColor3f((m_RgbImage.at(i).sample(x,y,0)/255.0),(m_RgbImage.at(i).sample(x,y,1)/255.0),(m_RgbImage.at(i).sample(x,y,2)/255.0));
00109         }
00110         else
00111         {
00112           glColor3f(1,1,1);
00113         }
00114         glVertex3d(m_Points.at(i).at(x+y*m_Columns).x, m_Points.at(i).at(x+y*m_Columns).y, m_Points.at(i).at(x+y*m_Columns).z);
00115       }
00116     }
00117 
00118     glEnd();
00119 
00120     glPopMatrix();
00121 
00122   }
00123 }
00124 
00125 #undef THIS


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