]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/gen_for_gnuplot.cc
Add gen plot for lra and rra points
[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 gpl_slot(bcar::ParkingSlot& s, std::string fn)
71 {
72         if (fn.compare("") == 0) {
73                 return;
74         }
75         using namespace std;
76         ofstream f;
77         f.open(fn);
78         s.gen_gnuplot_to(f);
79         f.close();
80 }
81
82 void
83 gen_pl_script(std::vector<M>& ms, std::string with_slot)
84 {
85         using namespace std;
86         ofstream f;
87         f.open("plot.pl");
88         f << "#!/usr/bin/gnuplot" << endl;
89         f << "set size ratio -1" << endl;
90         f << "plot";
91         for (auto& m: ms) {
92                 f << " '" << m.fn << "'" << " w l,";
93         }
94         if (with_slot.compare("") != 0) {
95                 f << " '" << with_slot << "' w l";
96         }
97         f << endl;
98         f << "pause -1" << endl;
99         f.close();
100 }
101
102 int
103 main()
104 {
105         using namespace std;
106         cout << fixed;
107         cerr << fixed;
108
109         bcar::ParkingSlot s(bcar::Point(0, 0), 0, 2.5, 6);
110         string sn("slot");
111         gpl_slot(s, sn);
112
113         INIT_V
114         P(LF_POINT)
115         P(LFM_POINT)
116         P(RF_POINT)
117         P(RFM_POINT)
118         P(CRA_POINT)
119
120         for (unsigned int i = 0; i < STEPS; i++) {
121                 for (auto& m: V) {
122                         m.gpl();
123                 }
124         }
125         gen_pl_script(V, sn);
126         return 0;
127 }