Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 }