OccupancyGrid.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, 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 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON 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
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef CORELIB_INCLUDE_RTABMAP_CORE_IMPL_OCCUPANCYGRID_HPP_
29 #define CORELIB_INCLUDE_RTABMAP_CORE_IMPL_OCCUPANCYGRID_HPP_
30 
34 
35 namespace rtabmap {
36 
37 template<typename PointT>
38 typename pcl::PointCloud<PointT>::Ptr OccupancyGrid::segmentCloud(
39  const typename pcl::PointCloud<PointT>::Ptr & cloudIn,
40  const pcl::IndicesPtr & indicesIn,
41  const Transform & pose,
42  const cv::Point3f & viewPoint,
43  pcl::IndicesPtr & groundIndices,
44  pcl::IndicesPtr & obstaclesIndices,
45  pcl::IndicesPtr * flatObstacles) const
46 {
47  groundIndices.reset(new std::vector<int>);
48  obstaclesIndices.reset(new std::vector<int>);
49  if(flatObstacles)
50  {
51  flatObstacles->reset(new std::vector<int>);
52  }
53 
54  typename pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>);
55  pcl::IndicesPtr indices(new std::vector<int>);
56 
58  {
59  // voxelize to grid cell size
60  cloud = util3d::voxelize(cloudIn, indicesIn, cellSize_);
61 
62  indices->resize(cloud->size());
63  for(unsigned int i=0; i<indices->size(); ++i)
64  {
65  indices->at(i) = i;
66  }
67  }
68  else
69  {
70  cloud = cloudIn;
71  if(indicesIn->empty() && cloud->is_dense)
72  {
73  indices->resize(cloud->size());
74  for(unsigned int i=0; i<indices->size(); ++i)
75  {
76  indices->at(i) = i;
77  }
78  }
79  else
80  {
81  indices = indicesIn;
82  }
83  }
84 
85  // add pose rotation without yaw
86  float roll, pitch, yaw;
87  pose.getEulerAngles(roll, pitch, yaw);
88  UDEBUG("node.getPose()=%s projMapFrame_=%d", pose.prettyPrint().c_str(), projMapFrame_?1:0);
89  cloud = util3d::transformPointCloud(cloud, Transform(0,0, projMapFrame_?pose.z():0, roll, pitch, 0));
90 
91  // filter footprint
92  if(footprintLength_ > 0.0f || footprintWidth_ > 0.0f || footprintHeight_ > 0.0f)
93  {
94  indices = util3d::cropBox(
95  cloud,
96  indices,
97  Eigen::Vector4f(
100  0,
101  1),
102  Eigen::Vector4f(
106  1),
108  true);
109  }
110 
111  // filter ground/obstacles zone
112  if(minGroundHeight_ != 0.0f || maxObstacleHeight_ != 0.0f)
113  {
114  indices = util3d::passThrough(cloud, indices, "z",
117  UDEBUG("indices after max obstacles height filtering = %d", (int)indices->size());
118  }
119 
120  if(indices->size())
121  {
123  {
124  UDEBUG("normalKSearch=%d", normalKSearch_);
125  UDEBUG("maxGroundAngle=%f", maxGroundAngle_);
126  UDEBUG("Cluster radius=%f", clusterRadius_);
127  UDEBUG("flatObstaclesDetected=%d", flatObstaclesDetected_?1:0);
128  UDEBUG("maxGroundHeight=%f", maxGroundHeight_);
129  util3d::segmentObstaclesFromGround<PointT>(
130  cloud,
131  indices,
132  groundIndices,
133  obstaclesIndices,
140  flatObstacles,
141  Eigen::Vector4f(viewPoint.x, viewPoint.y, viewPoint.z+(projMapFrame_?pose.z():0), 1));
142  UDEBUG("viewPoint=%f,%f,%f", viewPoint.x, viewPoint.y, viewPoint.z+(projMapFrame_?pose.z():0));
143  //UWARN("Saving ground.pcd and obstacles.pcd");
144  //pcl::io::savePCDFile("ground.pcd", *cloud, *groundIndices);
145  //pcl::io::savePCDFile("obstacles.pcd", *cloud, *obstaclesIndices);
146  }
147  else
148  {
149  UDEBUG("");
150  // passthrough filter
151  groundIndices = rtabmap::util3d::passThrough(cloud, indices, "z",
154 
155  pcl::IndicesPtr notObstacles = groundIndices;
156  if(indices->size())
157  {
158  notObstacles = util3d::extractIndices(cloud, indices, true);
159  notObstacles = util3d::concatenate(notObstacles, groundIndices);
160  }
161  obstaclesIndices = rtabmap::util3d::extractIndices(cloud, notObstacles, true);
162  }
163 
164  UDEBUG("groundIndices=%d obstaclesIndices=%d", (int)groundIndices->size(), (int)obstaclesIndices->size());
165 
166  // Do radius filtering after voxel filtering ( a lot faster)
168  {
169  UDEBUG("");
170  if(groundIndices->size())
171  {
173  }
174  if(obstaclesIndices->size())
175  {
176  obstaclesIndices = rtabmap::util3d::radiusFiltering(cloud, obstaclesIndices, noiseFilteringRadius_, noiseFilteringMinNeighbors_);
177  }
178  if(flatObstacles && (*flatObstacles)->size())
179  {
181  }
182 
183  if(groundIndices->empty() && obstaclesIndices->empty())
184  {
185  UWARN("Cloud (with %d points) is empty after noise "
186  "filtering. Occupancy grid cannot be "
187  "created.",
188  (int)cloud->size());
189 
190  }
191  }
192  }
193  return cloud;
194 }
195 
196 }
197 
198 
199 #endif /* CORELIB_INCLUDE_RTABMAP_CORE_IMPL_OCCUPANCYGRID_HPP_ */
GLM_FUNC_DECL T roll(detail::tquat< T, P > const &x)
std::string prettyPrint() const
Definition: Transform.cpp:295
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP transformPointCloud(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const Transform &transform)
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)
f
static Transform getIdentity()
Definition: Transform.cpp:380
GLM_FUNC_DECL T pitch(detail::tquat< T, P > const &x)
pcl::IndicesPtr RTABMAP_EXP extractIndices(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, bool negative)
void getEulerAngles(float &roll, float &pitch, float &yaw) const
Definition: Transform.cpp:232
pcl::PointCloud< PointT >::Ptr segmentCloud(const typename pcl::PointCloud< PointT >::Ptr &cloud, const pcl::IndicesPtr &indices, const Transform &pose, const cv::Point3f &viewPoint, pcl::IndicesPtr &groundIndices, pcl::IndicesPtr &obstaclesIndices, pcl::IndicesPtr *flatObstacles=0) const
pcl::IndicesPtr RTABMAP_EXP radiusFiltering(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, float radiusSearch, int minNeighborsInRadius)
#define UDEBUG(...)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
pcl::IndicesPtr RTABMAP_EXP cropBox(const pcl::PCLPointCloud2::Ptr &cloud, const pcl::IndicesPtr &indices, const Eigen::Vector4f &min, const Eigen::Vector4f &max, const Transform &transform=Transform::getIdentity(), bool negative=false)
ULogger class and convenient macros.
#define UWARN(...)
GLM_FUNC_DECL T yaw(detail::tquat< T, P > const &x)
pcl::IndicesPtr RTABMAP_EXP concatenate(const std::vector< pcl::IndicesPtr > &indices)
Concatenate a vector of indices to a single vector.
Definition: util3d.cpp:3133
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_EXP voxelize(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, float voxelSize)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:59