ImagePainter.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  ImagePainter.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 "ImagePainter.h"
00012 
00013 #include "Messages/ImageStreamM.h"
00014 #include "Messages/ImageM.h"
00015 #include "Messages/SceneGraphM.h"
00016 
00017 #include <QtOpenGL>
00018 #include <GL/glut.h>
00019 
00020 
00021 #define THIS ImagePainter
00022 
00023 using namespace puma2;
00024 
00025 THIS::THIS() : PainterPlugin( )
00026 {
00027   setName ( "Image Painter" );
00028 
00029   m_ImageSources ["TopCameraImage"] = ImageSources::TopCameraStream;
00030   m_ImageSources ["KinectCameraImage"] = ImageSources::KinectCameraStream;
00031   m_ImageSources ["CenterCameraImage"] = ImageSources::BottomCameraStream;
00032   m_ImageSources ["BottomCameraImage"] = ImageSources::BottomCameraStream;
00033   m_ImageSources ["WiiMoteImage"] = ImageSources::WiiMoteStream;
00034 }
00035 
00036 
00037 THIS::~THIS()
00038 {
00039 }
00040 
00041 
00042 void THIS::processMessage ( Message* newMessage )
00043 {
00044   switch ( newMessage->getType() )
00045   {
00046     case MessageTypes::IMAGE_STREAM_M:
00047     {
00048       ImageStreamM* castMessage = Message::castTo<ImageStreamM> ( newMessage );
00049       if ( ( castMessage != 0 ) &&
00050              ( m_ImageSources.find ( m_NodeName ) != m_ImageSources.end() ) &&
00051              ( castMessage->getSourceId() == m_ImageSources[m_NodeName] )
00052          )
00053       {
00054         m_GLImagePainter.setColorImage ( castMessage->getRgbImage() );
00055 
00056         m_GLImagePainter.clearForms();
00057         //store vertices
00058         std::list< VectorObject2D >::iterator vectorObjectIt;
00059         std::list< VectorObject2D > vectorObjects = castMessage->getVectorObjects();
00060         for ( vectorObjectIt = vectorObjects.begin(); vectorObjectIt != vectorObjects.end(); vectorObjectIt++ )
00061         {
00062           m_GLImagePainter.addVectorObject ( *vectorObjectIt );
00063         }
00064         requestRedraw();
00065       }
00066       break;
00067     }
00068 
00069 
00070     case MessageTypes::IMAGE_M:
00071     {
00072       ImageM* castMessage = Message::castTo<ImageM> ( newMessage );
00073       if ( ( castMessage != 0 ) &&
00074              ( m_ImageSources.find ( m_NodeName ) != m_ImageSources.end() ) &&
00075              ( castMessage->getSourceId() == m_ImageSources[m_NodeName] )
00076          )
00077       {
00078         m_GLImagePainter.setColorImage ( castMessage->getRgbImage() );
00079 
00080         m_GLImagePainter.clearForms();
00081         //store vertices
00082         std::list< VectorObject2D >::iterator vectorObjectIt;
00083         std::list< VectorObject2D > vectorObjects = castMessage->getVectorObjects();
00084         for ( vectorObjectIt = vectorObjects.begin(); vectorObjectIt != vectorObjects.end(); vectorObjectIt++ )
00085         {
00086           m_GLImagePainter.addVectorObject ( *vectorObjectIt );
00087         }
00088         requestRedraw();
00089       }
00090       break;
00091     }
00092 
00093 
00094     case MessageTypes::SCENE_GRAPH_M:
00095     {
00096       if ( SceneGraphM* message = Message::castTo<SceneGraphM> ( newMessage ) )
00097       {
00098         if ( m_ImageSources.find ( m_NodeName ) != m_ImageSources.end() )
00099         {
00100           m_ImageToWorld = message->getSceneGraph().getTransformation ( m_NodeName, "World" );
00101           //TRACE_INFO ( m_ImageToWorld.niceString ( 2, "m_ImageToWorld" ) );
00102         }
00103       }
00104       break;
00105     }
00106 
00107     default:
00108       break;
00109 
00110   }
00111 }
00112 
00113 
00114 void THIS::paint ( float next2DLayer )
00115 {
00116   if ( m_ImageSources.find ( m_NodeName ) != m_ImageSources.end() )
00117   {
00118     glDisable( GL_DEPTH_TEST );
00119 
00120     //TRACE_INFO ( "painting" );
00121     glPushMatrix();
00122 
00123     //transform normalized image coordinates to world coordinates
00124     double glMat[16];
00125     m_ImageToWorld.toColumnMajor ( glMat );
00126     glMultMatrixd ( glMat );
00127 
00128     //make everything bigger
00129     //glScalef ( 50000, 50000, 50000 );
00130     glScalef ( 500,500,500 );
00131 
00132     glTranslatef ( 0, 0, 1.0 );
00133     glScalef ( 2.0, 2.0, 2.0 );
00134 
00135     glPolygonMode ( GL_FRONT_AND_BACK, GL_LINE );
00136     //paint white border
00137     glColor3f ( 1.0, 1.0, 1.0 );
00138     glLineWidth( 1.0 );
00139     glBegin ( GL_POLYGON );
00140     glVertex3f ( -0.5, -0.5, 0.0 );
00141     glVertex3f ( -0.5, 0.5, 0.0 );
00142     glVertex3f ( 0.5, 0.5, 0.0 );
00143     glVertex3f ( 0.5, -0.5, 0.0 );
00144     glEnd();
00145 
00146 
00147     m_GLImagePainter.paintImage();
00148     m_GLImagePainter.paintVectorObjects();
00149 
00150     glPopMatrix();
00151 
00152     glEnable ( GL_DEPTH_TEST );
00153   }
00154 }
00155 
00156 void THIS::nodeSelected ( string nodeName )
00157 {
00158   m_NodeName = nodeName;
00159   TRACE_INFO ( nodeName );
00160 }
00161 
00162 
00163 
00164 #undef THIS


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