g2o
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
g2o::EdgeCreator Struct Reference

#include <edge_creator.h>

Classes

struct  EdgeCreatorEntry
 

Public Types

typedef std::map< std::string, EdgeCreatorEntryEntryMap
 

Public Member Functions

bool addAssociation (const std::string &vertexTypes, const std::string &edgeType)
 
bool addAssociation (const std::string &vertexTypes, const std::string &edgeType, const std::vector< int > &parameterIds)
 
bool removeAssociation (const std::string &vertexTypes)
 
OptimizableGraph::EdgecreateEdge (std::vector< OptimizableGraph::Vertex * > &vertices)
 

Protected Attributes

EntryMap _vertexToEdgeMap
 

Detailed Description

Class that implements a simple edge_creation, based on the types and the ordes of the vertices passed as argument. Namely, based on an ordered vector of vertices this class implements a method that construct a new edge compatible with the vertices in the vector. The order of the vector matters. This class is heavily based on the Factory, and utilizes strings to identify the edge types.

Definition at line 45 of file edge_creator.h.

Member Typedef Documentation

◆ EntryMap

typedef std::map<std::string, EdgeCreatorEntry> g2o::EdgeCreator::EntryMap

Definition at line 58 of file edge_creator.h.

Member Function Documentation

◆ addAssociation() [1/2]

bool g2o::EdgeCreator::addAssociation ( const std::string &  vertexTypes,
const std::string &  edgeType 
)

Adds an association to the association map

Parameters
vertexTypesa string containing the tags of the vertices separated by a ";". For instance an edge between a VertexSE2 and and EdgeSE2 is identified by the string "VERTEX_SE2;EDGE_SE2;". The order matters.
edgeTypethe tag of edge to create
Returns
false on failure (incompatible types). Currently returns always true because i did not have time to implement checks

Definition at line 49 of file edge_creator.cpp.

50 {
51 return addAssociation(vertexTypes, edgeType, std::vector<int>());
52}
bool addAssociation(const std::string &vertexTypes, const std::string &edgeType)

References addAssociation().

Referenced by addAssociation(), and main().

◆ addAssociation() [2/2]

bool g2o::EdgeCreator::addAssociation ( const std::string &  vertexTypes,
const std::string &  edgeType,
const std::vector< int > &  parameterIds 
)

Adds an association to the association map

Parameters
vertexTypesa string containing the tags of the vertices separated by a ";". For instance an edge between a VertexSE2 and and EdgeSE2 is identified by the string "VERTEX_SE2;EDGE_SE2;". The order matters.
edgeTypethe tag of edge to create
parameterIdsthe ids of the parameters uses as argument when creating the edge (the same as Edge::_parameterIds)
Returns
false on failure (incompatible types). Currently returns always true because i did not have time to implement checks

Definition at line 37 of file edge_creator.cpp.

39 {
40 EntryMap::iterator it = _vertexToEdgeMap.find(vertexTypes);
41 if (it != _vertexToEdgeMap.end())
42 it->second = edgeType;
43 else
44 _vertexToEdgeMap.insert(
45 make_pair(vertexTypes, EdgeCreatorEntry(edgeType, parameterIds)));
46 return true;
47}
EntryMap _vertexToEdgeMap

References _vertexToEdgeMap.

◆ createEdge()

OptimizableGraph::Edge * g2o::EdgeCreator::createEdge ( std::vector< OptimizableGraph::Vertex * > &  vertices)

constructs an edge based on the verticesVector given as argument The vertices of the newly created edge are set to the parameter @params vertices: the vertices to be connected by the new edge

Returns
the new edge on success, 0 on failure (no edge association in the map compatible with the vertices in the parameter)

Definition at line 61 of file edge_creator.cpp.

62 {
63 std::stringstream key;
64 Factory* factory = Factory::instance();
65 for (size_t i = 0; i < vertices.size(); i++) {
66 key << factory->tag(vertices[i]) << ";";
67 }
68 EntryMap::iterator it = _vertexToEdgeMap.find(key.str());
69 if (it == _vertexToEdgeMap.end()) {
70 cerr << "no thing in factory: " << key.str() << endl;
71 return 0;
72 }
73 HyperGraph::HyperGraphElement* element =
74 factory->construct(it->second._edgeTypeName);
75 if (!element) {
76 cerr << "no thing can be created" << endl;
77 return 0;
78 }
79 OptimizableGraph::Edge* e = dynamic_cast<OptimizableGraph::Edge*>(element);
80 assert(it->second._parameterIds.size() == e->numParameters());
81 for (size_t i = 0; i < it->second._parameterIds.size(); i++) {
82 if (!e->setParameterId(i, it->second._parameterIds[i])) {
83 cerr << "no thing in good for setting params" << endl;
84 return 0;
85 }
86 }
87 assert(e);
88 for (size_t i = 0; i < vertices.size(); i++) e->vertices()[i] = vertices[i];
89 return e;
90}
static Factory * instance()
return the instance
Definition factory.cpp:46

References _vertexToEdgeMap, g2o::Factory::construct(), g2o::Factory::instance(), g2o::OptimizableGraph::Edge::numParameters(), g2o::OptimizableGraph::Edge::setParameterId(), g2o::Factory::tag(), and g2o::HyperGraph::Edge::vertices().

Referenced by g2o::assignHierarchicalEdges(), and g2o::computeSimpleStars().

◆ removeAssociation()

bool g2o::EdgeCreator::removeAssociation ( const std::string &  vertexTypes)

Removes an association to the association map. @params vertexTypes: the string of the vertex ids connected by the edge

Definition at line 54 of file edge_creator.cpp.

54 {
55 EntryMap::iterator it = _vertexToEdgeMap.find(vertexTypes);
56 if (it == _vertexToEdgeMap.end()) return false;
57 _vertexToEdgeMap.erase(it);
58 return true;
59}

References _vertexToEdgeMap.

Member Data Documentation

◆ _vertexToEdgeMap

EntryMap g2o::EdgeCreator::_vertexToEdgeMap
protected

Definition at line 96 of file edge_creator.h.

Referenced by addAssociation(), createEdge(), and removeAssociation().


The documentation for this struct was generated from the following files: