CloudMap.cpp
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 
29 #include <rtabmap/core/util3d.h>
34 #include <rtabmap/utilite/UStl.h>
35 #include <rtabmap/utilite/UTimer.h>
36 
37 #include <pcl/io/pcd_io.h>
38 
39 namespace rtabmap {
40 
41 CloudMap::CloudMap(const LocalGridCache * cache, const ParametersMap & parameters) :
42  GlobalMap(cache, parameters),
43  assembledGround_(new pcl::PointCloud<pcl::PointXYZRGB>),
44  assembledObstacles_(new pcl::PointCloud<pcl::PointXYZRGB>),
45  assembledEmptyCells_(new pcl::PointCloud<pcl::PointXYZ>)
46 {
47 }
48 
50 {
51  assembledGround_->clear();
52  assembledObstacles_->clear();
53  assembledEmptyCells_->clear();
55 }
56 
57 void CloudMap::assemble(const std::list<std::pair<int, Transform> > & newPoses)
58 {
59  UTimer timer;
60 
61  bool assembledGroundUpdated = false;
62  bool assembledObstaclesUpdated = false;
63  bool assembledEmptyCellsUpdated = false;
64 
65  if(!cache().empty())
66  {
67  UDEBUG("Updating from cache");
68  for(std::list<std::pair<int, Transform> >::const_iterator iter = newPoses.begin(); iter!=newPoses.end(); ++iter)
69  {
70  if(uContains(cache(), iter->first))
71  {
72  const LocalGrid & localGrid = cache().at(iter->first);
73 
74  UDEBUG("Adding grid %d: ground=%d obstacles=%d empty=%d", iter->first, localGrid.groundCells.cols, localGrid.obstacleCells.cols, localGrid.emptyCells.cols);
75 
76  addAssembledNode(iter->first, iter->second);
77 
78  //ground
79  if(localGrid.groundCells.cols)
80  {
81  if(localGrid.groundCells.rows > 1 && localGrid.groundCells.cols == 1)
82  {
83  UFATAL("Occupancy local maps should be 1 row and X cols! (rows=%d cols=%d)", localGrid.groundCells.rows, localGrid.groundCells.cols);
84  }
85 
87  assembledGroundUpdated = true;
88  }
89 
90  //empty
91  if(localGrid.emptyCells.cols)
92  {
93  if(localGrid.emptyCells.rows > 1 && localGrid.emptyCells.cols == 1)
94  {
95  UFATAL("Occupancy local maps should be 1 row and X cols! (rows=%d cols=%d)", localGrid.emptyCells.rows, localGrid.emptyCells.cols);
96  }
97 
99  assembledEmptyCellsUpdated = true;
100  }
101 
102  //obstacles
103  if(localGrid.obstacleCells.cols)
104  {
105  if(localGrid.obstacleCells.rows > 1 && localGrid.obstacleCells.cols == 1)
106  {
107  UFATAL("Occupancy local maps should be 1 row and X cols! (rows=%d cols=%d)", localGrid.obstacleCells.rows, localGrid.obstacleCells.cols);
108  }
109 
111  assembledObstaclesUpdated = true;
112  }
113  }
114  }
115  }
116 
117 
118  if(assembledGroundUpdated && assembledGround_->size() > 1)
119  {
121  }
122  if(assembledObstaclesUpdated && assembledGround_->size() > 1)
123  {
125  }
126  if(assembledEmptyCellsUpdated && assembledEmptyCells_->size() > 1)
127  {
129  }
130 
131  UDEBUG("Occupancy Grid update time = %f s", timer.ticks());
132 }
133 
134 unsigned long CloudMap::getMemoryUsed() const
135 {
136  unsigned long memoryUsage = GlobalMap::getMemoryUsed();
137 
138  if(assembledGround_.get())
139  {
140  memoryUsage += assembledGround_->points.size() * sizeof(pcl::PointXYZRGB);
141  }
142  if(assembledObstacles_.get())
143  {
144  memoryUsage += assembledObstacles_->points.size() * sizeof(pcl::PointXYZRGB);
145  }
146  if(assembledEmptyCells_.get())
147  {
148  memoryUsage += assembledEmptyCells_->points.size() * sizeof(pcl::PointXYZ);
149  }
150  return memoryUsage;
151 }
152 
153 }
pcl
Definition: CameraOpenni.h:47
rtabmap::GlobalMap::clear
virtual void clear()
Definition: GlobalMap.cpp:85
rtabmap::CloudMap::assembledGround_
pcl::PointCloud< pcl::PointXYZRGB >::Ptr assembledGround_
Definition: CloudMap.h:57
rtabmap::LaserScan::backwardCompatibility
static LaserScan backwardCompatibility(const cv::Mat &oldScanFormat, int maxPoints=0, int maxRange=0, const Transform &localTransform=Transform::getIdentity())
Definition: LaserScan.cpp:133
timer
rtabmap::LocalGrid::obstacleCells
cv::Mat obstacleCells
Definition: LocalGrid.h:50
rtabmap::util3d::voxelize
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_CORE_EXPORT voxelize(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, float voxelSize)
Definition: util3d_filtering.cpp:613
rtabmap::GlobalMap::getMemoryUsed
virtual unsigned long getMemoryUsed() const
Definition: GlobalMap.cpp:93
rtabmap::LocalGridCache
Definition: LocalGrid.h:56
rtabmap::LocalGrid::groundCells
cv::Mat groundCells
Definition: LocalGrid.h:49
util3d.h
rtabmap::ParametersMap
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
UTimer.h
rtabmap::CloudMap::assemble
virtual void assemble(const std::list< std::pair< int, Transform > > &newPoses)
Definition: CloudMap.cpp:57
rtabmap::CloudMap::CloudMap
CloudMap(const LocalGridCache *cache, const ParametersMap &parameters=ParametersMap())
Definition: CloudMap.cpp:41
rtabmap::LocalGrid
Definition: LocalGrid.h:38
uContains
bool uContains(const std::list< V > &list, const V &value)
Definition: UStl.h:407
UFATAL
#define UFATAL(...)
CloudMap.h
rtabmap::LocalGrid::emptyCells
cv::Mat emptyCells
Definition: LocalGrid.h:51
rtabmap::GlobalMap
Definition: GlobalMap.h:40
UConversion.h
Some conversion functions.
util3d_filtering.h
rtabmap::util3d::laserScanToPointCloudRGB
pcl::PointCloud< pcl::PointXYZRGB >::Ptr RTABMAP_CORE_EXPORT laserScanToPointCloudRGB(const LaserScan &laserScan, const Transform &transform=Transform(), unsigned char r=100, unsigned char g=100, unsigned char b=100)
Definition: util3d.cpp:2322
rtabmap::GlobalMap::addAssembledNode
void addAssembledNode(int id, const Transform &pose)
Definition: GlobalMap.cpp:160
util3d_mapping.h
rtabmap::CloudMap::assembledObstacles_
pcl::PointCloud< pcl::PointXYZRGB >::Ptr assembledObstacles_
Definition: CloudMap.h:58
ULogger.h
ULogger class and convenient macros.
empty
iter
iterator iter(handle obj)
UStl.h
Wrappers of STL for convenient functions.
UDEBUG
#define UDEBUG(...)
rtabmap::CloudMap::getMemoryUsed
unsigned long getMemoryUsed() const
Definition: CloudMap.cpp:134
UTimer
Definition: UTimer.h:46
rtabmap::GlobalMap::cache
const std::map< int, LocalGrid > & cache() const
Definition: GlobalMap.h:76
rtabmap::GlobalMap::cellSize_
float cellSize_
Definition: GlobalMap.h:83
rtabmap::util3d::laserScanToPointCloud
pcl::PointCloud< pcl::PointXYZ >::Ptr RTABMAP_CORE_EXPORT laserScanToPointCloud(const LaserScan &laserScan, const Transform &transform=Transform())
Definition: util3d.cpp:2269
rtabmap
Definition: CameraARCore.cpp:35
rtabmap::CloudMap::clear
virtual void clear()
Definition: CloudMap.cpp:49
rtabmap::CloudMap::assembledEmptyCells_
pcl::PointCloud< pcl::PointXYZ >::Ptr assembledEmptyCells_
Definition: CloudMap.h:59


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:07