31 #include <QVBoxLayout> 32 #include <QtCore/QMetaType> 35 #ifndef Q_MOC_RUN // Mac OS X issue 60 odometryCorrection_(
Transform::getIdentity()),
61 processingStatistics_(
false),
62 lastOdometryProcessed_(
true)
64 this->setWindowFlags(Qt::Dialog);
65 this->setWindowTitle(tr(
"3D Map"));
66 this->setMinimumWidth(800);
67 this->setMinimumHeight(600);
71 QVBoxLayout *layout =
new QVBoxLayout();
72 layout->addWidget(cloudViewer_);
73 this->setLayout(layout);
75 qRegisterMetaType<rtabmap::OdometryEvent>(
"rtabmap::OdometryEvent");
76 qRegisterMetaType<rtabmap::Statistics>(
"rtabmap::Statistics");
78 QAction * pause =
new QAction(
this);
79 this->addAction(pause);
80 pause->setShortcut(Qt::Key_Space);
81 connect(pause, SIGNAL(triggered()),
this, SLOT(pauseDetection()));
86 this->unregisterFromEventsManager();
95 if(camera_->isCapturing())
108 if(!this->isVisible())
117 cloudViewer_->setBackgroundColor(Qt::darkRed);
119 pose = lastOdomPose_;
123 cloudViewer_->setBackgroundColor(cloudViewer_->getDefaultBackgroundColor());
127 lastOdomPose_ = pose;
141 if(!cloudViewer_->addCloud(
"cloudOdom", cloud, odometryCorrection_*pose))
143 UERROR(
"Adding cloudOdom to viewer failed!");
148 cloudViewer_->setCloudVisibility(
"cloudOdom",
false);
149 UWARN(
"Empty cloudOdom!");
156 cloudViewer_->updateCameraTargetPosition(odometryCorrection_*odom.
pose());
159 cloudViewer_->update();
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.begin(); 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);
186 if(tCloud.
isNull() || iter->second != tCloud)
188 if(!cloudViewer_->updateCloudPose(cloudName, iter->second))
190 UERROR(
"Updating pose cloud %d failed!", iter->first);
193 cloudViewer_->setCloudVisibility(cloudName,
true);
206 if(!cloudViewer_->addCloud(cloudName, cloud, iter->second))
208 UERROR(
"Adding cloud %d to viewer failed!", iter->first);
213 UWARN(
"Empty cloud %d!", 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.begin(); 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);
249 for(std::map<int, Transform>::const_reverse_iterator iter = stats.
poses().rbegin(); iter!=stats.
poses().rend(); ++iter)
251 int id = iter->first;
252 if(grid_.addedNodes().find(
id) == grid_.addedNodes().end())
254 std::map<int, Signature>::const_iterator jter = stats.
getSignatures().find(
id);
255 if(jter != stats.
getSignatures().end() && jter->second.sensorData().gridCellSize() > 0.0f)
257 cv::Mat groundCells, obstacleCells, emptyCells;
258 jter->second.sensorData().uncompressDataConst(0, 0, 0, 0, &groundCells, &obstacleCells, &emptyCells);
259 grid_.addToCache(
id, groundCells, obstacleCells, emptyCells);
268 if(grid_.addedNodes().size() || grid_.cacheSize())
270 grid_.update(stats.
poses());
272 if(grid_.addedNodes().size())
275 cv::Mat map8S = grid_.getMap(xMin, yMin);
280 cloudViewer_->addOccupancyGridMap(map8U, grid_.getCellSize(), xMin, yMin, 0.75);
286 cloudViewer_->update();
288 processingStatistics_ =
false;
298 if(this->isVisible())
303 else if(event->
getClassName().compare(
"OdometryEvent") == 0)
307 if(this->isVisible() &&
308 lastOdometryProcessed_ &&
309 !processingStatistics_)
311 lastOdometryProcessed_ =
false;
bool processingStatistics_
virtual void pauseDetection()
const std::map< int, Signature > & getSignatures() const
const Statistics & getStats() const
Some conversion functions.
MapBuilder(CameraThread *camera=0)
const cv::Mat & imageRaw() const
Wrappers of STL for convenient functions.
const Transform & pose() const
bool isValidForProjection() const
bool lastOdometryProcessed_
virtual std::string getClassName() const =0
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 >())
virtual void processOdometry(const rtabmap::OdometryEvent &odom)
const cv::Mat & depthOrRightRaw() const
bool uContains(const std::list< V > &list, const V &value)
const std::map< int, Transform > & poses() const
cv::Mat RTABMAP_EXP convertMap2Image8U(const cv::Mat &map8S, bool pgmFormat=false)
const std::vector< CameraModel > & cameraModels() const
SensorData & sensorData()
ULogger class and convenient macros.
const StereoCameraModel & stereoCameraModel() const
virtual void processStatistics(const rtabmap::Statistics &stats)
virtual bool handleEvent(UEvent *event)
const Transform & mapCorrection() const
std::string UTILITE_EXP uFormat(const char *fmt,...)