]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blob - src/gen_for_gnuplot.cc
f669b61ce5a12868cd26cafc90569e9d47c42db2
[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) LC = c;
20 //#define A P(CAR_POINT) LC = c;
21
22 class M {
23 public:
24         static unsigned int cntr;
25         std::string fn;
26         std::string fc;
27         std::ofstream f;
28         bcar::BicycleCar c;
29         bcar::BicycleCar::GenPlotOpts o;
30
31         void gpl()
32         {
33                 this->c.gen_gnuplot_to(this->f, this->o);
34                 this->c.next();
35         }
36
37         ~M()
38         {
39                 this->f.close();
40         }
41         M(std::string fn) : fn(fn)
42         {
43                 this->fc = std::to_string(this->cntr++);
44                 this->f.open(this->fn + this->fc);
45                 this->o.ALL = false;
46         }
47         M(M const& m) : fn(m.fn), c(m.c), o(m.o)
48         {
49                 this->fc = std::to_string(this->cntr++);
50                 this->f.open(this->fn + this->fc);
51         }
52         M& operator=(M m)
53         {
54                 swap(*this, m);
55                 return *this;
56         }
57         friend void swap(M& f, M& t)
58         {
59                 using std::swap;
60                 f.f.close();
61                 t.f.close();
62                 swap(f.fn, t.fn);
63                 swap(f.fc, t.fc);
64                 swap(f.c, t.c);
65                 swap(f.o, t.o);
66                 f.f.open(f.fn + f.fc);
67                 t.f.open(t.fn + t.fc);
68         }
69         M(M&& m) noexcept
70         {
71                 swap(*this, m);
72         }
73 };
74 unsigned int M::cntr = 10;
75
76 void
77 gpl_slot(bcar::ParkingSlot& s, std::string fn = "")
78 {
79         if (fn.compare("") == 0) {
80                 return;
81         }
82         using namespace std;
83         ofstream f;
84         f.open(fn);
85         s.gen_gnuplot_to(f);
86         f.close();
87 }
88
89 void
90 gen_pl_script(std::vector<M>& ms, std::string with_slot)
91 {
92         using namespace std;
93         ofstream f;
94         f.open("plot.pl");
95         f << "#!/usr/bin/gnuplot" << endl;
96         f << "set terminal pdf size 16,9 enhance color lw 4" << endl;
97         f << "set output 'out.pdf'" << endl;
98         f << "unset key" << endl;
99         f << "set size ratio -1" << endl;
100         f << "set xrange [-0.5:6.5]" << endl;
101         f << "set yrange [-2.8:1.9]" << endl;
102         if (with_slot.compare("") != 0) {
103                 f << "plot '" << with_slot << "' w l lc 'blue',";
104         } else {
105                 f << "plot";
106         }
107         for (auto& m: ms) {
108                 f << " '" << (m.fn + m.fc) << "'" << " w l lc 'red',";
109         }
110         f << endl;
111         //f << "pause -1" << endl;
112         f.close();
113 }
114
115 int
116 main(int argc, char **argv)
117 {
118         int what_plot;
119         using namespace std;
120         if (argc != 2) {
121                 //cerr << "Specify `what_plot` number." << endl;
122                 // what_plot values 50 - 72 correspond to OSP
123                 //exit(1);
124         }
125         cout << fixed;
126         cerr << fixed;
127
128         //bcar::ParkingSlot s(bcar::Point(0, 0), 0, 2.5, 6); // orig
129         //bcar::ParkingSlot s(bcar::Point(0, 0), 0, 2.2, 6); // less width
130         //bcar::ParkingSlot s(bcar::Point(1, 0), 0, 2.5, 5); // less length
131         bcar::ParkingSlot s(bcar::Point(1, 0), 0, 2.2, 5); // less all
132         string sn("slot");
133         gpl_slot(s, sn);
134
135         s.fe(bcar::BicycleCar());
136         s.compute_entries();
137
138         if (argc == 2) {
139                 what_plot = atoi(argv[1]);
140         } else {
141                 what_plot = 1;
142         }
143
144         INIT_V
145
146 #if 0 /* in slot */
147         // this is ep
148         //int len = s._ispaths.size();
149         //auto c = s._ispaths[len / 2].front(); // orig
150         //auto c = s._ispaths[len - 1].front(); // for less width
151         //auto c = s._ispaths[len - len].front(); // for less length
152         auto c = s._ispaths[38].front(); // for less all
153
154         A
155
156         c.set_max_steer();
157         c.sp(-0.1);
158
159         if (what_plot > 0) {
160                 while (!s.collide(c)) {
161                         A
162                         c.next();
163                         if (s.parked(c)) {
164                                 goto here;
165                         }
166                 }
167                 c.sp(c.sp() * -1.0);
168                 c.next();
169
170                 // 1 cusp: go forward
171                 c.st(c.st() * -1.0);
172                 while (!s.collide(c)) {
173                         A
174                         c.next();
175                         if (s.parked(c)) {
176                                 goto here;
177                         }
178                 }
179                 c.sp(c.sp() * -1.0);
180                 c.next();
181
182                 // 2 cusp: go backward
183                 c.st(c.st() * -1.0);
184                 while (!s.collide(c)) {
185                         A
186                         c.next();
187                         if (s.parked(c)) {
188                                 goto here;
189                         }
190                 }
191                 c.sp(c.sp() * -1.0);
192                 c.next();
193         }
194         A
195 here:
196         cerr << s.parked(c) << endl;
197         A
198 #endif
199 #if 0 /* out of slot */
200         if (what_plot > 52) {
201                 c.set_max_steer();
202                 c.sp(0.1);
203                 for (int i = 0; i < 5; i++) {
204                         c.next();
205                 }
206         }A
207
208         if (what_plot > 54) { // can go anywhere forward
209                 c.set_max_steer();
210                 c.sp(0.1);
211                 while (!s.lf().inside_of(c.ccr(), c.iradi())) {
212                         c.next();
213                 }
214         }A
215 #endif
216 #if 0 /* path1 */
217         if (what_plot > 55) {
218                 c.st(0.0);
219                 for (int i = 0; i < 10; i++) {
220                         c.next();
221                 }
222         }A
223
224         if (what_plot > 56) {
225                 c.st(0.0);
226                 for (int i = 0; i < 10; i++) {
227                         c.next();
228                 }
229         }A
230
231         if (what_plot > 57) {
232                 c.st(0.0);
233                 for (int i = 0; i < 10; i++) {
234                         c.next();
235                 }
236         }A
237
238         if (what_plot > 58) { // few steps towards -- most up
239                 c.st(0.0);
240                 for (int i = 0; i < 10; i++) {
241                         c.next();
242                 }
243         }A
244
245         if (what_plot > 60) {
246                 c.set_max_steer();
247                 c.sp(-0.1);
248                 for (int i = 0; i < 10; i++) {
249                         c.next();
250                 }
251         }A
252
253         if (what_plot > 61) {
254                 c.set_max_steer();
255                 c.sp(-0.1);
256                 for (int i = 0; i < 10; i++) {
257                         c.next();
258                 }
259         }A
260
261         if (what_plot > 62) { // parallel to ps
262                 c.set_max_steer();
263                 c.sp(-0.1);
264                 for (int i = 0; i < 10; i++) {
265                         c.next();
266                 }
267         }A
268
269         if (what_plot > 66) { // what_plot should be up to 22 (init)
270                 int how_much = what_plot - 16 - 50;
271                 c.st(0.0);
272                 c.sp(-0.1);
273                 for (int i = 0; i < 20 * how_much; i++) {
274                         c.next();
275                 }
276         }A
277 #endif
278 #if 0 /* path2 */
279         if (what_plot > 58) {
280                 c.set_max_steer();
281                 c.st(c.st() * -1.0);
282                 c.sp(0.1);
283                 for (int i = 0; i < 10; i++) {
284                         c.next();
285                 }
286         }A
287
288         if (what_plot > 62) {
289                 c.set_max_steer();
290                 c.st(c.st() * -1.0);
291                 c.sp(0.1);
292                 for (int i = 0; i < 10; i++) {
293                         c.next();
294                 }
295         }A
296
297         if (what_plot > 66) {
298                 c.set_max_steer();
299                 c.st(c.st() * -1.0);
300                 c.sp(0.1);
301                 for (int i = 0; i < 10; i++) {
302                         c.next();
303                 }
304         }A
305
306         if (what_plot > 70) {
307                 c.st(0.0);
308                 c.sp(-0.1);
309                 for (int i = 0; i < 20; i++) {
310                         c.next();
311                 }
312         }A
313
314         if (what_plot > 72) {
315                 c.st(0.0);
316                 c.sp(-0.1);
317                 for (int i = 0; i < 20; i++) {
318                         c.next();
319                 }
320         }A
321
322         if (what_plot > 74) {
323                 c.set_max_steer();
324                 c.sp(-0.1);
325                 for (int i = 0; i < 10; i++) {
326                         c.next();
327                 }
328         }A
329
330         if (what_plot > 76) {
331                 c.st(0.0);
332                 c.sp(-0.1);
333                 for (int i = 0; i < 20; i++) {
334                         c.next();
335                 }
336         }A
337
338         if (what_plot > 78) {
339                 c.set_max_steer();
340                 c.st(c.st() * -1.0);
341                 c.sp(-0.1);
342                 for (int i = 0; i < 10; i++) {
343                         c.next();
344                 }
345         }A
346
347         if (what_plot > 80) { // up to 83 (init)
348                 int how_much = what_plot - 80;
349                 c.st(0.0);
350                 c.sp(-0.1);
351                 for (int i = 0; i < 20 * how_much; i++) {
352                         c.next();
353                 }
354         }A
355 #endif
356 #if 0 /* path3 */
357         if (what_plot > 56) {
358                 c.st(0.0);
359                 c.sp(0.1);
360                 for (int i = 0; i < 10; i++) {
361                         c.next();
362                 }
363         }A
364
365         if (what_plot > 58) {
366                 c.set_max_steer();
367                 c.st(c.st() * -1.0);
368                 c.sp(0.1);
369                 for (int i = 0; i < 10; i++) {
370                         c.next();
371                 }
372         }A
373
374         if (what_plot > 62) {
375                 c.set_max_steer();
376                 c.st(c.st() * -1.0);
377                 c.sp(0.1);
378                 for (int i = 0; i < 10; i++) {
379                         c.next();
380                 }
381         }A
382
383         if (what_plot > 66) {
384                 c.set_max_steer();
385                 c.sp(-0.1);
386                 for (int i = 0; i < 5; i++) {
387                         c.next();
388                 }
389         }A
390
391         if (what_plot > 68) {
392                 c.set_max_steer();
393                 c.sp(-0.1);
394                 for (int i = 0; i < 10; i++) {
395                         c.next();
396                 }
397         }A
398
399         if (what_plot > 70) {
400                 c.st(0.0);
401                 c.sp(-0.1);
402                 for (int i = 0; i < 20; i++) {
403                         c.next();
404                 }
405         }A
406
407         if (what_plot > 72) {
408                 c.st(0.0);
409                 c.sp(-0.1);
410                 for (int i = 0; i < 20; i++) {
411                         c.next();
412                 }
413         }A
414
415         if (what_plot > 73) {
416                 c.st(0.0);
417                 c.sp(-0.1);
418                 for (int i = 0; i < 20; i++) {
419                         c.next();
420                 }
421         }A
422
423         if (what_plot > 74) {
424                 c.set_max_steer();
425                 c.st(c.st() * -1.0);
426                 c.sp(-0.1);
427                 for (int i = 0; i < 5; i++) {
428                         c.next();
429                 }
430         }A
431
432         if (what_plot > 80) { // up to 83 (init)
433                 int how_much = what_plot - 80;
434                 c.st(0.0);
435                 c.sp(-0.1);
436                 for (int i = 0; i < 20 * how_much; i++) {
437                         c.next();
438                 }
439         }A
440 #endif
441
442         for (auto& m: V) {
443                 m.gpl();
444         }
445         gen_pl_script(V, sn);
446         cout << "mv out.pdf " << ((what_plot < 10)?"0":"");
447         cout << what_plot << ".pdf" << endl;
448         return 0;
449 }