31 #include <QVBoxLayout>
32 #include <QtCore/QMetaType>
35 #ifndef Q_MOC_RUN // Mac OS X issue
61 odometryCorrection_(
Transform::getIdentity()),
62 processingStatistics_(
false),
63 lastOdometryProcessed_(
true),
66 this->setWindowFlags(Qt::Dialog);
67 this->setWindowTitle(tr(
"3D Map"));
68 this->setMinimumWidth(800);
69 this->setMinimumHeight(600);
73 QVBoxLayout *layout =
new QVBoxLayout();
74 layout->addWidget(cloudViewer_);
75 this->setLayout(layout);
77 qRegisterMetaType<rtabmap::OdometryEvent>(
"rtabmap::OdometryEvent");
78 qRegisterMetaType<rtabmap::Statistics>(
"rtabmap::Statistics");
80 QAction * pause =
new QAction(
this);
81 this->addAction(pause);
82 pause->setShortcut(Qt::Key_Space);
83 connect(pause, SIGNAL(triggered()),
this, SLOT(pauseDetection()));
88 this->unregisterFromEventsManager();
97 if(camera_->isCapturing())
110 if(!this->isVisible())
119 cloudViewer_->setBackgroundColor(Qt::darkRed);
121 pose = lastOdomPose_;
125 cloudViewer_->setBackgroundColor(cloudViewer_->getDefaultBackgroundColor());
129 lastOdomPose_ = pose;
143 if(!cloudViewer_->addCloud(
"cloudOdom", cloud, odometryCorrection_*pose))
145 UERROR(
"Adding cloudOdom to viewer failed!");
150 cloudViewer_->setCloudVisibility(
"cloudOdom",
false);
151 UWARN(
"Empty cloudOdom!");
158 cloudViewer_->updateCameraTargetPosition(odometryCorrection_*odom.
pose());
161 cloudViewer_->update();
162 cloudViewer_->refreshView();
164 lastOdometryProcessed_ =
true;
170 processingStatistics_ =
true;
175 const std::map<int, Transform> & poses =
stats.poses();
176 QMap<std::string, Transform> clouds = cloudViewer_->getAddedClouds();
177 for(std::map<int, Transform>::const_iterator
iter = poses.lower_bound(1);
iter!=poses.end(); ++
iter)
179 if(!
iter->second.isNull())
181 std::string cloudName =
uFormat(
"cloud%d",
iter->first);
184 if(clouds.contains(cloudName))
188 cloudViewer_->getPose(cloudName, tCloud);
191 if(!cloudViewer_->updateCloudPose(cloudName,
iter->second))
193 UERROR(
"Updating pose cloud %d failed!",
iter->first);
196 cloudViewer_->setCloudVisibility(cloudName,
true);
198 else if(
iter->first ==
stats.getLastSignatureData().id())
201 s.sensorData().uncompressData();
209 if(!cloudViewer_->addCloud(cloudName, cloud,
iter->second))
211 UERROR(
"Adding cloud %d to viewer failed!",
iter->first);
222 UWARN(
"Null pose for %d ?!?",
iter->first);
229 cloudViewer_->removeAllGraphs();
230 cloudViewer_->removeCloud(
"graph_nodes");
234 pcl::PointCloud<pcl::PointXYZ>::Ptr
graph(
new pcl::PointCloud<pcl::PointXYZ>);
235 pcl::PointCloud<pcl::PointXYZ>::Ptr graphNodes(
new pcl::PointCloud<pcl::PointXYZ>);
236 for(std::map<int, Transform>::const_iterator
iter=poses.lower_bound(1);
iter!=poses.end(); ++
iter)
238 graph->push_back(pcl::PointXYZ(
iter->second.x(),
iter->second.y(),
iter->second.z()));
240 *graphNodes = *
graph;
244 cloudViewer_->addOrUpdateGraph(
"graph",
graph, Qt::gray);
246 cloudViewer_->setCloudPointSize(
"graph_nodes", 5);
252 if(grid_.addedNodes().find(
stats.getLastSignatureData().id()) == grid_.addedNodes().end())
254 if(
stats.getLastSignatureData().sensorData().gridCellSize() > 0.0f)
256 cv::Mat groundCells, obstacleCells, emptyCells;
257 stats.getLastSignatureData().sensorData().uncompressDataConst(0, 0, 0, 0, &groundCells, &obstacleCells, &emptyCells);
258 localGrids_.add(
stats.getLastSignatureData().id(), groundCells, obstacleCells, emptyCells,
stats.getLastSignatureData().sensorData().gridCellSize(),
stats.getLastSignatureData().sensorData().gridViewPoint());
262 if(grid_.addedNodes().size() || localGrids_.size())
264 grid_.update(
stats.poses());
266 if(grid_.addedNodes().size())
269 cv::Mat map8S = grid_.getMap(xMin, yMin);
274 cloudViewer_->addOccupancyGridMap(map8U, grid_.getCellSize(), xMin, yMin, 0.75);
278 odometryCorrection_ =
stats.mapCorrection();
280 cloudViewer_->update();
281 cloudViewer_->refreshView();
283 processingStatistics_ =
false;
293 if(this->isVisible())
298 else if(event->
getClassName().compare(
"OdometryEvent") == 0)
302 if(this->isVisible() &&
303 lastOdometryProcessed_ &&
304 !processingStatistics_)
306 lastOdometryProcessed_ =
false;
318 bool processingStatistics_;
319 bool lastOdometryProcessed_;