CameraViewer.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
29 
31 #include <rtabmap/core/util3d.h>
32 #include <rtabmap/core/util2d.h>
34 #include <rtabmap/gui/ImageView.h>
36 #include <rtabmap/utilite/UCv2Qt.h>
38 #include <QtCore/QMetaType>
39 #include <QHBoxLayout>
40 #include <QVBoxLayout>
41 #include <QLabel>
42 #include <QSpinBox>
43 #include <QDialogButtonBox>
44 #include <QCheckBox>
45 #include <QPushButton>
46 
47 namespace rtabmap {
48 
49 
50 CameraViewer::CameraViewer(QWidget * parent, const ParametersMap & parameters) :
51  QDialog(parent),
52  imageView_(new ImageView(this)),
53  cloudView_(new CloudViewer(this)),
54  processingImages_(false),
55  parameters_(parameters)
56 {
57  qRegisterMetaType<rtabmap::SensorData>("rtabmap::SensorData");
58 
60  imageView_->setMinimumSize(320, 240);
61  QHBoxLayout * layout = new QHBoxLayout();
62  layout->setMargin(0);
63  layout->addWidget(imageView_,1);
64  layout->addWidget(cloudView_,1);
65 
66  QLabel * decimationLabel = new QLabel("Decimation", this);
67  decimationSpin_ = new QSpinBox(this);
68  decimationSpin_->setMinimum(-16);
69  decimationSpin_->setMaximum(16);
70  decimationSpin_->setValue(2);
71 
72  pause_ = new QPushButton("Pause", this);
73  pause_->setCheckable(true);
74  showCloudCheckbox_ = new QCheckBox("Show RGB-D cloud", this);
75  showCloudCheckbox_->setEnabled(false);
76  showCloudCheckbox_->setChecked(true);
77  showScanCheckbox_ = new QCheckBox("Show scan", this);
78  showScanCheckbox_->setEnabled(false);
79 
80  imageSizeLabel_ = new QLabel(this);
81 
82  QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
83  buttonBox->setStandardButtons(QDialogButtonBox::Close);
84  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
85 
86  QHBoxLayout * layout2 = new QHBoxLayout();
87  layout2->addWidget(pause_);
88  layout2->addWidget(decimationLabel);
89  layout2->addWidget(decimationSpin_);
90  layout2->addWidget(showCloudCheckbox_);
91  layout2->addWidget(showScanCheckbox_);
92  layout2->addWidget(imageSizeLabel_);
93  layout2->addStretch(1);
94  layout2->addWidget(buttonBox);
95 
96  QVBoxLayout * vlayout = new QVBoxLayout(this);
97  vlayout->setMargin(0);
98  vlayout->setSpacing(0);
99  vlayout->addLayout(layout, 1);
100  vlayout->addLayout(layout2);
101 
102  this->setLayout(vlayout);
103 }
104 
106 {
108 }
109 
111 {
112  processingImages_ = true;
113  QString sizes;
114  if(!data.imageRaw().empty())
115  {
117  sizes.append(QString("Color=%1x%2").arg(data.imageRaw().cols).arg(data.imageRaw().rows));
118  }
119  if(!data.depthOrRightRaw().empty())
120  {
122  sizes.append(QString(" Depth=%1x%2").arg(data.depthOrRightRaw().cols).arg(data.depthOrRightRaw().rows));
123  }
124  imageSizeLabel_->setText(sizes);
125 
126  if(!data.depthOrRightRaw().empty() &&
127  (data.stereoCameraModel().isValidForProjection() || (data.cameraModels().size() && data.cameraModels().at(0).isValidForProjection())))
128  {
129  if(showCloudCheckbox_->isChecked())
130  {
131  if(!data.imageRaw().empty() && !data.depthOrRightRaw().empty())
132  {
133  showCloudCheckbox_->setEnabled(true);
134  cloudView_->addCloud("cloud", util3d::cloudRGBFromSensorData(data, decimationSpin_->value()!=0?decimationSpin_->value():1, 0, 0, 0, parameters_));
135  }
136  else if(!data.depthOrRightRaw().empty())
137  {
138  showCloudCheckbox_->setEnabled(true);
139  cloudView_->addCloud("cloud", util3d::cloudFromSensorData(data, decimationSpin_->value()!=0?fabs(decimationSpin_->value()):1, 0, 0, 0, parameters_));
140  }
141  }
142  }
143 
144  if(!data.laserScanRaw().isEmpty())
145  {
146  showScanCheckbox_->setEnabled(true);
147  if(showScanCheckbox_->isChecked())
148  {
150  }
151  }
152 
153  cloudView_->setVisible((showCloudCheckbox_->isEnabled() && showCloudCheckbox_->isChecked()) ||
154  (showScanCheckbox_->isEnabled() && showScanCheckbox_->isChecked()));
155  if(cloudView_->isVisible())
156  {
157  cloudView_->update();
158  }
159  if(cloudView_->getAddedClouds().contains("cloud"))
160  {
161  cloudView_->setCloudVisibility("cloud", showCloudCheckbox_->isChecked());
162  }
163  if(cloudView_->getAddedClouds().contains("scan"))
164  {
165  cloudView_->setCloudVisibility("scan", showScanCheckbox_->isChecked());
166  }
167 
168  processingImages_ = false;
169 }
170 
172 {
173  if(!pause_->isChecked())
174  {
175  if(event->getClassName().compare("CameraEvent") == 0)
176  {
177  CameraEvent * camEvent = (CameraEvent*)event;
178  if(camEvent->getCode() == CameraEvent::kCodeData)
179  {
180  if(camEvent->data().isValid())
181  {
182  if(!processingImages_ && this->isVisible() && camEvent->data().isValid())
183  {
184  processingImages_ = true;
185  QMetaObject::invokeMethod(this, "showImage",
186  Q_ARG(rtabmap::SensorData, camEvent->data()));
187  }
188  }
189  }
190  }
191  }
192  return false;
193 }
194 
195 } /* namespace rtabmap */
int getCode() const
Definition: UEvent.h:74
Definition: UEvent.h:57
void setCloudVisibility(const std::string &id, bool isVisible)
QCheckBox * showScanCheckbox_
Definition: CameraViewer.h:71
static Transform getIdentity()
Definition: Transform.cpp:380
CloudViewer * cloudView_
Definition: CameraViewer.h:64
bool isEmpty() const
Definition: LaserScan.h:101
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
void setImage(const QImage &image)
Definition: ImageView.cpp:1099
const LaserScan & laserScanRaw() const
Definition: SensorData.h:166
const cv::Mat & imageRaw() const
Definition: SensorData.h:164
QPushButton * pause_
Definition: CameraViewer.h:68
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP laserScanToPointCloud(const LaserScan &laserScan, const Transform &transform=Transform())
Definition: util3d.cpp:2382
CameraViewer(QWidget *parent=0, const ParametersMap &parameters=ParametersMap())
LaserScan RTABMAP_EXP downsample(const LaserScan &cloud, int step)
bool isValid() const
Definition: SensorData.h:137
QImage uCvMat2QImage(const cv::Mat &image, bool isBgr=true, uCvQtDepthColorMap colorMap=uCvQtDepthWhiteToBlack)
Definition: UCv2Qt.h:44
virtual std::string getClassName() const =0
void setImageDepth(const cv::Mat &imageDepth)
Definition: ImageView.cpp:1126
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP cloudRGBFromSensorData(const SensorData &sensorData, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0, const ParametersMap &stereoParameters=ParametersMap(), const std::vector< float > &roiRatios=std::vector< float >())
Definition: util3d.cpp:1031
QCheckBox * showCloudCheckbox_
Definition: CameraViewer.h:70
QSpinBox * decimationSpin_
Definition: CameraViewer.h:66
const cv::Mat & depthOrRightRaw() const
Definition: SensorData.h:165
const QMap< std::string, Transform > & getAddedClouds() const
Definition: CloudViewer.h:314
bool addCloud(const std::string &id, const pcl::PCLPointCloud2Ptr &binaryCloud, const Transform &pose, bool rgb, bool hasNormals, bool hasIntensity, const QColor &color=QColor(), int viewport=1)
ParametersMap parameters_
Definition: CameraViewer.h:67
#define false
Definition: ConvertUTF.c:56
const std::vector< CameraModel > & cameraModels() const
Definition: SensorData.h:215
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP cloudFromSensorData(const SensorData &sensorData, int decimation=1, float maxDepth=0.0f, float minDepth=0.0f, std::vector< int > *validIndices=0, const ParametersMap &stereoParameters=ParametersMap(), const std::vector< float > &roiRatios=std::vector< float >())
Definition: util3d.cpp:852
void showImage(const rtabmap::SensorData &data)
virtual bool handleEvent(UEvent *event)
ULogger class and convenient macros.
const StereoCameraModel & stereoCameraModel() const
Definition: SensorData.h:216
const SensorData & data() const
Definition: CameraEvent.h:79
ImageView * imageView_
Definition: CameraViewer.h:63
void unregisterFromEventsManager()
void setImageDepthShown(bool shown)
Definition: ImageView.cpp:430


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:58