g2o
edge_creator.cpp
Go to the documentation of this file.
1 #include "g2o/core/factory.h"
2 #include "edge_creator.h"
3 
4 namespace g2o {
5 
6  using namespace std;
7 
8  bool EdgeCreator::addAssociation(const std::string& vertexTypes, const std::string& edgeType, const std::vector<int>& parameterIds) {
9 
10  EntryMap::iterator it = _vertexToEdgeMap.find(vertexTypes);
11  if (it!=_vertexToEdgeMap.end())
12  it->second = edgeType;
13  else
14  _vertexToEdgeMap.insert(make_pair(vertexTypes,EdgeCreatorEntry(edgeType, parameterIds)));
15  return true;
16  }
17 
18  bool EdgeCreator::addAssociation(const std::string& vertexTypes, const std::string& edgeType) {
19  return addAssociation(vertexTypes, edgeType, std::vector<int>());
20  }
21 
22  bool EdgeCreator::removeAssociation(std::string vertexTypes){
23  EntryMap::iterator it = _vertexToEdgeMap.find(vertexTypes);
24  if (it==_vertexToEdgeMap.end())
25  return false;
26  _vertexToEdgeMap.erase(it);
27  return true;
28  }
29 
30 
31  OptimizableGraph::Edge* EdgeCreator::createEdge(std::vector<OptimizableGraph::Vertex*>& vertices ){
32  std::stringstream key;
33  Factory* factory=Factory::instance();
34  for (size_t i=0; i<vertices.size(); i++){
35  key << factory->tag(vertices[i]) << ";";
36  }
37  EntryMap::iterator it=_vertexToEdgeMap.find(key.str());
38  if (it==_vertexToEdgeMap.end()){
39  cerr << "no thing in factory: " << key.str() << endl;
40  return 0;
41  }
42  HyperGraph::HyperGraphElement* element=factory->construct(it->second._edgeTypeName);
43  if (! element) {
44  cerr << "no thing can be created" << endl;
45  return 0;
46  }
47  OptimizableGraph::Edge* e = dynamic_cast<OptimizableGraph::Edge*>(element);
48  assert(it->second._parameterIds.size() == e->numParameters());
49  for (size_t i=0; i<it->second._parameterIds.size(); i++){
50  if (! e->setParameterId(i,it->second._parameterIds[i])) {
51  cerr << "no thing in good for setting params" << endl;
52  return 0;
53  }
54  }
55  assert (e);
56  for (size_t i=0; i<vertices.size(); i++)
57  e->vertices()[i]=vertices[i];
58  return e;
59  }
60 
61 }
62 
static Factory * instance()
return the instance
Definition: factory.cpp:61
bool removeAssociation(std::string vertexTypes)
HyperGraph::HyperGraphElement * construct(const std::string &tag) const
Definition: factory.cpp:147
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the explicitly state the reprensentation poses are represented by poses by VERTEX_XYZRPY In the Quaternions and other representations could be but note that it is up to the SLAM algorithm to choose the internal representation of the angles The keyword is followed by a unique vertex ID and an optional initialization of the or edges in the explicitly state the type of the constraint pose constraints are given by pose constraints by EDGE_XYZRPY The keyword is followed by a unique edge the IDs of the referenced vertices
Definition: protocol.txt:7
bool setParameterId(int argNum, int paramId)
const VertexContainer & vertices() const
Definition: hyper_graph.h:178
const std::string & tag(const HyperGraph::HyperGraphElement *v) const
return the TAG given a vertex
Definition: factory.cpp:157
create vertices and edges based on TAGs in, for example, a file
Definition: factory.h:49
OptimizableGraph::Edge * createEdge(std::vector< OptimizableGraph::Vertex * > &vertices)
bool addAssociation(const std::string &vertexTypes, const std::string &edgeType)