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.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);
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.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);
253 cv::Mat groundCells, obstacleCells, emptyCells;
259 if(grid_.addedNodes().size() || grid_.cacheSize())
261 grid_.update(stats.
poses());
263 if(grid_.addedNodes().size())
266 cv::Mat map8S = grid_.getMap(xMin, yMin);
271 cloudViewer_->addOccupancyGridMap(map8U, grid_.getCellSize(), xMin, yMin, 0.75);
277 cloudViewer_->update();
279 processingStatistics_ =
false;
289 if(this->isVisible())
294 else if(event->
getClassName().compare(
"OdometryEvent") == 0)
298 if(this->isVisible() &&
299 lastOdometryProcessed_ &&
300 !processingStatistics_)
302 lastOdometryProcessed_ =
false;
bool processingStatistics_
void uncompressDataConst(cv::Mat *imageRaw, cv::Mat *depthOrRightRaw, LaserScan *laserScanRaw=0, cv::Mat *userDataRaw=0, cv::Mat *groundCellsRaw=0, cv::Mat *obstacleCellsRaw=0, cv::Mat *emptyCellsRaw=0) const
virtual void pauseDetection()
const Statistics & getStats() const
const Signature & getLastSignatureData() const
float gridCellSize() 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
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,...)