g2o
estimate_propagator.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
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
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // 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 #ifndef G2O_ESTIMATE_PROPAGATOR_H
28 #define G2O_ESTIMATE_PROPAGATOR_H
29 
30 #include "optimizable_graph.h"
31 #include "sparse_optimizer.h"
32 #include "g2o_core_api.h"
33 
34 #include <map>
35 #include <set>
36 #include <limits>
37 
38 #include <unordered_map>
39 
40 namespace g2o {
41 
48  public:
50  virtual double operator()(OptimizableGraph::Edge* edge, const OptimizableGraph::VertexSet& from, OptimizableGraph::Vertex* to_) const;
51  virtual const char* name() const { return "spanning tree";}
52  protected:
54  };
55 
63  public:
65  virtual double operator()(OptimizableGraph::Edge* edge, const OptimizableGraph::VertexSet& from_, OptimizableGraph::Vertex* to_) const;
66  virtual const char* name() const { return "odometry";}
67  };
68 
73  public:
74 
80  struct PropagateAction {
82  {
83  if (! to->fixed())
84  e->initialEstimate(from, to);
85  }
86  };
87 
89 
90  class AdjacencyMapEntry;
91 
95  class PriorityQueue : public std::multimap<double, AdjacencyMapEntry*> {
96  public:
97  void push(AdjacencyMapEntry* entry);
98  AdjacencyMapEntry* pop();
99  };
100 
105  public:
106  friend class EstimatePropagator;
107  friend class PriorityQueue;
109  void reset();
110  OptimizableGraph::Vertex* child() const {return _child;}
111  const OptimizableGraph::VertexSet& parent() const {return _parent;}
112  OptimizableGraph::Edge* edge() const {return _edge;}
113  double distance() const {return _distance;}
114  int frontierLevel() const { return _frontierLevel;}
115 
116  protected:
120  double _distance;
122  private: // for PriorityQueue
123  bool inQueue;
124  PriorityQueue::iterator queueIt;
125  };
126 
131  public:
132  size_t operator ()(const OptimizableGraph::Vertex* v) const { return v->id();}
133  };
134 
135  typedef std::unordered_map<OptimizableGraph::Vertex*, AdjacencyMapEntry, VertexIDHashFunction> AdjacencyMap;
136 
137  public:
139  OptimizableGraph::VertexSet& visited() {return _visited; }
140  AdjacencyMap& adjacencyMap() {return _adjacencyMap; }
141  OptimizableGraph* graph() {return _graph;}
142 
148  void propagate(OptimizableGraph::Vertex* v,
151  double maxDistance=std::numeric_limits<double>::max(),
152  double maxEdgeCost=std::numeric_limits<double>::max());
153 
157  void propagate(OptimizableGraph::VertexSet& vset,
160  double maxDistance=std::numeric_limits<double>::max(),
161  double maxEdgeCost=std::numeric_limits<double>::max());
162 
163  protected:
164  void reset();
165 
166  AdjacencyMap _adjacencyMap;
169  };
170 
171 }
172 #endif
int id() const
returns the id
Definition: hyper_graph.h:148
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
OptimizableGraph::VertexSet _visited
propagation of an initial guess
OptimizableGraph::VertexSet & visited()
Applying the action for propagating.
OptimizableGraph * graph()
data structure for loopuk during Dijkstra
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)=0
OptimizableGraph::Vertex * child() const
const OptimizableGraph::VertexSet & parent() const
virtual const char * name() const
cost for traversing along active edges in the optimizer
OptimizableGraph::Edge * edge() const
A general case Vertex for optimization.
virtual const char * name() const
bool fixed() const
true => this node is fixed during the optimization
virtual void operator()(OptimizableGraph::Edge *e, const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to) const
cost for traversing only odometry edges.
std::unordered_map< OptimizableGraph::Vertex *, AdjacencyMapEntry, VertexIDHashFunction > AdjacencyMap
EstimatePropagatorCost PropagateCost
#define G2O_CORE_API
Definition: g2o_core_api.h:29
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the graph
Definition: protocol.txt:7
priority queue for AdjacencyMapEntry