qt_gui.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2013, Intelligent Robotics Lab, DLUT.
00005  *  Author: Qinghua Li, Yan Zhuang, Fei Yan
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Intelligent Robotics Lab, DLUT. nor the names
00020  *     of its contributors may be used to endorse or promote products
00021  *     derived from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  */
00036 
00037 #include <QtGui>
00038 #include <QIcon>
00039 #include <QPixmap>
00040 #include <QKeySequence>
00041 #include <opencv/highgui.h>
00042 
00043 #include "dlut_place_recognition/qt_gui.h"
00044 
00045 // Constructs a QT GUI for easy control of Place Recognition
00046 Graphical_UI::Graphical_UI ()
00047   : query_glviewer (NULL), lib_glviewer (NULL)
00048 {
00049   infoText = new QString (tr (
00050              "<p><b>3D-SMART - Place Recognition</b> provides a novel 3D-laser-based indoor place "
00051              "recognition method to deal with the random disturbances caused by unexpected movements "
00052              "of people and other objects. "
00053              "The proposed approach can extract and match the Speeded-Up Robust Features (SURFs) "
00054              "from bearing-angle images generated by a 3D laser scanner. It can cope with the "
00055              "irregular disturbance of moving objects and the problem of observing-location changes "
00056              "of the laser scanner. Both global metric information and local SURF features are "
00057              "extracted from 3D laser point clouds and 2D bearing-angle images, respectively.</p>"
00058              "<p>For more detailed information, please refer to our recent published paper (IEEE "
00059              "Transactions on Instrument and Measurement, Vol. 62, No. 2, 2013), you can get it "
00060              "through <a href=\"http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=6305475\">"
00061              "http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=6305475</a>.</p>"));
00062   licenseText = new QString (tr (
00063                 "<p><b>3D-SMART - Place Recognition</b> is an open source software under the terms of "
00064                 "the 3-clause BSD license. See the Software License Agreement (BSD License) for more details.</p>"
00065                 "<p>If you have any questions, suggestions or corrections regarding usage of "
00066                 "3D-SMART - Place Recognition, please contact <b>Yan Zhuang</b> (zhuang@dlut.edu.cn).</p>"));
00067   helpText = new QString (tr (
00068              "<p><b>Two Steps:</b>"
00069              "<ul><li><b>1.</b> Please load 3D laser scanning data of query scene (Graph -> Load Data (Ctrl+L));</li>"
00070              "    <li><b>2.</b> Place recognition for query scene (Recognition -> Place Recognition (Ctrl+P)).</li><ul></p>"
00071              "<p><b>Optionally, 3D Viewer Mouse and Keyboard Commands:</b>"
00072              "<ul><li><i>Left/Right button:</i> rotation.</li>"
00073              "    <li><i>Middle button:</i> translation.</li>"
00074              "    <li><i>Wheel:</i> zoom.</li>"
00075              "    <li><i>R:</i> reset the initial view of scene.</li>"
00076              "    <li><i>Q, E, W, S, A, D:</i> translation in all directions.</li><ul></p>"));
00077 
00078   // Create widgets for image display
00079   query_BAimage_label = new QLabel ("<i>Waiting for bearing-angle image...</i>");
00080   query_BAimage_label->setFrameStyle (QFrame::StyledPanel | QFrame::Sunken);
00081   query_BAimage_label->setAlignment (Qt::AlignCenter);
00082   query_BAimage_label->setScaledContents (true);
00083 
00084   features_image_label = new QLabel (tr ("<i>Waiting for features image...</i>"));
00085   features_image_label->setFrameStyle (QFrame::StyledPanel | QFrame::Sunken);
00086   features_image_label->setAlignment (Qt::AlignCenter);
00087   features_image_label->setScaledContents (true);
00088 
00089   lib_BAimage_label = new QLabel (tr ("<i>Waiting for bearing-angle image...</i>"));
00090   lib_BAimage_label->setFrameStyle (QFrame::StyledPanel | QFrame::Sunken);
00091   lib_BAimage_label->setAlignment (Qt::AlignCenter);
00092   lib_BAimage_label->setScaledContents (true);
00093 
00094   query_glviewer = new GLViewer (GraphManager::query_cloud, 1, this); /* Displays 3D point cloud */
00095   lib_glviewer = new GLViewer (GraphManager::lib_cloud, 2, this);     /* Displays 3D point cloud */
00096 
00097   // Setup the layout:
00098   /* Use a splitter as main widget */
00099   vsplitter = new QSplitter (Qt::Vertical);
00100   setCentralWidget (vsplitter);
00101 
00102   /* Arrange glviewer splitters in horizontal layout */
00103   QSplitter* hsplitter1 = new QSplitter (Qt::Horizontal);
00104   hsplitter1->addWidget (query_glviewer);
00105   hsplitter1->addWidget (lib_glviewer);
00106   /* Add them as top item to splitter */
00107   vsplitter->addWidget (hsplitter1);
00108 
00109   /* Arrange image labels in horizontal layout */
00110   QSplitter* hsplitter2 = new QSplitter (Qt::Horizontal);
00111   hsplitter2->addWidget (query_BAimage_label);
00112   hsplitter2->addWidget (features_image_label);
00113   hsplitter2->addWidget (lib_BAimage_label);
00114   /* Add them as bottom item to splitter */
00115   vsplitter->addWidget (hsplitter2);
00116 
00117   createMenus ();
00118 
00119   statusLabel = new QLabel ();
00120   statusBar ()->insertWidget (0, statusLabel, 0);
00121   QString message = tr ("Ready for Place Recognition");
00122   statusBar ()->showMessage (message);
00123 
00124   infoLabel = new QLabel (tr ("Waiting for motion information..."));
00125   infoLabel->setFrameStyle (QFrame::StyledPanel | QFrame::Sunken);
00126   infoLabel->setAlignment (Qt::AlignRight);
00127   statusBar ()->addPermanentWidget (infoLabel, 0);
00128 
00129   infoLabel2 = new QLabel (tr ("<i>See Help->Usage Help to Start</i>"));
00130   infoLabel2->setFrameStyle (QFrame::StyledPanel | QFrame::Sunken);
00131   infoLabel2->setAlignment (Qt::AlignRight);
00132   statusBar ()->addPermanentWidget (infoLabel2, 0);
00133 
00134   setWindowTitle (tr ("3D SMART - Place Recognition"));
00135   setMinimumSize (790, 590);
00136   resize (1000, 700);
00137 }
00138 
00139 Graphical_UI::~Graphical_UI ()
00140 {
00141 }
00142 
00143 
00144 void Graphical_UI::setLibBAImage (QImage qimage)
00145 {
00146   if (lib_BAimage_label->isVisible ())
00147   {
00148     lib_BAimage_label->setPixmap (QPixmap::fromImage (qimage));
00149     lib_BAimage_label->repaint ();
00150   }
00151 }
00152 
00153 void Graphical_UI::setQueryBAImage (QImage qimage)
00154 {
00155   if (query_BAimage_label->isVisible ())
00156   {
00157     query_BAimage_label->setPixmap (QPixmap::fromImage (qimage));
00158     query_BAimage_label->repaint ();
00159   }
00160 }
00161 
00162 void Graphical_UI::setFeaturesImage (QImage qimage)
00163 {
00164   if (features_image_label->isVisible ())
00165   {
00166     features_image_label->setPixmap (QPixmap::fromImage (qimage));
00167     features_image_label->repaint ();
00168   }
00169 }
00170 
00171 void Graphical_UI::setStatus (QString message)
00172 {
00173   statusBar ()->showMessage (message);
00174 }
00175 
00176 void Graphical_UI::loadDataCmd ()
00177 {
00178   QString message = tr ("Please select 3D laser scanning data file what you want to load");
00179   statusBar ()->showMessage (message);
00180   Q_EMIT loadData();
00181 }
00182 
00183 void Graphical_UI::reset ()
00184 {
00185   GraphManager::query_cloud.clear ();
00186   GraphManager::lib_cloud.clear ();
00187   query_glviewer->reset ();
00188   lib_glviewer->reset ();
00189   query_BAimage_label->setText ("<i>Waiting for bearing-angle image...</i>");
00190   features_image_label->setText ("<i>Waiting for features image...</i>");
00191   lib_BAimage_label->setText ("<i>Waiting for bearing-angle image...</i>");
00192   QString message = tr ("Graph Reset, A fresh new graph is waiting...");
00193   statusBar ()->showMessage (message);
00194 }
00195 
00196 void Graphical_UI::showBAImageCmd ()
00197 {
00198   Q_EMIT showBAImage();
00199   QString message = tr ("Show Bearing-Angle image of Query scene");
00200   statusBar ()->showMessage (message);
00201 }
00202 
00203 void Graphical_UI::showFlowsheet ()
00204 {
00205   IplImage* image = cvLoadImage ("./dlut_place_recognition/flowsheet.jpg", -1);
00206   cvNamedWindow ("Flowsheet", 0);
00207   cvShowImage ("Flowsheet", image);
00208 
00209   cvWaitKey (0);
00210 
00211   cvDestroyWindow ("Flowsheet");
00212   cvReleaseImage (&image);
00213 }
00214 
00215 void Graphical_UI::extractFeaturesCmd ()
00216 {
00217   QString message = tr ("Extract global spatial features and local SURF features, then save to database");
00218   statusBar ()->showMessage (message);
00219   Q_EMIT extractFeatures();
00220 }
00221 
00222 void Graphical_UI::placeRecognitionCmd ()
00223 {
00224   QString message = tr ("Place recognition for Query scene");
00225   statusBar ()->showMessage (message);
00226   Q_EMIT placeRecognition();
00227 }
00228 
00229 void Graphical_UI::set2DImage (bool is_on)
00230 {
00231   if (is_on)
00232   {
00233     query_BAimage_label->show ();
00234     lib_BAimage_label->show ();
00235     features_image_label->show ();
00236     QList < int >list;
00237     list.append (1);      /* Upper part on */
00238     list.append (1);      /* Lower part off */
00239     vsplitter->setSizes (list);
00240   }
00241   else
00242   {
00243     query_BAimage_label->hide ();
00244     lib_BAimage_label->hide ();
00245     features_image_label->hide ();
00246     QList < int >list;
00247     list.append (1);      /* Upper part on */
00248     list.append (0);      /* Lower part off */
00249     vsplitter->setSizes (list);
00250   }
00251 }
00252 
00253 void Graphical_UI::help ()
00254 {
00255   QMessageBox::about (this, tr ("Help"), *helpText);
00256 }
00257 
00258 void Graphical_UI::about ()
00259 {
00260   QMessageBox::about (this, tr ("About 3D-SMART - Place Recognition"), *infoText + *licenseText);
00261 }
00262 
00263 void Graphical_UI::createMenus ()
00264 {
00265   // Menus are created here
00266   QMenu *graphMenu;
00267   QMenu *recognitionMenu;
00268   QMenu *viewMenu;
00269   QMenu *helpMenu;
00270 
00271   //############################## Graph Menu ###############################
00272 
00273   graphMenu = menuBar ()->addMenu (tr ("&Graph"));
00274 
00275   QAction *loadAct = new QAction (tr ("&Load Data"), this);
00276   loadAct->setShortcut (QString ("Ctrl+L"));
00277   loadAct->setStatusTip (tr ("Load data"));
00278   loadAct->setIcon (QIcon::fromTheme ("load")); //doesn't work for gnome
00279   connect (loadAct, SIGNAL (triggered ()), this, SLOT (loadDataCmd ()));
00280   graphMenu->addAction (loadAct);
00281   this->addAction (loadAct);
00282 
00283   QAction *resetAct = new QAction (tr ("&Reset"), this);
00284   resetAct->setShortcut (QString ("Ctrl+R"));
00285   resetAct->setStatusTip (tr ("Reset the graph, clear all data collected"));
00286   resetAct->setIcon (QIcon::fromTheme ("edit-delete")); //doesn't work (for gnome
00287   connect (resetAct, SIGNAL (triggered ()), this, SLOT (reset ()));
00288   graphMenu->addAction (resetAct);
00289   this->addAction (resetAct);
00290 
00291   graphMenu->addSeparator ();
00292 
00293   QAction *showBAImageAct = new QAction (tr ("Show &BA Image"), this);
00294   showBAImageAct->setShortcut (QString ("Ctrl+B"));
00295   showBAImageAct->setStatusTip (tr ("Show Bearing-Angle image"));
00296   showBAImageAct->setIcon (QIcon::fromTheme ("BA-show")); //doesn't work for gnome
00297   connect (showBAImageAct, SIGNAL (triggered ()), this, SLOT (showBAImageCmd ()));
00298   graphMenu->addAction (showBAImageAct);
00299   this->addAction (showBAImageAct);
00300 
00301   QAction *showFlowsheetAct = new QAction (tr ("Show &Flowsheet"), this);
00302   showFlowsheetAct->setShortcut (QString ("Ctrl+F"));
00303   showFlowsheetAct->setStatusTip (tr ("Show flowsheet"));
00304   showFlowsheetAct->setIcon (QIcon::fromTheme ("flowsheet-show")); //doesn't work for gnome
00305   connect (showFlowsheetAct, SIGNAL (triggered ()), this, SLOT (showFlowsheet ()));
00306   graphMenu->addAction (showFlowsheetAct);
00307   this->addAction (showFlowsheetAct);
00308 
00309   graphMenu->addSeparator ();
00310 
00311   QAction *exitAct = new QAction (tr ("&Exit"), this);
00312   exitAct->setShortcuts (QKeySequence::Quit);
00313   exitAct->setStatusTip (tr ("Exit the application"));
00314   exitAct->setIcon (QIcon::fromTheme ("application-exit")); //doesn't work for gnome
00315   connect (exitAct, SIGNAL (triggered ()), this, SLOT (close ()));
00316   graphMenu->addAction (exitAct);
00317   this->addAction (exitAct);
00318 
00319 
00320   //########################### Recognition Menu ############################
00321 
00322   recognitionMenu = menuBar ()->addMenu (tr ("&Recognition"));
00323 
00324   QAction *extractAct = new QAction (tr ("&Extract Features"), this);
00325   extractAct->setShortcut (QString ("Ctrl+E"));
00326   extractAct->setStatusTip (tr ("Extract global spatial and SURF features, then save to file"));
00327   extractAct->setIcon (QIcon::fromTheme ("extract-save")); //doesn't work (for gnome
00328   connect (extractAct, SIGNAL (triggered ()), this, SLOT (extractFeaturesCmd ()));
00329   recognitionMenu->addAction (extractAct);
00330   this->addAction (extractAct);
00331 
00332   recognitionMenu->addSeparator ();
00333 
00334   QAction *recognitionAct = new QAction (tr ("&Place Recognition"), this);
00335   recognitionAct->setShortcut (QString ("Ctrl+P"));
00336   recognitionAct->setStatusTip (tr ("Place recognition"));
00337   recognitionAct->setIcon (QIcon::fromTheme ("place-recognition")); //doesn't work for gnome
00338   connect (recognitionAct, SIGNAL (triggered ()), this, SLOT (placeRecognitionCmd ()));
00339   recognitionMenu->addAction (recognitionAct);
00340   this->addAction (recognitionAct);
00341 
00342 
00343   //############################## View Menu ################################
00344 
00345   viewMenu = menuBar ()->addMenu (tr ("&View"));
00346 
00347   QAction *toggleGLViewerAct = new QAction (tr ("Toggle &3D Display"), this);
00348   toggleGLViewerAct->setShortcut (QString ("3"));
00349   toggleGLViewerAct->setCheckable (true);
00350   toggleGLViewerAct->setChecked (true);
00351   toggleGLViewerAct->setStatusTip (tr ("Turn on/off the OpenGL Display"));
00352   connect (toggleGLViewerAct, SIGNAL (toggled (bool)), lib_glviewer, SLOT (setVisible (bool)));
00353   connect (toggleGLViewerAct, SIGNAL (toggled (bool)), query_glviewer, SLOT (setVisible (bool)));
00354   viewMenu->addAction (toggleGLViewerAct);
00355   this->addAction (toggleGLViewerAct);
00356 
00357   viewMenu->addSeparator ();
00358 
00359   QAction *toggleQLabelAct = new QAction (tr ("Toggle &2D Display"), this);
00360   toggleQLabelAct->setShortcut (QString ("2"));
00361   toggleQLabelAct->setCheckable (true);
00362   toggleQLabelAct->setChecked (true);
00363   toggleQLabelAct->setStatusTip (tr ("Turn on/off the Image Display"));
00364   connect (toggleQLabelAct, SIGNAL (toggled (bool)), this, SLOT (set2DImage (bool)));
00365   viewMenu->addAction (toggleQLabelAct);
00366   this->addAction (toggleQLabelAct);
00367 
00368 
00369   //############################### Help Menu ###############################
00370 
00371   helpMenu = menuBar ()->addMenu (tr ("&Help"));
00372 
00373   QAction *helpAct = new QAction (tr ("&Usage Help"), this);
00374   helpAct->setShortcuts (QKeySequence::HelpContents);
00375   helpAct->setStatusTip (tr ("Show usage information"));
00376   helpAct->setIcon (QIcon::fromTheme ("help-contents")); //doesn't work for gnome
00377   connect (helpAct, SIGNAL (triggered ()), this, SLOT (help ()));
00378   helpMenu->addAction (helpAct);
00379   this->addAction (helpAct);
00380 
00381   helpMenu->addSeparator ();
00382 
00383   QAction *aboutAct = new QAction (tr ("&About Place Recognition"), this);
00384   aboutAct->setShortcut (QString ("Ctrl+A"));
00385   aboutAct->setStatusTip (tr ("Show information about place recognition"));
00386   aboutAct->setIcon (QIcon::fromTheme ("help-about")); //doesn't work for gnome
00387   connect (aboutAct, SIGNAL (triggered ()), this, SLOT (about ()));
00388   helpMenu->addAction (aboutAct);
00389   this->addAction (aboutAct);
00390 }


dlut_place_recognition
Author(s): Qinghua Li, Yan Zhuang, Fei Yan
autogenerated on Sun Oct 5 2014 23:29:57