g2o
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
g2o::OptimizableGraph Struct Reference

#include <optimizable_graph.h>

Inheritance diagram for g2o::OptimizableGraph:
Inheritance graph
[legend]
Collaboration diagram for g2o::OptimizableGraph:
Collaboration graph
[legend]

Classes

class  Edge
 
struct  EdgeIDCompare
 order edges based on the internal ID, which is assigned to the edge in addEdge() More...
 
class  Vertex
 A general case Vertex for optimization. More...
 
struct  VertexIDCompare
 order vertices based on their ID More...
 

Public Types

enum  ActionType { AT_PREITERATION, AT_POSTITERATION, AT_NUM_ELEMENTS }
 
typedef std::set< HyperGraphAction * > HyperGraphActionSet
 
typedef std::vector< OptimizableGraph::Vertex * > VertexContainer
 vector container for vertices More...
 
typedef std::vector< OptimizableGraph::Edge * > EdgeContainer
 vector container for edges More...
 
- Public Types inherited from g2o::HyperGraph
typedef std::bitset< HyperGraph::HGET_NUM_ELEMS > GraphElemBitset
 
typedef std::set< Edge * > EdgeSet
 
typedef std::set< Vertex * > VertexSet
 
typedef std::unordered_map< int, Vertex * > VertexIDMap
 
typedef std::vector< Vertex * > VertexContainer
 

Public Member Functions

Vertexvertex (int id)
 returns the vertex number id appropriately casted More...
 
const Vertexvertex (int id) const
 returns the vertex number id appropriately casted More...
 
 OptimizableGraph ()
 empty constructor More...
 
virtual ~OptimizableGraph ()
 
void addGraph (OptimizableGraph *g)
 adds all edges and vertices of the graph g to this graph. More...
 
virtual bool addVertex (HyperGraph::Vertex *v, Data *userData)
 
virtual bool addVertex (HyperGraph::Vertex *v)
 
virtual bool addEdge (HyperGraph::Edge *e)
 
virtual bool setEdgeVertex (HyperGraph::Edge *e, int pos, HyperGraph::Vertex *v)
 
double chi2 () const
 returns the chi2 of the current configuration More...
 
int maxDimension () const
 return the maximum dimension of all vertices in the graph More...
 
std::set< int > dimensions () const
 
virtual int optimize (int iterations, bool online=false)
 
virtual void preIteration (int)
 called at the beginning of an iteration (argument is the number of the iteration) More...
 
virtual void postIteration (int)
 called at the end of an iteration (argument is the number of the iteration) More...
 
bool addPreIterationAction (HyperGraphAction *action)
 add an action to be executed before each iteration More...
 
bool addPostIterationAction (HyperGraphAction *action)
 add an action to be executed after each iteration More...
 
bool removePreIterationAction (HyperGraphAction *action)
 remove an action that should no longer be execured before each iteration More...
 
bool removePostIterationAction (HyperGraphAction *action)
 remove an action that should no longer be execured after each iteration More...
 
virtual void push ()
 push the estimate of all variables onto a stack More...
 
virtual void pop ()
 pop (restore) the estimate of all variables from the stack More...
 
virtual void discardTop ()
 discard the last backup of the estimate for all variables by removing it from the stack More...
 
virtual bool load (std::istream &is, bool createEdges=true)
 load the graph from a stream. Uses the Factory singleton for creating the vertices and edges. More...
 
bool load (const char *filename, bool createEdges=true)
 
virtual bool save (std::ostream &os, int level=0) const
 save the graph to a stream. Again uses the Factory system. More...
 
bool save (const char *filename, int level=0) const
 function provided for convenience, see save() above More...
 
bool saveSubset (std::ostream &os, HyperGraph::VertexSet &vset, int level=0)
 save a subgraph to a stream. Again uses the Factory system. More...
 
bool saveSubset (std::ostream &os, HyperGraph::EdgeSet &eset)
 save a subgraph to a stream. Again uses the Factory system. More...
 
virtual void push (HyperGraph::VertexSet &vset)
 push the estimate of a subset of the variables onto a stack More...
 
virtual void pop (HyperGraph::VertexSet &vset)
 pop (restore) the estimate a subset of the variables from the stack More...
 
virtual void discardTop (HyperGraph::VertexSet &vset)
 ignore the latest stored element on the stack, remove it from the stack but do not restore the estimate More...
 
virtual void setFixed (HyperGraph::VertexSet &vset, bool fixed)
 fixes/releases a set of vertices More...
 
void setRenamedTypesFromString (const std::string &types)
 
bool isSolverSuitable (const OptimizationAlgorithmProperty &solverProperty, const std::set< int > &vertDims=std::set< int >()) const
 
virtual void clearParameters ()
 
bool addParameter (Parameter *p)
 
Parameterparameter (int id)
 
bool verifyInformationMatrices (bool verbose=false) const
 
bool saveVertex (std::ostream &os, Vertex *v) const
 
bool saveParameter (std::ostream &os, Parameter *v) const
 
bool saveEdge (std::ostream &os, Edge *e) const
 
bool saveUserData (std::ostream &os, HyperGraph::Data *v) const
 
JacobianWorkspacejacobianWorkspace ()
 the workspace for storing the Jacobians of the graph More...
 
const JacobianWorkspacejacobianWorkspace () const
 
ParameterContainerparameters ()
 
const ParameterContainerparameters () const
 
- Public Member Functions inherited from g2o::HyperGraph
 HyperGraph ()
 constructs an empty hyper graph More...
 
virtual ~HyperGraph ()
 destroys the hyper-graph and all the vertices of the graph More...
 
