-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plotter.h
65 lines (52 loc) · 1.32 KB
/
Plotter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Created by Swapnil on 2/22/2018.
//
#include <iostream>
#include <fstream>
#include <vector>
#include <thread>
#include "GNUPlot.h"
#ifndef VECTORFIELDHISTOGRAMTESTING_PLOTTER_H
#define VECTORFIELDHISTOGRAMTESTING_PLOTTER_H
// TODO: Draw a thick line out of the center of the robot to indicate which
// direction it's traveling. - Josh
class Plotter {
private:
std::ofstream f;
std::string fPath = "tempdata.dat";
std::string header = "# x y";
GNUPlot plotter;
public:
Plotter()
{
std::vector<std::string> script;
f.open(fPath);
f << header << std::endl;
f.close();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
script.push_back("set xrange [0:60];");
script.push_back("set yrange [0:60];");
script.push_back("plot \"" + fPath + "\"" + "with points pointsize 7");
plotter.open();
plotter.execute(script);
}
~Plotter()
{
plotter.flush();
plotter.close();
}
void plot(const std::vector<discretePoint>& dataIn)
{
std::vector<std::string> script;
script.push_back("replot");
f.open(fPath);
f << header << std::endl;
for(int j = 0; j < dataIn.size(); j++)
{
f << dataIn[j].x << " " << dataIn[j].y << std::endl;
}
f.close();
plotter.execute(script);
}
};
#endif //VECTORFIELDHISTOGRAMTESTING_PLOTTER_H