]> rtime.felk.cvut.cz Git - hubacji1/bcar.git/blobdiff - src/gen_for_gnuplot.cc
Merge branch 'improve-plot'
[hubacji1/bcar.git] / src / gen_for_gnuplot.cc
index 81752174d4cb59dff1f7f89dfbfe87d8d83beed8..8b6a5cb01305e26f93b4714cbf9645ea7d725bea 100644 (file)
  * SPDX-License-Identifier: GPL-3.0-only
  */
 
+#include <fstream>
 #include <iostream>
 #include <vector>
 #include "pslot.hh"
 
-int main()
+#define SP 0.5
+#define STEPS 60
+
+#define V v
+#define INIT_V vector<M> V;
+#define P(W) V.push_back(M(#W)); V.back().o.W = true;
+
+class M {
+public:
+       std::string fn;
+       std::ofstream f;
+       bcar::BicycleCar c;
+       bcar::BicycleCar::GenPlotOpts o;
+
+       void gpl()
+       {
+               this->c.gen_gnuplot_to(this->f, this->o);
+               this->c.next();
+       }
+
+       ~M()
+       {
+               this->f.close();
+       }
+       M(std::string fn) : fn(fn)
+       {
+               this->f.open(this->fn);
+               this->o.ALL = false;
+       }
+       M(M const& m) : fn(m.fn), c(m.c), o(m.o)
+       {
+               this->f.open(this->fn);
+       }
+       M& operator=(M m)
+       {
+               swap(*this, m);
+               return *this;
+       }
+       friend void swap(M& f, M& t)
+       {
+               using std::swap;
+               f.f.close();
+               t.f.close();
+               swap(f.fn, t.fn);
+               swap(f.c, t.c);
+               swap(f.o, t.o);
+               f.f.open(f.fn);
+               t.f.open(t.fn);
+       }
+       M(M&& m) noexcept
+       {
+               swap(*this, m);
+       }
+};
+
+void
+gpl_slot(bcar::ParkingSlot& s, std::string fn)
+{
+       if (fn.compare("") == 0) {
+               return;
+       }
+       using namespace std;
+       ofstream f;
+       f.open(fn);
+       s.gen_gnuplot_to(f);
+       f.close();
+}
+
+void
+gen_pl_script(std::vector<M>& ms, std::string with_slot)
+{
+       using namespace std;
+       ofstream f;
+       f.open("plot.pl");
+       f << "#!/usr/bin/gnuplot" << endl;
+       f << "set size ratio -1" << endl;
+       f << "plot";
+       for (auto& m: ms) {
+               f << " '" << m.fn << "'" << " w l,";
+       }
+       if (with_slot.compare("") != 0) {
+               f << " '" << with_slot << "' w l";
+       }
+       f << endl;
+       f << "pause -1" << endl;
+       f.close();
+}
+
+int
+main()
 {
        using namespace std;
        cout << fixed;
        cerr << fixed;
 
-       bcar::BicycleCar c;
-       bcar::BicycleCar::GenPlotOpts o;
-       o.ALL = false;
-       o.FRONT = true;
-       o.REAR = true;
-       o.MIRRORS = true;
-       c.sp(0.5);
-       c.set_max_steer();
-       for (unsigned int i = 0; i < 10; i++) {
-               c.gen_gnuplot_to(cout, o);
-               c.next();
+       bcar::ParkingSlot s(bcar::Point(0, 0), 0, 2.5, 6);
+       string sn("slot");
+       gpl_slot(s, sn);
+
+       s.fe(bcar::BicycleCar());
+
+       INIT_V
+       P(RF_POINT)
+       P(RFM_POINT)
+       P(RRA_POINT)
+       P(RR_POINT)
+
+       for (auto& m: V) {
+               m.c = s._entries.front().front();
+               m.c.sp(m.c.sp() * -1.0);
+               m.c.st(m.c.st() * -1.0);
+       }
+       for (unsigned int i = 0; i < STEPS; i++) {
+               for (auto& m: V) {
+                       m.gpl();
+               }
        }
+       gen_pl_script(V, sn);
        return 0;
 }