log_plot.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <fstream>
3 #include <iostream>
4 #include <sys/types.h>
6 #include <log/sensorlog.h>
7 
8 
9 using namespace std;
10 using namespace GMapping;
11 
12 int main(int argc, char ** argv){
13  double maxrange=2.;
14  if (argc<2){
15  cout << "usage log_plot <filename> | gnuplot" << endl;
16  exit (-1);
17  }
18  ifstream is(argv[1]);
19  if (! is){
20  cout << "no file " << argv[1] << " found" << endl;
21  exit (-1);
22  }
24  conf.load(is);
25 
26  SensorMap m=conf.computeSensorMap();
27 
28  //for (SensorMap::const_iterator it=m.begin(); it!=m.end(); it++)
29  // cout << it->first << " " << it->second->getName() << endl;
30 
31  SensorLog log(m);
32  is.close();
33 
34  ifstream ls(argv[1]);
35  log.load(ls);
36  ls.close();
37  int count=0;
38  int frame=0;
39  cerr << "log size" << log.size() << endl;
40  for (SensorLog::iterator it=log.begin(); it!=log.end(); it++){
41  RangeReading* rr=dynamic_cast<RangeReading*>(*it);
42  if (rr){
43  count++;
44  if (count%3)
45  continue;
46  std::vector<Point> points(rr->size());
47  uint j=0;
48  for (uint i=0; i<rr->size(); i++){
49  const RangeSensor * rs=dynamic_cast<const RangeSensor*>(rr->getSensor());
50  double c=rs->beams()[i].c, s=rs->beams()[i].s;
51  double r=(*rr)[i];
52  if (r>maxrange)
53  continue;
54  points[j++]=Point(r*c,r*s);
55  }
56  if (j){
57  char buf[1024];
58  sprintf(buf,"frame-%05d.gif",frame);
59  frame++;
60  cout << "set terminal gif" << endl;
61  cout << "set output \"" << buf << "\"" << endl;
62  cout << "set size ratio -1" << endl;
63  cout << "plot [-3:3][0:3] '-' w p ps 1" << endl;
64  for (uint i=0; i<j; i++){
65  cout << points[i].y << " " << points[i].x << endl;
66  }
67  cout << "e" << endl;
68  }
69  }
70  }
71 }
point< double > Point
Definition: point.h:202
const Sensor * getSensor() const
Definition: sensorreading.h:13
virtual SensorMap computeSensorMap() const
virtual std::istream & load(std::istream &is)
double maxrange
Definition: gfs2stream.cpp:22
std::istream & load(std::istream &is)
Definition: sensorlog.cpp:23
std::map< std::string, Sensor * > SensorMap
Definition: sensor.h:19
unsigned int c
Definition: gfs2stream.cpp:41
ifstream is(argv[c])
int main(int argc, char **argv)
Definition: log_plot.cpp:12
const std::vector< Beam > & beams() const
Definition: rangesensor.h:23


openslam_gmapping
Author(s): Giorgio Grisetti, Cyrill Stachniss, Wolfram Burgard
autogenerated on Mon Jun 10 2019 14:04:22