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  validDecimationValue_(2),
56  parameters_(parameters)
57 {
58  qRegisterMetaType<rtabmap::SensorData>("rtabmap::SensorData");
59 
61  imageView_->setMinimumSize(320, 240);
62  QHBoxLayout * layout = new QHBoxLayout();
63  layout->setMargin(0);
64  layout->addWidget(imageView_,1);
65  layout->addWidget(cloudView_,1);
66 
67  QLabel * decimationLabel = new QLabel("Decimation", this);
68  decimationSpin_ = new QSpinBox(this);
69  decimationSpin_->setMinimum(1);
70  decimationSpin_->setMaximum(16);
71  decimationSpin_->setValue(2);
72 
73  pause_ = new QPushButton("Pause", this);
74  pause_->setCheckable(true);
75  showCloudCheckbox_ = new QCheckBox("Show RGB-D cloud", this);
76  showCloudCheckbox_->setEnabled(false);
77  showCloudCheckbox_->setChecked(true);
78  showScanCheckbox_ = new QCheckBox("Show scan", this);
79  showScanCheckbox_->setEnabled(false);
80 
81  QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
82  buttonBox->setStandardButtons(QDialogButtonBox::Close);
83  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
84 
85  QHBoxLayout * layout2 = new QHBoxLayout();
86  layout2->addWidget(pause_);
87  layout2->addWidget(decimationLabel);
88  layout2->addWidget(decimationSpin_);
89  layout2->addWidget(showCloudCheckbox_);
90  layout2->addWidget(showScanCheckbox_);
91  layout2->addStretch(1);
92  layout2->addWidget(buttonBox);
93 
94  QVBoxLayout * vlayout = new QVBoxLayout(this);
95  vlayout->setMargin(0);
96  vlayout->setSpacing(0);
97  vlayout->addLayout(layout, 1);
98  vlayout->addLayout(layout2);
99 
100  this->setLayout(vlayout);
101 }
102 
104 {
106 }
107 
109 {
110  if(!data.imageRaw().empty() || !data.depthOrRightRaw().empty())
111  {
112  if(data.imageRaw().cols % decimationSpin_->value() == 0 &&
113  data.imageRaw().rows % decimationSpin_->value() == 0 &&
114  data.depthOrRightRaw().cols % decimationSpin_->value() == 0 &&
115  data.depthOrRightRaw().rows % decimationSpin_->value() == 0)
116  {
118  }
119  else
120  {
121  UWARN("Decimation (%d) must be a denominator of the width and height of "
122  "the image (color=%d/%d depth=%d/%d). Using last valid decimation value (%d).",
123  decimationSpin_->value(),
124  data.imageRaw().cols,
125  data.imageRaw().rows,
126  data.depthOrRightRaw().cols,
127  data.depthOrRightRaw().rows,
129  }
130  }
131 
132  processingImages_ = true;
133  if(!data.imageRaw().empty())
134  {
136  }
137  if(!data.depthOrRightRaw().empty())
138  {
140  }
141 
142  if(!data.depthOrRightRaw().empty() &&
143  (data.stereoCameraModel().isValidForProjection() || (data.cameraModels().size() && data.cameraModels().at(0).isValidForProjection())))
144  {
145  if(showCloudCheckbox_->isChecked())
146  {
147  if(!data.imageRaw().empty() && !data.depthOrRightRaw().empty())
148  {
149  showCloudCheckbox_->setEnabled(true);
151  }
152  else if(!data.depthOrRightRaw().empty())
153  {
154  showCloudCheckbox_->setEnabled(true);
156  }
157  }
158  }
159 
160  if(!data.laserScanRaw().isEmpty())
161  {
162  showScanCheckbox_->setEnabled(true);
163  if(showScanCheckbox_->isChecked())
164  {
166  }
167  }
168 
169  cloudView_->setVisible((showCloudCheckbox_->isEnabled() && showCloudCheckbox_->isChecked()) ||
170  (showScanCheckbox_->isEnabled() && showScanCheckbox_->isChecked()));
171  if(cloudView_->isVisible())
172  {
173  cloudView_->update();
174  }
175  if(cloudView_->getAddedClouds().contains("cloud"))
176  {
177  cloudView_->setCloudVisibility("cloud", showCloudCheckbox_->isChecked());
178  }
179  if(cloudView_->getAddedClouds().contains("scan"))
180  {
181  cloudView_->setCloudVisibility("scan", showScanCheckbox_->isChecked());
182  }
183 
184  processingImages_ = false;
185 }
186 
188 {
189  if(!pause_->isChecked())
190  {
191  if(event->getClassName().compare("CameraEvent") == 0)
192  {
193  CameraEvent * camEvent = (CameraEvent*)event;
194  if(camEvent->getCode() == CameraEvent::kCodeData)
195  {
196  if(camEvent->data().isValid())
197  {
198  if(!processingImages_ && this->isVisible() && camEvent->data().isValid())
199  {
200  processingImages_ = true;
201  QMetaObject::invokeMethod(this, "showImage",
202  Q_ARG(rtabmap::SensorData, camEvent->data()));
203  }
204  }
205  }
206  }
207  }
208  return false;
209 }
210 
211 } /* 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:70
static Transform getIdentity()
Definition: Transform.cpp:364
CloudViewer * cloudView_
Definition: CameraViewer.h:63
bool isEmpty() const
Definition: LaserScan.h:69
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:41
void setImage(const QImage &image)
Definition: ImageView.cpp:871
const LaserScan & laserScanRaw() const
Definition: SensorData.h:163
const cv::Mat & imageRaw() const
Definition: SensorData.h:161
QPushButton * pause_
Definition: CameraViewer.h:68
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP laserScanToPointCloud(const LaserScan &laserScan, const Transform &transform=Transform())
Definition: util3d.cpp:2328
CameraViewer(QWidget *parent=0, const ParametersMap &parameters=ParametersMap())
bool addCloud(const std::string &id, const pcl::PCLPointCloud2Ptr &binaryCloud, const Transform &pose, bool rgb, bool hasNormals, bool hasIntensity, const QColor &color=QColor())
LaserScan RTABMAP_EXP downsample(const LaserScan &cloud, int step)
bool isValid() const
Definition: SensorData.h:134
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:898
cv::Mat RTABMAP_EXP decimate(const cv::Mat &image, int d)
Definition: util2d.cpp:1196
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:69
QSpinBox * decimationSpin_
Definition: CameraViewer.h:65
const cv::Mat & depthOrRightRaw() const
Definition: SensorData.h:162
const QMap< std::string, Transform > & getAddedClouds() const
Definition: CloudViewer.h:307
ParametersMap parameters_
Definition: CameraViewer.h:67
#define false
Definition: ConvertUTF.c:56
const std::vector< CameraModel > & cameraModels() const
Definition: SensorData.h:193
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:194
#define UWARN(...)
const SensorData & data() const
Definition: CameraEvent.h:79
ImageView * imageView_
Definition: CameraViewer.h:62
void unregisterFromEventsManager()
void setImageDepthShown(bool shown)
Definition: ImageView.cpp:356


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:30