]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/gen_for_gnuplot.cc
f77d47670cdd69819fa5efd0e8fc839cbe791858
[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 60
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 #define LC V.back().c
19 #define A {}// P(CAR_POINT) LC = c;
20
21 class M {
22 public:
23         static unsigned int cntr;
24         std::string fn;
25         std::string fc;
26         std::ofstream f;
27         bcar::BicycleCar c;
28         bcar::BicycleCar::GenPlotOpts o;
29
30         void gpl()
31         {
32                 this->c.gen_gnuplot_to(this->f, this->o);
33                 this->c.next();
34         }
35
36         ~M()
37         {
38                 this->f.close();
39         }
40         M(std::string fn) : fn(fn)
41         {
42                 this->fc = std::to_string(this->cntr++);
43                 this->f.open(this->fn + this->fc);
44                 this->o.ALL = false;
45         }
46         M(M const& m) : fn(m.fn), c(m.c), o(m.o)
47         {
48                 this->fc = std::to_string(this->cntr++);
49                 this->f.open(this->fn + this->fc);
50         }
51         M& operator=(M m)
52         {
53                 swap(*this, m);
54                 return *this;
55         }
56         friend void swap(M& f, M& t)
57         {
58                 using std::swap;
59                 f.f.close();
60                 t.f.close();
61                 swap(f.fn, t.fn);
62                 swap(f.fc, t.fc);
63                 swap(f.c, t.c);
64                 swap(f.o, t.o);
65                 f.f.open(f.fn + f.fc);
66                 t.f.open(t.fn + t.fc);
67         }
68         M(M&& m) noexcept
69         {
70                 swap(*this, m);
71         }
72 };
73 unsigned int M::cntr = 10;
74
75 void
76 gpl_slot(bcar::ParkingSlot& s, std::string fn = "")
77 {
78         if (fn.compare("") == 0) {
79                 return;
80         }
81         using namespace std;
82         ofstream f;
83         f.open(fn);
84         s.gen_gnuplot_to(f);
85         f.close();
86 }
87
88 void
89 gen_pl_script(std::vector<M>& ms, std::string with_slot)
90 {
91         using namespace std;
92         ofstream f;
93         f.open("plot.pl");
94         f << "#!/usr/bin/gnuplot" << endl;
95         f << "set terminal pdf size 16,9 enhance color lw 4" << endl;
96         f << "set output 'out.pdf'" << endl;
97         f << "unset key" << endl;
98         f << "set size ratio -1" << endl;
99         f << "set xrange [-9.5:9.9]" << endl;
100         f << "set yrange [-2.8:5.9]" << endl;
101         if (with_slot.compare("") != 0) {
102                 f << "plot '" << with_slot << "' w l lc 'blue',";
103         } else {
104                 f << "plot";
105         }
106         for (auto& m: ms) {
107                 f << " '" << (m.fn + m.fc) << "'" << " w l lc 'red',";
108         }
109         f << endl;
110         //f << "pause -1" << endl;
111         f.close();
112 }
113
114 int
115 main(int argc, char **argv)
116 {
117         using namespace std;
118         if (argc != 2) {
119                 cerr << "Specify `what_plot` number." << endl;
120                 // what_plot values 50 - 72 correspond to OSP
121                 exit(1);
122         }
123         cout << fixed;
124         cerr << fixed;
125
126         bcar::ParkingSlot s(bcar::Point(0, 0), 0, 2.5, 6);
127         string sn("slot");
128         gpl_slot(s, sn);
129
130         s.fe(bcar::BicycleCar());
131         s.compute_entries();
132
133         int what_plot = atoi(argv[1]);
134
135         INIT_V
136
137         // this is ep
138         int len = s._ispaths.size();
139         auto c = s._ispaths[len / 2].front();
140
141         A
142
143         if (what_plot > 52) {
144                 c.set_max_steer();
145                 c.sp(0.1);
146                 for (int i = 0; i < 5; i++) {
147                         c.next();
148                 }
149         }A
150
151         if (what_plot > 54) { // can go anywhere forward
152                 c.set_max_steer();
153                 c.sp(0.1);
154                 while (!s.lf().inside_of(c.ccr(), c.iradi())) {
155                         c.next();
156                 }
157         }A
158
159         if (what_plot > 55) {
160                 c.st(0.0);
161                 for (int i = 0; i < 10; i++) {
162                         c.next();
163                 }
164         }A
165
166         if (what_plot > 56) {
167                 c.st(0.0);
168                 for (int i = 0; i < 10; i++) {
169                         c.next();
170                 }
171         }A
172
173         if (what_plot > 57) {
174                 c.st(0.0);
175                 for (int i = 0; i < 10; i++) {
176                         c.next();
177                 }
178         }A
179
180         if (what_plot > 58) { // few steps towards -- most up
181                 c.st(0.0);
182                 for (int i = 0; i < 10; i++) {
183                         c.next();
184                 }
185         }A
186
187         if (what_plot > 60) {
188                 c.set_max_steer();
189                 c.sp(-0.1);
190                 for (int i = 0; i < 10; i++) {
191                         c.next();
192                 }
193         }A
194
195         if (what_plot > 61) {
196                 c.set_max_steer();
197                 c.sp(-0.1);
198                 for (int i = 0; i < 10; i++) {
199                         c.next();
200                 }
201         }A
202
203         if (what_plot > 62) { // parallel to ps
204                 c.set_max_steer();
205                 c.sp(-0.1);
206                 for (int i = 0; i < 10; i++) {
207                         c.next();
208                 }
209         }A
210
211         if (what_plot > 66) { // what_plot should be up to 22 (init)
212                 int how_much = what_plot - 16 - 50;
213                 c.st(0.0);
214                 c.sp(-0.1);
215                 for (int i = 0; i < 20 * how_much; i++) {
216                         c.next();
217                 }
218         }A
219
220         P(CAR)
221         LC = c;
222
223         for (auto& m: V) {
224                 m.gpl();
225         }
226         gen_pl_script(V, sn);
227         cout << "mv out.pdf " << ((what_plot < 10)?"0":"");
228         cout << what_plot << ".pdf" << endl;
229         return 0;
230 }