Vertexvertex (int id)
 returns a vertex id in the hyper-graph, or 0 if the vertex id is not present More...
 
const Vertexvertex (int id) const
 returns a vertex id in the hyper-graph, or 0 if the vertex id is not present More...
 
virtual bool removeVertex (Vertex *v, bool detach=false)
 removes a vertex from the graph. Returns true on success (vertex was present) More...
 
virtual bool removeEdge (Edge *e)
 removes a vertex from the graph. Returns true on success (edge was present) More...
 
virtual void clear ()
 clears the graph and empties all structures. More...
 
const VertexIDMapvertices () const
 
VertexIDMapvertices ()
 
const EdgeSetedges () const
 
EdgeSetedges ()
 
virtual bool mergeVertices (Vertex *vBig, Vertex *vSmall, bool erase)
 
virtual bool detachVertex (Vertex *v)
 
virtual bool changeId (Vertex *v, int newId)
 

Static Public Member Functions

static bool initMultiThreading ()
 

Public Attributes

class G2O_CORE_API Vertex
 
class G2O_CORE_API Edge
 
- Public Attributes inherited from g2o::HyperGraph
class G2O_CORE_API Data
 
class G2O_CORE_API DataContainer
 
class G2O_CORE_API Vertex
 
class G2O_CORE_API Edge
 

Protected Attributes

std::map< std::string, std::string > _renamedTypesLookup
 
long long _nextEdgeId
 
std::vector< HyperGraphActionSet_graphActions
 
bool _edge_has_id
 
ParameterContainer _parameters
 
JacobianWorkspace _jacobianWorkspace
 
- Protected Attributes inherited from g2o::HyperGraph
VertexIDMap _vertices
 
EdgeSet _edges
 

Additional Inherited Members

- Static Public Attributes inherited from g2o::HyperGraph
static const int UnassignedId = -1
 
static const int InvalidId = -2
 

Detailed Description

This is an abstract class that represents one optimization problem. It specializes the general graph to contain special vertices and edges. The vertices represent parameters that can be optimized, while the edges represent constraints. This class also provides basic functionalities to handle the backup/restore of portions of the vertices.

Definition at line 65 of file optimizable_graph.h.

Member Typedef Documentation

vector container for edges

Definition at line 102 of file optimizable_graph.h.

Definition at line 72 of file optimizable_graph.h.

vector container for vertices

Definition at line 100 of file optimizable_graph.h.

Member Enumeration Documentation

Enumerator
AT_PREITERATION 
AT_POSTITERATION 
AT_NUM_ELEMENTS 

Definition at line 67 of file optimizable_graph.h.

Constructor & Destructor Documentation

g2o::OptimizableGraph::OptimizableGraph ( )

empty constructor

Definition at line 219 of file optimizable_graph.cpp.

References _edge_has_id, _graphActions, _nextEdgeId, and AT_NUM_ELEMENTS.

220  {
221  _nextEdgeId = 0; _edge_has_id = false;
223  }
std::vector< HyperGraphActionSet > _graphActions
g2o::OptimizableGraph::~OptimizableGraph ( )
virtual

Definition at line 225 of file optimizable_graph.cpp.

References g2o::HyperGraph::clear(), and clearParameters().

226  {
227  clear();
228  clearParameters();
229  }
virtual void clearParameters()
virtual void clear()
clears the graph and empties all structures.

Member Function Documentation

bool g2o::OptimizableGraph::addEdge ( HyperGraph::Edge e)
virtual

adds a new edge. The edge should point to the vertices that it is connecting (setFrom/setTo).

Returns
false if the insertion does not work (incompatible types of the vertices/missing vertex). true otherwise.

Reimplemented from g2o::HyperGraph.

Definition at line 257 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Edge::_internalId, _jacobianWorkspace, _nextEdgeId, g2o::HyperGraph::addEdge(), g2o::HyperGraph::Edge::numUndefinedVertices(), g2o::OptimizableGraph::Edge::resolveCaches(), g2o::OptimizableGraph::Edge::resolveParameters(), and g2o::JacobianWorkspace::updateSize().

Referenced by g2o::G2oSlamInterface::addEdge(), addGraph(), g2o::addOdometryCalibLinksDifferential(), g2o::assignHierarchicalEdges(), g2o::computeSimpleStars(), main(), g2o::Gm2dlIO::readGm2dl(), g2o::SensorOdometry< R, E, O >::sense(), g2o::SensorPose3DOffset::sense(), g2o::SensorOdometry2D::sense(), g2o::SensorOdometry3D::sense(), g2o::SensorPose3D::sense(), g2o::SensorSE3Prior::sense(), g2o::SensorPointXYZDepth::sense(), g2o::SensorPointXY::sense(), g2o::SensorPose2D::sense(), g2o::SensorPointXYZ::sense(), g2o::SensorSegment2DPointLine::sense(), g2o::SensorPointXYZDisparity::sense(), g2o::SensorSegment2DLine::sense(), g2o::SensorSegment2D::sense(), g2o::SensorPointXYBearing::sense(), g2o::SensorPointXYOffset::sense(), and setFixed().

