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();
160 lastOdometryProcessed_ =
true;
166 processingStatistics_ =
true;
171 const std::map<int, Transform> & poses =
stats.poses();
172 QMap<std::string, Transform> clouds = cloudViewer_->getAddedClouds();
173 for(std::map<int, Transform>::const_iterator
iter = poses.lower_bound(1);
iter!=poses.end(); ++
iter)
175 if(!
iter->second.isNull())
177 std::string cloudName =
uFormat(
"cloud%d",
iter->first);
180 if(clouds.contains(cloudName))
184 cloudViewer_->getPose(cloudName, tCloud);
187 if(!cloudViewer_->updateCloudPose(cloudName,
iter->second))
189 UERROR(
"Updating pose cloud %d failed!",
iter->first);
192 cloudViewer_->setCloudVisibility(cloudName,
true);
194 else if(
iter->first ==
stats.getLastSignatureData().id())
197 s.sensorData().uncompressData();
205 if(!cloudViewer_->addCloud(cloudName, cloud,
iter->second))
207 UERROR(
"Adding cloud %d to viewer failed!",
iter->first);
218 UWARN(
"Null pose for %d ?!?",
iter->first);
225 cloudViewer_->removeAllGraphs();
226 cloudViewer_->removeCloud(
"graph_nodes");
230 pcl::PointCloud<pcl::PointXYZ>::Ptr
graph(
new pcl::PointCloud<pcl::PointXYZ>);
231 pcl::PointCloud<pcl::PointXYZ>::Ptr graphNodes(
new pcl::PointCloud<pcl::PointXYZ>);
232 for(std::map<int, Transform>::const_iterator
iter=poses.lower_bound(1);
iter!=poses.end(); ++
iter)
234 graph->push_back(pcl::PointXYZ(
iter->second.x(),
iter->second.y(),
iter->second.z()));
236 *graphNodes = *
graph;
240 cloudViewer_->addOrUpdateGraph(
"graph",
graph, Qt::gray);
242 cloudViewer_->setCloudPointSize(
"graph_nodes", 5);
245 odometryCorrection_ =
stats.mapCorrection();
247 cloudViewer_->update();
249 processingStatistics_ =
false;
259 if(this->isVisible())
264 else if(event->
getClassName().compare(
"OdometryEvent") == 0)
268 if(this->isVisible() &&
269 lastOdometryProcessed_ &&
270 !processingStatistics_)
272 lastOdometryProcessed_ =
false;
284 bool processingStatistics_;
285 bool lastOdometryProcessed_;