g2o
Loading...
Searching...
No Matches
optimization_algorithm_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_OPTIMIZATION_ALGORITHM_FACTORY_H
28#define G2O_OPTIMIZATION_ALGORITHM_FACTORY_H
29
30#include <iostream>
31#include <list>
32#include <memory>
33
34#include "g2o/config.h"
35#include "g2o/stuff/misc.h" // ForceLinker for the macros
36#include "g2o_core_api.h"
38
39// define to get some verbose output
40// #define G2O_DEBUG_OPTIMIZATION_ALGORITHM_FACTORY
41
42namespace g2o {
43
44// forward decl
46
65
74 public:
75 typedef std::list<std::shared_ptr<AbstractOptimizationAlgorithmCreator>>
77
79 static OptimizationAlgorithmFactory* instance();
80
82 static void destroy();
83
86 delete;
87
91 void registerSolver(
92 const std::shared_ptr<AbstractOptimizationAlgorithmCreator>& c);
93
97 void unregisterSolver(
98 const std::shared_ptr<AbstractOptimizationAlgorithmCreator>& c);
99
103 OptimizationAlgorithm* construct(
104 const std::string& tag,
105 OptimizationAlgorithmProperty& solverProperty) const;
106
108 void listSolvers(std::ostream& os) const;
109
111 const CreatorList& creatorList() const { return _creator; }
112
113 protected:
115
117
118 CreatorList::const_iterator findSolver(const std::string& name) const;
119 CreatorList::iterator findSolver(const std::string& name);
120
121 private:
122 static std::unique_ptr<OptimizationAlgorithmFactory> factoryInstance;
123};
124
126 public:
128 _creator.reset(c);
129#ifdef G2O_DEBUG_OPTIMIZATION_ALGORITHM_FACTORY
130 std::cout << __FUNCTION__ << ": Registering " << _creator->property().name
131 << " of type " << typeid(*_creator).name() << std::endl;
132#endif
134 }
135
136 private:
137 std::shared_ptr<AbstractOptimizationAlgorithmCreator> _creator;
138};
139
140} // namespace g2o
141
142#if defined _MSC_VER && defined G2O_SHARED_LIBS
143#define G2O_OAF_EXPORT __declspec(dllexport)
144#define G2O_OAF_IMPORT __declspec(dllimport)
145#else
146#define G2O_OAF_EXPORT
147#define G2O_OAF_IMPORT
148#endif
149
160#define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname) \
161 extern "C" void G2O_OAF_EXPORT g2o_optimization_library_##libraryname(void) {}
162
170#define G2O_USE_OPTIMIZATION_LIBRARY(libraryname) \
171 extern "C" void G2O_OAF_IMPORT g2o_optimization_library_##libraryname(void); \
172 static g2o::ForceLinker \
173 g2o_force_optimization_algorithm_library_##libraryname( \
174 g2o_optimization_library_##libraryname);
175
181#define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance) \
182 extern "C" void G2O_OAF_EXPORT g2o_optimization_algorithm_##optimizername( \
183 void) {} \
184 static g2o::RegisterOptimizationAlgorithmProxy \
185 g_optimization_algorithm_proxy_##optimizername(instance);
186
192#define G2O_USE_OPTIMIZATION_ALGORITHM(optimizername) \
193 extern "C" void G2O_OAF_IMPORT g2o_optimization_algorithm_##optimizername( \
194 void); \
195 static g2o::ForceLinker \
196 g2o_force_optimization_algorithm_link_##optimizername( \
197 g2o_optimization_algorithm_##optimizername);
198
199#endif
base for allocating an optimization algorithm
virtual OptimizationAlgorithm * construct()=0
allocate a solver operating on optimizer, re-implement for your creator
const OptimizationAlgorithmProperty & property() const
return the properties of the solver
create solvers based on their short name
void registerSolver(const std::shared_ptr< AbstractOptimizationAlgorithmCreator > &c)
const CreatorList & creatorList() const
return the underlying list of creators
OptimizationAlgorithmFactory & operator=(OptimizationAlgorithmFactory const &)=delete
OptimizationAlgorithmFactory(OptimizationAlgorithmFactory const &)=delete
static OptimizationAlgorithmFactory * instance()
return the instance
std::list< std::shared_ptr< AbstractOptimizationAlgorithmCreator > > CreatorList
static std::unique_ptr< OptimizationAlgorithmFactory > factoryInstance
Generic interface for a non-linear solver operating on a graph.
std::shared_ptr< AbstractOptimizationAlgorithmCreator > _creator
RegisterOptimizationAlgorithmProxy(AbstractOptimizationAlgorithmCreator *c)
#define G2O_CORE_API
some general case utility functions