258  {
259  OptimizableGraph::Edge* e = dynamic_cast<OptimizableGraph::Edge*>(e_);
260  assert(e && "Edge does not inherit from OptimizableGraph::Edge");
261  // std::cerr << "subclass of OptimizableGraph::Edge confirmed";
262  if (! e)
263  return false;
264  bool eresult = HyperGraph::addEdge(e);
265  if (! eresult)
266  return false;
267  // std::cerr << "called HyperGraph::addEdge" << std::endl;
268  e->_internalId = _nextEdgeId++;
269  if (e->numUndefinedVertices())
270  return true;
271  // std::cerr << "internalId set" << std::endl;
272  if (! e->resolveParameters()){
273  cerr << __FUNCTION__ << ": FATAL, cannot resolve parameters for edge " << e << endl;
274  return false;
275  }
276  // std::cerr << "parameters set" << std::endl;
277  if (! e->resolveCaches()){
278  cerr << __FUNCTION__ << ": FATAL, cannot resolve caches for edge " << e << endl;
279  return false;
280  }
281  // std::cerr << "updating jacobian size" << std::endl;
283 
284  // std::cerr << "about to return true" << std::endl;
285 
286  return true;
287  }
virtual bool addEdge(Edge *e)
class G2O_CORE_API Edge
void updateSize(const HyperGraph::Edge *e)
JacobianWorkspace _jacobianWorkspace
void g2o::OptimizableGraph::addGraph ( OptimizableGraph g)

adds all edges and vertices of the graph g to this graph.

Definition at line 741 of file optimizable_graph.cpp.

References addEdge(), addVertex(), g2o::OptimizableGraph::Vertex::clone(), g2o::OptimizableGraph::Edge::clone(), g2o::HyperGraph::Vertex::edges(), g2o::HyperGraph::edges(), g2o::HyperGraph::Vertex::id(), g2o::HyperGraph::Edge::resize(), g2o::OptimizableGraph::Vertex::setHessianIndex(), g2o::HyperGraph::Edge::setVertex(), g2o::HyperGraph::Edge::vertex(), g2o::HyperGraph::Edge::vertices(), and g2o::HyperGraph::vertices().

741  {
742  for (HyperGraph::VertexIDMap::iterator it=g->vertices().begin(); it!=g->vertices().end(); ++it){
744  if (vertex(v->id()))
745  continue;
746  OptimizableGraph::Vertex* v2=v->clone();
747  v2->edges().clear();
748  v2->setHessianIndex(-1);
749  addVertex(v2);
750  }
751  for (HyperGraph::EdgeSet::iterator it=g->edges().begin(); it!=g->edges().end(); ++it){
753  OptimizableGraph::Edge* en = e->clone();
754  en->resize(e->vertices().size());
755  int cnt = 0;
756  for (vector<HyperGraph::Vertex*>::const_iterator it = e->vertices().begin(); it != e->vertices().end(); ++it) {
758  assert(v);
759  en->setVertex(cnt++, v);
760  }
761  addEdge(en);
762  }
763 }
Vertex * vertex(int id)
returns the vertex number id appropriately casted
class G2O_CORE_API Vertex
class G2O_CORE_API Edge
virtual bool addEdge(HyperGraph::Edge *e)
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
bool g2o::OptimizableGraph::addParameter ( Parameter p)
inline

Definition at line 611 of file optimizable_graph.h.

Referenced by main().

611  {
612  return _parameters.addParameter(p);
613  }
bool addParameter(Parameter *p)
add parameter to the container
ParameterContainer _parameters
bool g2o::OptimizableGraph::addPostIterationAction ( HyperGraphAction action)

add an action to be executed after each iteration

Definition at line 855 of file optimizable_graph.cpp.

References _graphActions, and AT_POSTITERATION.

Referenced by main().

856 {
857  std::pair<HyperGraphActionSet::iterator, bool> insertResult = _graphActions[AT_POSTITERATION].insert(action);
858  return insertResult.second;
859 }
std::vector< HyperGraphActionSet > _graphActions
bool g2o::OptimizableGraph::addPreIterationAction ( HyperGraphAction action)

add an action to be executed before each iteration

Definition at line 861 of file optimizable_graph.cpp.

References _graphActions, and AT_PREITERATION.

Referenced by g2o::RunG2OViewer::run().

862 {
863  std::pair<HyperGraphActionSet::iterator, bool> insertResult = _graphActions[AT_PREITERATION].insert(action);
864  return insertResult.second;
865 }
std::vector< HyperGraphActionSet > _graphActions
bool g2o::OptimizableGraph::addVertex ( HyperGraph::Vertex v,
Data userData 
)
virtual

adds a new vertex. The new vertex is then "taken".

Returns
false if a vertex with the same id as v is already in the graph, true otherwise.

Definition at line 231 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Vertex::_graph, g2o::HyperGraph::addVertex(), g2o::HyperGraph::Vertex::id(), g2o::HyperGraph::DataContainer::setUserData(), and g2o::HyperGraph::Edge::vertex().

Referenced by addGraph(), g2o::addOdometryCalibLinksDifferential(), g2o::G2oSlamInterface::addVertex(), main(), g2o::Gm2dlIO::readGm2dl(), and setFixed().

232  {
233  if (v->id() <0){
234  cerr << __FUNCTION__ << ": FATAL, a vertex with (negative) ID " << v->id() << " cannot be inserted in the graph" << endl;
235  assert(0 && "Invalid vertex id");
236  return false;
237  }
238  Vertex* inserted = vertex(v->id());
239  if (inserted) {
240  cerr << __FUNCTION__ << ": FATAL, a vertex with ID " << v->id() << " has already been registered with this graph" << endl;
241  assert(0 && "Vertex with this ID already contained in the graph");
242  return false;
243  }
245  assert(ov && "Vertex does not inherit from OptimizableGraph::Vertex");
246  if (ov->_graph != 0 && ov->_graph != this) {
247  cerr << __FUNCTION__ << ": FATAL, vertex with ID " << v->id() << " has already registered with another graph " << ov->_graph << endl;
248  assert(0 && "Vertex already registered with another graph");
249  return false;
250  }
251  if (userData)
252  ov->setUserData(userData);
253  ov->_graph=this;
254  return HyperGraph::addVertex(v);
255  }
int id() const
returns the id
Definition: hyper_graph.h:148
Vertex * vertex(int id)
returns the vertex number id appropriately casted
class G2O_CORE_API Vertex
virtual bool addVertex(Vertex *v)
Definition: hyper_graph.cpp:94
virtual bool g2o::OptimizableGraph::addVertex ( HyperGraph::Vertex v)
inlinevirtual

adds a vertex to the graph. The id of the vertex should be set before invoking this function. the function fails if another vertex with the same id is already in the graph. returns true, on success, or false on failure.

Reimplemented from g2o::HyperGraph.

Definition at line 513 of file optimizable_graph.h.

References addVertex(), and types.

Referenced by addVertex().

513 { return addVertex(v, 0);}
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
double g2o::OptimizableGraph::chi2 ( ) const

returns the chi2 of the current configuration

Definition at line 315 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Edge::chi2(), and g2o::HyperGraph::edges().

Referenced by main().

316 {
317  double chi = 0.0;
318  for (OptimizableGraph::EdgeSet::const_iterator it = this->edges().begin(); it != this->edges().end(); ++it) {
319  const OptimizableGraph::Edge* e = static_cast<const OptimizableGraph::Edge*>(*it);
320  chi += e->chi2();
321  }
322  return chi;
323 }
const EdgeSet & edges() const
Definition: hyper_graph.h:230
class G2O_CORE_API Edge
void g2o::OptimizableGraph::clearParameters ( )
virtual

remove the parameters of the graph

Definition at line 940 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Edge::_parameters, and g2o::HyperGraph::clear().

Referenced by ~OptimizableGraph().

941 {
943  _parameters.clear();
944 }
virtual void clear()
clears the graph and empties all structures.
ParameterContainer _parameters
std::set< int > g2o::OptimizableGraph::dimensions ( ) const

iterates over all vertices and returns a set of all the vertex dimensions in the graph

Definition at line 823 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Vertex::dimension(), and g2o::HyperGraph::Edge::vertices().

Referenced by isSolverSuitable(), MainWindow::load(), and main().

824 {
825  std::set<int> auxDims;
826  for (VertexIDMap::const_iterator it = vertices().begin(); it != vertices().end(); ++it) {
827  OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(it->second);
828  auxDims.insert(v->dimension());
829  }
830  return auxDims;
831 }
const VertexIDMap & vertices() const
Definition: hyper_graph.h:225
class G2O_CORE_API Vertex
void g2o::OptimizableGraph::discardTop ( )
virtual

discard the last backup of the estimate for all variables by removing it from the stack

Reimplemented in g2o::SparseOptimizer.

Definition at line 341 of file optimizable_graph.cpp.

References g2o::HyperGraph::Edge::_vertices, and g2o::OptimizableGraph::Vertex::discardTop().

Referenced by g2o::SparseOptimizer::solver().

342 {
343  for (OptimizableGraph::VertexIDMap::iterator it=_vertices.begin(); it!=_vertices.end(); ++it) {
344  OptimizableGraph::Vertex* v= static_cast<OptimizableGraph::Vertex*>(it->second);
345  v->discardTop();
346  }
347 }
class G2O_CORE_API Vertex
VertexIDMap _vertices
Definition: hyper_graph.h:274
void g2o::OptimizableGraph::discardTop ( HyperGraph::VertexSet vset)
virtual

ignore the latest stored element on the stack, remove it from the stack but do not restore the estimate

Definition at line 365 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Vertex::discardTop().

366 {
367  for (HyperGraph::VertexSet::iterator it=vset.begin(); it!=vset.end(); ++it) {
368  OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*it);
369  v->discardTop();
370  }
371 }
class G2O_CORE_API Vertex
bool g2o::OptimizableGraph::initMultiThreading ( )
static

Eigen starting from version 3.1 requires that we call an initialize function, if we perform calls to Eigen from several threads. Currently, this function calls Eigen::initParallel if g2o is compiled with OpenMP support and Eigen's version is at least 3.1

Definition at line 980 of file optimizable_graph.cpp.

981 {
982 # if (defined G2O_OPENMP) && EIGEN_VERSION_AT_LEAST(3,1,0)
983  Eigen::initParallel();
984 # endif
985  return true;
986 }
bool g2o::OptimizableGraph::isSolverSuitable ( const OptimizationAlgorithmProperty solverProperty,
const std::set< int > &  vertDims = std::set<int>() 
) const

test whether a solver is suitable for optimizing this graph.

Parameters
solverPropertythe solver property to evaluate.
vertDimsshould equal to the set returned by dimensions() to avoid re-evaluating.

Definition at line 800 of file optimizable_graph.cpp.

References dimensions(), g2o::OptimizationAlgorithmProperty::landmarkDim, g2o::OptimizationAlgorithmProperty::poseDim, and g2o::OptimizationAlgorithmProperty::requiresMarginalize.

Referenced by MainWindow::load(), and main().

801 {
802  std::set<int> auxDims;
803  if (vertDims_.size() == 0) {
804  auxDims = dimensions();
805  }
806  const set<int>& vertDims = vertDims_.size() == 0 ? auxDims : vertDims_;
807  bool suitableSolver = true;
808  if (vertDims.size() == 2) {
809  if (solverProperty.requiresMarginalize) {
810  suitableSolver = vertDims.count(solverProperty.poseDim) == 1 && vertDims.count(solverProperty.landmarkDim) == 1;
811  }
812  else {
813  suitableSolver = solverProperty.poseDim == -1;
814  }
815  } else if (vertDims.size() == 1) {
816  suitableSolver = vertDims.count(solverProperty.poseDim) == 1 || solverProperty.poseDim == -1;
817  } else {
818  suitableSolver = solverProperty.poseDim == -1 && !solverProperty.requiresMarginalize;
819  }
820  return suitableSolver;
821 }
std::set< int > dimensions() const
JacobianWorkspace& g2o::OptimizableGraph::jacobianWorkspace ( )
inline

the workspace for storing the Jacobians of the graph

Definition at line 640 of file optimizable_graph.h.

Referenced by g2o::G2oSlamInterface::addEdge(), g2o::BlockSolver< Traits >::buildSystem(), and g2o::SparseOptimizerOnline::optimize().

640 { return _jacobianWorkspace;}
JacobianWorkspace _jacobianWorkspace
const JacobianWorkspace& g2o::OptimizableGraph::jacobianWorkspace ( ) const
inline

Definition at line 641 of file optimizable_graph.h.

641 { return _jacobianWorkspace;}
JacobianWorkspace _jacobianWorkspace
virtual bool g2o::OptimizableGraph::load ( std::istream &  is,
bool  createEdges = true 
)
virtual

load the graph from a stream. Uses the Factory singleton for creating the vertices and edges.

Referenced by load(), main(), and setFixed().

bool g2o::OptimizableGraph::load ( const char *  filename,
bool  createEdges = true 
)

Definition at line 629 of file optimizable_graph.cpp.

References __PRETTY_FUNCTION__, and load().

630 {
631  ifstream ifs(filename);
632  if (!ifs) {
633  cerr << __PRETTY_FUNCTION__ << " unable to open file " << filename << endl;
634  return false;
635  }
636  return load(ifs, createEdges);
637 }
#define __PRETTY_FUNCTION__
Definition: macros.h:89
virtual bool load(std::istream &is, bool createEdges=true)
load the graph from a stream. Uses the Factory singleton for creating the vertices and edges...
int g2o::OptimizableGraph::maxDimension ( ) const

return the maximum dimension of all vertices in the graph

Definition at line 765 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Vertex::dimension(), and g2o::HyperGraph::Edge::vertices().

765  {
766  int maxDim=0;
767  for (HyperGraph::VertexIDMap::const_iterator it=vertices().begin(); it!=vertices().end(); ++it){
768  const OptimizableGraph::Vertex* v= static_cast< const OptimizableGraph::Vertex*>(it->second);
769  maxDim = (std::max)(maxDim, v->dimension());
770  }
771  return maxDim;
772 }
const VertexIDMap & vertices() const
Definition: hyper_graph.h:225
class G2O_CORE_API Vertex
int g2o::OptimizableGraph::optimize ( int  iterations,
bool  online = false 
)
virtual

carry out n iterations

Returns
the number of performed iterations

Reimplemented in g2o::SparseOptimizer, g2o::SparseOptimizerOnline, and g2o::SparseOptimizerIncremental.

Definition at line 313 of file optimizable_graph.cpp.

313 {return 0;}
Parameter* g2o::OptimizableGraph::parameter ( int  id)
inline

Definition at line 615 of file optimizable_graph.h.

Referenced by main(), and g2o::OptimizableGraph::Edge::resolveParameters().

615  {
616  return _parameters.getParameter(id);
617  }
Parameter * getParameter(int id)
return a parameter based on its ID
ParameterContainer _parameters
ParameterContainer& g2o::OptimizableGraph::parameters ( )
inline

Definition at line 651 of file optimizable_graph.h.

651 {return _parameters;}
ParameterContainer _parameters
const ParameterContainer& g2o::OptimizableGraph::parameters ( ) const
inline

Definition at line 652 of file optimizable_graph.h.

652 {return _parameters;}
ParameterContainer _parameters
void g2o::OptimizableGraph::pop ( )
virtual

pop (restore) the estimate of all variables from the stack

Reimplemented in g2o::SparseOptimizer.

Definition at line 333 of file optimizable_graph.cpp.

References g2o::HyperGraph::Edge::_vertices, and g2o::OptimizableGraph::Vertex::pop().

334 {
335  for (OptimizableGraph::VertexIDMap::iterator it=_vertices.begin(); it!=_vertices.end(); ++it) {
336  OptimizableGraph::Vertex* v= static_cast<OptimizableGraph::Vertex*>(it->second);
337  v->pop();
338  }
339 }
class G2O_CORE_API Vertex
VertexIDMap _vertices
Definition: hyper_graph.h:274
void g2o::OptimizableGraph::pop ( HyperGraph::VertexSet vset)
virtual

pop (restore) the estimate a subset of the variables from the stack

Reimplemented in g2o::SparseOptimizer.

Definition at line 357 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Vertex::pop().

358 {
359  for (HyperGraph::VertexSet::iterator it=vset.begin(); it!=vset.end(); ++it) {
360  OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*it);
361  v->pop();
362  }
363 }
class G2O_CORE_API Vertex
void g2o::OptimizableGraph::postIteration ( int  iter)
virtual

called at the end of an iteration (argument is the number of the iteration)

Definition at line 844 of file optimizable_graph.cpp.

References _graphActions, actions, and AT_POSTITERATION.

Referenced by g2o::SparseOptimizer::initializeOptimization(), and g2o::SparseOptimizer::optimize().

