g2o
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 
27 #include "robust_kernel_factory.h"
28 #include "robust_kernel.h"
29 
30 #include <cassert>
31 
32 using namespace std;
33 
34 namespace g2o {
35 
36 RobustKernelFactory* RobustKernelFactory::factoryInstance = 0;
37 
38 RobustKernelFactory::RobustKernelFactory()
39 {
40 }
41 
42 RobustKernelFactory::~RobustKernelFactory()
43 {
44  for (CreatorMap::iterator it = _creator.begin(); it != _creator.end(); ++it) {
45  delete it->second;
46  }
47  _creator.clear();
48 }
49 
50 RobustKernelFactory* RobustKernelFactory::instance()
51 {
52  if (factoryInstance == 0) {
53  factoryInstance = new RobustKernelFactory;
54  }
55 
56  return factoryInstance;
57 }
58 
59 void RobustKernelFactory::registerRobustKernel(const std::string& tag, AbstractRobustKernelCreator* c)
60 {
61  CreatorMap::const_iterator foundIt = _creator.find(tag);
62  if (foundIt != _creator.end()) {
63  cerr << "RobustKernelFactory WARNING: Overwriting robust kernel tag " << tag << endl;
64  assert(0);
65  }
66 
67  _creator[tag] = c;
68 }
69 
70 void RobustKernelFactory::unregisterType(const std::string& tag)
71 {
72  CreatorMap::iterator tagPosition = _creator.find(tag);
73  if (tagPosition != _creator.end()) {
74  AbstractRobustKernelCreator* c = tagPosition->second;
75  delete c;
76  _creator.erase(tagPosition);
77  }
78 }
79 
80 RobustKernel* RobustKernelFactory::construct(const std::string& tag) const
81 {
82  CreatorMap::const_iterator foundIt = _creator.find(tag);
83  if (foundIt != _creator.end()) {
84  return foundIt->second->construct();
85  }
86  return 0;
87 }
88 
89 AbstractRobustKernelCreator* RobustKernelFactory::creator(const std::string& tag) const
90 {
91  CreatorMap::const_iterator foundIt = _creator.find(tag);
92  if (foundIt != _creator.end()) {
93  return foundIt->second;
94  }
95  return 0;
96 }
97 
98 void RobustKernelFactory::fillKnownKernels(std::vector<std::string>& types) const
99 {
100  types.clear();
101  for (CreatorMap::const_iterator it = _creator.begin(); it != _creator.end(); ++it)
102  types.push_back(it->first);
103 }
104 
105 void RobustKernelFactory::destroy()
106 {
107  delete factoryInstance;
108  factoryInstance = 0;
109 }
110 
111 } // end namespace
stuff to open files and other unsorted components ProjectiveCamera types
Abstract interface for allocating a robust kernel.
create robust kernels based on their human readable name
base for all robust cost functions
Definition: robust_kernel.h:48