LoopClosureViewer.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 #include "ui_loopClosureViewer.h"
30 
31 #include "rtabmap/core/Memory.h"
34 #include "rtabmap/core/util3d.h"
35 #include "rtabmap/core/Signature.h"
37 #include "rtabmap/utilite/UStl.h"
38 
39 #include <QtCore/QTimer>
40 
41 namespace rtabmap {
42 
44  QWidget(parent),
45  decimation_(1),
46  maxDepth_(0),
47  minDepth_(0)
48 {
49  ui_ = new Ui_loopClosureViewer();
50  ui_->setupUi(this);
51  ui_->cloudViewerTransform->setCameraLockZ(false);
52 
53  connect(ui_->checkBox_rawCloud, SIGNAL(clicked()), this, SLOT(updateView()));
54 }
55 
57  delete ui_;
58 }
59 
61 {
62  sA_ = sA;
63  sB_ = sB;
64  if(sA_.id()>0 && sB_.id()>0)
65  {
66  ui_->label_idA->setText(QString("[%1-%2]").arg(sA.id()).arg(sB.id()));
67  }
68 }
69 
70 void LoopClosureViewer::updateView(const Transform & transform, const ParametersMap & parameters)
71 {
72  if(sA_.id()>0 && sB_.id()>0)
73  {
74  int decimation = 1;
75  float maxDepth = 0;
76  float minDepth = 0;
77 
78  if(!ui_->checkBox_rawCloud->isChecked())
79  {
80  decimation = decimation_;
81  maxDepth = maxDepth_;
82  minDepth = minDepth_;
83  }
84 
85  UDEBUG("decimation = %d", decimation);
86  UDEBUG("maxDepth = %f", maxDepth);
87  UDEBUG("minDepth = %d", minDepth);
88 
89  Transform t;
90  if(!transform.isNull())
91  {
92  transform_ = transform;
93  t = transform;
94  }
95  else if(!transform_.isNull())
96  {
97  t = transform_;
98  }
99  else
100  {
101  t = sB_.getPose();
102  }
103 
104  UDEBUG("t= %s", t.prettyPrint().c_str());
105  ui_->label_transform->setText(QString("(%1)").arg(t.prettyPrint().c_str()));
106  if(!t.isNull())
107  {
108  //cloud 3d
109  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudA, cloudB;
110  cloudA = util3d::cloudRGBFromSensorData(sA_.sensorData(), decimation, maxDepth, minDepth, 0, parameters);
111  cloudB = util3d::cloudRGBFromSensorData(sB_.sensorData(), decimation, maxDepth, minDepth, 0, parameters);
112 
113  //cloud 2d
114  pcl::PointCloud<pcl::PointXYZ>::Ptr scanA, scanB;
117 
118  ui_->label_idA->setText(QString("[%1 (%2) -> %3 (%4)]").arg(sB_.id()).arg(cloudB->size()).arg(sA_.id()).arg(cloudA->size()));
119 
120  if(cloudA->size())
121  {
122  ui_->cloudViewerTransform->addCloud("cloud0", cloudA);
123  }
124  if(cloudB->size())
125  {
126  cloudB = util3d::transformPointCloud(cloudB, t);
127  ui_->cloudViewerTransform->addCloud("cloud1", cloudB);
128  }
129  if(scanA->size())
130  {
131  ui_->cloudViewerTransform->addCloud("scan0", scanA);
132  }
133  if(scanB->size())
134  {
135  scanB = util3d::transformPointCloud(scanB, t);
136  ui_->cloudViewerTransform->addCloud("scan1", scanB);
137  }
138  }
139  else
140  {
141  UERROR("loop transform is null !?!?");
142  ui_->cloudViewerTransform->removeAllClouds();
143  }
144  ui_->cloudViewerTransform->update();
145  }
146 }
147 
148 
149 void LoopClosureViewer::showEvent(QShowEvent * event)
150 {
151  QWidget::showEvent( event );
152  QTimer::singleShot(500, this, SLOT(updateView())); // make sure the QVTKWidget is shown!
153 }
154 
155 } /* namespace rtabmap */
std::string prettyPrint() const
Definition: Transform.cpp:295
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP transformPointCloud(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const Transform &transform)
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
void setData(const Signature &sA, const Signature &sB)
const LaserScan & laserScanRaw() const
Definition: SensorData.h:166
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP laserScanToPointCloud(const LaserScan &laserScan, const Transform &transform=Transform())
Definition: util3d.cpp:2382
virtual void showEvent(QShowEvent *event)
void updateView(const Transform &AtoB=Transform(), const ParametersMap &parameters=ParametersMap())
Wrappers of STL for convenient functions.
Ui_loopClosureViewer * ui_
bool isNull() const
Definition: Transform.cpp:107
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
int id() const
Definition: Signature.h:70
Transform localTransform() const
Definition: LaserScan.h:98
LoopClosureViewer(QWidget *parent=0)
const Signature & sB() const
const Transform & getPose() const
Definition: Signature.h:132
#define UDEBUG(...)
SensorData & sensorData()
Definition: Signature.h:137
#define UERROR(...)
ULogger class and convenient macros.
const Signature & sA() const


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