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 ground = clusteredFlatSurfaces.at(biggestFlatSurfaceIndex);
104 if(maxGroundHeight == 0.0
f || min[2] < maxGroundHeight)
106 for(
unsigned int i=0; i<clusteredFlatSurfaces.size(); ++i)
108 if((
int)i!=biggestFlatSurfaceIndex)
110 Eigen::Vector4f centroid(0,0,0,1);
111 pcl::compute3DCentroid(*cloud, *clusteredFlatSurfaces.at(i), centroid);
112 if(maxGroundHeight==0.0
f || centroid[2] <= maxGroundHeight || centroid[2] <= max[2])
116 else if(flatObstacles)
126 ground.reset(
new std::vector<int>);
129 *flatObstacles = flatSurfaces;
136 ground = flatSurfaces;
139 if(ground->size() != cloud->size())
142 pcl::IndicesPtr notObstacles = ground;
151 if(maxGroundHeight != 0.0
f)
157 if(otherStuffIndices->size())
172 template<
typename Po
intT>
174 const typename pcl::PointCloud<PointT>::Ptr & cloud,
175 pcl::IndicesPtr & ground,
176 pcl::IndicesPtr & obstacles,
178 float groundNormalAngle,
181 bool segmentFlatObstacles,
182 float maxGroundHeight,
183 pcl::IndicesPtr * flatObstacles,
184 const Eigen::Vector4f & viewPoint)
186 pcl::IndicesPtr indices(
new std::vector<int>);
187 segmentObstaclesFromGround<PointT>(
196 segmentFlatObstacles,
202 template<
typename Po
intT>
204 const typename pcl::PointCloud<PointT>::Ptr & cloud,
205 const pcl::IndicesPtr & groundIndices,
206 const pcl::IndicesPtr & obstaclesIndices,
211 typename pcl::PointCloud<PointT>::Ptr groundCloud(
new pcl::PointCloud<PointT>);
212 typename pcl::PointCloud<PointT>::Ptr obstaclesCloud(
new pcl::PointCloud<PointT>);
214 if(groundIndices->size())
216 pcl::copyPointCloud(*cloud, *groundIndices, *groundCloud);
219 if(obstaclesIndices->size())
221 pcl::copyPointCloud(*cloud, *obstaclesIndices, *obstaclesCloud);
224 occupancy2DFromGroundObstacles<PointT>(
232 template<
typename Po
intT>
234 const typename pcl::PointCloud<PointT>::Ptr & groundCloud,
235 const typename pcl::PointCloud<PointT>::Ptr & obstaclesCloud,
241 if(groundCloud->size())
244 typename pcl::PointCloud<PointT>::Ptr groundCloudProjected;
249 ground = cv::Mat(1, (
int)groundCloudProjected->size(), CV_32FC2);
250 for(
unsigned int i=0;i<groundCloudProjected->size(); ++i)
252 cv::Vec2f * ptr = ground.ptr<cv::Vec2f>();
253 ptr[i][0] = groundCloudProjected->at(i).x;
254 ptr[i][1] = groundCloudProjected->at(i).y;
258 obstacles = cv::Mat();
259 if(obstaclesCloud->size())
262 typename pcl::PointCloud<PointT>::Ptr obstaclesCloudProjected;
265 obstaclesCloudProjected =
util3d::voxelize(obstaclesCloudProjected, cellSize);
267 obstacles = cv::Mat(1, (
int)obstaclesCloudProjected->size(), CV_32FC2);
268 for(
unsigned int i=0;i<obstaclesCloudProjected->size(); ++i)
270 cv::Vec2f * ptr = obstacles.ptr<cv::Vec2f>();
271 ptr[i][0] = obstaclesCloudProjected->at(i).x;
272 ptr[i][1] = obstaclesCloudProjected->at(i).y;
277 template<
typename Po
intT>
279 const typename pcl::PointCloud<PointT>::Ptr & cloud,
280 const pcl::IndicesPtr & indices,
284 float groundNormalAngle,
286 bool segmentFlatObstacles,
287 float maxGroundHeight)
289 if(cloud->size() == 0)
293 pcl::IndicesPtr groundIndices, obstaclesIndices;
295 segmentObstaclesFromGround<PointT>(
304 segmentFlatObstacles,
307 occupancy2DFromGroundObstacles<PointT>(
316 template<
typename Po
intT>
318 const typename pcl::PointCloud<PointT>::Ptr & cloud,
322 float groundNormalAngle,
324 bool segmentFlatObstacles,
325 float maxGroundHeight)
327 pcl::IndicesPtr indices(
new std::vector<int>);
328 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)