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  showScanCheckbox_->setChecked(true);
80 
81  imageSizeLabel_ = new QLabel(this);
82 
83  QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
84  buttonBox->setStandardButtons(QDialogButtonBox::Close);
85  connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
86 
87  QHBoxLayout * layout2 = new QHBoxLayout();
88  layout2->addWidget(pause_);
89  layout2->addWidget(decimationLabel);
90  layout2->addWidget(decimationSpin_);
91  layout2->addWidget(showCloudCheckbox_);
92  layout2->addWidget(showScanCheckbox_);
93  layout2->addWidget(imageSizeLabel_);
94  layout2->addStretch(1);
95  layout2->addWidget(buttonBox);
96 
97  QVBoxLayout * vlayout = new QVBoxLayout(this);
98  vlayout->setMargin(0);
99  vlayout->setSpacing(0);
100  vlayout->addLayout(layout, 1);
101  vlayout->addLayout(layout2);
102 
103  this->setLayout(vlayout);
104 }
105 
107 {
109 }
110 
112 {
113  processingImages_ = true;
114  QString sizes;
115  if(!data.imageRaw().empty())
116  {
118  sizes.append(QString("Color=%1x%2").arg(data.imageRaw().cols).arg(data.imageRaw().rows));
119  }
120  if(!data.depthOrRightRaw().empty())
121  {
123  sizes.append(QString(" Depth=%1x%2").arg(data.depthOrRightRaw().cols).arg(data.depthOrRightRaw().rows));
124  }
125  imageSizeLabel_->setText(sizes);
126 
127  if(!data.depthOrRightRaw().empty() &&
128  ((data.stereoCameraModels().size() && data.stereoCameraModels()[0].isValidForProjection()) || (data.cameraModels().size() && data.cameraModels().at(0).isValidForProjection())))
129  {
130  if(showCloudCheckbox_->isChecked())
131  {
132  if(!data.imageRaw().empty() && !data.depthOrRightRaw().empty())
133  {
134  showCloudCheckbox_->setEnabled(true);
135  cloudView_->addCloud("cloud", util3d::cloudRGBFromSensorData(data, decimationSpin_->value()!=0?decimationSpin_->value():1, 0, 0, 0, parameters_));
136  }
137  else if(!data.depthOrRightRaw().empty())
138  {
139  showCloudCheckbox_->setEnabled(true);
140  cloudView_->addCloud("cloud", util3d::cloudFromSensorData(data, decimationSpin_->value()!=0?fabs(decimationSpin_->value()):1, 0, 0, 0, parameters_));
141  }
142  }
143  }
144 
145  if(!data.laserScanRaw().isEmpty())
146  {
147  showScanCheckbox_->setEnabled(true);
148  if(showScanCheckbox_->isChecked())
149  {
150  if(data.laserScanRaw().hasNormals())
151  {
152  if(data.laserScanRaw().hasIntensity())
153  {
155  }
156  else if(data.laserScanRaw().hasRGB())
157  {
159  }
160  else
161  {
163  }
164  }
165  else if(data.laserScanRaw().hasIntensity())
166  {
168  }
169  else if(data.laserScanRaw().hasRGB())
170  {
172  }
173  else
174  {
176  }
177  }
178  }
179 
180  cloudView_->setVisible((showCloudCheckbox_->isEnabled() && showCloudCheckbox_->isChecked()) ||
181  (showScanCheckbox_->isEnabled() && showScanCheckbox_->isChecked()));
182  if(cloudView_->isVisible())
183  {
185  }
186  if(cloudView_->getAddedClouds().contains("cloud"))
187  {
188  cloudView_->setCloudVisibility("cloud", showCloudCheckbox_->isChecked());
189  }
190  if(cloudView_->getAddedClouds().contains("scan"))
191  {
192  cloudView_->setCloudVisibility("scan", showScanCheckbox_->isChecked());
193  }
194 
195  processingImages_ = false;
196 }
197 
199 {
200  if(!pause_->isChecked())
201  {
202  if(event->getClassName().compare("CameraEvent") == 0)
203  {
204  CameraEvent * camEvent = (CameraEvent*)event;
205  if(camEvent->getCode() == CameraEvent::kCodeData)
206  {
207  if(camEvent->data().isValid())
208  {
209  if(!processingImages_ && this->isVisible() && camEvent->data().isValid())
210  {
211  processingImages_ = true;
212  QMetaObject::invokeMethod(this, "showImage",
213  Q_ARG(rtabmap::SensorData, camEvent->data()));
214  }
215  }
216  }
217  }
218  }
219  return false;
220 }
221 
222 } /* namespace rtabmap */
Definition: UEvent.h:57
void setCloudVisibility(const std::string &id, bool isVisible)
QCheckBox * showScanCheckbox_
Definition: CameraViewer.h:71
pcl::PointCloud< pcl::PointXYZRGBNormal >::Ptr RTABMAP_EXP laserScanToPointCloudRGBNormal(const LaserScan &laserScan, const Transform &transform=Transform(), unsigned char r=100, unsigned char g=100, unsigned char b=100)
Definition: util3d.cpp:2268
const cv::Mat & depthOrRightRaw() const
Definition: SensorData.h:184
CloudViewer * cloudView_
Definition: CameraViewer.h:64
QImage uCvMat2QImage(const cv::Mat &image, bool isBgr=true, uCvQtDepthColorMap colorMap=uCvQtDepthWhiteToBlack, float depthMin=0, float depthMax=0)
Definition: UCv2Qt.h:47
const std::vector< StereoCameraModel > & stereoCameraModels() const
Definition: SensorData.h:237
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
void setImage(const QImage &image)
Definition: ImageView.cpp:1143
bool isEmpty() const
Definition: LaserScan.h:125
int getCode() const
Definition: UEvent.h:74
QPushButton * pause_
Definition: CameraViewer.h:68
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP laserScanToPointCloud(const LaserScan &laserScan, const Transform &transform=Transform())
Definition: util3d.cpp:2197
CameraViewer(QWidget *parent=0, const ParametersMap &parameters=ParametersMap())
bool hasRGB() const
Definition: LaserScan.h:130
LaserScan RTABMAP_EXP downsample(const LaserScan &cloud, int step)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_EXP laserScanToPointCloudRGB(const LaserScan &laserScan, const Transform &transform=Transform(), unsigned char r=100, unsigned char g=100, unsigned char b=100)
Definition: util3d.cpp:2232
bool hasNormals() const
Definition: LaserScan.h:129
const std::vector< CameraModel > & cameraModels() const
Definition: SensorData.h:236
virtual std::string getClassName() const =0
pcl::PointCloud< pcl::PointXYZINormal >::Ptr RTABMAP_EXP laserScanToPointCloudINormal(const LaserScan &laserScan, const Transform &transform=Transform(), float intensity=0.0f)
Definition: util3d.cpp:2285
void setImageDepth(const cv::Mat &imageDepth)
Definition: ImageView.cpp:1170
const cv::Mat & imageRaw() const
Definition: SensorData.h:183
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:1056
QCheckBox * showCloudCheckbox_
Definition: CameraViewer.h:70
QSpinBox * decimationSpin_
Definition: CameraViewer.h:66
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
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:853
void showImage(const rtabmap::SensorData &data)
const LaserScan & laserScanRaw() const
Definition: SensorData.h:185
pcl::PointCloud< pcl::PointNormal >::Ptr RTABMAP_EXP laserScanToPointCloudNormal(const LaserScan &laserScan, const Transform &transform=Transform())
Definition: util3d.cpp:2215
virtual bool handleEvent(UEvent *event)
ULogger class and convenient macros.
bool hasIntensity() const
Definition: LaserScan.h:131
ImageView * imageView_
Definition: CameraViewer.h:63
void unregisterFromEventsManager()
pcl::PointCloud< pcl::PointXYZI >::Ptr RTABMAP_EXP laserScanToPointCloudI(const LaserScan &laserScan, const Transform &transform=Transform(), float intensity=0.0f)
Definition: util3d.cpp:2250
bool isValid() const
Definition: SensorData.h:156
const QMap< std::string, Transform > & getAddedClouds() const
Definition: CloudViewer.h:329
Transform localTransform() const
Definition: LaserScan.h:122
const SensorData & data() const
Definition: CameraEvent.h:79
void setImageDepthShown(bool shown)
Definition: ImageView.cpp:448


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:28