845 {
847  if (actions.size() > 0) {
848  HyperGraphAction::ParametersIteration params(iter);
849  for (HyperGraphActionSet::iterator it = actions.begin(); it != actions.end(); ++it) {
850  (*(*it))(this, &params);
851  }
852  }
853 }
Protocol The SLAM executable accepts actions
Definition: protocol.txt:3
std::set< HyperGraphAction * > HyperGraphActionSet
std::vector< HyperGraphActionSet > _graphActions
void g2o::OptimizableGraph::preIteration ( int  iter)
virtual

called at the beginning of an iteration (argument is the number of the iteration)

Definition at line 833 of file optimizable_graph.cpp.

References _graphActions, actions, and AT_PREITERATION.

Referenced by g2o::SparseOptimizer::initializeOptimization(), and g2o::SparseOptimizer::optimize().

834 {
836  if (actions.size() > 0) {
837  HyperGraphAction::ParametersIteration params(iter);
838  for (HyperGraphActionSet::iterator it = actions.begin(); it != actions.end(); ++it) {
839  (*(*it))(this, &params);
840  }
841  }
842 }
Protocol The SLAM executable accepts actions
Definition: protocol.txt:3
std::set< HyperGraphAction * > HyperGraphActionSet
std::vector< HyperGraphActionSet > _graphActions
void g2o::OptimizableGraph::push ( )
virtual

push the estimate of all variables onto a stack

Reimplemented in g2o::SparseOptimizer.

Definition at line 325 of file optimizable_graph.cpp.

References g2o::HyperGraph::Edge::_vertices, and g2o::OptimizableGraph::Vertex::push().

326 {
327  for (OptimizableGraph::VertexIDMap::iterator it=_vertices.begin(); it!=_vertices.end(); ++it) {
328  OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(it->second);
329  v->push();
330  }
331 }
class G2O_CORE_API Vertex
VertexIDMap _vertices
Definition: hyper_graph.h:274
void g2o::OptimizableGraph::push ( HyperGraph::VertexSet vset)
virtual

push the estimate of a subset of the variables onto a stack

Reimplemented in g2o::SparseOptimizer.

Definition at line 349 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Vertex::push().

350 {
351  for (HyperGraph::VertexSet::iterator it=vset.begin(); it!=vset.end(); ++it) {
352  OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*it);
353  v->push();
354  }
355 }
class G2O_CORE_API Vertex
bool g2o::OptimizableGraph::removePostIterationAction ( HyperGraphAction action)

remove an action that should no longer be execured after each iteration

Definition at line 872 of file optimizable_graph.cpp.

References _graphActions, and AT_POSTITERATION.

873 {
874  return _graphActions[AT_POSTITERATION].erase(action) > 0;
875 }
std::vector< HyperGraphActionSet > _graphActions
bool g2o::OptimizableGraph::removePreIterationAction ( HyperGraphAction action)

remove an action that should no longer be execured before each iteration

Definition at line 867 of file optimizable_graph.cpp.

References _graphActions, and AT_PREITERATION.

868 {
869  return _graphActions[AT_PREITERATION].erase(action) > 0;
870 }
std::vector< HyperGraphActionSet > _graphActions
virtual bool g2o::OptimizableGraph::save ( std::ostream &  os,
int  level = 0 
) const
virtual

save the graph to a stream. Again uses the Factory system.

Referenced by main(), and save().

bool g2o::OptimizableGraph::save ( const char *  filename,
int  level = 0 
) const

function provided for convenience, see save() above

Definition at line 639 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Edge::_parameters, g2o::HyperGraph::edges(), g2o::OptimizableGraph::Edge::level(), save(), saveEdge(), saveSubset(), saveVertex(), and g2o::HyperGraph::Edge::vertices().

640 {
641  ofstream ofs(filename);
642  if (!ofs)
643  return false;
644  return save(ofs, level);
645 }
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
bool g2o::OptimizableGraph::saveEdge ( std::ostream &  os,
OptimizableGraph::Edge e 
) const

Definition at line 920 of file optimizable_graph.cpp.

References _edge_has_id, g2o::HyperGraph::Edge::id(), g2o::Factory::instance(), saveUserData(), g2o::Factory::tag(), g2o::HyperGraph::UnassignedId, g2o::HyperGraph::DataContainer::userData(), g2o::HyperGraph::Edge::vertices(), and g2o::OptimizableGraph::Edge::write().

Referenced by save().

921 {
922  Factory* factory = Factory::instance();
923  string tag = factory->tag(e);
924  if (tag.size() > 0) {
925  os << tag << " ";
926  if (_edge_has_id)
927  os << e->id() << " ";
928  for (vector<HyperGraph::Vertex*>::const_iterator it = e->vertices().begin(); it != e->vertices().end(); ++it) {
929  int vertexId = (*it) ? (*it)->id() : HyperGraph::UnassignedId;
930  os << vertexId << " ";
931  }
932  e->write(os);
933  os << endl;
934  saveUserData(os, e->userData());
935  return os.good();
936  }
937  return false;
938 }
static Factory * instance()
return the instance
Definition: factory.cpp:61
bool saveUserData(std::ostream &os, HyperGraph::Data *v) const
static const int UnassignedId
Definition: hyper_graph.h:71
bool g2o::OptimizableGraph::saveParameter ( std::ostream &  os,
Parameter v 
) const

Definition at line 908 of file optimizable_graph.cpp.

References g2o::Parameter::id(), g2o::Factory::instance(), g2o::Factory::tag(), and g2o::Parameter::write().

909 {
910  Factory* factory = Factory::instance();
911  string tag = factory->tag(p);
912  if (tag.size() > 0) {
913  os << tag << " " << p->id() << " ";
914  p->write(os);
915  os << endl;
916  }
917  return os.good();
918 }
static Factory * instance()
return the instance
Definition: factory.cpp:61
bool g2o::OptimizableGraph::saveSubset ( std::ostream &  os,
HyperGraph::VertexSet vset,
int  level = 0 
)

save a subgraph to a stream. Again uses the Factory system.

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

bool g2o::OptimizableGraph::saveSubset ( std::ostream &  os,
HyperGraph::EdgeSet eset 
)

save a subgraph to a stream. Again uses the Factory system.

bool g2o::OptimizableGraph::saveUserData ( std::ostream &  os,
HyperGraph::Data v 
) const

Definition at line 877 of file optimizable_graph.cpp.

References g2o::Factory::instance(), g2o::HyperGraph::Data::next(), g2o::Factory::tag(), and g2o::HyperGraph::Data::write().

Referenced by saveEdge(), and saveVertex().

877  {
878  Factory* factory = Factory::instance();
879  while (d) { // write the data packet for the vertex
880  string tag = factory->tag(d);
881  if (tag.size() > 0) {
882  os << tag << " ";
883  d->write(os);
884  os << endl;
885  }
886  d=d->next();
887  }
888  return os.good();
889 }
static Factory * instance()
return the instance
Definition: factory.cpp:61
bool g2o::OptimizableGraph::saveVertex ( std::ostream &  os,
OptimizableGraph::Vertex v 
) const

Definition at line 891 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Vertex::fixed(), g2o::HyperGraph::Vertex::id(), g2o::Factory::instance(), saveUserData(), g2o::Factory::tag(), g2o::HyperGraph::DataContainer::userData(), and g2o::OptimizableGraph::Vertex::write().

Referenced by save().

892 {
893  Factory* factory = Factory::instance();
894  string tag = factory->tag(v);
895  if (tag.size() > 0) {
896  os << tag << " " << v->id() << " ";
897  v->write(os);
898  os << endl;
899  saveUserData(os, v->userData());
900  if (v->fixed()) {
901  os << "FIX " << v->id() << endl;
902  }
903  return os.good();
904  }
905  return false;
906 }
static Factory * instance()
return the instance
Definition: factory.cpp:61
bool saveUserData(std::ostream &os, HyperGraph::Data *v) const
bool g2o::OptimizableGraph::setEdgeVertex ( HyperGraph::Edge e,
int  pos,
HyperGraph::Vertex v 
)
virtual

overridden from HyperGraph, to mantain the bookkeeping of the caches/parameters and jacobian workspaces consistent upon a change in the veretx.

Returns
false if something goes wriong.

Reimplemented from g2o::HyperGraph.

Definition at line 289 of file optimizable_graph.cpp.

References _jacobianWorkspace, g2o::HyperGraph::Edge::numUndefinedVertices(), g2o::OptimizableGraph::Edge::resolveCaches(), g2o::OptimizableGraph::Edge::resolveParameters(), g2o::HyperGraph::setEdgeVertex(), and g2o::JacobianWorkspace::updateSize().

Referenced by anonymizeLandmarkEdge(), and anonymizePoseEdge().

289  {
290  if (! HyperGraph::setEdgeVertex(e,pos,v)){
291  return false;
292  }
293  if (!e->numUndefinedVertices()){
294 #ifndef NDEBUG
295  OptimizableGraph::Edge* ee = dynamic_cast<OptimizableGraph::Edge*>(e);
296  assert(ee && "Edge is not a OptimizableGraph::Edge");
297 #else
298  OptimizableGraph::Edge* ee = static_cast<OptimizableGraph::Edge*>(e);
299 #endif
300  if (! ee->resolveParameters()){
301  cerr << __FUNCTION__ << ": FATAL, cannot resolve parameters for edge " << e << endl;
302  return false;
303  }
304  if (! ee->resolveCaches()){
305  cerr << __FUNCTION__ << ": FATAL, cannot resolve caches for edge " << e << endl;
306  return false;
307  }
309  }
310  return true;
311  }
virtual bool setEdgeVertex(Edge *e, int pos, Vertex *v)
class G2O_CORE_API Edge
void updateSize(const HyperGraph::Edge *e)
JacobianWorkspace _jacobianWorkspace
void g2o::OptimizableGraph::setFixed ( HyperGraph::VertexSet vset,
bool  fixed 
)
virtual
void g2o::OptimizableGraph::setRenamedTypesFromString ( const std::string &  types)

set the renamed types lookup from a string, format is for example: VERTEX_CAM=VERTEX_SE3:EXPMAP,EDGE_PROJECT_P2MC=EDGE_PROJECT_XYZ:EXPMAP This will change the occurance of VERTEX_CAM in the file to VERTEX_SE3:EXPMAP

Definition at line 774 of file optimizable_graph.cpp.

References __PRETTY_FUNCTION__, _renamedTypesLookup, g2o::Factory::instance(), g2o::Factory::knowsTag(), g2o::strSplit(), and g2o::trim().

Referenced by main().

