g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
core
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
39
namespace
g2o
{
40
41
class
RobustKernel
;
42
46
class
G2O_CORE_API
AbstractRobustKernelCreator
{
47
public
:
51
virtual
RobustKernel
*
construct
() = 0;
52
virtual
~AbstractRobustKernelCreator
() {}
53
using
Ptr
= std::shared_ptr<AbstractRobustKernelCreator>;
54
};
55
59
template
<
typename
T>
60
class
RobustKernelCreator
:
public
AbstractRobustKernelCreator
{
61
public
:
62
RobustKernel
*
construct
() {
return
new
T; }
63
};
64
68
class
G2O_CORE_API
RobustKernelFactory
{
69
public
:
71
static
RobustKernelFactory
*
instance
();
72
73
RobustKernelFactory
(
RobustKernelFactory
const
&) =
delete
;
74
RobustKernelFactory
&
operator=
(
RobustKernelFactory
const
&) =
delete
;
75
77
static
void
destroy
();
78
82
void
registerRobustKernel
(
const
std::string& tag,
83
const
AbstractRobustKernelCreator::Ptr
& c);
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
;
107
RobustKernelFactory
() =
default
;
108
109
CreatorMap
_creator
;
110
111
private
:
112
static
std::unique_ptr<RobustKernelFactory>
factoryInstance
;
113
};
114
115
template
<
typename
T>
116
class
RegisterRobustKernelProxy
{
117
public
:
118
RegisterRobustKernelProxy
(
const
std::string& name) :
_name
(name) {
119
RobustKernelFactory::instance
()->
registerRobustKernel
(
120
_name
,
AbstractRobustKernelCreator::Ptr
(
new
RobustKernelCreator<T>
()));
121
}
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
g2o::AbstractRobustKernelCreator
Abstract interface for allocating a robust kernel.
Definition
robust_kernel_factory.h:46
g2o::AbstractRobustKernelCreator::Ptr
std::shared_ptr< AbstractRobustKernelCreator > Ptr
Definition
robust_kernel_factory.h:53
g2o::AbstractRobustKernelCreator::construct
virtual RobustKernel * construct()=0
g2o::AbstractRobustKernelCreator::~AbstractRobustKernelCreator
virtual ~AbstractRobustKernelCreator()
Definition
robust_kernel_factory.h:52
g2o::RegisterRobustKernelProxy::RegisterRobustKernelProxy
RegisterRobustKernelProxy(const std::string &name)
Definition
robust_kernel_factory.h:118
g2o::RegisterRobustKernelProxy::_name
std::string _name
Definition
robust_kernel_factory.h:124
g2o::RobustKernelCreator
templatized creator class which creates graph elements
Definition
robust_kernel_factory.h:60
g2o::RobustKernelCreator::construct
RobustKernel * construct()
Definition
robust_kernel_factory.h:62
g2o::RobustKernelFactory::construct
RobustKernel * construct(const std::string &tag) const
Definition
robust_kernel_factory.cpp:66
g2o::RobustKernelFactory::fillKnownKernels
void fillKnownKernels(std::vector< std::string > &types) const
Definition
robust_kernel_factory.cpp:83
g2o::RobustKernelFactory::registerRobustKernel
void registerRobustKernel(const std::string &tag, const AbstractRobustKernelCreator::Ptr &c)
Definition
robust_kernel_factory.cpp:47
g2o::RobustKernelFactory::creator
AbstractRobustKernelCreator * creator(const std::string &tag) const
Definition
robust_kernel_factory.cpp:74
g2o::RobustKernelFactory::operator=
RobustKernelFactory & operator=(RobustKernelFactory const &)=delete
g2o::RobustKernelFactory::RobustKernelFactory
RobustKernelFactory()=default
g2o::RobustKernelFactory::CreatorMap
std::map< std::string, AbstractRobustKernelCreator::Ptr > CreatorMap
Definition
robust_kernel_factory.h:106
g2o::RobustKernelFactory::destroy
static void destroy()
free the instance
Definition
robust_kernel_factory.cpp:91
g2o::RobustKernelFactory::instance
static RobustKernelFactory * instance()
return the instance
Definition
robust_kernel_factory.cpp:39
g2o::RobustKernelFactory::RobustKernelFactory
RobustKernelFactory(RobustKernelFactory const &)=delete
g2o::RobustKernelFactory::factoryInstance
static std::unique_ptr< RobustKernelFactory > factoryInstance
Definition
robust_kernel_factory.h:112
g2o::RobustKernelFactory::unregisterType
void unregisterType(const std::string &tag)
Definition
robust_kernel_factory.cpp:59
g2o::RobustKernelFactory::_creator
CreatorMap _creator
look-up map for the existing creators
Definition
robust_kernel_factory.h:109
g2o::RobustKernel
base for all robust cost functions
Definition
robust_kernel.h:48
g2o_core_api.h
G2O_CORE_API
#define G2O_CORE_API
Definition
g2o_core_api.h:29
misc.h
some general case utility functions
g2o
Definition
dl_wrapper.cpp:55
Generated on
for g2o by
1.17.0