g2o
tools.cpp
Go to the documentation of this file.
1 #include "tools.h"
2 
3 #include <queue>
4 #include <iostream>
5 #include <vector>
6 #include <map>
7 #include <set>
8 #include <limits>
9 #include <cassert>
10 
11 #include "g2o/types/slam2d/types_three_dof.h"
12 
13 namespace g2o{
14 
15  using namespace std;
16 
18  HyperGraph::EdgeSet& border,
19  HyperGraph::Edge* start,
21  double maxEdgeCost,
22  double comparisonConditioner){
23 
24  (void) comparisonConditioner; // no warning (unused)
25  typedef std::queue<HyperGraph::Edge*> EdgeDeque;
26  EdgeDeque frontier;
27  frontier.push(start);
28 
29  selected.clear();
30  border.clear();
31 
32  while (! frontier.empty()){
33  HyperGraph::Edge* e=frontier.front();
34  frontier.pop();
35 
36  const VertexSE2* from = dynamic_cast<const VertexSE2*>(e->vertices()[0]);
37  const VertexSE2* to = dynamic_cast<const VertexSE2*>(e->vertices()[1]);
38 
39  if (!(from && to))
40  continue;
41 
42  double edgecost=(*cost)(e, e->vertices()[0], e->vertices()[1]);
43  if (edgecost != std::numeric_limits< double >::max()) {
44 
45  if (edgecost > maxEdgeCost) {// + comparisonConditioner) {
46  border.insert(e);
47  }
48  else if (edgecost <= maxEdgeCost) {
49  selected.insert(e);
50 
51  for (HyperGraph::EdgeSet::iterator it=e->vertices()[0]->edges().begin();
52  it!=e->vertices()[0]->edges().end(); ++it) {
53  if (selected.find(*it)==selected.end())
54  frontier.push(dynamic_cast<HyperGraph::Edge*>(*it));
55  }
56  for (HyperGraph::EdgeSet::iterator it=e->vertices()[1]->edges().begin();
57  it!=e->vertices()[1]->edges().end(); ++it) {
58  if (selected.find(*it)==selected.end())
59  frontier.push(dynamic_cast<HyperGraph::Edge*>(*it));
60  }
61  }
62  else
63  cerr << "? nan ?" << endl;
64  }
65  else
66  cerr << "? max ?" << endl;
67  }
68  }
69 
70 };
virtual void push()
backup the position of the vertex to a stack
Definition: base_vertex.h:93
2D pose Vertex, (x,y,theta)
Definition: vertex_se2.h:41
std::set< Edge * > EdgeSet
Definition: hyper_graph.h:135
const VertexContainer & vertices() const
Definition: hyper_graph.h:178
void findConnectedEdgesWithCostLimit(HyperGraph::EdgeSet &selected, HyperGraph::EdgeSet &border, HyperGraph::Edge *start, HyperDijkstra::CostFunction *cost, double maxEdgeCost, double comparisonConditioner)
Definition: tools.cpp:17