775 {
776  Factory* factory = Factory::instance();
777  vector<string> typesMap = strSplit(types, ",");
778  for (size_t i = 0; i < typesMap.size(); ++i) {
779  vector<string> m = strSplit(typesMap[i], "=");
780  if (m.size() != 2) {
781  cerr << __PRETTY_FUNCTION__ << ": unable to extract type map from " << typesMap[i] << endl;
782  continue;
783  }
784  string typeInFile = trim(m[0]);
785  string loadedType = trim(m[1]);
786  if (! factory->knowsTag(loadedType)) {
787  cerr << __PRETTY_FUNCTION__ << ": unknown type " << loadedType << endl;
788  continue;
789  }
790 
791  _renamedTypesLookup[typeInFile] = loadedType;
792  }
793 
794  cerr << "# load look up table" << endl;
795  for (std::map<std::string, std::string>::const_iterator it = _renamedTypesLookup.begin(); it != _renamedTypesLookup.end(); ++it) {
796  cerr << "#\t" << it->first << " -> " << it->second << endl;
797  }
798 }
stuff to open files and other unsorted components ProjectiveCamera types
#define __PRETTY_FUNCTION__
Definition: macros.h:89
static Factory * instance()
return the instance
Definition: factory.cpp:61
std::string trim(const std::string &s)
std::vector< std::string > strSplit(const std::string &str, const std::string &delimiters)
std::map< std::string, std::string > _renamedTypesLookup
bool g2o::OptimizableGraph::verifyInformationMatrices ( bool  verbose = false) const

verify that all the information of the edges are semi positive definite, i.e., all Eigenvalues are >= 0.

Parameters
verboseoutput edges with not PSD information matrix on cerr
Returns
true if all edges have PSD information matrix

Definition at line 946 of file optimizable_graph.cpp.

References g2o::OptimizableGraph::Edge::dimension(), g2o::HyperGraph::edges(), g2o::HyperGraph::Vertex::id(), g2o::OptimizableGraph::Edge::informationData(), g2o::HyperGraph::Edge::vertex(), and g2o::HyperGraph::Edge::vertices().

947 {
948  bool allEdgeOk = true;
949  Eigen::SelfAdjointEigenSolver<MatrixXD> eigenSolver;
950  for (OptimizableGraph::EdgeSet::const_iterator it = edges().begin(); it != edges().end(); ++it) {
951  OptimizableGraph::Edge* e = static_cast<OptimizableGraph::Edge*>(*it);
952  MatrixXD::MapType information(e->informationData(), e->dimension(), e->dimension());
953  // test on symmetry
954  bool isSymmetric = information.transpose() == information;
955  bool okay = isSymmetric;
956  if (isSymmetric) {
957  // compute the eigenvalues
958  eigenSolver.compute(information, Eigen::EigenvaluesOnly);
959  bool isSPD = eigenSolver.eigenvalues()(0) >= 0.;
960  okay = okay && isSPD;
961  }
962  allEdgeOk = allEdgeOk && okay;
963  if (! okay) {
964  if (verbose) {
965  if (! isSymmetric)
966  cerr << "Information Matrix for an edge is not symmetric:";
967  else
968  cerr << "Information Matrix for an edge is not SPD:";
969  for (size_t i = 0; i < e->vertices().size(); ++i)
970  cerr << " " << e->vertex(i)->id();
971  if (isSymmetric)
972  cerr << "\teigenvalues: " << eigenSolver.eigenvalues().transpose();
973  cerr << endl;
974  }
975  }
976  }
977  return allEdgeOk;
978 }
const EdgeSet & edges() const
Definition: hyper_graph.h:230
class G2O_CORE_API Edge
Vertex* g2o::OptimizableGraph::vertex ( int  id)
inline

returns the vertex number id appropriately casted

Definition at line 496 of file optimizable_graph.h.

References g2o::HyperGraph::vertex().

Referenced by g2o::G2oSlamInterface::addEdge(), g2o::G2oSlamInterface::fixNode(), main(), g2o::G2oSlamInterface::queryState(), g2o::Gm2dlIO::readGm2dl(), g2o::SolverSLAM2DLinear::solveOrientation(), g2o::Gm2dlIO::updateLaserData(), and g2o::VertexLine2D::write().

496 { return reinterpret_cast<Vertex*>(HyperGraph::vertex(id));}
Vertex * vertex(int id)
returns a vertex id in the hyper-graph, or 0 if the vertex id is not present
Definition: hyper_graph.cpp:78
class G2O_CORE_API Vertex
const Vertex* g2o::OptimizableGraph::vertex ( int  id) const
inline

returns the vertex number id appropriately casted

Definition at line 499 of file optimizable_graph.h.

References g2o::HyperGraph::vertex().

499 { return reinterpret_cast<const Vertex*>(HyperGraph::vertex(id));}
Vertex * vertex(int id)
returns a vertex id in the hyper-graph, or 0 if the vertex id is not present
Definition: hyper_graph.cpp:78
class G2O_CORE_API Vertex

Member Data Documentation

bool g2o::OptimizableGraph::_edge_has_id
protected

Definition at line 660 of file optimizable_graph.h.

Referenced by OptimizableGraph(), saveEdge(), and setFixed().

std::vector<HyperGraphActionSet> g2o::OptimizableGraph::_graphActions
protected
JacobianWorkspace g2o::OptimizableGraph::_jacobianWorkspace
protected
long long g2o::OptimizableGraph::_nextEdgeId
protected

Definition at line 656 of file optimizable_graph.h.

Referenced by addEdge(), and OptimizableGraph().

ParameterContainer g2o::OptimizableGraph::_parameters
protected

Definition at line 662 of file optimizable_graph.h.

std::map<std::string, std::string> g2o::OptimizableGraph::_renamedTypesLookup
protected

Definition at line 655 of file optimizable_graph.h.

Referenced by setFixed(), and setRenamedTypesFromString().

Definition at line 76 of file optimizable_graph.h.

Definition at line 75 of file optimizable_graph.h.


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