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 "optimizable_graph.h"
33 
34 namespace g2o {
35 
36  class CacheContainer;
37 
39  {
40  public:
41  friend class CacheContainer;
42  class CacheKey
43  {
44  public:
45  friend class CacheContainer;
46  CacheKey();
47  CacheKey(const std::string& type_, const ParameterVector& parameters_);
48 
49  bool operator<(const CacheKey& c) const;
50 
51  const std::string& type() const { return _type;}
52  const ParameterVector& parameters() const { return _parameters;}
53 
54  protected:
55  std::string _type;
57  };
58 
59  Cache(CacheContainer* container_ = 0, const ParameterVector& parameters_ = ParameterVector());
60 
61  CacheKey key() const;
62 
67 
68  void update();
69 
71 
72  protected:
74  virtual void updateImpl() = 0;
75 
87  Cache* installDependency(const std::string& type_, const std::vector<int>& parameterIndices);
88 
95  virtual bool resolveDependancies();
96 
99  std::vector<Cache*> _parentCaches;
101  };
102 
103  class CacheContainer: public std::map<Cache::CacheKey, Cache*>
104  {
105  public:
107  virtual ~CacheContainer();
110  Cache* findCache(const Cache::CacheKey& key);
111  Cache* createCache(const Cache::CacheKey& key);
112  void setUpdateNeeded(bool needUpdate=true);
113  void update();
114  protected:
117  };
118 
119 
120  template <typename CacheType>
121  void OptimizableGraph::Edge::resolveCache(CacheType*& cache,
123  const std::string& type_,
124  const ParameterVector& parameters_)
125  {
126  cache = 0;
128  Cache::CacheKey key(type_, parameters_);
129  Cache* c = container->findCache(key);
130  if (!c) {
131  c = container->createCache(key);
132  }
133  if (c) {
134  cache = dynamic_cast<CacheType*>(c);
135  }
136  }
137 
138 } // end namespace
139 
140 #endif
bool _updateNeeded
Definition: cache.h:97
ParameterVector _parameters
Definition: cache.h:98
virtual bool resolveDependancies()
Definition: cache.cpp:114
Cache(CacheContainer *container_=0, const ParameterVector &parameters_=ParameterVector())
Definition: cache.cpp:46
OptimizableGraph::Vertex * _vertex
Definition: cache.h:115
CacheContainer * _container
Definition: cache.h:100
HyperGraphElementType
enum of all the types we have in our graphs
Definition: hyper_graph.h:65
OptimizableGraph::Vertex * vertex()
Definition: cache.cpp:59
virtual void updateImpl()=0
redefine this to do the update
CacheKey key() const
Definition: cache.cpp:79
Cache * findCache(const Cache::CacheKey &key)
Definition: cache.cpp:122
bool _updateNeeded
Definition: cache.h:116
ParameterVector _parameters
Definition: cache.h:56
Cache * installDependency(const std::string &type_, const std::vector< int > &parameterIndices)
Definition: cache.cpp:95
void resolveCache(CacheType *&cache, OptimizableGraph::Vertex *, const std::string &_type, const ParameterVector &parameters)
Definition: cache.h:121
bool operator<(const CacheKey &c) const
Definition: cache.cpp:51
std::vector< Parameter * > ParameterVector
Definition: parameter.h:52
virtual HyperGraph::HyperGraphElementType elementType() const
Definition: cache.h:70
friend class CacheContainer
Definition: cache.h:45
OptimizableGraph * graph()
Definition: cache.cpp:65
A general case Vertex for optimization.
CacheContainer * container()
Definition: cache.cpp:71
const std::string & type() const
Definition: cache.h:51
Cache * createCache(const Cache::CacheKey &key)
Definition: cache.cpp:129
std::vector< Cache * > _parentCaches
Definition: cache.h:99
const ParameterVector & parameters() const
Definition: cache.h:52
std::string _type
Definition: cache.h:55
void update()
Definition: cache.cpp:85


orb_slam2_with_maps_odom
Author(s): teng zhang
autogenerated on Fri Sep 25 2020 03:24:47