g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
core
cache.h
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
7
// met:
8
//
9
// * Redistributions of source code must retain the above copyright notice,
10
// this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above copyright
12
// notice, this list of conditions and the following disclaimer in the
13
// documentation and/or other materials provided with the distribution.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27
#ifndef G2O_CACHE_HH_
28
#define G2O_CACHE_HH_
29
30
#include <map>
31
32
#include "
g2o_core_api.h
"
33
#include "
optimizable_graph.h
"
34
35
namespace
g2o
{
36
37
class
CacheContainer
;
38
39
class
G2O_CORE_API
Cache
:
public
HyperGraph::HyperGraphElement
{
40
public
:
41
friend
class
CacheContainer
;
42
class
G2O_CORE_API
CacheKey
{
43
public
:
44
friend
class
CacheContainer
;
45
CacheKey
();
46
CacheKey
(
const
std::string& type_,
const
ParameterVector
& parameters_);
47
48
bool
operator<
(
const
CacheKey
& c)
const
;
49
50
const
std::string&
type
()
const
{
return
_type
; }
51
const
ParameterVector
&
parameters
()
const
{
return
_parameters
; }
52
53
protected
:
54
std::string
_type
;
55
ParameterVector
_parameters
;
56
};
57
58
Cache
(
CacheContainer
* container_ = 0,
59
const
ParameterVector
& parameters_ =
ParameterVector
());
60
61
CacheKey
key
()
const
;
62
63
OptimizableGraph::Vertex
*
vertex
();
64
OptimizableGraph
*
graph
();
65
CacheContainer
*
container
();
66
ParameterVector
&
parameters
();
67
68
void
update
();
69
70
virtual
HyperGraph::HyperGraphElementType
elementType
()
const
{
71
return
HyperGraph::HGET_CACHE;
72
}
73
74
protected
:
76
virtual
void
updateImpl
() = 0;
77
90
Cache
*
installDependency
(
const
std::string& type_,
91
const
std::vector<int>& parameterIndices);
92
100
virtual
bool
resolveDependencies
();
101
102
bool
_updateNeeded
;
103
ParameterVector
_parameters
;
104
std::vector<Cache*>
_parentCaches
;
105
CacheContainer
*
_container
;
106
};
107
108
class
G2O_CORE_API
CacheContainer
:
public
std::map<Cache::CacheKey, Cache*> {
109
public
:
110
CacheContainer
(
OptimizableGraph::Vertex
* vertex_);
111
virtual
~CacheContainer
();
112
OptimizableGraph::Vertex
*
vertex
();
113
OptimizableGraph
*
graph
();
114
Cache
*
findCache
(
const
Cache::CacheKey
& key);
115
Cache
*
createCache
(
const
Cache::CacheKey
& key);
116
void
setUpdateNeeded
(
bool
needUpdate =
true
);
117
void
update
();
118
119
protected
:
120
OptimizableGraph::Vertex
*
_vertex
;
121
bool
_updateNeeded
;
122
};
123
124
template
<
typename
CacheType>
125
void
OptimizableGraph::Edge::resolveCache
(CacheType*& cache,
126
OptimizableGraph::Vertex
* v,
127
const
std::string& type_,
128
const
ParameterVector
& parameters_) {
129
cache = 0;
130
CacheContainer
* container = v->
cacheContainer
();
131
Cache::CacheKey
key(type_, parameters_);
132
Cache
* c = container->
findCache
(key);
133
if
(!c) {
134
c = container->
createCache
(key);
135
}
136
if
(c) {
137
cache =
dynamic_cast<
CacheType*
>
(c);
138
}
139
}
140
141
}
// namespace g2o
142
143
#endif
g2o::CacheContainer
Definition
cache.h:108
g2o::CacheContainer::createCache
Cache * createCache(const Cache::CacheKey &key)
Definition
cache.cpp:118
g2o::CacheContainer::setUpdateNeeded
void setUpdateNeeded(bool needUpdate=true)
Definition
cache.cpp:157
g2o::CacheContainer::findCache
Cache * findCache(const Cache::CacheKey &key)
Definition
cache.cpp:112
g2o::CacheContainer::graph
OptimizableGraph * graph()
Definition
cache.cpp:145
g2o::CacheContainer::_updateNeeded
bool _updateNeeded
Definition
cache.h:121
g2o::CacheContainer::_vertex
OptimizableGraph::Vertex * _vertex
Definition
cache.h:120
g2o::CacheContainer::update
void update()
Definition
cache.cpp:150
g2o::CacheContainer::vertex
OptimizableGraph::Vertex * vertex()
Definition
cache.cpp:143
g2o::CacheContainer::CacheContainer
CacheContainer(OptimizableGraph::Vertex *vertex_)
Definition
cache.cpp:107
g2o::Cache::CacheKey
Definition
cache.h:42
g2o::Cache::CacheKey::operator<
bool operator<(const CacheKey &c) const
Definition
cache.cpp:47
g2o::Cache::CacheKey::_parameters
ParameterVector _parameters
Definition
cache.h:55
g2o::Cache::CacheKey::CacheKey
CacheKey()
Definition
cache.cpp:38
g2o::Cache::CacheKey::type
const std::string & type() const
Definition
cache.h:50
g2o::Cache::CacheKey::CacheContainer
friend class CacheContainer
Definition
cache.h:44
g2o::Cache::CacheKey::_type
std::string _type
Definition
cache.h:54
g2o::Cache::CacheKey::parameters
const ParameterVector & parameters() const
Definition
cache.h:51
g2o::Cache
Definition
cache.h:39
g2o::Cache::_container
CacheContainer * _container
Definition
cache.h:105
g2o::Cache::_parentCaches
std::vector< Cache * > _parentCaches
Definition
cache.h:104
g2o::Cache::parameters
ParameterVector & parameters()
Definition
cache.cpp:69
g2o::Cache::graph
OptimizableGraph * graph()
Definition
cache.cpp:62
g2o::Cache::container
CacheContainer * container()
Definition
cache.cpp:67
g2o::Cache::_updateNeeded
bool _updateNeeded
Definition
cache.h:102
g2o::Cache::key
CacheKey key() const
Definition
cache.cpp:71
g2o::Cache::installDependency
Cache * installDependency(const std::string &type_, const std::vector< int > ¶meterIndices)
Definition
cache.cpp:86
g2o::Cache::CacheContainer
friend class CacheContainer
Definition
cache.h:41
g2o::Cache::resolveDependencies
virtual bool resolveDependencies()
Definition
cache.cpp:105
g2o::Cache::update
void update()
Definition
cache.cpp:76
g2o::Cache::vertex
OptimizableGraph::Vertex * vertex()
Definition
cache.cpp:57
g2o::Cache::elementType
virtual HyperGraph::HyperGraphElementType elementType() const
Definition
cache.h:70
g2o::Cache::_parameters
ParameterVector _parameters
Definition
cache.h:103
g2o::Cache::Cache
Cache(CacheContainer *container_=0, const ParameterVector ¶meters_=ParameterVector())
Definition
cache.cpp:44
g2o::Cache::updateImpl
virtual void updateImpl()=0
redefine this to do the update
g2o::OptimizableGraph::Edge::resolveCache
void resolveCache(CacheType *&cache, OptimizableGraph::Vertex *, const std::string &_type, const ParameterVector ¶meters)
Definition
cache.h:125
g2o::OptimizableGraph::Vertex
A general case Vertex for optimization.
Definition
optimizable_graph.h:108
g2o::OptimizableGraph::Vertex::cacheContainer
CacheContainer * cacheContainer()
Definition
optimizable_graph.cpp:66
g2o_core_api.h
G2O_CORE_API
#define G2O_CORE_API
Definition
g2o_core_api.h:29
g2o
Definition
dl_wrapper.cpp:55
g2o::ParameterVector
std::vector< Parameter * > ParameterVector
Definition
parameter.h:54
optimizable_graph.h
g2o::HyperGraph::HyperGraphElement
Definition
hyper_graph.h:80
g2o::OptimizableGraph
Definition
optimizable_graph.h:62
Generated on
for g2o by
1.17.0