g2o
Loading...
Searching...
No Matches
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 <iostream>
31#include <map>
32#include <memory>
33#include <string>
34#include <vector>
35
36#include "g2o/stuff/misc.h" // ForceLinker for the macros
37#include "g2o_core_api.h"
38
39namespace g2o {
40
41class RobustKernel;
42
47 public:
51 virtual RobustKernel* construct() = 0;
53 using Ptr = std::shared_ptr<AbstractRobustKernelCreator>;
54};
55
59template <typename T>
61 public:
62 RobustKernel* construct() { return new T; }
63};
64
69 public:
71 static RobustKernelFactory* instance();
72
75
77 static void destroy();
78
82 void registerRobustKernel(const std::string& tag,
84
88 void unregisterType(const std::string& tag);
89
93 RobustKernel* construct(const std::string& tag) const;
94
98 AbstractRobustKernelCreator* creator(const std::string& tag) const;
99
103 void fillKnownKernels(std::vector<std::string>& types) const;
104
105 protected:
106 typedef std::map<std::string, AbstractRobustKernelCreator::Ptr> CreatorMap;
108
110
111 private:
112 static std::unique_ptr<RobustKernelFactory> factoryInstance;
113};
114
115template <typename T>
117 public:
122
123 private:
124 std::string _name;
125};
126
127} // end namespace g2o
128
129#if defined _MSC_VER && defined G2O_SHARED_LIBS
130#define G2O_ROBUST_KERNEL_FACTORY_EXPORT __declspec(dllexport)
131#define G2O_ROBUST_KERNEL_FACTORY_IMPORT __declspec(dllimport)
132#else
133#define G2O_ROBUST_KERNEL_FACTORY_EXPORT
134#define G2O_ROBUST_KERNEL_FACTORY_IMPORT
135#endif
136
137// These macros are used to automate registering of robust kernels and forcing
138// linkage
139#define G2O_REGISTER_ROBUST_KERNEL(name, classname) \
140 extern "C" void G2O_ROBUST_KERNEL_FACTORY_EXPORT \
141 g2o_robust_kernel_##classname(void) {} \
142 static g2o::RegisterRobustKernelProxy<classname> \
143 g_robust_kernel_proxy_##classname(#name);
144
145#define G2O_USE_ROBUST_KERNEL(classname) \
146 extern "C" void G2O_ROBUST_KERNEL_FACTORY_IMPORT \
147 g2o_robust_kernel_##classname(void); \
148 static g2o::ForceLinker g2o_force_robust_kernel_link_##classname( \
149 g2o_robust_kernel_##classname);
150
151#endif
Abstract interface for allocating a robust kernel.
std::shared_ptr< AbstractRobustKernelCreator > Ptr
virtual RobustKernel * construct()=0
RegisterRobustKernelProxy(const std::string &name)
templatized creator class which creates graph elements
create robust kernels based on their human readable name
void registerRobustKernel(const std::string &tag, const AbstractRobustKernelCreator::Ptr &c)
RobustKernelFactory & operator=(RobustKernelFactory const &)=delete
std::map< std::string, AbstractRobustKernelCreator::Ptr > CreatorMap
static RobustKernelFactory * instance()
return the instance
RobustKernelFactory(RobustKernelFactory const &)=delete
static std::unique_ptr< RobustKernelFactory > factoryInstance
CreatorMap _creator
look-up map for the existing creators
base for all robust cost functions
#define G2O_CORE_API
some general case utility functions