ImageMessagesDisplay.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  ImageMessagesDisplay.cpp
00003  *
00004  *  (C) 2006 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  *  Additional information:
00008  *  $Id: ImageMessagesDisplay.cpp 23656 2008-03-30 18:21:56Z dgossow $
00009  *******************************************************************************/
00010 
00011 #include <QGridLayout>
00012 #include <QLabel>
00013 #include <QMatrix>
00014 #include <QPixmap>
00015 #include <QSize>
00016 #include <QComboBox>
00017 #include <QPushButton>
00018 #include <QFileDialog>
00019 #include <QSpinBox>
00020 #include <QCheckBox>
00021 #include <QTimer>
00022 #include <QWidget>
00023 
00024 #include "ImageMessagesDisplay.h"
00025 #include "ImageSourceSelector.h"
00026 
00027 #include "../../Widgets/GLImageWidget/GLImageWidget.h"
00028 
00029 // TODO add messages
00030 //#include "Messages/ImageM.h"
00031 //#include "Messages/ImageStreamM.h"
00032 //#include "Messages/StereoImageM.h"
00033 //#include "Messages/GetImageM.h"
00034 
00035 #define THIS ImageMessagesDisplay
00036 
00037 using namespace std;
00038 using namespace puma2;
00039 
00040 
00041 THIS::THIS ( QWidget* parent, ImageSources::SourceId sourceId, bool showGrabButton, bool showSelector )
00042         : QGLWidget ( parent )
00043 {
00044         m_GlImageWidget = new GLImageWidget ( this );
00045         m_SourceId = sourceId;
00046 
00047         QGridLayout* grid = new QGridLayout;
00048 
00049     if(showSelector)
00050     {
00051       ImageSourceSelector* sourceSelector = new ImageSourceSelector ( sourceId, this );
00052       connect ( sourceSelector, SIGNAL ( sourceSelected ( ImageSources::SourceId ) ), this,
00053                 SLOT ( setSourceId ( ImageSources::SourceId ) ) );
00054 
00055       grid->addWidget ( sourceSelector, 0, 0, 1, 5 );
00056 
00057       grid->addWidget ( m_GlImageWidget, 1, 0, 1, 5 );
00058     }
00059     else
00060     {
00061       grid->addWidget(m_GlImageWidget, 0,0,0,0);
00062     }
00063 
00064         m_YuvCheckBox = 0;
00065 
00066         if ( showGrabButton )
00067         {
00068                 QPushButton* button = new QPushButton ( "Get Image" );
00069                 grid->addWidget ( button, 2, 0 );
00070                 connect ( button, SIGNAL ( pressed() ), this, SLOT ( grabImage() ) );
00071 
00072                 button = new QPushButton ( "Save Image" );
00073                 grid->addWidget ( button, 2, 1 );
00074                 connect ( button, SIGNAL ( pressed() ), this, SLOT ( saveImage() ) );
00075 
00076                 m_PollTimer = new QTimer ( this );
00077                 connect ( m_PollTimer, SIGNAL ( timeout() ), this, SLOT ( grabImage() ) );
00078 
00079                 QCheckBox* pollCheckBox = new QCheckBox ( "Poll [ms]" );
00080                 pollCheckBox->setCheckState ( Qt::Unchecked );
00081                 connect ( pollCheckBox, SIGNAL ( stateChanged ( int ) ), this,
00082                           SLOT ( togglePoll ( int ) ) );
00083 
00084                 m_PollSpinBox = new QSpinBox();
00085                 m_PollSpinBox->setRange ( 50, 20000 );
00086                 m_PollSpinBox->setSingleStep ( 250 );
00087                 m_PollSpinBox->setValue ( 1000 );
00088                 m_PollSpinBox->setMaximumWidth ( 80 );
00089                 m_PollSpinBox->setEnabled ( false );
00090                 connect ( m_PollSpinBox, SIGNAL ( valueChanged ( int ) ), this,
00091                           SLOT ( changePollInterval ( int ) ) );
00092 
00093                 m_YuvCheckBox  = new QCheckBox ( "YUV", this );
00094                 m_YuvCheckBox->setChecked ( false );
00095 
00096                 grid->addWidget ( pollCheckBox, 2, 2 );
00097                 grid->addWidget ( m_PollSpinBox, 2, 3 );
00098                 grid->addWidget ( m_YuvCheckBox, 2, 4 );
00099         }
00100 
00101         grid->setRowStretch ( 1, 1 );
00102         grid->setColumnStretch ( 0, 1 );
00103         grid->setColumnStretch ( 1, 1 );
00104         setLayout ( grid );
00105 
00106 //      m_Timer = Timer ( ProfilerEntry::CODE_SEGMENT, "GUI Thread", "Image Message Display" ); // TODO
00107 }
00108 
00109 
00110 void THIS::togglePoll ( int checkState )
00111 {
00112         if ( checkState == Qt::Checked )
00113         {
00114                 m_PollTimer->start ( m_PollSpinBox->value() );
00115                 m_PollSpinBox->setEnabled ( true );
00116         }
00117         else
00118         {
00119                 m_PollTimer->stop();
00120                 m_PollSpinBox->setEnabled ( false );
00121         }
00122 }
00123 
00124 
00125 void THIS::changePollInterval ( int interval )
00126 {
00127         if ( m_PollTimer->isActive() )
00128         {
00129                 m_PollTimer->setInterval ( interval );
00130         }
00131 }
00132 
00133 void THIS::grabImage()
00134 {
00135         if ( m_YuvCheckBox && ( m_YuvCheckBox->checkState() == Qt::Checked ) )
00136         {
00137         // TODO
00138         // sendMessage ( new GetImageM ( m_SourceId, ImageGrabber::Y8UV8, ImageGrabber::FULL ) );
00139         }
00140         else
00141         {
00142         // TODO
00143         // sendMessage ( new GetImageM ( m_SourceId, ImageGrabber::RGB8, ImageGrabber::FULL ) );
00144         }
00145 }
00146 
00147 void THIS::saveImage()
00148 {
00149         QString filename = QFileDialog::getSaveFileName ( this, tr ( "Save Image" ), "images",
00150                            tr ( "*.png" ) );
00151         if ( filename.size() != 0 )
00152         {
00153                 string filenameString = filename.toStdString();
00154                 if ( filenameString.find ( ".png" ) == string::npos )
00155                 {
00156                         filenameString += ".png";
00157                 }
00158                 m_GlImageWidget->saveImage ( filenameString );
00159         }
00160 }
00161 
00162 void THIS::setSourceId ( ImageSources::SourceId sourceId )
00163 {
00164         m_SourceId = sourceId;
00165         ostringstream stream;
00166         stream << "Setting source id to " << int ( m_SourceId )
00167         << " (" << ImageSources::getSourceDesc ( m_SourceId )
00168         << ") and grabbing image.";
00169     // TRACE_SYSTEMINFO ( stream.str() ) // TODO use ros
00170         grabImage();
00171 }
00172 
00173 void THIS::updateImage(const unsigned char* image, unsigned width, unsigned height)
00174 {
00175     // IMAGE_STREAM_M:
00176     //  if ( m_SourceId == castMessage->getSourceId() )
00177 
00178     m_GlImageWidget->clearForms();
00179 //            //store vertices
00180 //            std::list< VectorObject2D >::iterator vectorObjectIt;
00181 //            std::list< VectorObject2D > vectorObjects = castMessage->getVectorObjects();
00182 //            for ( vectorObjectIt = vectorObjects.begin(); vectorObjectIt != vectorObjects.end(); vectorObjectIt++ )
00183 //            {
00184 //                m_GlImageWidget->addVectorObject ( *vectorObjectIt );
00185 //            }
00186     m_GlImageWidget->setColorImage ( image, width, height );
00187 }
00188 
00189 
00190 // TODO add message handling
00191 
00192 /*
00193 
00194 void THIS::processMessage ( Message* message )
00195 {
00196     ostringstream stream;
00197     ostringstream filename;
00198 
00199         case MessageTypes::IMAGE_M:
00200         {
00201             ImageM* castMessage = Message::castTo<ImageM> ( message );
00202             if ( m_SourceId == castMessage->getSourceId() )
00203             {
00204                 stream << "m_SourceId " << m_SourceId << " castMessage->getSourceId() "
00205                 << castMessage->getSourceId();
00206                 TRACE_SYSTEMINFO ( stream.str() )
00207                 m_GlImageWidget->clearForms();
00208                 //store vertices
00209                 std::list< VectorObject2D >::iterator vectorObjectIt;
00210                 std::list< VectorObject2D > vectorObjects = castMessage->getVectorObjects();
00211                 for ( vectorObjectIt = vectorObjects.begin(); vectorObjectIt != vectorObjects.end(); vectorObjectIt++ )
00212                 {
00213                     m_GlImageWidget->addVectorObject ( *vectorObjectIt );
00214                 }
00215                 //store&display image
00216                 //ImageSources::SourceId sid = castMessage->getSourceId();
00217                 switch ( castMessage->getColorFormat() )
00218                 {
00219                     case ImageGrabber::RGB8:
00220                                                 TRACE_SYSTEMINFO ( "Received RGB8 image" )
00221                         m_GlImageWidget->setColorImage ( castMessage->getRgbImage() );
00222                         break;
00223                     case ImageGrabber::Y8UV8:
00224                                                 TRACE_SYSTEMINFO ( "Received Y8UV8 image" )
00225                         m_GlImageWidget->setColorImage ( castMessage->getGrayLevelImage(),
00226                                                          castMessage->getUvImage() );
00227                         break;
00228                     default:
00229                                                 TRACE_ERROR ("Received unknown image type")
00230                         break;
00231                 }
00232             }
00233         }
00234 
00235 }
00236 
00237   */
00238 
00239 #undef THIS
00240 
00241 
00242 


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