Graph.h
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #ifndef GRAPH_H_
00029 #define GRAPH_H_
00030 
00031 #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
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 // Graph optimizers
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         // Get connected poses and constraints from a set of links
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 // Graph utilities
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 } /* namespace graph */
00223 
00224 } /* namespace rtabmap */
00225 #endif /* GRAPH_H_ */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Fri Aug 28 2015 12:51:31