tools/CleanupLocalGrids/main.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2021, 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 #include <rtabmap/core/Rtabmap.h>
29 #include <rtabmap/core/Memory.h>
30 #include <rtabmap/utilite/UFile.h>
31 #include <rtabmap/utilite/UTimer.h>
33 
34 using namespace rtabmap;
35 
36 void showUsage()
37 {
38  printf("\n"
39  "Clear empty space from local occupancy grids and laser scans based on the saved optimized global 2d grid map.\n"
40  "Advantages:\n"
41  " * If the map needs to be regenerated in the future (e.g., when \n"
42  " we re-use the map in SLAM mode), removed obstacles won't reappear.\n"
43  " * [--scan] The cropped laser scans will be also used for localization,\n"
44  " so if dynamic obstacles have been removed, localization won't try to\n"
45  " match them anymore.\n\n"
46  "Disadvantage:\n"
47  " * [--scan] Cropping the laser scans cannot be reverted, but grids can.\n"
48  "\nUsage:\n"
49  "rtabmap-cleanupLocalGrids [options] database.db\n"
50  "Options:\n"
51  " --radius # Radius in cells around empty cell without obstacles to clear\n"
52  " underlying obstacles. Default is 1.\n"
53  " --scan Filter also scans, otherwise only local grids are filtered.\n"
54  "\n");
55  ;
56  exit(1);
57 }
58 
59 int main(int argc, char * argv[])
60 {
63 
64  if(argc < 2)
65  {
66  showUsage();
67  }
68 
69  int cropRadius = 1;
70  bool filterScans = false;
71 
72  for(int i=1; i<argc; ++i)
73  {
74  if(std::strcmp(argv[i], "--help") == 0)
75  {
76  showUsage();
77  }
78  else if(std::strcmp(argv[i], "--scan") == 0)
79  {
80  filterScans = true;
81  }
82  else if(std::strcmp(argv[i], "--radius") == 0)
83  {
84  ++i;
85  if(i<argc-1)
86  {
87  cropRadius = uStr2Int(argv[i]);
88  UASSERT(cropRadius>=0);
89  }
90  else
91  {
92  showUsage();
93  }
94  }
95  }
96 
97  std::string dbPath = argv[argc-1];
98 
99  if(!UFile::exists(dbPath))
100  {
101  UERROR("File \"%s\" doesn't exist!", dbPath.c_str());
102  return -1;
103  }
104 
105  // Get parameters
106  ParametersMap parameters;
108  rtabmap.init(ParametersMap(), dbPath, true);
109 
110  float xMin, yMin, cellSize;
111  cv::Mat map = rtabmap.getMemory()->load2DMap(xMin, yMin, cellSize);
112  if(map.empty())
113  {
114  UERROR("Database %s doesn't have optimized 2d map saved in it!", dbPath.c_str());
115  return -1;
116  }
117 
118  printf("Options:\n");
119  printf(" --radius: %d cell(s) (cell size=%.3fm)\n", cropRadius, cellSize);
120  printf(" --scan: %s\n", filterScans?"true":"false");
121 
122  std::map<int, Transform> poses = rtabmap.getLocalOptimizedPoses();
123  if(poses.empty() || poses.lower_bound(1) == poses.end())
124  {
125  UERROR("Database %s doesn't have optimized poses saved in it!", dbPath.c_str());
126  return -1;
127  }
128 
129  UTimer timer;
130  printf("Cleaning grids...\n");
131  int modifiedCells = rtabmap.cleanupLocalGrids(poses, map, xMin, yMin, cellSize, cropRadius, filterScans);
132  printf("Cleanup %d cells! (%fs)\n", modifiedCells, timer.ticks());
133 
134  rtabmap.close();
135 
136  printf("Done!\n");
137  return 0;
138 }
timer
ULogger::kTypeConsole
@ kTypeConsole
Definition: ULogger.h:244
ULogger::setLevel
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
rtabmap::ParametersMap
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
showUsage
void showUsage()
Definition: tools/CleanupLocalGrids/main.cpp:36
UTimer.h
util3d_transforms.h
Rtabmap.h
ULogger::kInfo
@ kInfo
Definition: ULogger.h:252
UASSERT
#define UASSERT(condition)
rtabmap_netvlad.argv
argv
Definition: rtabmap_netvlad.py:15
ULogger::setType
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
Memory.h
uStr2Int
int UTILITE_EXPORT uStr2Int(const std::string &str)
Definition: UConversion.cpp:125
main
int main(int argc, char *argv[])
Definition: tools/CleanupLocalGrids/main.cpp:59
UTimer
Definition: UTimer.h:46
rtabmap::Rtabmap
Definition: Rtabmap.h:54
UFile.h
rtabmap
Definition: CameraARCore.cpp:35
UFile::exists
bool exists()
Definition: UFile.h:104
UERROR
#define UERROR(...)
i
int i


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