Optimizer.h
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 OPTIMIZER_H_
29 #define OPTIMIZER_H_
30 
31 #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
32 
33 #include <map>
34 #include <list>
35 #include <rtabmap/core/Link.h>
37 #include <rtabmap/core/Signature.h>
38 
39 namespace rtabmap {
40 
42 // Graph optimizers
45 {
46 public:
47  enum Type {
48  kTypeUndef = -1,
49  kTypeTORO = 0,
50  kTypeG2O = 1,
51  kTypeGTSAM = 2,
52  kTypeCVSBA = 3
53  };
54  static bool isAvailable(Optimizer::Type type);
55  static Optimizer * create(const ParametersMap & parameters);
56  static Optimizer * create(Optimizer::Type type, const ParametersMap & parameters = ParametersMap());
57 
58  // Get connected poses and constraints from a set of links
59  static void getConnectedGraph(
60  int fromId,
61  const std::map<int, Transform> & posesIn,
62  const std::multimap<int, Link> & linksIn, // only one link between two poses
63  std::map<int, Transform> & posesOut,
64  std::multimap<int, Link> & linksOut,
65  int depth = 0);
66 
67 public:
68  virtual ~Optimizer() {}
69 
70  virtual Type type() const = 0;
71 
72  // getters
73  int iterations() const {return iterations_;}
74  bool isSlam2d() const {return slam2d_;}
75  bool isCovarianceIgnored() const {return covarianceIgnored_;}
76  double epsilon() const {return epsilon_;}
77  bool isRobust() const {return robust_;}
78  bool priorsIgnored() const {return priorsIgnored_;}
79 
80  // setters
81  void setIterations(int iterations) {iterations_ = iterations;}
82  void setSlam2d(bool enabled) {slam2d_ = enabled;}
83  void setCovarianceIgnored(bool enabled) {covarianceIgnored_ = enabled;}
84  void setEpsilon(double epsilon) {epsilon_ = epsilon;}
85  void setRobust(bool enabled) {robust_ = enabled;}
86  void setPriorsIgnored(bool enabled) {priorsIgnored_ = enabled;}
87 
88  virtual void parseParameters(const ParametersMap & parameters);
89 
90  std::map<int, Transform> optimizeIncremental(
91  int rootId,
92  const std::map<int, Transform> & poses,
93  const std::multimap<int, Link> & constraints,
94  std::list<std::map<int, Transform> > * intermediateGraphes = 0,
95  double * finalError = 0,
96  int * iterationsDone = 0);
97 
98  std::map<int, Transform> optimize(
99  int rootId,
100  const std::map<int, Transform> & poses,
101  const std::multimap<int, Link> & constraints,
102  std::list<std::map<int, Transform> > * intermediateGraphes = 0,
103  double * finalError = 0,
104  int * iterationsDone = 0);
105 
106  // inherited classes should implement one of these methods
107  virtual std::map<int, Transform> optimize(
108  int rootId,
109  const std::map<int, Transform> & poses,
110  const std::multimap<int, Link> & constraints,
111  cv::Mat & outputCovariance,
112  std::list<std::map<int, Transform> > * intermediateGraphes = 0,
113  double * finalError = 0,
114  int * iterationsDone = 0);
115  virtual std::map<int, Transform> optimizeBA(
116  int rootId, // if negative, all other poses are fixed
117  const std::map<int, Transform> & poses,
118  const std::multimap<int, Link> & links,
119  const std::map<int, CameraModel> & models, // in case of stereo, Tx should be set
120  std::map<int, cv::Point3f> & points3DMap,
121  const std::map<int, std::map<int, cv::Point3f> > & wordReferences, // <ID words, IDs frames + keypoint(x,y,depth)>
122  std::set<int> * outliers = 0);
123 
124  std::map<int, Transform> optimizeBA(
125  int rootId,
126  const std::map<int, Transform> & poses,
127  const std::multimap<int, Link> & links,
128  const std::map<int, Signature> & signatures);
129 
130  Transform optimizeBA(
131  const Link & link,
132  const CameraModel & model,
133  std::map<int, cv::Point3f> & points3DMap,
134  const std::map<int, std::map<int, cv::Point3f> > & wordReferences,
135  std::set<int> * outliers = 0);
136 
137  void computeBACorrespondences(
138  const std::map<int, Transform> & poses,
139  const std::multimap<int, Link> & links,
140  const std::map<int, Signature> & signatures,
141  std::map<int, cv::Point3f> & points3DMap,
142  std::map<int, std::map<int, cv::Point3f> > & wordReferences); // <ID words, IDs frames + keypoint/depth>
143 
144 protected:
145  Optimizer(
146  int iterations = Parameters::defaultOptimizerIterations(),
147  bool slam2d = Parameters::defaultRegForce3DoF(),
148  bool covarianceIgnored = Parameters::defaultOptimizerVarianceIgnored(),
149  double epsilon = Parameters::defaultOptimizerEpsilon(),
150  bool robust = Parameters::defaultOptimizerRobust(),
151  bool priorsIgnored = Parameters::defaultOptimizerPriorsIgnored());
152  Optimizer(const ParametersMap & parameters);
153 
154 private:
156  bool slam2d_;
158  double epsilon_;
159  bool robust_;
161 };
162 
163 } /* namespace rtabmap */
164 #endif /* OPTIMIZER_H_ */
bool priorsIgnored() const
Definition: Optimizer.h:78
double epsilon
void setIterations(int iterations)
Definition: Optimizer.h:81
bool isSlam2d() const
Definition: Optimizer.h:74
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:41
bool isCovarianceIgnored() const
Definition: Optimizer.h:75
#define RTABMAP_EXP
Definition: RtabmapExp.h:38
void setSlam2d(bool enabled)
Definition: Optimizer.h:82
void setPriorsIgnored(bool enabled)
Definition: Optimizer.h:86
double epsilon() const
Definition: Optimizer.h:76
int iterations() const
Definition: Optimizer.h:73
bool isRobust() const
Definition: Optimizer.h:77
void setRobust(bool enabled)
Definition: Optimizer.h:85
void setCovarianceIgnored(bool enabled)
Definition: Optimizer.h:83
virtual ~Optimizer()
Definition: Optimizer.h:68
void setEpsilon(double epsilon)
Definition: Optimizer.h:84


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:32