g2o
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_OPTMIZATION_ALGORITHM_PROPERTY_H
28 #define G2O_OPTMIZATION_ALGORITHM_PROPERTY_H
29 
30 #include "g2o/config.h"
31 #include "g2o/stuff/misc.h"
33 
34 #include <list>
35 #include <iostream>
36 #include <typeinfo>
37 
38 #include "g2o_core_api.h"
39 
40 // define to get some verbose output
41 //#define G2O_DEBUG_OPTIMIZATION_ALGORITHM_FACTORY
42 
43 namespace g2o {
44 
45  // forward decl
48 
56  {
57  public:
61  virtual OptimizationAlgorithm* construct() = 0;
63  const OptimizationAlgorithmProperty& property() const { return _property;}
64  protected:
66  };
67 
76  {
77  public:
78  typedef std::list<AbstractOptimizationAlgorithmCreator*> CreatorList;
79 
81  static OptimizationAlgorithmFactory* instance();
82 
84  static void destroy();
85 
89  void registerSolver(AbstractOptimizationAlgorithmCreator* c);
90 
94  void unregisterSolver(AbstractOptimizationAlgorithmCreator* c);
95 
99  OptimizationAlgorithm* construct(const std::string& tag, OptimizationAlgorithmProperty& solverProperty) const;
100 
102  void listSolvers(std::ostream& os) const;
103 
105  const CreatorList& creatorList() const { return _creator;}
106 
107  protected:
110 
111  CreatorList _creator;
112 
113  CreatorList::const_iterator findSolver(const std::string& name) const;
114  CreatorList::iterator findSolver(const std::string& name);
115 
116  private:
118  };
119 
121  {
122  public:
124  {
125  _creator = c;
126 #ifdef G2O_DEBUG_OPTIMIZATION_ALGORITHM_FACTORY
127  std::cout << __FUNCTION__ << ": Registering " << _creator->property().name << " of type " << typeid(*_creator).name() << std::endl;
128 #endif
130  }
131 
133  {
134 #ifdef G2O_DEBUG_OPTIMIZATION_ALGORITHM_FACTORY
135  std::cout << __FUNCTION__ << ": Unregistering " << _creator->property().name << std::endl;
136 #endif
138  }
139  private:
141  };
142 
143 }
144 
145 #if defined _MSC_VER && defined G2O_SHARED_LIBS
146 # define G2O_OAF_EXPORT __declspec(dllexport)
147 # define G2O_OAF_IMPORT __declspec(dllimport)
148 #else
149 # define G2O_OAF_EXPORT
150 # define G2O_OAF_IMPORT
151 #endif
152 
163 #define G2O_REGISTER_OPTIMIZATION_LIBRARY(libraryname) \
164  extern "C" void G2O_OAF_EXPORT g2o_optimization_library_##libraryname(void) {}
165 
173 #define G2O_USE_OPTIMIZATION_LIBRARY(libraryname) \
174  extern "C" void G2O_OAF_IMPORT g2o_optimization_library_##libraryname(void); \
175  static g2o::ForceLinker g2o_force_optimization_algorithm_library_##libraryname(g2o_optimization_library_##libraryname);
176 
182 #define G2O_REGISTER_OPTIMIZATION_ALGORITHM(optimizername, instance) \
183  extern "C" void G2O_OAF_EXPORT g2o_optimization_algorithm_##optimizername(void) {} \
184  static g2o::RegisterOptimizationAlgorithmProxy g_optimization_algorithm_proxy_##optimizername(instance);
185 
191 #define G2O_USE_OPTIMIZATION_ALGORITHM(optimizername) \
192  extern "C" void G2O_OAF_IMPORT g2o_optimization_algorithm_##optimizername(void); \
193  static g2o::ForceLinker g2o_force_optimization_algorithm_link_##optimizername(g2o_optimization_algorithm_##optimizername);
194 
195 #endif
some general case utility functions
std::string name
name of the solver, e.g., var
describe the properties of a solver
const OptimizationAlgorithmProperty & property() const
return the properties of the solver
static OptimizationAlgorithmFactory * factoryInstance
create solvers based on their short name
const CreatorList & creatorList() const
return the underlying list of creators
base for allocating an optimization algorithm
RegisterOptimizationAlgorithmProxy(AbstractOptimizationAlgorithmCreator *c)
void registerSolver(AbstractOptimizationAlgorithmCreator *c)
static OptimizationAlgorithmFactory * instance()
return the instance
AbstractOptimizationAlgorithmCreator * _creator
void unregisterSolver(AbstractOptimizationAlgorithmCreator *c)
std::list< AbstractOptimizationAlgorithmCreator * > CreatorList
Generic interface for a non-linear solver operating on a graph.
#define G2O_CORE_API
Definition: g2o_core_api.h:29