g2o
Loading...
Searching...
No Matches
robust_kernel_factory.cpp
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
28
29#include <cassert>
30
31#include "g2o/stuff/logger.h"
32
33using namespace std;
34
35namespace g2o {
36
37std::unique_ptr<RobustKernelFactory> RobustKernelFactory::factoryInstance;
38
46
48 const std::string& tag, const AbstractRobustKernelCreator::Ptr& c) {
49 CreatorMap::const_iterator foundIt = _creator.find(tag);
50 if (foundIt != _creator.end()) {
51 G2O_WARN("RobustKernelFactory WARNING: Overwriting robust kernel tag {}",
52 tag);
53 assert(0);
54 }
55
56 _creator[tag] = c;
57}
58
59void RobustKernelFactory::unregisterType(const std::string& tag) {
60 CreatorMap::iterator tagPosition = _creator.find(tag);
61 if (tagPosition != _creator.end()) {
62 _creator.erase(tagPosition);
63 }
64}
65
66RobustKernel* RobustKernelFactory::construct(const std::string& tag) const {
67 CreatorMap::const_iterator foundIt = _creator.find(tag);
68 if (foundIt != _creator.end()) {
69 return foundIt->second->construct();
70 }
71 return nullptr;
72}
73
75 const std::string& tag) const {
76 CreatorMap::const_iterator foundIt = _creator.find(tag);
77 if (foundIt != _creator.end()) {
78 return foundIt->second.get();
79 }
80 return nullptr;
81}
82
84 std::vector<std::string>& types) const {
85 types.clear();
86 for (CreatorMap::const_iterator it = _creator.begin(); it != _creator.end();
87 ++it)
88 types.push_back(it->first);
89}
90
92 std::unique_ptr<RobustKernelFactory> aux;
93 factoryInstance.swap(aux);
94}
95
96} // namespace g2o
Abstract interface for allocating a robust kernel.
std::shared_ptr< AbstractRobustKernelCreator > Ptr
create robust kernels based on their human readable name
RobustKernel * construct(const std::string &tag) const
void fillKnownKernels(std::vector< std::string > &types) const
void registerRobustKernel(const std::string &tag, const AbstractRobustKernelCreator::Ptr &c)
AbstractRobustKernelCreator * creator(const std::string &tag) const
static void destroy()
free the instance
static RobustKernelFactory * instance()
return the instance
static std::unique_ptr< RobustKernelFactory > factoryInstance
void unregisterType(const std::string &tag)
CreatorMap _creator
look-up map for the existing creators
base for all robust cost functions
#define G2O_WARN(...)
Definition logger.h:88
Definition jet.h:876