g2o
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>
29 #include "g2o/stuff/command_args.h"
32 #include <iostream>
33 #include <fstream>
34 #include <sstream>
35 
36 using namespace g2o;
37 using namespace std;
38 
39 template <typename T>
41  T* e= dynamic_cast<T*> (e_);
42  if (!e)
43  return false;
44  g.setEdgeVertex(e,1,0);
45  return true;
46 }
47 
48 template <typename T>
50  T* e= dynamic_cast<T*> (e_);
51  if (!e)
52  return false;
53  HyperGraph::Vertex* from = e->vertex(0);
54  HyperGraph::Vertex* to = e->vertex(1);
55  if (from && to && from!=to){
56  int deltaId = abs(from->id() - to->id());
57  if (deltaId>1) {
58  if (from->id()>to->id()){
59  g.setEdgeVertex(e,0,0);
60  } else {
61  g.setEdgeVertex(e,1,0);
62  }
63  return true;
64  }
65  }
66  return false;
67 }
68 
69 
70 int main(int argc, char** argv) {
71  CommandArgs arg;
72  std::string outputFilename;
73  std::string inputFilename;
74  arg.param("o", outputFilename, "anon.g2o", "output file" );
75  arg.paramLeftOver("graph-output", inputFilename, "", "graph file which will be read", true);
76  arg.parseArgs(argc, argv);
78 
79  if (inputFilename.size() == 0) {
80  cerr << "No input data specified" << endl;
81  return 0;
82  } else if (inputFilename == "-") {
83  cerr << "Read input from stdin" << endl;
84  if (!graph.load(cin)) {
85  cerr << "Error loading graph" << endl;
86  return 2;
87  }
88  } else {
89  cerr << "Read input from " << inputFilename << endl;
90  ifstream ifs(inputFilename.c_str());
91  if (!ifs) {
92  cerr << "Failed to open file" << endl;
93  return 1;
94  }
95  if (!graph.load(ifs)) {
96  cerr << "Error loading graph" << endl;
97  return 2;
98  }
99  }
100 
101  for (HyperGraph::EdgeSet::iterator it = graph.edges().begin(); 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 }
int main(int argc, char **argv)
virtual bool setEdgeVertex(HyperGraph::Edge *e, int pos, HyperGraph::Vertex *v)
int id() const
returns the id
Definition: hyper_graph.h:148
Command line parsing of argc and argv.
Definition: command_args.h:46
bool anonymizeLandmarkEdge(HyperGraph::Edge *e_, OptimizableGraph &g)
bool parseArgs(int argc, char **argv, bool exitOnError=true)
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
const EdgeSet & edges() const
Definition: hyper_graph.h:230
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
bool anonymizePoseEdge(HyperGraph::Edge *e_, OptimizableGraph &g)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
abstract Vertex, your types must derive from that one
Definition: hyper_graph.h:142
virtual bool load(std::istream &is, bool createEdges=true)
load the graph from a stream. Uses the Factory singleton for creating the vertices and edges...
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the graph
Definition: protocol.txt:7