00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef GRAPH_H_
00029 #define GRAPH_H_
00030
00031 #include "rtabmap/core/RtabmapExp.h"
00032
00033 #include <map>
00034 #include <list>
00035 #include <rtabmap/core/Link.h>
00036 #include <rtabmap/core/Parameters.h>
00037
00038 namespace rtabmap {
00039
00040 namespace graph {
00041
00043
00045 class RTABMAP_EXP Optimizer
00046 {
00047 public:
00048 enum Type {
00049 kTypeUndef = -1,
00050 kTypeTORO = 0,
00051 kTypeG2O = 1
00052 };
00053 static Optimizer * create(const ParametersMap & parameters);
00054 static Optimizer * create(Optimizer::Type & type, const ParametersMap & parameters = ParametersMap());
00055
00056
00057 static void getConnectedGraph(
00058 int fromId,
00059 const std::map<int, Transform> & posesIn,
00060 const std::multimap<int, Link> & linksIn,
00061 std::map<int, Transform> & posesOut,
00062 std::multimap<int, Link> & linksOut,
00063 int depth = 0);
00064
00065 public:
00066 virtual ~Optimizer() {}
00067
00068 virtual Type type() const = 0;
00069
00070 int iterations() const {return iterations_;}
00071 bool isSlam2d() const {return slam2d_;}
00072 bool isCovarianceIgnored() const {return covarianceIgnored_;}
00073
00074 virtual std::map<int, Transform> optimize(
00075 int rootId,
00076 const std::map<int, Transform> & poses,
00077 const std::multimap<int, Link> & constraints,
00078 std::list<std::map<int, Transform> > * intermediateGraphes = 0) = 0;
00079
00080 virtual void parseParameters(const ParametersMap & parameters);
00081
00082 protected:
00083 Optimizer(int iterations = 100, bool slam2d = false, bool covarianceIgnored = false);
00084 Optimizer(const ParametersMap & parameters);
00085
00086 private:
00087 int iterations_;
00088 bool slam2d_;
00089 bool covarianceIgnored_;
00090 };
00091
00092 class RTABMAP_EXP TOROOptimizer : public Optimizer
00093 {
00094 public:
00095 static bool saveGraph(
00096 const std::string & fileName,
00097 const std::map<int, Transform> & poses,
00098 const std::multimap<int, Link> & edgeConstraints);
00099 static bool loadGraph(
00100 const std::string & fileName,
00101 std::map<int, Transform> & poses,
00102 std::multimap<int, Link> & edgeConstraints);
00103
00104 public:
00105 TOROOptimizer(int iterations = 100, bool slam2d = false, bool covarianceIgnored = false) :
00106 Optimizer(iterations, slam2d, covarianceIgnored) {}
00107 TOROOptimizer(const ParametersMap & parameters) :
00108 Optimizer(parameters) {}
00109 virtual ~TOROOptimizer() {}
00110
00111 virtual Type type() const {return kTypeTORO;}
00112
00113 virtual std::map<int, Transform> optimize(
00114 int rootId,
00115 const std::map<int, Transform> & poses,
00116 const std::multimap<int, Link> & edgeConstraints,
00117 std::list<std::map<int, Transform> > * intermediateGraphes = 0);
00118 };
00119
00120 class RTABMAP_EXP G2OOptimizer : public Optimizer
00121 {
00122 public:
00123 static bool available();
00124
00125 public:
00126 G2OOptimizer(int iterations = 100, bool slam2d = false, bool covarianceIgnored = false) :
00127 Optimizer(iterations, slam2d, covarianceIgnored) {}
00128 G2OOptimizer(const ParametersMap & parameters) :
00129 Optimizer(parameters) {}
00130 virtual ~G2OOptimizer() {}
00131
00132 virtual Type type() const {return kTypeG2O;}
00133
00134 virtual std::map<int, Transform> optimize(
00135 int rootId,
00136 const std::map<int, Transform> & poses,
00137 const std::multimap<int, Link> & edgeConstraints,
00138 std::list<std::map<int, Transform> > * intermediateGraphes = 0);
00139 };
00140
00142
00144 std::multimap<int, Link>::iterator RTABMAP_EXP findLink(
00145 std::multimap<int, Link> & links,
00146 int from,
00147 int to);
00148 std::multimap<int, int>::iterator RTABMAP_EXP findLink(
00149 std::multimap<int, int> & links,
00150 int from,
00151 int to);
00152
00161 std::map<int, Transform> RTABMAP_EXP radiusPosesFiltering(
00162 const std::map<int, Transform> & poses,
00163 float radius,
00164 float angle,
00165 bool keepLatest = true);
00166
00174 std::multimap<int, int> RTABMAP_EXP radiusPosesClustering(
00175 const std::map<int, Transform> & poses,
00176 float radius,
00177 float angle);
00178
00188 std::list<std::pair<int, Transform> > RTABMAP_EXP computePath(
00189 const std::map<int, rtabmap::Transform> & poses,
00190 const std::multimap<int, int> & links,
00191 int from,
00192 int to,
00193 bool updateNewCosts = false);
00194
00195 int RTABMAP_EXP findNearestNode(
00196 const std::map<int, rtabmap::Transform> & nodes,
00197 const rtabmap::Transform & targetPose);
00198
00207 std::map<int, float> RTABMAP_EXP getNodesInRadius(
00208 int nodeId,
00209 const std::map<int, Transform> & nodes,
00210 float radius);
00211 std::map<int, Transform> RTABMAP_EXP getPosesInRadius(
00212 int nodeId,
00213 const std::map<int, Transform> & nodes,
00214 float radius);
00215
00216 float RTABMAP_EXP computePathLength(
00217 const std::vector<std::pair<int, Transform> > & path,
00218 unsigned int fromIndex = 0,
00219 unsigned int toIndex = 0);
00220
00221
00222 }
00223
00224 }
00225 #endif