g2o
Loading...
Searching...
No Matches
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 <iosfwd>
31#include <iostream>
32#include <memory>
33#include <string>
34#include <typeinfo>
35
36#include "g2o/stuff/property.h"
37#include "g2o_core_api.h"
38#include "hyper_graph.h"
39
40// define to get verbose output
41// #define G2O_DEBUG_ACTIONLIB
42
43namespace g2o {
44
45class CacheContainer;
50 public:
52 public:
53 virtual ~Parameters();
54 };
55
57 public:
58 explicit ParametersIteration(int iter);
60 };
61
62 virtual ~HyperGraphAction();
63
67 virtual HyperGraphAction* operator()(const HyperGraph* graph,
68 Parameters* parameters = 0);
69};
70
75 public:
77 virtual ~Parameters();
78 };
79 typedef std::shared_ptr<HyperGraphElementAction> HyperGraphElementActionPtr;
80 typedef std::map<std::string, HyperGraphElementActionPtr> ActionMap;
83 explicit HyperGraphElementAction(const std::string& typeName_ = "");
84
87 virtual HyperGraphElementAction* operator()(
88 HyperGraph::HyperGraphElement* element, Parameters* parameters);
89
92 virtual HyperGraphElementAction* operator()(
93 const HyperGraph::HyperGraphElement* element, Parameters* parameters);
94
96
98 const std::string& typeName() const { return _typeName; }
99
101 const std::string& name() const { return _name; }
102
104 void setTypeName(const std::string& typeName_);
105
106 protected:
107 std::string _typeName;
108 std::string _name;
109};
110
119 : public HyperGraphElementAction {
120 public:
122 explicit HyperGraphElementActionCollection(const std::string& name_);
127 virtual HyperGraphElementAction* operator()(
128 HyperGraph::HyperGraphElement* element, Parameters* parameters);
129 virtual HyperGraphElementAction* operator()(
130 const HyperGraph::HyperGraphElement* element, Parameters* parameters);
131 ActionMap& actionMap() { return _actionMap; }
135 bool registerAction(
137 bool unregisterAction(
139
140 protected:
142};
143
151 public:
153 static HyperGraphActionLibrary* instance();
155 static void destroy();
156
159
160 // returns a pointer to a collection indexed by name
161 HyperGraphElementAction* actionByName(const std::string& name);
162 // registers a basic action in the pool. If necessary a container is created
163 bool registerAction(
165 bool unregisterAction(
167
168 inline HyperGraphElementAction::ActionMap& actionMap() { return _actionMap; }
169
170 protected:
173
174 private:
175 static std::unique_ptr<HyperGraphActionLibrary> actionLibInstance;
176};
177
181void G2O_CORE_API
184 const std::string& typeName = "");
185
190 public:
192 std::ostream* os;
193 };
194 WriteGnuplotAction(const std::string& typeName_);
195};
196
202 public:
204 public PropertyMap {
205 public:
206 Parameters();
207 };
208 DrawAction(const std::string& typeName_);
209
210 protected:
211 virtual bool refreshPropertyPtrs(
213 void initializeDrawActionsCache();
214 void drawCache(CacheContainer* caches,
216 void drawUserData(HyperGraph::Data* data,
221};
222
223template <typename T>
225 public:
227#ifdef G2O_DEBUG_ACTIONLIB
228 std::cout << __FUNCTION__ << ": Registering action of type "
229 << typeid(T).name() << std::endl;
230#endif
231 _action.reset(new T());
233 }
234
235 private:
237};
238
239} // namespace g2o
240
241#define G2O_REGISTER_ACTION(classname) \
242 extern "C" void g2o_action_##classname(void) {} \
243 static g2o::RegisterActionProxy<classname> g_action_proxy_##classname;
244
245#endif
BoolProperty * _show
HyperGraphElementAction * _cacheDrawActions
Parameters * _previousParams
library of actions, indexed by the action name;
bool registerAction(const HyperGraphElementAction::HyperGraphElementActionPtr &action)
static HyperGraphActionLibrary * instance()
return the single instance of the HyperGraphActionLibrary
HyperGraphActionLibrary(HyperGraphActionLibrary const &)=delete
HyperGraphActionLibrary & operator=(HyperGraphActionLibrary const &)=delete
static std::unique_ptr< HyperGraphActionLibrary > actionLibInstance
HyperGraphElementAction::ActionMap & actionMap()
HyperGraphElementAction::ActionMap _actionMap
Abstract action that operates on an entire graph.
Abstract action that operates on a graph entity.
std::map< std::string, HyperGraphElementActionPtr > ActionMap
const std::string & name() const
returns the name of an action, e.g "draw"
const std::string & typeName() const
returns the typeid name of the action
std::shared_ptr< HyperGraphElementAction > HyperGraphElementActionPtr
data packet for a vertex. Extend this class to store in the vertices the potential additional informa...
Definition hyper_graph.h:93
a collection of properties mapping from name to the property itself
Definition property.h:78
HyperGraphElementAction::HyperGraphElementActionPtr _action
#define G2O_CORE_API
void applyAction(HyperGraph *graph, HyperGraphElementAction *action, HyperGraphElementAction::Parameters *params, const std::string &typeName)