g2o
Functions
g2o_anonymize_observations.cpp File Reference
#include <cstdlib>
#include "g2o/core/optimizable_graph.h"
#include "g2o/stuff/command_args.h"
#include "g2o/types/slam2d/types_slam2d.h"
#include "g2o/types/slam3d/types_slam3d.h"
#include <iostream>
#include <fstream>
#include <sstream>
Include dependency graph for g2o_anonymize_observations.cpp:

Go to the source code of this file.

Functions

template<typename T >
bool anonymizeLandmarkEdge (HyperGraph::Edge *e_, OptimizableGraph &g)
 
template<typename T >
bool anonymizePoseEdge (HyperGraph::Edge *e_, OptimizableGraph &g)
 
int main (int argc, char **argv)
 

Function Documentation

template<typename T >
bool anonymizeLandmarkEdge ( HyperGraph::Edge e_,
OptimizableGraph g 
)

Definition at line 40 of file g2o_anonymize_observations.cpp.

References g2o::OptimizableGraph::setEdgeVertex().

40  {
41  T* e= dynamic_cast<T*> (e_);
42  if (!e)
43  return false;
44  g.setEdgeVertex(e,1,0);
45  return true;
46 }
virtual bool setEdgeVertex(HyperGraph::Edge *e, int pos, HyperGraph::Vertex *v)
template<typename T >
bool anonymizePoseEdge ( HyperGraph::Edge e_,
OptimizableGraph g 
)

Definition at line 49 of file g2o_anonymize_observations.cpp.

References g2o::HyperGraph::Vertex::id(), and g2o::OptimizableGraph::setEdgeVertex().

49  {
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 }
virtual bool setEdgeVertex(HyperGraph::Edge *e, int pos, HyperGraph::Vertex *v)
int id() const
returns the id
Definition: hyper_graph.h:148
abstract Vertex, your types must derive from that one
Definition: hyper_graph.h:142
int main ( int  argc,
char **  argv 
)

Definition at line 70 of file g2o_anonymize_observations.cpp.

References g2o::HyperGraph::edges(), graph, g2o::OptimizableGraph::load(), g2o::CommandArgs::param(), g2o::CommandArgs::paramLeftOver(), g2o::CommandArgs::parseArgs(), and g2o::OptimizableGraph::save().

70  {
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 }
Command line parsing of argc and argv.
Definition: command_args.h:46
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)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
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