28 #ifndef UTIL3D_MAPPING_HPP_ 29 #define UTIL3D_MAPPING_HPP_ 33 #include <pcl/common/common.h> 34 #include <pcl/common/centroid.h> 35 #include <pcl/common/io.h> 40 template<
typename Po
intT>
42 const typename pcl::PointCloud<PointT> & cloud)
44 typename pcl::PointCloud<PointT>::Ptr output(
new pcl::PointCloud<PointT>);
46 for(
unsigned int i=0; i<output->size(); ++i)
53 template<
typename Po
intT>
55 const typename pcl::PointCloud<PointT>::Ptr & cloud,
56 const typename pcl::IndicesPtr & indices,
57 pcl::IndicesPtr & ground,
58 pcl::IndicesPtr & obstacles,
60 float groundNormalAngle,
63 bool segmentFlatObstacles,
64 float maxGroundHeight,
65 pcl::IndicesPtr * flatObstacles,
66 const Eigen::Vector4f & viewPoint)
68 ground.reset(
new std::vector<int>);
69 obstacles.reset(
new std::vector<int>);
72 flatObstacles->reset(
new std::vector<int>);
82 Eigen::Vector4f(0,0,1,0),
86 if(segmentFlatObstacles && flatSurfaces->size())
88 int biggestFlatSurfaceIndex;
95 &biggestFlatSurfaceIndex);
98 if(clusteredFlatSurfaces.size())
100 Eigen::Vector4f biggestSurfaceMin,biggestSurfaceMax;
101 if(maxGroundHeight != 0.0
f)
105 biggestFlatSurfaceIndex = -1;
106 for(
size_t i=0;i<clusteredFlatSurfaces.size();++i)
110 if(min[2]<maxGroundHeight && clusteredFlatSurfaces.size() > points)
112 points = clusteredFlatSurfaces.at(i)->size();
113 biggestFlatSurfaceIndex = i;
114 biggestSurfaceMin =
min;
115 biggestSurfaceMax =
max;
121 pcl::getMinMax3D(*cloud, *clusteredFlatSurfaces.at(biggestFlatSurfaceIndex), biggestSurfaceMin, biggestSurfaceMax);
123 if(biggestFlatSurfaceIndex>=0)
125 ground = clusteredFlatSurfaces.at(biggestFlatSurfaceIndex);
128 if(!ground->empty() && (maxGroundHeight == 0.0f || biggestSurfaceMin[2] < maxGroundHeight))
130 for(
unsigned int i=0; i<clusteredFlatSurfaces.size(); ++i)
132 if((
int)i!=biggestFlatSurfaceIndex)
134 Eigen::Vector4f centroid(0,0,0,1);
135 pcl::compute3DCentroid(*cloud, *clusteredFlatSurfaces.at(i), centroid);
136 if(maxGroundHeight==0.0
f || centroid[2] <= maxGroundHeight || centroid[2] <= biggestSurfaceMax[2])
140 else if(flatObstacles)
150 ground.reset(
new std::vector<int>);
153 *flatObstacles = flatSurfaces;
160 ground = flatSurfaces;
163 if(ground->size() != cloud->size())
166 pcl::IndicesPtr notObstacles = ground;
175 if(maxGroundHeight != 0.0
f)
181 if(otherStuffIndices->size())
196 template<
typename Po
intT>
198 const typename pcl::PointCloud<PointT>::Ptr & cloud,
199 pcl::IndicesPtr & ground,
200 pcl::IndicesPtr & obstacles,
202 float groundNormalAngle,
205 bool segmentFlatObstacles,
206 float maxGroundHeight,
207 pcl::IndicesPtr * flatObstacles,
208 const Eigen::Vector4f & viewPoint)
210 pcl::IndicesPtr indices(
new std::vector<int>);
211 segmentObstaclesFromGround<PointT>(
220 segmentFlatObstacles,
226 template<
typename Po
intT>
228 const typename pcl::PointCloud<PointT>::Ptr & cloud,
229 const pcl::IndicesPtr & groundIndices,
230 const pcl::IndicesPtr & obstaclesIndices,
235 typename pcl::PointCloud<PointT>::Ptr groundCloud(
new pcl::PointCloud<PointT>);
236 typename pcl::PointCloud<PointT>::Ptr obstaclesCloud(
new pcl::PointCloud<PointT>);
238 if(groundIndices->size())
240 pcl::copyPointCloud(*cloud, *groundIndices, *groundCloud);
243 if(obstaclesIndices->size())
245 pcl::copyPointCloud(*cloud, *obstaclesIndices, *obstaclesCloud);
248 occupancy2DFromGroundObstacles<PointT>(
256 template<
typename Po
intT>
258 const typename pcl::PointCloud<PointT>::Ptr & groundCloud,
259 const typename pcl::PointCloud<PointT>::Ptr & obstaclesCloud,
265 if(groundCloud->size())
268 typename pcl::PointCloud<PointT>::Ptr groundCloudProjected;
273 ground = cv::Mat(1, (
int)groundCloudProjected->size(), CV_32FC2);
274 for(
unsigned int i=0;i<groundCloudProjected->size(); ++i)
276 cv::Vec2f * ptr = ground.ptr<cv::Vec2f>();
277 ptr[i][0] = groundCloudProjected->at(i).x;
278 ptr[i][1] = groundCloudProjected->at(i).y;
282 obstacles = cv::Mat();
283 if(obstaclesCloud->size())
286 typename pcl::PointCloud<PointT>::Ptr obstaclesCloudProjected;
289 obstaclesCloudProjected =
util3d::voxelize(obstaclesCloudProjected, cellSize);
291 obstacles = cv::Mat(1, (
int)obstaclesCloudProjected->size(), CV_32FC2);
292 for(
unsigned int i=0;i<obstaclesCloudProjected->size(); ++i)
294 cv::Vec2f * ptr = obstacles.ptr<cv::Vec2f>();
295 ptr[i][0] = obstaclesCloudProjected->at(i).x;
296 ptr[i][1] = obstaclesCloudProjected->at(i).y;
301 template<
typename Po
intT>
303 const typename pcl::PointCloud<PointT>::Ptr & cloud,
304 const pcl::IndicesPtr & indices,
308 float groundNormalAngle,
310 bool segmentFlatObstacles,
311 float maxGroundHeight)
313 if(cloud->size() == 0)
317 pcl::IndicesPtr groundIndices, obstaclesIndices;
319 segmentObstaclesFromGround<PointT>(
328 segmentFlatObstacles,
331 occupancy2DFromGroundObstacles<PointT>(
340 template<
typename Po
intT>
342 const typename pcl::PointCloud<PointT>::Ptr & cloud,
346 float groundNormalAngle,
348 bool segmentFlatObstacles,
349 float maxGroundHeight)
351 pcl::IndicesPtr indices(
new std::vector<int>);
352 occupancy2DFromCloud3D<PointT>(cloud, indices, ground, obstacles, cellSize, groundNormalAngle, minClusterSize, segmentFlatObstacles, maxGroundHeight);
std::vector< pcl::IndicesPtr > RTABMAP_EXP extractClusters(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, float clusterTolerance, int minClusterSize, int maxClusterSize=std::numeric_limits< int >::max(), int *biggestClusterIndex=0)
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
pcl::IndicesPtr RTABMAP_EXP passThrough(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, const std::string &axis, float min, float max, bool negative=false)
void RTABMAP_EXP getMinMax3D(const cv::Mat &laserScan, cv::Point3f &min, cv::Point3f &max)
pcl::IndicesPtr RTABMAP_EXP extractIndices(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, bool negative)
void segmentObstaclesFromGround(const typename pcl::PointCloud< PointT >::Ptr &cloud, const typename pcl::IndicesPtr &indices, pcl::IndicesPtr &ground, pcl::IndicesPtr &obstacles, int normalKSearch, float groundNormalAngle, float clusterRadius, int minClusterSize, bool segmentFlatObstacles, float maxGroundHeight, pcl::IndicesPtr *flatObstacles, const Eigen::Vector4f &viewPoint)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
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)
pcl::IndicesPtr RTABMAP_EXP concatenate(const std::vector< pcl::IndicesPtr > &indices)
Concatenate a vector of indices to a single vector.
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP voxelize(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, float voxelSize)
pcl::PointCloud< PointT >::Ptr projectCloudOnXYPlane(const typename pcl::PointCloud< PointT > &cloud)
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)
pcl::IndicesPtr RTABMAP_EXP normalFiltering(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, float angleMax, const Eigen::Vector4f &normal, int normalKSearch, const Eigen::Vector4f &viewpoint)