RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
util3d_mapping.h
1/*
2Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Universite de Sherbrooke nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef UTIL3D_MAPPING_H_
29#define UTIL3D_MAPPING_H_
30
31#include "rtabmap/core/rtabmap_core_export.h"
32
33#include <opencv2/core/core.hpp>
34#include <map>
35#include <rtabmap/core/Transform.h>
36#include <pcl/pcl_base.h>
37#include <pcl/point_cloud.h>
38#include <pcl/point_types.h>
39
40namespace rtabmap
41{
42
43namespace util3d
44{
45
47RTABMAP_DEPRECATED void RTABMAP_CORE_EXPORT occupancy2DFromLaserScan(
48 const cv::Mat & scan, // in /base_link frame
49 cv::Mat & empty,
50 cv::Mat & occupied,
51 float cellSize,
52 bool unknownSpaceFilled = false,
53 float scanMaxRange = 0.0f);
54
56RTABMAP_DEPRECATED void RTABMAP_CORE_EXPORT occupancy2DFromLaserScan(
57 const cv::Mat & scan, // in /base_link frame
58 const cv::Point3f & viewpoint, // /base_link -> /base_scan
59 cv::Mat & empty,
60 cv::Mat & occupied,
61 float cellSize,
62 bool unknownSpaceFilled = false,
63 float scanMaxRange = 0.0f);
64
92void RTABMAP_CORE_EXPORT occupancy2DFromLaserScan(
93 const cv::Mat & scanHit, // in /base_link frame
94 const cv::Mat & scanNoHit, // in /base_link frame
95 const cv::Point3f & viewpoint, // /base_link -> /base_scan
96 cv::Mat & empty,
97 cv::Mat & occupied,
98 float cellSize,
99 bool unknownSpaceFilled = false,
100 float scanMaxRange = 0.0f); // would be set if unknownSpaceFilled=true
101
138cv::Mat RTABMAP_CORE_EXPORT create2DMapFromOccupancyLocalMaps(
139 const std::map<int, Transform> & poses,
140 const std::map<int, std::pair<cv::Mat, cv::Mat> > & occupancy,
141 float cellSize,
142 float & xMin,
143 float & yMin,
144 float minMapSize = 0.0f,
145 bool erode = false,
146 float footprintRadius = 0.0f);
147
149RTABMAP_DEPRECATED cv::Mat RTABMAP_CORE_EXPORT create2DMap(const std::map<int, Transform> & poses,
150 const std::map<int, pcl::PointCloud<pcl::PointXYZ>::Ptr > & scans, // in /base_link frame
151 float cellSize,
152 bool unknownSpaceFilled,
153 float & xMin,
154 float & yMin,
155 float minMapSize = 0.0f,
156 float scanMaxRange = 0.0f);
157
159RTABMAP_DEPRECATED cv::Mat RTABMAP_CORE_EXPORT create2DMap(const std::map<int, Transform> & poses,
160 const std::map<int, pcl::PointCloud<pcl::PointXYZ>::Ptr > & scans, // in /base_link frame
161 const std::map<int, cv::Point3f > & viewpoints, // /base_link -> /base_scan
162 float cellSize,
163 bool unknownSpaceFilled,
164 float & xMin,
165 float & yMin,
166 float minMapSize = 0.0f,
167 float scanMaxRange = 0.0f);
168
204cv::Mat RTABMAP_CORE_EXPORT create2DMap(const std::map<int, Transform> & poses,
205 const std::map<int, std::pair<cv::Mat, cv::Mat> > & scans, // <id, <hit, no hit> >, in /base_link frame
206 const std::map<int, cv::Point3f > & viewpoints, // /base_link -> /base_scan
207 float cellSize,
208 bool unknownSpaceFilled,
209 float & xMin,
210 float & yMin,
211 float minMapSize = 0.0f,
212 float scanMaxRange = 0.0f);
213
235void RTABMAP_CORE_EXPORT rayTrace(const cv::Point2i & start,
236 const cv::Point2i & end,
237 cv::Mat & grid,
238 bool stopOnObstacle);
239
263cv::Mat RTABMAP_CORE_EXPORT convertMap2Image8U(const cv::Mat & map8S, bool pgmFormat = false);
264
293cv::Mat RTABMAP_CORE_EXPORT convertImage8U2Map(const cv::Mat & map8U, bool pgmFormat = false);
294
312cv::Mat RTABMAP_CORE_EXPORT erodeMap(const cv::Mat & map);
313
314// templated methods
315
327template<typename PointT>
328typename pcl::PointCloud<PointT>::Ptr projectCloudOnXYPlane(
329 const typename pcl::PointCloud<PointT> & cloud);
330
331
362template<typename PointT>
363void segmentObstaclesFromGround(
364 const typename pcl::PointCloud<PointT>::Ptr & cloud,
365 const pcl::IndicesPtr & indices,
366 pcl::IndicesPtr & ground,
367 pcl::IndicesPtr & obstacles,
368 int normalKSearch,
369 float groundNormalAngle,
370 float clusterRadius,
371 int minClusterSize,
372 bool segmentFlatObstacles = false,
373 float maxGroundHeight = 0.0f,
374 pcl::IndicesPtr * flatObstacles = 0,
375 const Eigen::Vector4f & viewPoint = Eigen::Vector4f(0,0,100,0),
376 float groundNormalsUp = 0);
381template<typename PointT>
382void segmentObstaclesFromGround(
383 const typename pcl::PointCloud<PointT>::Ptr & cloud,
384 pcl::IndicesPtr & ground,
385 pcl::IndicesPtr & obstacles,
386 int normalKSearch,
387 float groundNormalAngle,
388 float clusterRadius,
389 int minClusterSize,
390 bool segmentFlatObstacles = false,
391 float maxGroundHeight = 0.0f,
392 pcl::IndicesPtr * flatObstacles = 0,
393 const Eigen::Vector4f & viewPoint = Eigen::Vector4f(0,0,100,0),
394 float groundNormalsUp = 0);
395
412template<typename PointT>
414 const typename pcl::PointCloud<PointT>::Ptr & groundCloud,
415 const typename pcl::PointCloud<PointT>::Ptr & obstaclesCloud,
416 cv::Mat & ground,
417 cv::Mat & obstacles,
418 float cellSize);
423template<typename PointT>
425 const typename pcl::PointCloud<PointT>::Ptr & cloud,
426 const pcl::IndicesPtr & groundIndices,
427 const pcl::IndicesPtr & obstaclesIndices,
428 cv::Mat & ground,
429 cv::Mat & obstacles,
430 float cellSize);
431
458template<typename PointT>
460 const typename pcl::PointCloud<PointT>::Ptr & cloud,
461 const pcl::IndicesPtr & indices,
462 cv::Mat & ground,
463 cv::Mat & obstacles,
464 float cellSize = 0.05f,
465 float groundNormalAngle = M_PI_4,
466 int minClusterSize = 20,
467 bool segmentFlatObstacles = false,
468 float maxGroundHeight = 0.0f);
473template<typename PointT>
475 const typename pcl::PointCloud<PointT>::Ptr & cloud,
476 cv::Mat & ground,
477 cv::Mat & obstacles,
478 float cellSize = 0.05f,
479 float groundNormalAngle = M_PI_4,
480 int minClusterSize = 20,
481 bool segmentFlatObstacles = false,
482 float maxGroundHeight = 0.0f);
483
484} // namespace util3d
485} // namespace rtabmap
486
487#include "rtabmap/core/impl/util3d_mapping.hpp"
488
489#endif /* UTIL3D_MAPPING_H_ */
void RTABMAP_CORE_EXPORT rayTrace(const cv::Point2i &start, const cv::Point2i &end, cv::Mat &grid, bool stopOnObstacle)
Performs a 2D ray tracing operation between two points on a grid map.
pcl::PointCloud< PointT >::Ptr projectCloudOnXYPlane(const typename pcl::PointCloud< PointT > &cloud)
Projects a point cloud onto the XY plane by setting all Z coordinates to zero.
RTABMAP_DEPRECATED void RTABMAP_CORE_EXPORT occupancy2DFromLaserScan(const cv::Mat &scan, cv::Mat &empty, cv::Mat &occupied, float cellSize, bool unknownSpaceFilled=false, float scanMaxRange=0.0f)
void occupancy2DFromCloud3D(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, cv::Mat &ground, cv::Mat &obstacles, float cellSize, float groundNormalAngle, int minClusterSize, bool segmentFlatObstacles, float maxGroundHeight)
Generates 2D ground and obstacle occupancy data from a 3D point cloud.
cv::Mat RTABMAP_CORE_EXPORT create2DMapFromOccupancyLocalMaps(const std::map< int, Transform > &poses, const std::map< int, std::pair< cv::Mat, cv::Mat > > &occupancy, float cellSize, float &xMin, float &yMin, float minMapSize=0.0f, bool erode=false, float footprintRadius=0.0f)
Creates a 2D occupancy grid map from local occupancy data.
cv::Mat RTABMAP_CORE_EXPORT erodeMap(const cv::Mat &map)
Performs erosion on an occupancy grid map to reduce small noisy obstacles.
void occupancy2DFromGroundObstacles(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &groundIndices, const pcl::IndicesPtr &obstaclesIndices, cv::Mat &ground, cv::Mat &obstacles, float cellSize)
Projects 3D ground and obstacle point clouds onto the 2D XY plane and voxelizes them into 2D occupanc...
cv::Mat RTABMAP_CORE_EXPORT convertImage8U2Map(const cv::Mat &map8U, bool pgmFormat=false)
Converts a grayscale occupancy image (CV_8U) to an occupancy grid map (CV_8S).
cv::Mat RTABMAP_CORE_EXPORT convertMap2Image8U(const cv::Mat &map8S, bool pgmFormat=false)
Converts an occupancy grid map (CV_8S) to a grayscale image (CV_8U).
RTABMAP_DEPRECATED cv::Mat RTABMAP_CORE_EXPORT create2DMap(const std::map< int, Transform > &poses, const std::map< int, pcl::PointCloud< pcl::PointXYZ >::Ptr > &scans, float cellSize, bool unknownSpaceFilled, float &xMin, float &yMin, float minMapSize=0.0f, float scanMaxRange=0.0f)