TofPainter.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  MyPainter.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 "TofPainter.h"
00012 
00013 #include "Messages/TofDataM.h"
00014 #include "Messages/TofStatusM.h"
00015 #include "Messages/SceneGraphM.h"
00016 #include "Architecture/Config/Config.h"
00017 #include "Architecture/Singleton/Clock.h"
00018 
00019 #include <QtOpenGL>
00020 #include <GL/glut.h>
00021 
00022 #include<iostream>
00023 using namespace std;
00024 
00025 #define THIS TofPainter
00026 
00027 THIS::THIS() : PainterPlugin( )
00028 {
00029   setName ( "TOF Data" );
00030 
00031   m_Height=0;
00032   m_Width=0;
00033   m_Amplitudes=0;
00034   m_Depths=0;
00035   m_Points=0;
00036 
00037   m_SceneGraphInitialized=false;
00038 
00039   m_ColorFactor=1.0/Config::getFloat("TofPainter.fRedDistance");
00040   m_AmplitudeScaling=Config::getFloat("TofPainter.fAmplitudeScaling");
00041   m_AmplitudeThreshold=Config::getFloat("TofPainter.fAmplitudeThreshold");
00042   m_ViewMode=Config::getInt("TofPainter.iViewMode");
00043   m_DisplayDuration=Config::getInt("TofPainter.iDisplayDuration");
00044 }
00045 
00046 
00047 THIS::~THIS()
00048 {
00049   delete[] m_Depths;
00050   delete[] m_Amplitudes;
00051   delete[] m_Points;
00052 }
00053 
00054 
00055 void THIS::processMessage( Message* newMessage )
00056 {
00057   switch(newMessage->getType())
00058   {
00059   case MessageTypes::TOF_DATA_M:
00060     {
00061       if ( TofDataM* message = Message::castTo<TofDataM> ( newMessage ) )
00062       {
00063         m_LastDataTime = Clock::getInstance()->getTimestamp();
00064 
00065         if( message->getHeight() != m_Height || message->getWidth() != m_Width)
00066           initBuffers( message->getHeight(), message->getWidth() );
00067 
00068         memcpy( m_Depths, message->getDepths(),
00069                 message->getHeight()*message->getWidth()*sizeof(float) );
00070         memcpy( m_Amplitudes, message->getAmplitudes(),
00071                 message->getHeight()*message->getWidth()*sizeof(float) );
00072         memcpy( m_Points, message->getPoints(),
00073                 message->getHeight()*message->getWidth()*sizeof(BaseLib::Math::Vec3f) );
00074 
00075         BaseLib::Math::Mat4d tofToWorld;
00076 
00077         tofToWorld = m_SceneGraph.getTransformation( "Kinect" , "World" );
00078         tofToWorld.toColumnMajor( m_Transformation );
00079         requestRedraw();
00080       }
00081       break;
00082     }
00083 
00084   case MessageTypes::SCENE_GRAPH_M:
00085     {
00086       if ( SceneGraphM* message = Message::castTo<SceneGraphM> ( newMessage ) )
00087       {
00088         m_SceneGraph = message->getSceneGraph();
00089         m_SceneGraphInitialized = true;
00090         requestRedraw();
00091       }
00092       break;
00093     }
00094   default:
00095     break;
00096 
00097   }
00098 }
00099 
00100 void THIS::paint ( float )
00101 {
00102   if( Clock::getInstance()->getTimestamp() < m_LastDataTime + m_DisplayDuration
00103     && m_SceneGraphInitialized )
00104   {
00105     glMultMatrixd( m_Transformation );
00106     glPointSize( 2 );
00107     glBegin(GL_POINTS);
00108     for( int i=0; i<m_Width*m_Height ; i++)
00109     {
00110       if(m_Amplitudes[i]*m_AmplitudeScaling >m_AmplitudeThreshold )
00111       {
00112         if( m_ViewMode==0)
00113         {
00114           glColor3f( 2*m_Depths[i] * m_ColorFactor,
00115                      2*(1-m_Depths[i] * m_ColorFactor),
00116                      0 );
00117         }
00118         else if( m_ViewMode == 1)
00119         {
00120           float c = m_Amplitudes[i] * m_AmplitudeScaling;
00121           glColor3f( c, c, c );
00122         }
00123         else if( m_ViewMode == 2)
00124         {
00125           float brightness = m_Amplitudes[i] * m_AmplitudeScaling;
00126           if(brightness < 0 )
00127           {
00128             brightness = 0;
00129           }
00130           else if(brightness >1 )
00131           {
00132             brightness = 1;
00133           }
00134           glColor3f( 2*m_Depths[i] * m_ColorFactor * brightness,
00135                      2*(1 - m_Depths[i] * m_ColorFactor )*brightness,
00136                      0 );
00137         }
00138         glVertex3f( m_Points[i].x, m_Points[i].y, m_Points[i].z );
00139       }
00140     }
00141     glEnd();
00142   }
00143 }
00144 
00145 void THIS::initBuffers ( int height, int width )
00146 {
00147   if( height == 0 || width == 0){
00148     m_Height = m_Width = 0;
00149     m_Depths = 0;
00150     m_Points = 0;
00151     m_Amplitudes = 0;
00152   }
00153   else if( height != m_Height || width != m_Width) {
00154     if( m_Depths && m_Amplitudes && m_Points){
00155       delete m_Depths;
00156       delete m_Amplitudes;
00157       delete m_Points;
00158     }
00159     m_Height = height;
00160     m_Width = width;
00161     m_Depths = new float[ m_Height * m_Width ];
00162     m_Amplitudes = new float[ m_Height * m_Width ];
00163     m_Points = new BaseLib::Math::Vec3f[ m_Height * m_Width ];
00164 
00165   }
00166 }
00167 
00168 #undef THIS


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