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 
41 class FeatureBA
42 {
43 public:
44  FeatureBA(const cv::KeyPoint & kptIn, const float & depthIn = 0.0f, const cv::Mat & descriptorIn = cv::Mat(), int cameraIndexIn = 0):
45  kpt(kptIn),
46  depth(depthIn),
47  descriptor(descriptorIn),
48  cameraIndex(cameraIndexIn)
49  {
50  //UDEBUG("kpt=(%f,%f) depth=%f, camIndex=%d", kpt.pt.x, kpt.pt.y, depth, cameraIndex);
51  }
52  cv::KeyPoint kpt;
53  float depth;
54  cv::Mat descriptor;
56 };
57 
59 // Graph optimizers
62 {
63 public:
64  enum Type {
65  kTypeUndef = -1,
66  kTypeTORO = 0,
67  kTypeG2O = 1,
68  kTypeGTSAM = 2,
69  kTypeCeres = 3,
70  kTypeCVSBA = 4
71  };
72  static bool isAvailable(Optimizer::Type type);
73  static Optimizer * create(const ParametersMap & parameters);
74  static Optimizer * create(Optimizer::Type type, const ParametersMap & parameters = ParametersMap());
75 
76  // Get connected poses and constraints from a set of links
77  void getConnectedGraph(
78  int fromId,
79  const std::map<int, Transform> & posesIn,
80  const std::multimap<int, Link> & linksIn,
81  std::map<int, Transform> & posesOut,
82  std::multimap<int, Link> & linksOut,
83  bool adjustPosesWithConstraints = true) const;
84 
85 public:
86  virtual ~Optimizer() {}
87 
88  virtual Type type() const = 0;
89 
90  // getters
91  int iterations() const {return iterations_;}
92  bool isSlam2d() const {return slam2d_;}
93  bool isCovarianceIgnored() const {return covarianceIgnored_;}
94  double epsilon() const {return epsilon_;}
95  bool isRobust() const {return robust_;}
96  bool priorsIgnored() const {return priorsIgnored_;}
97  bool landmarksIgnored() const {return landmarksIgnored_;}
98  float gravitySigma() const {return gravitySigma_;}
99 
100  // setters
101  void setIterations(int iterations) {iterations_ = iterations;}
102  void setSlam2d(bool enabled) {slam2d_ = enabled;}
103  void setCovarianceIgnored(bool enabled) {covarianceIgnored_ = enabled;}
104  void setEpsilon(double epsilon) {epsilon_ = epsilon;}
105  void setRobust(bool enabled) {robust_ = enabled;}
106  void setPriorsIgnored(bool enabled) {priorsIgnored_ = enabled;}
107  void setLandmarksIgnored(bool enabled) {landmarksIgnored_ = enabled;}
108  void setGravitySigma(float value) {gravitySigma_ = value;}
109 
110  virtual void parseParameters(const ParametersMap & parameters);
111 
112  std::map<int, Transform> optimizeIncremental(
113  int rootId,
114  const std::map<int, Transform> & poses,
115  const std::multimap<int, Link> & constraints,
116  std::list<std::map<int, Transform> > * intermediateGraphes = 0,
117  double * finalError = 0,
118  int * iterationsDone = 0);
119 
120  std::map<int, Transform> optimize(
121  int rootId,
122  const std::map<int, Transform> & poses,
123  const std::multimap<int, Link> & constraints,
124  std::list<std::map<int, Transform> > * intermediateGraphes = 0,
125  double * finalError = 0,
126  int * iterationsDone = 0);
127 
128  // inherited classes should implement one of these methods
129  virtual std::map<int, Transform> optimize(
130  int rootId,
131  const std::map<int, Transform> & poses,
132  const std::multimap<int, Link> & constraints,
133  cv::Mat & outputCovariance,
134  std::list<std::map<int, Transform> > * intermediateGraphes = 0,
135  double * finalError = 0,
136  int * iterationsDone = 0);
137  virtual std::map<int, Transform> optimizeBA(
138  int rootId, // if negative, all other poses are fixed
139  const std::map<int, Transform> & poses,
140  const std::multimap<int, Link> & links,
141  const std::map<int, std::vector<CameraModel> > & models, // in case of stereo, Tx should be set
142  std::map<int, cv::Point3f> & points3DMap,
143  const std::map<int, std::map<int, FeatureBA> > & wordReferences, // <ID words, IDs frames + keypoint/depth/descriptor>
144  std::set<int> * outliers = 0);
145 
146  std::map<int, Transform> optimizeBA(
147  int rootId,
148  const std::map<int, Transform> & poses,
149  const std::multimap<int, Link> & links,
150  const std::map<int, Signature> & signatures,
151  std::map<int, cv::Point3f> & points3DMap,
152  std::map<int, std::map<int, FeatureBA> > & wordReferences, // <ID words, IDs frames + keypoint/depth/descriptor>
153  bool rematchFeatures = false);
154 
155  std::map<int, Transform> optimizeBA(
156  int rootId,
157  const std::map<int, Transform> & poses,
158  const std::multimap<int, Link> & links,
159  const std::map<int, Signature> & signatures,
160  bool rematchFeatures = false);
161 
162  Transform optimizeBA(
163  const Link & link,
164  const CameraModel & model,
165  std::map<int, cv::Point3f> & points3DMap,
166  const std::map<int, std::map<int, FeatureBA> > & wordReferences,
167  std::set<int> * outliers = 0);
168 
169  void computeBACorrespondences(
170  const std::map<int, Transform> & poses,
171  const std::multimap<int, Link> & links,
172  const std::map<int, Signature> & signatures,
173  std::map<int, cv::Point3f> & points3DMap,
174  std::map<int, std::map<int, FeatureBA > > & wordReferences, // <ID words, IDs frames + keypoint/depth/descriptor>
175  bool rematchFeatures = false);
176 
177 protected:
178  Optimizer(
179  int iterations = Parameters::defaultOptimizerIterations(),
180  bool slam2d = Parameters::defaultRegForce3DoF(),
181  bool covarianceIgnored = Parameters::defaultOptimizerVarianceIgnored(),
182  double epsilon = Parameters::defaultOptimizerEpsilon(),
183  bool robust = Parameters::defaultOptimizerRobust(),
184  bool priorsIgnored = Parameters::defaultOptimizerPriorsIgnored(),
185  bool landmarksIgnored = Parameters::defaultOptimizerLandmarksIgnored(),
186  float gravitySigma = Parameters::defaultOptimizerGravitySigma());
187  Optimizer(const ParametersMap & parameters);
188 
189 private:
191  bool slam2d_;
193  double epsilon_;
194  bool robust_;
198 };
199 
200 } /* namespace rtabmap */
201 #endif /* OPTIMIZER_H_ */
double epsilon
FeatureBA(const cv::KeyPoint &kptIn, const float &depthIn=0.0f, const cv::Mat &descriptorIn=cv::Mat(), int cameraIndexIn=0)
Definition: Optimizer.h:44
void setIterations(int iterations)
Definition: Optimizer.h:101
bool isSlam2d() const
Definition: Optimizer.h:92
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
double epsilon() const
Definition: Optimizer.h:94
float gravitySigma() const
Definition: Optimizer.h:98
cv::KeyPoint kpt
Definition: Optimizer.h:52
#define RTABMAP_EXP
Definition: RtabmapExp.h:38
void setSlam2d(bool enabled)
Definition: Optimizer.h:102
void setPriorsIgnored(bool enabled)
Definition: Optimizer.h:106
bool landmarksIgnored() const
Definition: Optimizer.h:97
cv::Mat descriptor
Definition: Optimizer.h:54
void setLandmarksIgnored(bool enabled)
Definition: Optimizer.h:107
int iterations() const
Definition: Optimizer.h:91
void setGravitySigma(float value)
Definition: Optimizer.h:108
bool isRobust() const
Definition: Optimizer.h:95
void setRobust(bool enabled)
Definition: Optimizer.h:105
void setCovarianceIgnored(bool enabled)
Definition: Optimizer.h:103
virtual ~Optimizer()
Definition: Optimizer.h:86
model
Definition: trace.py:4
bool isCovarianceIgnored() const
Definition: Optimizer.h:93
bool priorsIgnored() const
Definition: Optimizer.h:96
void setEpsilon(double epsilon)
Definition: Optimizer.h:104


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:29