g2o
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 "g2o_core_api.h"
31 #include "g2o/stuff/misc.h"
32 
33 #include <string>
34 #include <map>
35 #include <vector>
36 #include <iostream>
37 
38 namespace g2o {
39 
40  class RobustKernel;
41 
46  {
47  public:
51  virtual RobustKernel* construct() = 0;
53  };
54 
58  template <typename T>
60  {
61  public:
62  RobustKernel* construct() { return new T;}
63  };
64 
69  {
70  public:
71 
73  static RobustKernelFactory* instance();
74 
76  static void destroy();
77 
81  void registerRobustKernel(const std::string& tag, AbstractRobustKernelCreator* c);
82 
86  void unregisterType(const std::string& tag);
87 
91  RobustKernel* construct(const std::string& tag) const;
92 
96  AbstractRobustKernelCreator* creator(const std::string& tag) const;
97 
101  void fillKnownKernels(std::vector<std::string>& types) const;
102 
103  protected:
104 
105  typedef std::map<std::string, AbstractRobustKernelCreator*> CreatorMap;
108 
109  CreatorMap _creator;
110 
111  private:
113  };
114 
115  template<typename T>
117  {
118  public:
119  RegisterRobustKernelProxy(const std::string& name) : _name(name)
120  {
122  }
123 
125  {
127  }
128 
129  private:
130  std::string _name;
131  };
132 
133 #if defined _MSC_VER && defined G2O_SHARED_LIBS
134 # define G2O_ROBUST_KERNEL_FACTORY_EXPORT __declspec(dllexport)
135 # define G2O_ROBUST_KERNEL_FACTORY_IMPORT __declspec(dllimport)
136 #else
137 # define G2O_ROBUST_KERNEL_FACTORY_EXPORT
138 # define G2O_ROBUST_KERNEL_FACTORY_IMPORT
139 #endif
140 
141  // These macros are used to automate registering of robust kernels and forcing linkage
142 #define G2O_REGISTER_ROBUST_KERNEL(name, classname) \
143  extern "C" void G2O_ROBUST_KERNEL_FACTORY_EXPORT g2o_robust_kernel_##classname(void) {} \
144  static g2o::RegisterRobustKernelProxy<classname> g_robust_kernel_proxy_##classname(#name);
145 
146 #define G2O_USE_ROBUST_KERNEL(classname) \
147  extern "C" void G2O_ROBUST_KERNEL_FACTORY_IMPORT g2o_robust_kernel_##classname(void); \
148  static g2o::TypeFunctionProxy proxy_##classname(g2o_robust_kernel_##classname);
149 
150 } // end namespace g2o
151 
152 #endif
void unregisterType(const std::string &tag)
stuff to open files and other unsorted components ProjectiveCamera types
RegisterRobustKernelProxy(const std::string &name)
some general case utility functions
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:48
templatized creator class which creates graph elements
void registerRobustKernel(const std::string &tag, AbstractRobustKernelCreator *c)
#define G2O_CORE_API
Definition: g2o_core_api.h:29