g2o
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
g2o::Cache Class Referenceabstract

#include <cache.h>

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

Classes

class  CacheKey
 

Public Member Functions

 Cache (CacheContainer *container_=0, const ParameterVector &parameters_=ParameterVector())
 
CacheKey key () const
 
OptimizableGraph::Vertexvertex ()
 
OptimizableGraphgraph ()
 
CacheContainercontainer ()
 
ParameterVectorparameters ()
 
void update ()
 
virtual HyperGraph::HyperGraphElementType elementType () const
 
- Public Member Functions inherited from g2o::HyperGraph::HyperGraphElement
virtual ~HyperGraphElement ()
 
HyperGraphElementclone () const
 

Protected Member Functions

virtual void updateImpl ()=0
 redefine this to do the update More...
 
CacheinstallDependency (const std::string &type_, const std::vector< int > &parameterIndices)
 
virtual bool resolveDependancies ()
 

Protected Attributes

bool _updateNeeded
 
ParameterVector _parameters
 
std::vector< Cache * > _parentCaches
 
CacheContainer_container
 

Friends

class CacheContainer
 

Detailed Description

Definition at line 39 of file cache.h.

Constructor & Destructor Documentation

g2o::Cache::Cache ( CacheContainer container_ = 0,
const ParameterVector parameters_ = ParameterVector() 
)

Definition at line 46 of file cache.cpp.

46  :
47  _updateNeeded(true), _parameters(parameters_), _container(container_)
48  {
49  }
bool _updateNeeded
Definition: cache.h:98
ParameterVector _parameters
Definition: cache.h:99
CacheContainer * _container
Definition: cache.h:101

Member Function Documentation

CacheContainer * g2o::Cache::container ( )

Definition at line 73 of file cache.cpp.

References _container.

Referenced by graph(), installDependency(), and vertex().

73  {
74  return _container;
75  }
CacheContainer * _container
Definition: cache.h:101
virtual HyperGraph::HyperGraphElementType g2o::Cache::elementType ( ) const
inlinevirtual

returns the type of the graph element, see HyperGraphElementType

Implements g2o::HyperGraph::HyperGraphElement.

Definition at line 71 of file cache.h.

References HGET_CACHE.

71 { return HyperGraph::HGET_CACHE;}
HGET_CACHE
Definition: hyper_graph.h:63
OptimizableGraph * g2o::Cache::graph ( )

Definition at line 67 of file cache.cpp.

References container(), and g2o::CacheContainer::graph().

67  {
68  if (container())
69  return container()->graph();
70  return 0;
71  }
OptimizableGraph * graph()
Definition: cache.cpp:159
CacheContainer * container()
Definition: cache.cpp:73
Cache * g2o::Cache::installDependency ( const std::string &  type_,
const std::vector< int > &  parameterIndices 
)
protected

this function installs and satisfies a cache

Parameters
type_the typename of the dependency
parameterIndicesa vector containing the indices if the parameters in _parameters that will be used to assemble the Key of the cache being created For example if I have a cache of type C2, having parameters "A, B, and C", and it depends on a cache of type C1 that depends on the parameters A and C, the parameterIndices should contain "0, 2", since they are the positions in the parameter vector of C2 of the parameters needed to construct C1.
Returns
the newly created cache

Definition at line 97 of file cache.cpp.

References _parameters, _parentCaches, container(), g2o::CacheContainer::createCache(), and g2o::CacheContainer::findCache().

