g2o
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 "g2o/stuff/property.h"
32 
33 #include <typeinfo>
34 #include <iosfwd>
35 #include <set>
36 #include <string>
37 #include <iostream>
38 
39 #include "g2o_core_api.h"
40 
41 // define to get verbose output
42 //#define G2O_DEBUG_ACTIONLIB
43 
44 namespace g2o {
45 
46  class CacheContainer;
51  public:
53  public:
54  virtual ~Parameters();
55  };
56 
58  public:
59  explicit ParametersIteration(int iter);
60  int iteration;
61  };
62 
63  virtual ~HyperGraphAction();
64 
68  virtual HyperGraphAction* operator()(const HyperGraph* graph, Parameters* parameters = 0);
69  };
70 
75  public:
77  virtual ~Parameters();
78  };
79  typedef std::map<std::string, HyperGraphElementAction*> ActionMap;
82  HyperGraphElementAction(const std::string& typeName_="");
83 
85  virtual HyperGraphElementAction* operator()(HyperGraph::HyperGraphElement* element, Parameters* parameters);
86 
88  virtual HyperGraphElementAction* operator()(const HyperGraph::HyperGraphElement* element, Parameters* parameters);
89 
91  virtual ~HyperGraphElementAction();
92 
94  const std::string& typeName() const { return _typeName;}
95 
97  const std::string& name() const{ return _name;}
98 
100  void setTypeName(const std::string& typeName_);
101 
102  protected:
103  std::string _typeName;
104  std::string _name;
105  };
106 
114  public:
116  HyperGraphElementActionCollection(const std::string& name_);
121  virtual HyperGraphElementAction* operator()(HyperGraph::HyperGraphElement* element, Parameters* parameters);
122  virtual HyperGraphElementAction* operator()(const HyperGraph::HyperGraphElement* element, Parameters* parameters);
123  ActionMap& actionMap() {return _actionMap;}
126  bool registerAction(HyperGraphElementAction* action);
127  bool unregisterAction(HyperGraphElementAction* action);
128  protected:
130  };
131 
139  public:
141  static HyperGraphActionLibrary* instance();
143  static void destroy();
144 
145  // returns a pointer to a collection indexed by name
146  HyperGraphElementAction* actionByName(const std::string& name);
147  // registers a basic action in the pool. If necessary a container is created
148  bool registerAction(HyperGraphElementAction* action);
149  bool unregisterAction(HyperGraphElementAction* action);
150 
151  inline HyperGraphElementAction::ActionMap& actionMap() {return _actionMap;}
152  protected:
156  private:
158  };
159 
163  void G2O_CORE_API applyAction(HyperGraph* graph, HyperGraphElementAction* action, HyperGraphElementAction::Parameters* parameters=0, const std::string& typeName="");
164 
169  public:
171  std::ostream* os;
172  };
173  WriteGnuplotAction(const std::string& typeName_);
174  };
175 
181  public:
183  public:
184  Parameters();
185  };
186  DrawAction(const std::string& typeName_);
187  protected:
188  virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters* params_);
189  void initializeDrawActionsCache() ;
190  void drawCache(CacheContainer* caches, HyperGraphElementAction::Parameters* params_);
191  void drawUserData(HyperGraph::Data* data, HyperGraphElementAction::Parameters* params_);
196  };
197 
198  template<typename T> class RegisterActionProxy
199  {
200  public:
202  {
203 #ifdef G2O_DEBUG_ACTIONLIB
204  std::cout << __FUNCTION__ << ": Registering action of type " << typeid(T).name() << std::endl;
205 #endif
206  _action = new T();
208  }
209 
211  {
212 #ifdef G2O_DEBUG_ACTIONLIB
213  std::cout << __FUNCTION__ << ": Unregistering action of type " << typeid(T).name() << std::endl;
214 #endif
216  delete _action;
217  }
218 
219  private:
221  };
222 
223 #define G2O_REGISTER_ACTION(classname) \
224  extern "C" void g2o_action_##classname(void) {} \
225  static g2o::RegisterActionProxy<classname> g_action_proxy_##classname;
226 };
227 
228 #endif
data packet for a vertex. Extend this class to store in the vertices the potential additional informa...
Definition: hyper_graph.h:97
Abstract action that operates on a graph entity.
Parameters * _previousParams
void applyAction(HyperGraph *graph, HyperGraphElementAction *action, HyperGraphElementAction::Parameters *params, const std::string &typeName)
HyperGraphElementAction::ActionMap & actionMap()
const std::string & name() const
returns the name of an action, e.g "draw"
HyperGraphElementAction * _cacheDrawActions
std::map< std::string, HyperGraphElementAction * > ActionMap
BoolProperty * _showId
static HyperGraphActionLibrary * instance()
return the single instance of the HyperGraphActionLibrary
bool registerAction(HyperGraphElementAction *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:76
bool unregisterAction(HyperGraphElementAction *action)
#define G2O_CORE_API
Definition: g2o_core_api.h:29
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the graph
Definition: protocol.txt:7
Abstract action that operates on an entire graph.
library of actions, indexed by the action name;
BoolProperty * _show