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  typename pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>);
48  pcl::IndicesPtr indices(new std::vector<int>);
49 
51  {
52  // voxelize to grid cell size
53  cloud = util3d::voxelize(cloudIn, indicesIn, cellSize_);
54 
55  indices->resize(cloud->size());
56  for(unsigned int i=0; i<indices->size(); ++i)
57  {
58  indices->at(i) = i;
59  }
60  }
61  else
62  {
63  cloud = cloudIn;
64  if(indicesIn->empty() && cloud->is_dense)
65  {
66  indices->resize(cloud->size());
67  for(unsigned int i=0; i<indices->size(); ++i)
68  {
69  indices->at(i) = i;
70  }
71  }
72  else
73  {
74  indices = indicesIn;
75  }
76  }
77 
78  // add pose rotation without yaw
79  float roll, pitch, yaw;
80  pose.getEulerAngles(roll, pitch, yaw);
81  UDEBUG("node.getPose()=%s projMapFrame_=%d", pose.prettyPrint().c_str(), projMapFrame_?1:0);
82  cloud = util3d::transformPointCloud(cloud, Transform(0,0, projMapFrame_?pose.z():0, roll, pitch, 0));
83 
84  // filter footprint
85  if(footprintLength_ > 0.0f || footprintWidth_ > 0.0f || footprintHeight_ > 0.0f)
86  {
87  indices = util3d::cropBox(
88  cloud,
89  indices,
90  Eigen::Vector4f(
93  0,
94  1),
95  Eigen::Vector4f(
99  1),
101  true);
102  }
103 
104  // filter ground/obstacles zone
105  if(minGroundHeight_ != 0.0f || maxObstacleHeight_ != 0.0f)
106  {
107  indices = util3d::passThrough(cloud, indices, "z",
110  UDEBUG("indices after max obstacles height filtering = %d", (int)indices->size());
111  }
112 
113  if(indices->size())
114  {
116  {
117  UDEBUG("normalKSearch=%d", normalKSearch_);
118  UDEBUG("maxGroundAngle=%f", maxGroundAngle_);
119  UDEBUG("Cluster radius=%f", clusterRadius_);
120  UDEBUG("flatObstaclesDetected=%d", flatObstaclesDetected_?1:0);
121  UDEBUG("maxGroundHeight=%f", maxGroundHeight_);
122  util3d::segmentObstaclesFromGround<PointT>(
123  cloud,
124  indices,
125  groundIndices,
126  obstaclesIndices,
133  flatObstacles,
134  Eigen::Vector4f(viewPoint.x, viewPoint.y, viewPoint.z+(projMapFrame_?pose.z():0), 1));
135  UDEBUG("viewPoint=%f,%f,%f", viewPoint.x, viewPoint.y, viewPoint.z+(projMapFrame_?pose.z():0));
136  //UWARN("Saving ground.pcd and obstacles.pcd");
137  //pcl::io::savePCDFile("ground.pcd", *cloud, *groundIndices);
138  //pcl::io::savePCDFile("obstacles.pcd", *cloud, *obstaclesIndices);
139  }
140  else
141  {
142  UDEBUG("");
143  // passthrough filter
144  groundIndices = rtabmap::util3d::passThrough(cloud, indices, "z",
147 
148  pcl::IndicesPtr notObstacles = groundIndices;
149  if(indices->size())
150  {
151  notObstacles = util3d::extractIndices(cloud, indices, true);
152  notObstacles = util3d::concatenate(notObstacles, groundIndices);
153  }
154  obstaclesIndices = rtabmap::util3d::extractIndices(cloud, notObstacles, true);
155  }
156 
157  UDEBUG("groundIndices=%d obstaclesIndices=%d", (int)groundIndices->size(), (int)obstaclesIndices->size());
158 
159  // Do radius filtering after voxel filtering ( a lot faster)
161  {
162  UDEBUG("");
163  if(groundIndices->size())
164  {
166  }
167  if(obstaclesIndices->size())
168  {
169  obstaclesIndices = rtabmap::util3d::radiusFiltering(cloud, obstaclesIndices, noiseFilteringRadius_, noiseFilteringMinNeighbors_);
170  }
171  if(flatObstacles && (*flatObstacles)->size())
172  {
174  }
175 
176  if(groundIndices->empty() && obstaclesIndices->empty())
177  {
178  UWARN("Cloud (with %d points) is empty after noise "
179  "filtering. Occupancy grid cannot be "
180  "created.",
181  (int)cloud->size());
182 
183  }
184  }
185  }
186  return cloud;
187 }
188 
189 }
190 
191 
192 #endif /* CORELIB_INCLUDE_RTABMAP_CORE_IMPL_OCCUPANCYGRID_HPP_ */
GLM_FUNC_DECL T roll(detail::tquat< T, P > const &x)
pcl::IndicesPtr RTABMAP_EXP cropBox(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, const Eigen::Vector4f &min, const Eigen::Vector4f &max, const Transform &transform=Transform::getIdentity(), bool negative=false)
std::string prettyPrint() const
Definition: Transform.cpp:274
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:364
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:211
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)
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:3060
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 Wed Jun 5 2019 22:41:32