g2o
Public Types | Public Member Functions | Protected Attributes | List of all members
g2o::JacobianWorkspace Class Reference

provide memory workspace for computing the Jacobians More...

#include <jacobian_workspace.h>

Public Types

typedef std::vector< VectorXD, Eigen::aligned_allocator< VectorXD > > WorkspaceVector
 

Public Member Functions

 JacobianWorkspace ()
 
 ~JacobianWorkspace ()
 
bool allocate ()
 
void updateSize (const HyperGraph::Edge *e)
 
void updateSize (const OptimizableGraph &graph)
 
void updateSize (int numVertices, int dimension)
 
double * workspaceForVertex (int vertexIndex)
 

Protected Attributes

WorkspaceVector _workspace
 the memory pre-allocated for computing the Jacobians More...
 
int _maxNumVertices
 the maximum number of vertices connected by a hyper-edge More...
 
int _maxDimension
 the maximum dimension (number of elements) for a Jacobian More...
 

Detailed Description

provide memory workspace for computing the Jacobians

The workspace is used by an OptimizableGraph to provide temporary memory for computing the Jacobian of the error functions. Before calling linearizeOplus on an edge, the workspace needs to be allocated by calling allocate().

Definition at line 52 of file jacobian_workspace.h.

Member Typedef Documentation

typedef std::vector<VectorXD, Eigen::aligned_allocator<VectorXD> > g2o::JacobianWorkspace::WorkspaceVector

Definition at line 55 of file jacobian_workspace.h.

Constructor & Destructor Documentation

g2o::JacobianWorkspace::JacobianWorkspace ( )

Definition at line 37 of file jacobian_workspace.cpp.

37  :
39 {
40 }
int _maxDimension
the maximum dimension (number of elements) for a Jacobian
int _maxNumVertices
the maximum number of vertices connected by a hyper-edge
g2o::JacobianWorkspace::~JacobianWorkspace ( )

Definition at line 42 of file jacobian_workspace.cpp.

43 {
44 }

Member Function Documentation

bool g2o::JacobianWorkspace::allocate ( )

allocate the workspace

Definition at line 46 of file jacobian_workspace.cpp.

References _maxDimension, _maxNumVertices, and _workspace.

Referenced by g2o::G2oSlamInterface::addEdge(), g2o::StructureOnlySolver< PointDoF >::calc(), g2o::SparseOptimizer::initializeOptimization(), and main().

47 {
48  //cerr << __PRETTY_FUNCTION__ << " " << PVAR(this) << " " << PVAR(_maxNumVertices) << " " << PVAR(_maxDimension) << endl;
49  if (_maxNumVertices <=0 || _maxDimension <= 0)
50  return false;
52  for (WorkspaceVector::iterator it = _workspace.begin(); it != _workspace.end(); ++it) {
53  it->resize(_maxDimension);
54  it->setZero();
55  }
56  return true;
57 }
int _maxDimension
the maximum dimension (number of elements) for a Jacobian
WorkspaceVector _workspace
the memory pre-allocated for computing the Jacobians
int _maxNumVertices
the maximum number of vertices connected by a hyper-edge
void g2o::JacobianWorkspace::updateSize ( const HyperGraph::Edge e)

update the maximum required workspace needed by taking into account this edge

Definition at line 59 of file jacobian_workspace.cpp.

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

Referenced by g2o::OptimizableGraph::addEdge(), g2o::StructureOnlySolver< PointDoF >::calc(), main(), g2o::OptimizableGraph::setEdgeVertex(), and updateSize().

60 {
61  const OptimizableGraph::Edge* e = static_cast<const OptimizableGraph::Edge*>(e_);
62  int errorDimension = e->dimension();
63  int numVertices = e->vertices().size();
64  int maxDimensionForEdge = -1;
65  for (int i = 0; i < numVertices; ++i) {
66  const OptimizableGraph::Vertex* v = static_cast<const OptimizableGraph::Vertex*>(e->vertex(i));
67  assert(v && "Edge has no vertex assigned");
68  maxDimensionForEdge = max(v->dimension() * errorDimension, maxDimensionForEdge);
69  }
70  _maxNumVertices = max(numVertices, _maxNumVertices);
71  _maxDimension = max(maxDimensionForEdge, _maxDimension);
72  //cerr << __PRETTY_FUNCTION__ << " " << PVAR(this) << " " << PVAR(_maxNumVertices) << " " << PVAR(_maxDimension) << endl;
73 }
int _maxDimension
the maximum dimension (number of elements) for a Jacobian
class G2O_CORE_API Vertex
class G2O_CORE_API Edge
int _maxNumVertices
the maximum number of vertices connected by a hyper-edge
void g2o::JacobianWorkspace::updateSize ( const OptimizableGraph graph)

update the required workspace by looking at a full graph

Definition at line 75 of file jacobian_workspace.cpp.

References g2o::HyperGraph::edges(), and updateSize().

76 {
77  for (OptimizableGraph::EdgeSet::const_iterator it = graph.edges().begin(); it != graph.edges().end(); ++it) {
78  const OptimizableGraph::Edge* e = static_cast<const OptimizableGraph::Edge*>(*it);
79  updateSize(e);
80  }
81 }
class G2O_CORE_API Edge
void updateSize(const HyperGraph::Edge *e)
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the graph
Definition: protocol.txt:7
void g2o::JacobianWorkspace::updateSize ( int  numVertices,
int  dimension 
)

manually update with the given parameters

Definition at line 83 of file jacobian_workspace.cpp.

References _maxDimension, and _maxNumVertices.

84 {
85  _maxNumVertices = max(numVertices, _maxNumVertices);
86  _maxDimension = max(dimension, _maxDimension);
87 }
int _maxDimension
the maximum dimension (number of elements) for a Jacobian
int _maxNumVertices
the maximum number of vertices connected by a hyper-edge
double* g2o::JacobianWorkspace::workspaceForVertex ( int  vertexIndex)
inline

return the workspace for a vertex in an edge

Definition at line 84 of file jacobian_workspace.h.

Referenced by g2o::BlockSolver< Traits >::buildSystem(), and main().

85  {
86  assert(vertexIndex >= 0 && (size_t)vertexIndex < _workspace.size() && "Index out of bounds");
87  return _workspace[vertexIndex].data();
88  }
WorkspaceVector _workspace
the memory pre-allocated for computing the Jacobians

Member Data Documentation

int g2o::JacobianWorkspace::_maxDimension
protected

the maximum dimension (number of elements) for a Jacobian

Definition at line 93 of file jacobian_workspace.h.

Referenced by allocate(), and updateSize().

int g2o::JacobianWorkspace::_maxNumVertices
protected

the maximum number of vertices connected by a hyper-edge

Definition at line 92 of file jacobian_workspace.h.

Referenced by allocate(), and updateSize().

WorkspaceVector g2o::JacobianWorkspace::_workspace
protected

the memory pre-allocated for computing the Jacobians

Definition at line 91 of file jacobian_workspace.h.

Referenced by allocate().


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