#ifndef PLOTTY_H #define PLOTTY_H class Plotty { public: K::Gnuplot gp; K::GnuplotSplot splot; K::GnuplotSplotElementPoints points; K::GnuplotSplotElementColorPoints cpoints; K::GnuplotSplotElementLines lines; public: Plotty(Floorplan::IndoorMap* map) { //gp << "set view equal xy\n"; gp << "set palette model RGB\n"; //gp << "set palette defined (0 '#0000ff', 1 '#ff0000')\n"; gp << "r(x) = (x < 0) ? 0 : (x/2)\n"; gp << "g(x) = 0\n"; gp << "b(x) = (x > 0) ? 0 : (-x/2)\n"; gp << "set palette model RGB functions r(gray),g(gray),b(gray)\n"; // draw floorplan splot.add(&lines); for (Floorplan::Floor* floor : map->floors) { for (Floorplan::FloorObstacle* obs : floor->obstacles) { Floorplan::FloorObstacleLine* line = dynamic_cast(obs); if (line) { const K::GnuplotPoint3 p1(line->from.x, line->from.y, floor->atHeight); const K::GnuplotPoint3 p2(line->to.x, line->to.y, floor->atHeight); lines.addSegment(p1, p2); } } for (Floorplan::Stair* s : floor->stairs) { for (const Floorplan::StairPart& sp : s->getParts()) { const K::GnuplotPoint3 p1(sp.start.x, sp.start.y, sp.start.z + floor->atHeight); const K::GnuplotPoint3 p2(sp.end.x, sp.end.y, sp.end.z + floor->atHeight); lines.addSegment(p1, p2); } } } splot.add(&points); points.setPointType(7); points.setPointSize(0.5); splot.add(&cpoints); cpoints.setPointSize(2); cpoints.setPointType(7); } void setPaletteRedBlue() { float max = -9999; float min = +9999; for (const auto& e : cpoints.get()) { if (e.color > max) {max = e.color;} if (e.color < min) {min = e.color;} } setPaletteRedBlue(min, max); } void setPaletteRedBlue(const float blueVal, const float redVal) { // we need to map the range from [blueVal:redVal] to [0:1] const float min = blueVal; const float max = redVal; const float range = (max - min); const float center01 = (0-min)/range; // values above 0 dB = red // values below 0 dB = blue gp << "set palette model RGB\n"; gp << "cen01 = " << center01 << "\n"; gp << "r(x) = (x < cen01) ? 0 : ((x-cen01) / (1-cen01))\n"; gp << "g(x) = 0\n"; gp << "b(x) = (x > cen01) ? 0 : (1 - (x/cen01))\n"; gp << "set palette model RGB functions r(gray),g(gray),b(gray)\n"; } void addLabel(const std::string& txt, const Point3 pos) { gp << "set label '" << txt << "' at " << pos.x << "," << pos.y << "," << pos.z << "\n"; } void setTitle(const std::string& title) { gp << "set title '" << title << "'\n"; } void plot() { gp.draw(splot); gp.flush(); } }; #endif // PLOTTY_H