tools/DetectMoreLoopClosures/main.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 
28 #include <rtabmap/core/DBDriver.h>
29 #include <rtabmap/core/Rtabmap.h>
30 #include <rtabmap/core/util3d.h>
34 #include <rtabmap/utilite/UMath.h>
35 #include <rtabmap/utilite/UTimer.h>
36 #include <rtabmap/utilite/UFile.h>
37 #include <rtabmap/utilite/UStl.h>
38 #include <pcl/filters/filter.h>
39 #include <pcl/io/ply_io.h>
40 #include <pcl/io/obj_io.h>
41 #include <pcl/common/common.h>
42 #include <pcl/surface/poisson.h>
43 #include <stdio.h>
44 #include <signal.h>
45 
46 using namespace rtabmap;
47 
48 void showUsage()
49 {
50  printf("\nUsage:\n"
51  "rtabmap-detectMoreLoopClosures [options] database.db\n"
52  "Options:\n"
53  " -r # Cluster radius (default 1 m).\n"
54  " -a # Cluster angle (default 30 deg).\n"
55  " -i # Iterations (default 1).\n"
56  " --intra Add only intra-session loop closures.\n"
57  " --inter Add only inter-session loop closures.\n"
58  "\n%s", Parameters::showUsage());
59  exit(1);
60 }
61 
62 // catch ctrl-c
63 bool g_loopForever = true;
64 void sighandler(int sig)
65 {
66  printf("\nSignal %d caught...\n", sig);
67  g_loopForever = false;
68 }
69 
71 {
72 public:
73  virtual bool callback(const std::string & msg) const
74  {
75  if(!msg.empty())
76  printf("%s \n", msg.c_str());
77  return g_loopForever;
78  }
79 };
80 
81 int main(int argc, char * argv[])
82 {
83  signal(SIGABRT, &sighandler);
84  signal(SIGTERM, &sighandler);
85  signal(SIGINT, &sighandler);
86 
89 
90  if(argc < 2)
91  {
92  showUsage();
93  }
94 
95  float clusterRadius = 1.0f;
96  float clusterAngle = CV_PI/6.0f;
97  int iterations = 1;
98  bool intraSession = false;
99  bool interSession = false;
100  for(int i=1; i<argc-1; ++i)
101  {
102  if(std::strcmp(argv[i], "--help") == 0)
103  {
104  showUsage();
105  }
106  else if(std::strcmp(argv[i], "--intra") == 0)
107  {
108  intraSession = true;
109  if(interSession)
110  {
111  showUsage();
112  }
113  }
114  else if(std::strcmp(argv[i], "--inter") == 0)
115  {
116  interSession = true;
117  if(intraSession)
118  {
119  showUsage();
120  }
121  }
122  else if(std::strcmp(argv[i], "-r") == 0)
123  {
124  ++i;
125  if(i<argc-1)
126  {
127  clusterRadius = uStr2Float(argv[i]);
128  }
129  else
130  {
131  showUsage();
132  }
133  }
134  else if(std::strcmp(argv[i], "-a") == 0)
135  {
136  ++i;
137  if(i<argc-1)
138  {
139  clusterAngle = uStr2Float(argv[i])*CV_PI/180.0f;
140  }
141  else
142  {
143  showUsage();
144  }
145  }
146  else if(std::strcmp(argv[i], "-i") == 0)
147  {
148  ++i;
149  if(i<argc-1)
150  {
151  iterations = uStr2Int(argv[i]);
152  }
153  else
154  {
155  showUsage();
156  }
157  }
158  }
159  ParametersMap inputParams = Parameters::parseArguments(argc, argv);
160 
161  std::string dbPath = argv[argc-1];
162  if(!UFile::exists(dbPath))
163  {
164  printf("Database %s doesn't exist!\n", dbPath.c_str());
165  }
166 
167  printf("\nDatabase: %s\n", dbPath.c_str());
168  printf("Cluster radius = %f m\n", clusterRadius);
169  printf("Cluster angle = %f deg\n", clusterAngle*180.0f/CV_PI);
170  if(intraSession)
171  {
172  printf("Intra-session only\n");
173  }
174  else if(interSession)
175  {
176  printf("Inter-session only\n");
177  }
178 
179  if(!intraSession && !interSession)
180  {
181  intraSession = true;
182  interSession = true;
183  }
184 
185  // Get parameters
186  ParametersMap parameters;
187  DBDriver * driver = DBDriver::create();
188  if(driver->openConnection(dbPath))
189  {
190  parameters = driver->getLastParameters();
191  driver->closeConnection(false);
192  }
193  else
194  {
195  UERROR("Cannot open database %s!", dbPath.c_str());
196  }
197  delete driver;
198 
199  // Get the global optimized map
201  printf("Initialization...\n");
202  uInsert(parameters, inputParams);
203  rtabmap.init(parameters, dbPath);
204 
205  PrintProgressState progress;
206  printf("Detecting...\n");
207  int detected = rtabmap.detectMoreLoopClosures(clusterRadius, clusterAngle, iterations, intraSession, interSession, &progress);
208  if(detected < 0)
209  {
210  if(!g_loopForever)
211  {
212  printf("Detection interrupted. Loop closures found so far (if any) are not saved.\n");
213  }
214  else
215  {
216  printf("Loop closure detection failed!\n");
217  }
218  }
219 
220  rtabmap.close();
221 
222  return 0;
223 }
int UTILITE_EXP uStr2Int(const std::string &str)
f
int detectMoreLoopClosures(float clusterRadius=0.5f, float clusterAngle=M_PI/6.0f, int iterations=1, bool intraSession=true, bool interSession=true, const ProgressState *state=0)
Definition: Rtabmap.cpp:4629
static const char * showUsage()
Definition: Parameters.cpp:548
static ParametersMap parseArguments(int argc, char *argv[], bool onlyParameters=false)
Definition: Parameters.cpp:575
float UTILITE_EXP uStr2Float(const std::string &str)
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
void init(const ParametersMap &parameters, const std::string &databasePath="", bool loadDatabaseParameters=false)
Definition: Rtabmap.cpp:292
Basic mathematics functions.
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
bool openConnection(const std::string &url, bool overwritten=false)
Definition: DBDriver.cpp:86
Wrappers of STL for convenient functions.
void close(bool databaseSaved=true, const std::string &ouputDatabasePath="")
Definition: Rtabmap.cpp:392
virtual bool callback(const std::string &msg) const
void closeConnection(bool save=true, const std::string &outputUrl="")
Definition: DBDriver.cpp:64
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
int main(int argc, char *argv[])
static DBDriver * create(const ParametersMap &parameters=ParametersMap())
Definition: DBDriver.cpp:41
bool exists()
Definition: UFile.h:104
#define UERROR(...)
ParametersMap getLastParameters() const
Definition: DBDriver.cpp:239
void sighandler(int sig)
void uInsert(std::map< K, V > &map, const std::pair< K, V > &pair)
Definition: UStl.h:443


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