CameraViewer.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include "rtabmap/gui/CameraViewer.h"
00029 
00030 #include <rtabmap/core/CameraEvent.h>
00031 #include <rtabmap/core/util3d.h>
00032 #include <rtabmap/gui/ImageView.h>
00033 #include <rtabmap/gui/CloudViewer.h>
00034 #include <rtabmap/gui/UCv2Qt.h>
00035 #include <QtCore/QMetaType>
00036 #include <QHBoxLayout>
00037 #include <QVBoxLayout>
00038 #include <QDialogButtonBox>
00039 
00040 namespace rtabmap {
00041 
00042 
00043 CameraViewer::CameraViewer(QWidget * parent) :
00044                 QDialog(parent),
00045         imageView_(new ImageView(this)),
00046         cloudView_(new CloudViewer(this)),
00047         processingImages_(false)
00048 {
00049         qRegisterMetaType<rtabmap::SensorData>("rtabmap::SensorData");
00050 
00051         imageView_->setImageDepthShown(true);
00052         imageView_->setMinimumSize(320, 240);
00053         QHBoxLayout * layout = new QHBoxLayout();
00054         layout->setMargin(0);
00055         layout->addWidget(imageView_,1);
00056         layout->addWidget(cloudView_,1);
00057 
00058         QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
00059         buttonBox->setStandardButtons(QDialogButtonBox::Close);
00060         connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
00061 
00062         QVBoxLayout * vlayout = new QVBoxLayout(this);
00063         vlayout->setMargin(0);
00064         vlayout->setSpacing(0);
00065         vlayout->addLayout(layout, 1);
00066         vlayout->addWidget(buttonBox);
00067 
00068         this->setLayout(vlayout);
00069 }
00070 
00071 CameraViewer::~CameraViewer()
00072 {
00073         this->unregisterFromEventsManager();
00074 }
00075 
00076 void CameraViewer::showImage(const rtabmap::SensorData & data)
00077 {
00078         processingImages_ = true;
00079         imageView_->setImage(uCvMat2QImage(data.image()));
00080         imageView_->setImageDepth(uCvMat2QImage(data.depthOrRightImage()));
00081         if(!data.depth().empty() && data.fx() && data.fy())
00082         {
00083                 cloudView_->addOrUpdateCloud("cloud",
00084                                 util3d::cloudFromDepthRGB(data.image(), data.depth(), data.cx(), data.cy(), data.fx(), data.fy()),
00085                                 data.localTransform());
00086         }
00087         else if(!data.rightImage().empty() && data.fx() && data.baseline())
00088         {
00089                 cloudView_->addOrUpdateCloud("cloud",
00090                                 util3d::cloudFromStereoImages(data.image(), data.rightImage(), data.cx(), data.cy(), data.fx(), data.baseline()),
00091                                 data.localTransform());
00092         }
00093         else
00094         {
00095                 cloudView_->setVisible(false);
00096         }
00097         cloudView_->update();
00098         processingImages_ = false;
00099 }
00100 
00101 void CameraViewer::handleEvent(UEvent * event)
00102 {
00103         if(event->getClassName().compare("CameraEvent") == 0)
00104         {
00105                 CameraEvent * camEvent = (CameraEvent*)event;
00106                 if(camEvent->getCode() == CameraEvent::kCodeImageDepth ||
00107                    camEvent->getCode() == CameraEvent::kCodeImage)
00108                 {
00109                         if(camEvent->data().isValid())
00110                         {
00111                                 if(!processingImages_ && this->isVisible() && camEvent->data().isValid())
00112                                 {
00113                                         processingImages_ = true;
00114                                         QMetaObject::invokeMethod(this, "showImage",
00115                                                         Q_ARG(rtabmap::SensorData, camEvent->data()));
00116                                 }
00117                         }
00118                 }
00119         }
00120 }
00121 
00122 } /* namespace rtabmap */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Fri Aug 28 2015 12:51:31