]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/gen_for_gnuplot.cc
Improve generate for gnuplot example code
[hubacji1/bcar.git] / src / gen_for_gnuplot.cc
1 /*
2  * SPDX-FileCopyrightText: 2021 Jiri Vlasak <jiri.vlasak.2@cvut.cz>
3  *
4  * SPDX-License-Identifier: GPL-3.0-only
5  */
6
7 #include <fstream>
8 #include <iostream>
9 #include <vector>
10 #include "pslot.hh"
11
12 #define SP 0.5
13 #define STEPS 10
14
15 #define V v
16 #define INIT_V vector<M> V;
17 #define P(W) V.push_back(M(#W)); V.back().o.W = true;
18
19 class M {
20 public:
21         std::string fn;
22         std::ofstream f;
23         bcar::BicycleCar c;
24         bcar::BicycleCar::GenPlotOpts o;
25
26         void gpl()
27         {
28                 this->c.gen_gnuplot_to(this->f, this->o);
29                 this->c.next();
30         }
31
32         ~M()
33         {
34                 this->f.close();
35         }
36         M(std::string fn) : fn(fn)
37         {
38                 this->f.open(this->fn);
39                 this->c.sp(SP);
40                 this->c.set_max_steer();
41                 this->o.ALL = false;
42         }
43         M(M const& m) : fn(m.fn), c(m.c), o(m.o)
44         {
45                 this->f.open(this->fn);
46         }
47         M& operator=(M m)
48         {
49                 swap(*this, m);
50                 return *this;
51         }
52         friend void swap(M& f, M& t)
53         {
54                 using std::swap;
55                 f.f.close();
56                 t.f.close();
57                 swap(f.fn, t.fn);
58                 swap(f.c, t.c);
59                 swap(f.o, t.o);
60                 f.f.open(f.fn);
61                 t.f.open(t.fn);
62         }
63         M(M&& m) noexcept
64         {
65                 swap(*this, m);
66         }
67 };
68
69 void
70 gen_pl_script(std::vector<M>& ms)
71 {
72         using namespace std;
73         ofstream f;
74         f.open("plot.pl");
75         f << "#!/usr/bin/gnuplot" << endl;
76         f << "set size ratio -1" << endl;
77         f << "plot";
78         for (auto& m: ms) {
79                 f << " '" << m.fn << "'" << " w l,";
80         }
81         f << endl;
82         f << "pause -1" << endl;
83         f.close();
84 }
85
86 int
87 main()
88 {
89         using namespace std;
90         cout << fixed;
91         cerr << fixed;
92
93         INIT_V
94         P(LF_POINT)
95         P(LFM_POINT)
96         P(RF_POINT)
97         P(RFM_POINT)
98         P(CRA_POINT)
99
100         for (unsigned int i = 0; i < STEPS; i++) {
101                 for (auto& m: V) {
102                         m.gpl();
103                 }
104         }
105         gen_pl_script(V);
106         return 0;
107 }