g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
examples
anonymize_observations
g2o_anonymize_observations.cpp
Go to the documentation of this file.
1
// g2o - General Graph Optimization
2
// Copyright (C) 2011 G. Grisetti, R. Kuemmerle, 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
#include <cstdlib>
28
#include <fstream>
29
#include <iostream>
30
#include <sstream>
31
32
#include "
g2o/core/optimizable_graph.h
"
33
#include "
g2o/stuff/command_args.h
"
34
#include "
g2o/types/slam2d/types_slam2d.h
"
35
#include "
g2o/types/slam3d/types_slam3d.h
"
36
37
using namespace
g2o
;
38
using namespace
std
;
39
40
template
<
typename
T>
41
bool
anonymizeLandmarkEdge
(
HyperGraph::Edge
* e_,
OptimizableGraph
& g) {
42
T* e =
dynamic_cast<
T*
>
(e_);
43
if
(!e)
return
false
;
44
g.
setEdgeVertex
(e, 1, 0);
45
return
true
;
46
}
47
48
template
<
typename
T>
49
bool
anonymizePoseEdge
(
HyperGraph::Edge
* e_,
OptimizableGraph
& g) {
50
T* e =
dynamic_cast<
T*
>
(e_);
51
if
(!e)
return
false
;
52
HyperGraph::Vertex
* from = e->vertex(0);
53
HyperGraph::Vertex
* to = e->vertex(1);
54
if
(from && to && from != to) {
55
int
deltaId = abs(from->
id
() - to->
id
());
56
if
(deltaId > 1) {
57
if
(from->
id
() > to->
id
()) {
58
g.
setEdgeVertex
(e, 0, 0);
59
}
else
{
60
g.
setEdgeVertex
(e, 1, 0);
61
}
62
return
true
;
63
}
64
}
65
return
false
;
66
}
67
68
int
main
(
int
argc,
char
** argv) {
69
CommandArgs
arg;
70
std::string outputFilename;
71
std::string inputFilename;
72
arg.
param
(
"o"
, outputFilename,
"anon.g2o"
,
"output file"
);
73
arg.
paramLeftOver
(
"graph-output"
, inputFilename,
""
,
74
"graph file which will be read"
,
true
);
75
arg.
parseArgs
(argc, argv);
76
OptimizableGraph
graph;
77
78
if
(inputFilename.size() == 0) {
79
cerr <<
"No input data specified"
<< endl;
80
return
0;
81
}
else
if
(inputFilename ==
"-"
) {
82
cerr <<
"Read input from stdin"
<< endl;
83
if
(!graph.
load
(cin)) {
84
cerr <<
"Error loading graph"
<< endl;
85
return
2;
86
}
87
}
else
{
88
cerr <<
"Read input from "
<< inputFilename << endl;
89
ifstream ifs(inputFilename.c_str());
90
if
(!ifs) {
91
cerr <<
"Failed to open file"
<< endl;
92
return
1;
93
}
94
if
(!graph.
load
(ifs)) {
95
cerr <<
"Error loading graph"
<< endl;
96
return
2;
97
}
98
}
99
100
for
(HyperGraph::EdgeSet::iterator it = graph.
edges
().begin();
101
it != graph.
edges
().end(); ++it) {
102
HyperGraph::Edge
* e = *it;
103
if
(
anonymizeLandmarkEdge<EdgeSE2PointXY>
(e, graph))
continue
;
104
if
(
anonymizeLandmarkEdge<EdgeSE2PointXYOffset>
(e, graph))
continue
;
105
if
(
anonymizeLandmarkEdge<EdgeSE2PointXYBearing>
(e, graph))
continue
;
106
if
(
anonymizePoseEdge<EdgeSE2>
(e, graph))
continue
;
107
if
(
anonymizePoseEdge<EdgeSE2Offset>
(e, graph))
continue
;
108
}
109
110
ofstream os(outputFilename.c_str());
111
graph.
save
(os);
112
}
g2o::CommandArgs
Command line parsing of argc and argv.
Definition
command_args.h:45
g2o::CommandArgs::parseArgs
bool parseArgs(int argc, char **argv, bool exitOnError=true)
Definition
command_args.cpp:106
g2o::CommandArgs::paramLeftOver
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
Definition
command_args.cpp:331
g2o::CommandArgs::param
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
Definition
command_args.cpp:188
g2o::HyperGraph::Edge
Definition
hyper_graph.h:172
g2o::HyperGraph::Vertex
abstract Vertex, your types must derive from that one
Definition
hyper_graph.h:148
g2o::HyperGraph::Vertex::id
int id() const
returns the id
Definition
hyper_graph.h:154
g2o::HyperGraph::edges
const EdgeSet & edges() const
Definition
hyper_graph.h:253
command_args.h
anonymizePoseEdge
bool anonymizePoseEdge(HyperGraph::Edge *e_, OptimizableGraph &g)
Definition
g2o_anonymize_observations.cpp:49
anonymizeLandmarkEdge
bool anonymizeLandmarkEdge(HyperGraph::Edge *e_, OptimizableGraph &g)
Definition
g2o_anonymize_observations.cpp:41
main
int main()
Definition
gicp_demo.cpp:44
g2o
Definition
dl_wrapper.cpp:55
std
Definition
jet.h:876
optimizable_graph.h
g2o::OptimizableGraph
Definition
optimizable_graph.h:62
g2o::OptimizableGraph::setEdgeVertex
virtual bool setEdgeVertex(HyperGraph::Edge *e, int pos, HyperGraph::Vertex *v)
Definition
optimizable_graph.cpp:259
g2o::OptimizableGraph::save
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
g2o::OptimizableGraph::load
virtual bool load(std::istream &is)
types_slam2d.h
types_slam3d.h
Generated on
for g2o by
1.17.0