estimate_propagator.h
Go to the documentation of this file.
00001 // g2o - General Graph Optimization
00002 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
00003 // 
00004 // g2o is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU Lesser General Public License as published
00006 // by the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // g2o is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef G2O_ESTIMATE_PROPAGATOR_H
00018 #define G2O_ESTIMATE_PROPAGATOR_H
00019 
00020 #include "optimizable_graph.h"
00021 #include "graph_optimizer_sparse.h"
00022 
00023 #include <map>
00024 #include <set>
00025 #include <limits>
00026 
00027 #ifdef _MSC_VER
00028 #include <unordered_map>
00029 #else
00030 #include <tr1/unordered_map>
00031 #endif
00032 
00033 namespace g2o {
00034 
00038   class EstimatePropagator {
00039     public:
00040 
00046       struct PropagateAction {
00047         virtual void operator()(OptimizableGraph::Edge* e, const OptimizableGraph::VertexSet& from, OptimizableGraph::Vertex* to) const
00048         {
00049           if (! to->fixed())
00050             e->initialEstimate(from, to);
00051         }
00052       };
00053 
00059       class PropagateCost {
00060         public:
00061           PropagateCost(SparseOptimizer* graph) : _graph(graph) {}
00062           virtual double operator()(OptimizableGraph::Edge* edge, const OptimizableGraph::VertexSet& from, OptimizableGraph::Vertex* to_) const
00063           {
00064             OptimizableGraph::Edge* e = dynamic_cast<OptimizableGraph::Edge*>(edge);
00065             OptimizableGraph::Vertex* to = dynamic_cast<OptimizableGraph::Vertex*>(to_);
00066             SparseOptimizer::EdgeContainer::const_iterator it = _graph->findActiveEdge(e);
00067             if (it == _graph->activeEdges().end()) // it has to be an active edge
00068               return std::numeric_limits<double>::max();
00069             return e->initialEstimatePossible(from, to);
00070           }
00071         protected:
00072           SparseOptimizer* _graph;
00073       };
00074 
00075       class AdjacencyMapEntry;
00076 
00080       class PriorityQueue : public std::multimap<double, AdjacencyMapEntry*> {
00081         public:
00082           void push(AdjacencyMapEntry* entry);
00083           AdjacencyMapEntry* pop();
00084       };
00085 
00089       class AdjacencyMapEntry {
00090         public:
00091           friend class EstimatePropagator;
00092           friend class PriorityQueue;
00093           AdjacencyMapEntry();
00094           void reset();
00095           OptimizableGraph::Vertex* child() const {return _child;}
00096           const OptimizableGraph::VertexSet& parent() const {return _parent;}
00097           OptimizableGraph::Edge* edge() const {return _edge;}
00098           double distance() const {return _distance;}
00099           int frontierLevel() const { return _frontierLevel;}
00100 
00101         protected:
00102           OptimizableGraph::Vertex* _child;
00103           OptimizableGraph::VertexSet _parent;
00104           OptimizableGraph::Edge* _edge;
00105           double _distance;
00106           int _frontierLevel;
00107         private: // for PriorityQueue
00108           bool inQueue;
00109           PriorityQueue::iterator queueIt;
00110       };
00111 
00115       class VertexIDHashFunction {
00116         public:
00117           size_t operator ()(const OptimizableGraph::Vertex* v) const { return v->id();}
00118       };
00119 
00120       typedef std::tr1::unordered_map<OptimizableGraph::Vertex*, AdjacencyMapEntry, VertexIDHashFunction> AdjacencyMap;
00121 
00122     public:
00123       EstimatePropagator(OptimizableGraph* g);
00124       OptimizableGraph::VertexSet& visited() {return _visited; }
00125       AdjacencyMap& adjacencyMap() {return _adjacencyMap; }
00126       OptimizableGraph* graph() {return _graph;} 
00127 
00133       void propagate(OptimizableGraph::Vertex* v, 
00134           const EstimatePropagator::PropagateCost& cost, 
00135           const EstimatePropagator::PropagateAction& action = PropagateAction(),
00136           double maxDistance=std::numeric_limits<double>::max(), 
00137           double maxEdgeCost=std::numeric_limits<double>::max());
00138 
00142       void propagate(OptimizableGraph::VertexSet& vset, 
00143           const EstimatePropagator::PropagateCost& cost, 
00144           const EstimatePropagator::PropagateAction& action = PropagateAction(),
00145           double maxDistance=std::numeric_limits<double>::max(), 
00146           double maxEdgeCost=std::numeric_limits<double>::max());
00147 
00148     protected:
00149       void reset();
00150 
00151       AdjacencyMap _adjacencyMap;
00152       OptimizableGraph::VertexSet _visited;
00153       OptimizableGraph* _graph;
00154   };
00155 
00156 }
00157 #endif


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:08