robust_kernel_factory.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_ROBUST_KERNEL_FACTORY_H
28 #define G2O_ROBUST_KERNEL_FACTORY_H
29 
30 #include "../stuff/misc.h"
31 
32 #include <string>
33 #include <map>
34 #include <vector>
35 #include <iostream>
36 
37 namespace g2o {
38 
39  class RobustKernel;
40 
45  {
46  public:
50  virtual RobustKernel* construct() = 0;
52  };
53 
57  template <typename T>
59  {
60  public:
61  RobustKernel* construct() { return new T;}
62  };
63 
68  {
69  public:
70 
72  static RobustKernelFactory* instance();
73 
75  static void destroy();
76 
80  void registerRobustKernel(const std::string& tag, AbstractRobustKernelCreator* c);
81 
85  void unregisterType(const std::string& tag);
86 
90  RobustKernel* construct(const std::string& tag) const;
91 
95  AbstractRobustKernelCreator* creator(const std::string& tag) const;
96 
100  void fillKnownKernels(std::vector<std::string>& types) const;
101 
102  protected:
103 
104  typedef std::map<std::string, AbstractRobustKernelCreator*> CreatorMap;
107 
108  CreatorMap _creator;
109 
110  private:
112  };
113 
114  template<typename T>
116  {
117  public:
118  RegisterRobustKernelProxy(const std::string& name) : _name(name)
119  {
121  }
122 
124  {
126  }
127 
128  private:
129  std::string _name;
130  };
131 
132 #if defined _MSC_VER && defined G2O_SHARED_LIBS
133 # define G2O_ROBUST_KERNEL_FACTORY_EXPORT __declspec(dllexport)
134 # define G2O_ROBUST_KERNEL_FACTORY_IMPORT __declspec(dllimport)
135 #else
136 # define G2O_ROBUST_KERNEL_FACTORY_EXPORT
137 # define G2O_ROBUST_KERNEL_FACTORY_IMPORT
138 #endif
139 
140  // These macros are used to automate registering of robust kernels and forcing linkage
141 #define G2O_REGISTER_ROBUST_KERNEL(name, classname) \
142  extern "C" void G2O_ROBUST_KERNEL_FACTORY_EXPORT g2o_robust_kernel_##classname(void) {} \
143  static g2o::RegisterRobustKernelProxy<classname> g_robust_kernel_proxy_##classname(#name);
144 
145 #define G2O_USE_ROBUST_KERNEL(classname) \
146  extern "C" void G2O_ROBUST_KERNEL_FACTORY_IMPORT g2o_robust_kernel_##classname(void); \
147  static g2o::TypeFunctionProxy proxy_##classname(g2o_robust_kernel_##classname);
148 
149 } // end namespace g2o
150 
151 #endif
void unregisterType(const std::string &tag)
RegisterRobustKernelProxy(const std::string &name)
Abstract interface for allocating a robust kernel.
CreatorMap _creator
look-up map for the existing creators
std::map< std::string, AbstractRobustKernelCreator * > CreatorMap
create robust kernels based on their human readable name
static RobustKernelFactory * instance()
return the instance
static RobustKernelFactory * factoryInstance
base for all robust cost functions
Definition: robust_kernel.h:51
templatized creator class which creates graph elements
void registerRobustKernel(const std::string &tag, AbstractRobustKernelCreator *c)
virtual RobustKernel * construct()=0


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05