From 2a647a2446a41171b847820133f1b78171616803 Mon Sep 17 00:00:00 2001 From: Jiri Vlasak Date: Wed, 19 Jan 2022 22:55:42 +0100 Subject: [PATCH] Extend gen plot for parking slot --- incl/bcar.hh | 3 +++ incl/pslot.hh | 3 +++ src/bcar.cc | 8 ++++++++ src/gen_for_gnuplot.cc | 24 ++++++++++++++++++++++-- src/pslot.cc | 8 ++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/incl/bcar.hh b/incl/bcar.hh index f5ca928..c2265a5 100644 --- a/incl/bcar.hh +++ b/incl/bcar.hh @@ -144,6 +144,9 @@ public: double h() const; + /*! Generate output for plotting with gnuplot. */ + void gen_gnuplot_to(std::ostream& out); + friend std::ostream& operator<<(std::ostream& out, Line const& li); }; diff --git a/incl/pslot.hh b/incl/pslot.hh index 843d9f9..fbadd41 100644 --- a/incl/pslot.hh +++ b/incl/pslot.hh @@ -161,6 +161,9 @@ public: */ PoseRange recompute_entry(PoseRange p); + /*! Generate output for plotting with gnuplot. */ + void gen_gnuplot_to(std::ostream& out); + friend std::ostream& operator<<(std::ostream& o, ParkingSlot const& s); }; diff --git a/src/bcar.cc b/src/bcar.cc index 6f6f77e..4c8307c 100644 --- a/src/bcar.cc +++ b/src/bcar.cc @@ -270,6 +270,14 @@ Line::h() const return atan2(this->_e.y() - this->_b.y(), this->_e.x() - this->_b.x()); } +void +Line::gen_gnuplot_to(std::ostream& out) +{ + this->b().gen_gnuplot_to(out); + this->e().gen_gnuplot_to(out); + out << std::endl; +} + std::ostream& operator<<(std::ostream& out, Line const& li) { diff --git a/src/gen_for_gnuplot.cc b/src/gen_for_gnuplot.cc index d719e06..a2b02e4 100644 --- a/src/gen_for_gnuplot.cc +++ b/src/gen_for_gnuplot.cc @@ -67,7 +67,20 @@ public: }; void -gen_pl_script(std::vector& ms) +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& ms, std::string with_slot) { using namespace std; ofstream f; @@ -78,6 +91,9 @@ gen_pl_script(std::vector& ms) 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(); @@ -90,6 +106,10 @@ main() cout << fixed; cerr << fixed; + bcar::ParkingSlot s(bcar::Point(0, 0), 0, 2.5, 6); + string sn("slot"); + gpl_slot(s, sn); + INIT_V P(LF_POINT) P(LFM_POINT) @@ -102,6 +122,6 @@ main() m.gpl(); } } - gen_pl_script(V); + gen_pl_script(V, sn); return 0; } diff --git a/src/pslot.cc b/src/pslot.cc index 1d84e28..6a9a9bb 100644 --- a/src/pslot.cc +++ b/src/pslot.cc @@ -411,6 +411,14 @@ ParkingSlot::recompute_entry(PoseRange p) return p; } +void +ParkingSlot::gen_gnuplot_to(std::ostream& out) +{ + this->rear().gen_gnuplot_to(out); + this->curb().gen_gnuplot_to(out); + this->front().gen_gnuplot_to(out); +} + std::ostream& operator<<(std::ostream& o, ParkingSlot const& s) { -- 2.39.2