g2o
Loading...
Searching...
No Matches
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
36
37using namespace g2o;
38using namespace std;
39
40template <typename T>
42 T* e = dynamic_cast<T*>(e_);
43 if (!e) return false;
44 g.setEdgeVertex(e, 1, 0);
45 return true;
46}
47
48template <typename T>
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
68int 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}
Command line parsing of argc and argv.
bool parseArgs(int argc, char **argv, bool exitOnError=true)
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
abstract Vertex, your types must derive from that one
int id() const
returns the id
const EdgeSet & edges() const
bool anonymizePoseEdge(HyperGraph::Edge *e_, OptimizableGraph &g)
bool anonymizeLandmarkEdge(HyperGraph::Edge *e_, OptimizableGraph &g)
int main()
Definition gicp_demo.cpp:44
Definition jet.h:876
virtual bool setEdgeVertex(HyperGraph::Edge *e, int pos, HyperGraph::Vertex *v)
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
virtual bool load(std::istream &is)