g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
core
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
43
namespace
g2o
{
44
45
class
CacheContainer
;
49
class
G2O_CORE_API
HyperGraphAction
{
50
public
:
51
class
G2O_CORE_API
Parameters
{
52
public
:
53
virtual
~Parameters
();
54
};
55
56
class
G2O_CORE_API
ParametersIteration
:
public
Parameters
{
57
public
:
58
explicit
ParametersIteration
(
int
iter);
59
int
iteration
;
60
};
61
62
virtual
~HyperGraphAction
();
63
67
virtual
HyperGraphAction
*
operator()
(
const
HyperGraph
* graph,
68
Parameters
* parameters = 0);
69
};
70
74
class
G2O_CORE_API
HyperGraphElementAction
{
75
public
:
76
struct
G2O_CORE_API
Parameters
{
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
95
virtual
~HyperGraphElementAction
();
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
118
class
G2O_CORE_API
HyperGraphElementActionCollection
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(
136
const
HyperGraphElementAction::HyperGraphElementActionPtr
& action);
137
bool
unregisterAction(
138
const
HyperGraphElementAction::HyperGraphElementActionPtr
& action);
139
140
protected
:
141
ActionMap
_actionMap
;
142
};
143
150
class
G2O_CORE_API
HyperGraphActionLibrary
{
151
public
:
153
static
HyperGraphActionLibrary
*
instance
();
155
static
void
destroy
();
156
157
HyperGraphActionLibrary
(
HyperGraphActionLibrary
const
&) =
delete
;
158
HyperGraphActionLibrary
&
operator=
(
HyperGraphActionLibrary
const
&) =
delete
;
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
(
164
const
HyperGraphElementAction::HyperGraphElementActionPtr
& action);
165
bool
unregisterAction
(
166
const
HyperGraphElementAction::HyperGraphElementActionPtr
& action);
167
168
inline
HyperGraphElementAction::ActionMap
&
actionMap
() {
return
_actionMap
; }
169
170
protected
:
171
HyperGraphActionLibrary
() =
default
;
172
HyperGraphElementAction::ActionMap
_actionMap
;
173
174
private
:
175
static
std::unique_ptr<HyperGraphActionLibrary>
actionLibInstance
;
176
};
177
181
void
G2O_CORE_API
182
applyAction
(
HyperGraph
* graph,
HyperGraphElementAction
* action,
183
HyperGraphElementAction::Parameters
* parameters = 0,
184
const
std::string& typeName =
""
);
185
189
class
G2O_CORE_API
WriteGnuplotAction
:
public
HyperGraphElementAction
{
190
public
:
191
struct
G2O_CORE_API
Parameters
:
public
HyperGraphElementAction::Parameters
{
192
std::ostream*
os
;
193
};
194
WriteGnuplotAction
(
const
std::string& typeName_);
195
};
196
200
201
class
G2O_CORE_API
DrawAction
:
public
HyperGraphElementAction
{
202
public
:
203
class
G2O_CORE_API
Parameters
:
public
HyperGraphElementAction::Parameters
,
204
public
PropertyMap
{
205
public
:
206
Parameters
();
207
};
208
DrawAction
(
const
std::string& typeName_);
209
210
protected
:
211
virtual
bool
refreshPropertyPtrs
(
212
HyperGraphElementAction::Parameters
* params_);
213
void
initializeDrawActionsCache
();
214
void
drawCache
(
CacheContainer
* caches,
215
HyperGraphElementAction::Parameters
* params_);
216
void
drawUserData
(
HyperGraph::Data
* data,
217
HyperGraphElementAction::Parameters
* params_);
218
Parameters
*
_previousParams
;
219
BoolProperty
*
_show
;
220
HyperGraphElementAction
*
_cacheDrawActions
;
221
};
222
223
template
<
typename
T>
224
class
RegisterActionProxy
{
225
public
:
226
RegisterActionProxy
() {
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());
232
HyperGraphActionLibrary::instance
()->
registerAction
(
_action
);
233
}
234
235
private
:
236
HyperGraphElementAction::HyperGraphElementActionPtr
_action
;
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
g2o::CacheContainer
Definition
cache.h:108
g2o::DrawAction::Parameters
Definition
hyper_graph_action.h:204
g2o::DrawAction::Parameters::Parameters
Parameters()
Definition
hyper_graph_action.cpp:211
g2o::DrawAction::initializeDrawActionsCache
void initializeDrawActionsCache()
Definition
hyper_graph_action.cpp:235
g2o::DrawAction::_show
BoolProperty * _show
Definition
hyper_graph_action.h:219
g2o::DrawAction::_cacheDrawActions
HyperGraphElementAction * _cacheDrawActions
Definition
hyper_graph_action.h:220
g2o::DrawAction::drawCache
void drawCache(CacheContainer *caches, HyperGraphElementAction::Parameters *params_)
Definition
hyper_graph_action.cpp:242
g2o::DrawAction::DrawAction
DrawAction(const std::string &typeName_)
Definition
hyper_graph_action.cpp:213
g2o::DrawAction::drawUserData
void drawUserData(HyperGraph::Data *data, HyperGraphElementAction::Parameters *params_)
Definition
hyper_graph_action.cpp:253
g2o::DrawAction::refreshPropertyPtrs
virtual bool refreshPropertyPtrs(HyperGraphElementAction::Parameters *params_)
Definition
hyper_graph_action.cpp:221
g2o::DrawAction::_previousParams
Parameters * _previousParams
Definition
hyper_graph_action.h:218
g2o::HyperGraphActionLibrary::registerAction
bool registerAction(const HyperGraphElementAction::HyperGraphElementActionPtr &action)
Definition
hyper_graph_action.cpp:147
g2o::HyperGraphActionLibrary::instance
static HyperGraphActionLibrary * instance()
return the single instance of the HyperGraphActionLibrary
Definition
hyper_graph_action.cpp:127
g2o::HyperGraphActionLibrary::HyperGraphActionLibrary
HyperGraphActionLibrary(HyperGraphActionLibrary const &)=delete
g2o::HyperGraphActionLibrary::operator=
HyperGraphActionLibrary & operator=(HyperGraphActionLibrary const &)=delete
g2o::HyperGraphActionLibrary::destroy
static void destroy()
free the instance
Definition
hyper_graph_action.cpp:135
g2o::HyperGraphActionLibrary::HyperGraphActionLibrary
HyperGraphActionLibrary()=default
g2o::HyperGraphActionLibrary::actionByName
HyperGraphElementAction * actionByName(const std::string &name)
Definition
hyper_graph_action.cpp:140
g2o::HyperGraphActionLibrary::actionLibInstance
static std::unique_ptr< HyperGraphActionLibrary > actionLibInstance
Definition
hyper_graph_action.h:175
g2o::HyperGraphActionLibrary::actionMap
HyperGraphElementAction::ActionMap & actionMap()
Definition
hyper_graph_action.h:168
g2o::HyperGraphActionLibrary::unregisterAction
bool unregisterAction(const HyperGraphElementAction::HyperGraphElementActionPtr &action)
Definition
hyper_graph_action.cpp:175
g2o::HyperGraphActionLibrary::_actionMap
HyperGraphElementAction::ActionMap _actionMap
Definition
hyper_graph_action.h:172
g2o::HyperGraphAction::ParametersIteration::iteration
int iteration
Definition
hyper_graph_action.h:59
g2o::HyperGraphAction::ParametersIteration::ParametersIteration
ParametersIteration(int iter)
Definition
hyper_graph_action.cpp:45
g2o::HyperGraphAction::Parameters
Definition
hyper_graph_action.h:51
g2o::HyperGraphAction
Abstract action that operates on an entire graph.
Definition
hyper_graph_action.h:49
g2o::HyperGraphAction::operator()
virtual HyperGraphAction * operator()(const HyperGraph *graph, Parameters *parameters=0)
Definition
hyper_graph_action.cpp:50
g2o::HyperGraphElementActionCollection::actionMap
ActionMap & actionMap()
Definition
hyper_graph_action.h:131
g2o::HyperGraphElementActionCollection::operator()
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, Parameters *parameters)
Definition
hyper_graph_action.cpp:81
g2o::HyperGraphElementActionCollection::_actionMap
ActionMap _actionMap
Definition
hyper_graph_action.h:141
g2o::HyperGraphElementActionCollection::HyperGraphElementActionCollection
HyperGraphElementActionCollection(const std::string &name_)
constructor. name_ is the name of the action e.g.draw).
Definition
hyper_graph_action.cpp:76
g2o::HyperGraphElementAction
Abstract action that operates on a graph entity.
Definition
hyper_graph_action.h:74
g2o::HyperGraphElementAction::HyperGraphElementAction
HyperGraphElementAction(const std::string &typeName_="")
Definition
hyper_graph_action.cpp:56
g2o::HyperGraphElementAction::operator()
virtual HyperGraphElementAction * operator()(HyperGraph::HyperGraphElement *element, Parameters *parameters)
Definition
hyper_graph_action.cpp:63
g2o::HyperGraphElementAction::_name
std::string _name
Definition
hyper_graph_action.h:108
g2o::HyperGraphElementAction::ActionMap
std::map< std::string, HyperGraphElementActionPtr > ActionMap
Definition
hyper_graph_action.h:80
g2o::HyperGraphElementAction::name
const std::string & name() const
returns the name of an action, e.g "draw"
Definition
hyper_graph_action.h:101
g2o::HyperGraphElementAction::_typeName
std::string _typeName
Definition
hyper_graph_action.h:107
g2o::HyperGraphElementAction::typeName
const std::string & typeName() const
returns the typeid name of the action
Definition
hyper_graph_action.h:98
g2o::HyperGraphElementAction::HyperGraphElementActionPtr
std::shared_ptr< HyperGraphElementAction > HyperGraphElementActionPtr
Definition
hyper_graph_action.h:79
g2o::HyperGraph::Data
data packet for a vertex. Extend this class to store in the vertices the potential additional informa...
Definition
hyper_graph.h:93
g2o::HyperGraph
Definition
hyper_graph.h:53
g2o::PropertyMap
a collection of properties mapping from name to the property itself
Definition
property.h:78
g2o::RegisterActionProxy::_action
HyperGraphElementAction::HyperGraphElementActionPtr _action
Definition
hyper_graph_action.h:236
g2o::RegisterActionProxy::RegisterActionProxy
RegisterActionProxy()
Definition
hyper_graph_action.h:226
g2o::WriteGnuplotAction::WriteGnuplotAction
WriteGnuplotAction(const std::string &typeName_)
Definition
hyper_graph_action.cpp:206
g2o_core_api.h
G2O_CORE_API
#define G2O_CORE_API
Definition
g2o_core_api.h:29
hyper_graph.h
g2o
Definition
dl_wrapper.cpp:55
g2o::BoolProperty
Property< bool > BoolProperty
Definition
property.h:149
g2o::applyAction
void applyAction(HyperGraph *graph, HyperGraphElementAction *action, HyperGraphElementAction::Parameters *params, const std::string &typeName)
Definition
hyper_graph_action.cpp:261
property.h
g2o::HyperGraphElementAction::Parameters
Definition
hyper_graph_action.h:76
g2o::HyperGraph::HyperGraphElement
Definition
hyper_graph.h:80
g2o::WriteGnuplotAction::Parameters
Definition
hyper_graph_action.h:191
g2o::WriteGnuplotAction::Parameters::os
std::ostream * os
Definition
hyper_graph_action.h:192
Generated on
for g2o by
1.17.0