31 #include <QVBoxLayout>
32 #include <QtCore/QMetaType>
35 #ifndef Q_MOC_RUN // Mac OS X issue
59 odometryCorrection_(
Transform::getIdentity()),
60 processingStatistics_(
false),
61 lastOdometryProcessed_(
true)
63 this->setWindowFlags(Qt::Dialog);
64 this->setWindowTitle(tr(
"3D Map"));
65 this->setMinimumWidth(800);
66 this->setMinimumHeight(600);
70 QVBoxLayout *layout =
new QVBoxLayout();
71 layout->addWidget(cloudViewer_);
72 this->setLayout(layout);
74 qRegisterMetaType<rtabmap::OdometryEvent>(
"rtabmap::OdometryEvent");
75 qRegisterMetaType<rtabmap::Statistics>(
"rtabmap::Statistics");
77 QAction * pause =
new QAction(
this);
78 this->addAction(pause);
79 pause->setShortcut(Qt::Key_Space);
80 connect(pause, SIGNAL(triggered()),
this, SLOT(pauseDetection()));
85 this->unregisterFromEventsManager();
94 if(camera_->isCapturing())
107 if(!this->isVisible())
116 cloudViewer_->setBackgroundColor(Qt::darkRed);
118 pose = lastOdomPose_;
122 cloudViewer_->setBackgroundColor(cloudViewer_->getDefaultBackgroundColor());
126 lastOdomPose_ = pose;
140 if(!cloudViewer_->addCloud(
"cloudOdom", cloud, odometryCorrection_*pose))
142 UERROR(
"Adding cloudOdom to viewer failed!");
147 cloudViewer_->setCloudVisibility(
"cloudOdom",
false);
148 UWARN(
"Empty cloudOdom!");
155 cloudViewer_->updateCameraTargetPosition(odometryCorrection_*odom.
pose());
158 cloudViewer_->update();
159 cloudViewer_->refreshView();
161 lastOdometryProcessed_ =
true;
167 processingStatistics_ =
true;
172 const std::map<int, Transform> & poses =
stats.poses();
173 QMap<std::string, Transform> clouds = cloudViewer_->getAddedClouds();
174 for(std::map<int, Transform>::const_iterator
iter = poses.lower_bound(1);
iter!=poses.end(); ++
iter)
176 if(!
iter->second.isNull())
178 std::string cloudName =
uFormat(
"cloud%d",
iter->first);
181 if(clouds.contains(cloudName))
185 cloudViewer_->getPose(cloudName, tCloud);
188 if(!cloudViewer_->updateCloudPose(cloudName,
iter->second))
190 UERROR(
"Updating pose cloud %d failed!",
iter->first);
193 cloudViewer_->setCloudVisibility(cloudName,
true);
195 else if(
iter->first ==
stats.getLastSignatureData().id())
198 s.sensorData().uncompressData();
206 if(!cloudViewer_->addCloud(cloudName, cloud,
iter->second))
208 UERROR(
"Adding cloud %d to viewer failed!",
iter->first);
219 UWARN(
"Null pose for %d ?!?",
iter->first);
226 cloudViewer_->removeAllGraphs();
227 cloudViewer_->removeCloud(
"graph_nodes");
231 pcl::PointCloud<pcl::PointXYZ>::Ptr
graph(
new pcl::PointCloud<pcl::PointXYZ>);
232 pcl::PointCloud<pcl::PointXYZ>::Ptr graphNodes(
new pcl::PointCloud<pcl::PointXYZ>);
233 for(std::map<int, Transform>::const_iterator
iter=poses.lower_bound(1);
iter!=poses.end(); ++
iter)
235 graph->push_back(pcl::PointXYZ(
iter->second.x(),
iter->second.y(),
iter->second.z()));
237 *graphNodes = *
graph;
241 cloudViewer_->addOrUpdateGraph(
"graph",
graph, Qt::gray);
243 cloudViewer_->setCloudPointSize(
"graph_nodes", 5);
246 odometryCorrection_ =
stats.mapCorrection();
248 cloudViewer_->update();
249 cloudViewer_->refreshView();
251 processingStatistics_ =
false;
261 if(this->isVisible())
266 else if(event->
getClassName().compare(
"OdometryEvent") == 0)
270 if(this->isVisible() &&
271 lastOdometryProcessed_ &&
272 !processingStatistics_)
274 lastOdometryProcessed_ =
false;
286 bool processingStatistics_;
287 bool lastOdometryProcessed_;