97  {
98  ParameterVector pv(parameterIndices.size());
99  for (size_t i=0; i<parameterIndices.size(); i++){
100  if (parameterIndices[i]<0 || parameterIndices[i] >=(int)_parameters.size())
101  return 0;
102  pv[i]=_parameters[ parameterIndices[i] ];
103  }
104  CacheKey k(type_, pv);
105  if (!container())
106  return 0;
107  Cache* c=container()->findCache(k);
108  if (!c) {
109  c = container()->createCache(k);
110  }
111  if (c)
112  _parentCaches.push_back(c);
113  return c;
114  }
ParameterVector _parameters
Definition: cache.h:99
Cache(CacheContainer *container_=0, const ParameterVector &parameters_=ParameterVector())
Definition: cache.cpp:46
Cache * findCache(const Cache::CacheKey &key)
Definition: cache.cpp:124
std::vector< Parameter * > ParameterVector
Definition: parameter.h:52
CacheContainer * container()
Definition: cache.cpp:73
Cache * createCache(const Cache::CacheKey &key)
Definition: cache.cpp:131
std::vector< Cache * > _parentCaches
Definition: cache.h:100
Cache::CacheKey g2o::Cache::key ( ) const

Definition at line 81 of file cache.cpp.

References _parameters, g2o::Factory::instance(), and g2o::Factory::tag().

81  {
82  Factory* factory=Factory::instance();
83  return CacheKey(factory->tag(this), _parameters);
84  };
ParameterVector _parameters
Definition: cache.h:99
static Factory * instance()
return the instance
Definition: factory.cpp:61
ParameterVector & g2o::Cache::parameters ( )

Definition at line 77 of file cache.cpp.

References _parameters.

77  {
78  return _parameters;
79  }
ParameterVector _parameters
Definition: cache.h:99
bool g2o::Cache::resolveDependancies ( )
protectedvirtual

Function to be called from a cache that has dependencies. It just invokes a sequence of installDependency(). Although the caches returned are stored in the _parentCache vector, it is better that you redefine your own cache member variables, for better readability

Reimplemented in g2o::CacheSE2Offset, g2o::deprecated::CacheSE3Offset, g2o::CacheSE3Offset, g2o::deprecated::CacheCamera, g2o::CacheCamera, and g2o::tutorial::CacheSE2Offset.

Definition at line 116 of file cache.cpp.

Referenced by g2o::CacheContainer::createCache().

116  {
117  return true;
118  }
void g2o::Cache::update ( )

Definition at line 87 of file cache.cpp.

References _parentCaches, _updateNeeded, and updateImpl().

Referenced by g2o::CacheContainer::createCache(), and g2o::CacheContainer::update().

87  {
88  if (! _updateNeeded)
89  return;
90  for(std::vector<Cache*>::iterator it=_parentCaches.begin(); it!=_parentCaches.end(); it++){
91  (*it)->update();
92  }
93  updateImpl();
94  _updateNeeded=false;
95  }
bool _updateNeeded
Definition: cache.h:98
virtual void updateImpl()=0
redefine this to do the update
std::vector< Cache * > _parentCaches
Definition: cache.h:100
virtual void g2o::Cache::updateImpl ( )
protectedpure virtual
OptimizableGraph::Vertex * g2o::Cache::vertex ( )

Definition at line 61 of file cache.cpp.

References container(), and g2o::CacheContainer::vertex().

Referenced by g2o::CacheSE3Offset::updateImpl(), g2o::CacheSE2Offset::updateImpl(), and g2o::deprecated::CacheSE3Offset::updateImpl().

61  {
62  if (container() )
63  return container()->vertex();
64  return 0;
65  }
CacheContainer * container()
Definition: cache.cpp:73
OptimizableGraph::Vertex * vertex()
Definition: cache.cpp:155

Friends And Related Function Documentation

friend class CacheContainer
friend

Definition at line 42 of file cache.h.

Member Data Documentation

CacheContainer* g2o::Cache::_container
protected

Definition at line 101 of file cache.h.

Referenced by container(), and g2o::CacheContainer::createCache().

ParameterVector g2o::Cache::_parameters
protected
std::vector<Cache*> g2o::Cache::_parentCaches
protected

Definition at line 100 of file cache.h.

Referenced by installDependency(), and update().

bool g2o::Cache::_updateNeeded
protected

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