hyper_graph_action.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_HYPER_GRAPH_ACTION_H
28 #define G2O_HYPER_GRAPH_ACTION_H
29 
30 #include "hyper_graph.h"
31 #include "../stuff/property.h"
32 
33 #include <typeinfo>
34 #include <iosfwd>
35 #include <set>
36 #include <string>
37 #include <iostream>
38 
39 
40 // define to get verbose output
41 //#define G2O_DEBUG_ACTIONLIB
42 
43 namespace g2o {
44 
49  public:
50  class Parameters {
51  public:
52  virtual ~Parameters();
53  };
54 
56  public:
57  explicit ParametersIteration(int iter);
58  int iteration;
59  };
60 
61  virtual ~HyperGraphAction();
62 
66  virtual HyperGraphAction* operator()(const HyperGraph* graph, Parameters* parameters = 0);
67  };
68 
73  public:
74  struct Parameters{
75  virtual ~Parameters();
76  };
77  typedef std::map<std::string, HyperGraphElementAction*> ActionMap;
80  HyperGraphElementAction(const std::string& typeName_="");
81 
84 
86  virtual HyperGraphElementAction* operator()(const HyperGraph::HyperGraphElement* element, Parameters* parameters);
87 
89  virtual ~HyperGraphElementAction();
90 
92  const std::string& typeName() const { return _typeName;}
93 
95  const std::string& name() const{ return _name;}
96 
98  void setTypeName(const std::string& typeName_);
99 
100  protected:
101  std::string _typeName;
102  std::string _name;
103  };
104 
112  public:
114  HyperGraphElementActionCollection(const std::string& name_);
120  virtual HyperGraphElementAction* operator()(const HyperGraph::HyperGraphElement* element, Parameters* parameters);
121  ActionMap& actionMap() {return _actionMap;}
124  bool registerAction(HyperGraphElementAction* action);
125  bool unregisterAction(HyperGraphElementAction* action);
126  protected:
128  };
129 
137  public:
139  static HyperGraphActionLibrary* instance();
141  static void destroy();
142 
143  // returns a pointer to a collection indexed by name
144  HyperGraphElementAction* actionByName(const std::string& name);
145  // registers a basic action in the pool. If necessary a container is created
146  bool registerAction(HyperGraphElementAction* action);
147  bool unregisterAction(HyperGraphElementAction* action);
148 
149  inline HyperGraphElementAction::ActionMap& actionMap() {return _actionMap;}
150  protected:
154  private:
156  };
157 
161  void applyAction(HyperGraph* graph, HyperGraphElementAction* action, HyperGraphElementAction::Parameters* parameters=0, const std::string& typeName="");
162 
167  public:
169  std::ostream* os;
170  };
171  WriteGnuplotAction(const std::string& typeName_);
172  };
173 
179  public:
181  public:
182  Parameters();
183  };
184  DrawAction(const std::string& typeName_);
185  protected:
186  virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters* params_);
190  };
191 
192  template<typename T> class RegisterActionProxy
193  {
194  public:
196  {
197 #ifdef G2O_DEBUG_ACTIONLIB
198  std::cout << __FUNCTION__ << ": Registering action of type " << typeid(T).name() << std::endl;
199 #endif
200  _action = new T();
202  }
203 
205  {
206 #ifdef G2O_DEBUG_ACTIONLIB
207  std::cout << __FUNCTION__ << ": Unregistering action of type " << typeid(T).name() << std::endl;
208 #endif
210  delete _action;
211  }
212 
213  private:
215  };
216 
217 #define G2O_REGISTER_ACTION(classname) \
218  extern "C" void g2o_action_##classname(void) {} \
219  static g2o::RegisterActionProxy<classname> g_action_proxy_##classname;
220 };
221 
222 #endif
Abstract action that operates on a graph entity.
Parameters * _previousParams
HyperGraphElementAction::ActionMap & actionMap()
const std::string & name() const
returns the name of an action, e.g "draw"
std::map< std::string, HyperGraphElementAction * > ActionMap
BoolProperty * _showId
static HyperGraphActionLibrary * instance()
return the single instance of the HyperGraphActionLibrary
bool registerAction(HyperGraphElementAction *action)
void applyAction(HyperGraph *graph, HyperGraphElementAction *action, HyperGraphElementAction::Parameters *params, const std::string &typeName)
action
const std::string & typeName() const
returns the typeid name of the action
HyperGraphElementAction * _action
HyperGraphElementAction::ActionMap _actionMap
static HyperGraphActionLibrary * actionLibInstance
a collection of properties mapping from name to the property itself
Definition: property.h:75
bool unregisterAction(HyperGraphElementAction *action)
Abstract action that operates on an entire graph.
library of actions, indexed by the action name;
BoolProperty * _show
virtual HyperGraphAction * operator()(const HyperGraph *graph, Parameters *parameters=0)


orb_slam2_with_maps_odom
Author(s): teng zhang
autogenerated on Fri Sep 25 2020 03:24:47