g2o
Loading...
Searching...
No Matches
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 ()
 

Protected Member Functions

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

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

◆ Cache()

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

Definition at line 44 of file cache.cpp.

45 : _updateNeeded(true), _parameters(parameters_), _container(container_) {}
CacheContainer * _container
Definition cache.h:105
bool _updateNeeded
Definition cache.h:102
ParameterVector _parameters
Definition cache.h:103

Member Function Documentation

◆ container()

CacheContainer * g2o::Cache::container ( )

Definition at line 67 of file cache.cpp.

67{ return _container; }

References _container.

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

◆ elementType()

virtual HyperGraph::HyperGraphElementType g2o::Cache::elementType ( ) const
inlinevirtual

returns the type of the graph element, see HyperGraphElementType

Implements g2o::HyperGraph::HyperGraphElement.

Definition at line 70 of file cache.h.

70 {
71 return HyperGraph::HGET_CACHE;
72 }

◆ graph()

OptimizableGraph * g2o::Cache::graph ( )

Definition at line 62 of file cache.cpp.

62 {
63 if (container()) return container()->graph();
64 return nullptr;
65}
OptimizableGraph * graph()
Definition cache.cpp:145
CacheContainer * container()
Definition cache.cpp:67

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

◆ installDependency()

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 86 of file cache.cpp.

87 {
88 ParameterVector pv(parameterIndices.size());
89 for (size_t i = 0; i < parameterIndices.size(); i++) {
90 if (parameterIndices[i] < 0 ||
91 parameterIndices[i] >= (int)_parameters.size())
92 return nullptr;
93 pv[i] = _parameters[parameterIndices[i]];
94 }
95 CacheKey k(type_, pv);
96 if (!container()) return nullptr;
97 Cache* c = container()->findCache(k);
98 if (!c) {
99 c = container()->createCache(k);
100 }
101 if (c) _parentCaches.push_back(c);
102 return c;
103}
Cache * createCache(const Cache::CacheKey &key)
Definition cache.cpp:118
Cache * findCache(const Cache::CacheKey &key)
Definition cache.cpp:112
std::vector< Cache * > _parentCaches
Definition cache.h:104
Cache(CacheContainer *container_=0, const ParameterVector &parameters_=ParameterVector())
Definition cache.cpp:44
std::vector< Parameter * > ParameterVector
Definition parameter.h:54

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

◆ key()

Cache::CacheKey g2o::Cache::key ( ) const

Definition at line 71 of file cache.cpp.

71 {
72 Factory* factory = Factory::instance();
73 return CacheKey(factory->tag(this), _parameters);
74};
static Factory * instance()
return the instance
Definition factory.cpp:46

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

◆ parameters()

ParameterVector & g2o::Cache::parameters ( )

Definition at line 69 of file cache.cpp.

69{ return _parameters; }

References _parameters.

◆ resolveDependencies()

bool g2o::Cache::resolveDependencies ( )
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::tutorial::CacheSE2Offset, g2o::CacheSE2Offset, g2o::CacheCamera, and g2o::CacheSE3Offset.

Definition at line 105 of file cache.cpp.

105{ return true; }

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

◆ update()

void g2o::Cache::update ( )

Definition at line 76 of file cache.cpp.

76 {
77 if (!_updateNeeded) return;
78 for (std::vector<Cache*>::iterator it = _parentCaches.begin();
79 it != _parentCaches.end(); ++it) {
80 (*it)->update();
81 }
82 updateImpl();
83 _updateNeeded = false;
84}
virtual void updateImpl()=0
redefine this to do the update

References _parentCaches, _updateNeeded, and updateImpl().

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

◆ updateImpl()

virtual void g2o::Cache::updateImpl ( )
protectedpure virtual

redefine this to do the update

Implemented in g2o::tutorial::CacheSE2Offset, g2o::CacheSE2Offset, g2o::CacheCamera, and g2o::CacheSE3Offset.

Referenced by update().

◆ vertex()

OptimizableGraph::Vertex * g2o::Cache::vertex ( )

Definition at line 57 of file cache.cpp.

57 {
58 if (container()) return container()->vertex();
59 return nullptr;
60}
OptimizableGraph::Vertex * vertex()
Definition cache.cpp:143

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

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

Friends And Related Symbol Documentation

◆ CacheContainer

friend class CacheContainer
friend

Definition at line 41 of file cache.h.

Member Data Documentation

◆ _container

CacheContainer* g2o::Cache::_container
protected

Definition at line 105 of file cache.h.

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

◆ _parameters

ParameterVector g2o::Cache::_parameters
protected

◆ _parentCaches

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

Definition at line 104 of file cache.h.

Referenced by installDependency(), and update().

◆ _updateNeeded

bool g2o::Cache::_updateNeeded
protected

Definition at line 102 of file cache.h.

Referenced by update().


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