current state

This commit is contained in:
2017-04-18 18:03:31 +02:00
parent 3e244118cc
commit 11cb939758
18 changed files with 1809 additions and 516 deletions

View File

@@ -71,6 +71,10 @@ public:
return gp;
}
K::GnuplotPlot& getPlot() {
return gplot;
}
void writeCodeTo(const std::string& file) {
this->codeFile = file;
}

View File

@@ -19,6 +19,7 @@ private:
K::GnuplotPlotElementLines lineErr[8];
K::GnuplotPlotElementLines lineB;
K::GnuplotPlotElementLines lineC;
std::string codeFile;
public:
@@ -40,6 +41,25 @@ public:
}
void clear() {
for (int i = 0; i < 8; ++i) {lineErr[i].clear();}
lineB.clear();
lineC.clear();
}
void writeCodeTo(const std::string& file) {
this->codeFile = file;
}
void writeEpsTex(const std::string file, K::GnuplotSize size = K::GnuplotSize(8.5, 5.1)) {
gp.setTerminal("epslatex", size);
gp.setOutput(file);
gp << "set key\n";
gp << "set rmargin 0.2\n";
gp << "set tmargin 0.2\n";
gp << "set bmargin 1.2\n";
}
K::GnuplotPlot& getPlot() {
return gpplot;
}
@@ -63,6 +83,11 @@ public:
void plot() {
gp.draw(gpplot);
if (codeFile != "") {
std::ofstream out(codeFile);
out << gp.getBuffer();
out.close();
}
gp.flush();
}

163
plots/PlotWiFiGroundProb.h Normal file
View File

@@ -0,0 +1,163 @@
#ifndef EVALWIFIGROUNDPROB_H
#define EVALWIFIGROUNDPROB_H
#include <KLib/math/statistics/Statistics.h>
#include "Indoor/sensors/radio/setup/WiFiOptimizer.h"
#include "Indoor/sensors/radio/setup/WiFiFingerprint.h"
#include "Indoor/sensors/radio/setup/WiFiFingerprints.h"
#include "Indoor/sensors/radio/setup/WiFiOptimizer.h"
#include "Indoor/sensors/radio/setup/WiFiOptimizerLogDistCeiling.h"
#include "Indoor/sensors/radio/VAPGrouper.h"
#include "Indoor/floorplan/v2/Floorplan.h"
#include "Indoor/floorplan/v2/FloorplanReader.h"
#include "Indoor/floorplan/v2/FloorplanHelper.h"
#include "Indoor/floorplan/v2/FloorplanCeilings.h"
#include "Indoor/sensors/radio/model/WiFiModelLogDistCeiling.h"
#include "Indoor/sensors/offline/FileReader.h"
#include "Indoor/sensors/radio/WiFiProbabilityFree.h"
#include "../Helper.h"
#include <vector>
#include "../plots/Plotty.h"
class PlotWiFiGroundProb {
private:
const Floorplan::IndoorMap* map;
const float stepSize_m = 3.0;
//std::vector<Point3> pos;
struct Entry {
Point3 pos;
K::GnuplotObjectPolygon* poly;
float max = 0;
float sum = 0;
int cnt = 0;
};
std::vector<Entry> pos;
Plotty plot;
public:
/** ctor */
PlotWiFiGroundProb(const Floorplan::IndoorMap* map) : map(map), plot(map) {
buildEvalPoints();
plot.settings.outline = false;
plot.buildFloorplan();
}
void show(const WiFiObserverFree& prob, const WiFiMeasurements& _mes) {
VAPGrouper vap(VAPGrouper::Mode::LAST_MAC_DIGIT_TO_ZERO, VAPGrouper::Aggregation::AVERAGE);
const WiFiMeasurements mes = vap.group(_mes);
double min = +99999;
double max = -99999;
for (Entry& e : pos) {
const double p = prob.getProbability(e.pos, mes.entries.front().getTimestamp(), mes);
if (p < min) {min = p;}
if (p > max) {max = p;}
}
double diff = max-min;
for (Entry& e : pos) {
const double p = prob.getProbability(e.pos, mes.entries.front().getTimestamp(), mes);
const double f = (p-min) / diff * 255;
e.sum += p;
e.cnt++;
//if (f > e.max) {
const K::GnuplotColor c = K::GnuplotColor::fromHSV(0, f, 255);
e.poly->getFill().setColor(c);
e.max = f;
//}
//plot.cpoints.add(K::GnuplotPoint3(pt.x, pt.y, pt.z), p);
}
}
void update() {
double min = +99999;
double max = -99999;
for (Entry& e : pos) {
const double p = e.sum / e.cnt;
if (p < min) {min = p;}
if (p > max) {max = p;}
}
double diff = max-min;
for (Entry& e : pos) {
const double p = e.sum / e.cnt;
const double f = (p-min) / diff * 255;
const K::GnuplotColor c = K::GnuplotColor::fromHSV(0, f, 255);
e.poly->getFill().setColor(c);
}
}
void plotMe() {
plot.plot();
}
private:
/** get a list of all points among the outline */
void buildEvalPoints() {
BBox3 bbox = FloorplanHelper::getBBox(map);
for (Floorplan::Floor* f : map->floors) {
for (float y = bbox.getMin().y; y < bbox.getMax().y; y += stepSize_m) {
for (float x = bbox.getMin().x; x < bbox.getMax().x; x += stepSize_m) {
GridFactory<int>::PartOfOutline part = GridFactory<int>::isPartOfFloorOutline(x*100, y*100, f->outline);
if (part != GridFactory<int>::PartOfOutline::NO) {
const float s = stepSize_m/2.0f;
Entry e;
e.poly = new K::GnuplotObjectPolygon();
e.poly->add(K::GnuplotCoordinate3(x-s, y-s, f->atHeight, K::GnuplotCoordinateSystem::FIRST));
e.poly->add(K::GnuplotCoordinate3(x+s, y-s, f->atHeight, K::GnuplotCoordinateSystem::FIRST));
e.poly->add(K::GnuplotCoordinate3(x+s, y+s, f->atHeight, K::GnuplotCoordinateSystem::FIRST));
e.poly->add(K::GnuplotCoordinate3(x-s, y+s, f->atHeight, K::GnuplotCoordinateSystem::FIRST));
e.poly->close();
e.poly->getFill().setStyle(K::GnuplotFillStyle::SOLID);
e.poly->setStroke(K::GnuplotStroke::NONE());
e.pos = Point3(x, y, f->atHeight);
pos.push_back(e);
plot.splot.getObjects().add(e.poly);
}
}
}
}
}
};
#endif // EVALWIFIGROUNDPROB_H

View File

@@ -3,6 +3,7 @@
#include <Indoor/floorplan/v2/Floorplan.h>
#include <Indoor/floorplan/v2/FloorplanHelper.h>
#include <Indoor/geo/BBoxes3.h>
#include <KLib/misc/gnuplot/Gnuplot.h>
#include <KLib/misc/gnuplot/GnuplotSplot.h>
@@ -11,6 +12,7 @@
#include <KLib/misc/gnuplot/GnuplotSplotElementLines.h>
#include <KLib/misc/gnuplot/GnuplotPlot.h>
#include <KLib/misc/gnuplot/GnuplotPlotElementHistogram.h>
#include <KLib/misc/gnuplot/objects/GnuplotObjects.h>
struct Color {
@@ -99,6 +101,7 @@ public:
K::GnuplotSplotElementLines mapOutlineGlass;
K::GnuplotSplotElementLines mapOutlineDrywall;
K::GnuplotSplotElementLines mapOutlineConcrete;
K::GnuplotSplotElementLines mapBBoxes;
std::string codeFile;
@@ -130,9 +133,11 @@ public:
mapOutlineConcrete.getStroke().getColor().setHexStr("#888888"); mapOutlineConcrete.getStroke().setWidth(2);
mapOutlineDrywall.getStroke().getColor().setHexStr("#888888");
mapOutlineGlass.getStroke().getColor().setHexStr("#888888"); mapOutlineGlass.getStroke().setType(K::GnuplotDashtype::DASHED);
mapBBoxes.getStroke().setWidth(2);
splot.add(&mapOutlineConcrete);
splot.add(&mapOutlineDrywall);
splot.add(&mapOutlineGlass);
splot.add(&mapBBoxes);
splot.add(&particles); particles.setPointSize(0.20); //particles.setColorHex("#777777");
@@ -149,6 +154,52 @@ public:
}
void addBBoxes(const BBoxes3& boxes, const K::GnuplotColor& c) {
for (const BBox3& bb : boxes.get()) {
addBBoxPoly(bb, c);
}
}
void addBBox(const BBox3& bb) {
// floor
mapBBoxes.add({bb.getMin().x, bb.getMin().y, bb.getMin().z});
mapBBoxes.add({bb.getMax().x, bb.getMin().y, bb.getMin().z});
mapBBoxes.add({bb.getMax().x, bb.getMax().y, bb.getMin().z});
mapBBoxes.add({bb.getMin().x, bb.getMax().y, bb.getMin().z});
mapBBoxes.add({bb.getMin().x, bb.getMin().y, bb.getMin().z});
mapBBoxes.splitFace(); mapBBoxes.splitFace();
// ceil
mapBBoxes.add({bb.getMin().x, bb.getMin().y, bb.getMax().z});
mapBBoxes.add({bb.getMax().x, bb.getMin().y, bb.getMax().z});
mapBBoxes.add({bb.getMax().x, bb.getMax().y, bb.getMax().z});
mapBBoxes.add({bb.getMin().x, bb.getMax().y, bb.getMax().z});
mapBBoxes.add({bb.getMin().x, bb.getMin().y, bb.getMax().z});
mapBBoxes.splitFace(); mapBBoxes.splitFace();
// up
mapBBoxes.addSegment({bb.getMin().x, bb.getMin().y, bb.getMin().z}, {bb.getMin().x, bb.getMin().y, bb.getMax().z});
mapBBoxes.addSegment({bb.getMax().x, bb.getMin().y, bb.getMin().z}, {bb.getMax().x, bb.getMin().y, bb.getMax().z});
mapBBoxes.addSegment({bb.getMin().x, bb.getMax().y, bb.getMin().z}, {bb.getMin().x, bb.getMax().y, bb.getMax().z});
mapBBoxes.addSegment({bb.getMax().x, bb.getMax().y, bb.getMin().z}, {bb.getMax().x, bb.getMax().y, bb.getMax().z});
}
void addBBoxPoly(const BBox3& bb, K::GnuplotColor c) {
K::GnuplotObjectPolygon* poly = new K::GnuplotObjectPolygon();
poly->add(K::GnuplotCoordinate3(bb.getMin().x, bb.getMin().y, bb.getMin().z, K::GnuplotCoordinateSystem::FIRST));
poly->add(K::GnuplotCoordinate3(bb.getMax().x, bb.getMin().y, bb.getMin().z, K::GnuplotCoordinateSystem::FIRST));
poly->add(K::GnuplotCoordinate3(bb.getMax().x, bb.getMax().y, bb.getMin().z, K::GnuplotCoordinateSystem::FIRST));
poly->add(K::GnuplotCoordinate3(bb.getMin().x, bb.getMax().y, bb.getMin().z, K::GnuplotCoordinateSystem::FIRST));
poly->close();
poly->setStroke(K::GnuplotStroke::NONE());
poly->setFill(K::GnuplotFill(K::GnuplotFillStyle::SOLID, c));
splot.getObjects().add(poly);
}
void setGroundTruth(const Point3 pos_m) {
gp << "set arrow 998 from " << pos_m.x << "," << pos_m.y << "," << pos_m.z << " to " << pos_m.x << "," << pos_m.y << "," << pos_m.z+1 << " front \n";
}
@@ -202,7 +253,25 @@ public:
addPolygon(points, c.toHEX(), front, fill);
}
void addPolygon(const std::vector<Point3>& points, const std::string& color, bool front = false, bool fill = true) {
void addRectangleW(const Point3 p1, const Point3 p2, const K::GnuplotColor c, const float w, bool front = false) {
std::vector<Point3> points = {
Point3(p1.x, p1.y, p1.z),
Point3(p2.x, p1.y, p1.z),
Point3(p2.x, p2.y, p1.z),
Point3(p1.x, p2.y, p1.z),
Point3(p1.x, p1.y, p1.z),
};
K::GnuplotObjectPolygon* poly = new K::GnuplotObjectPolygon();
poly->getStroke().setWidth(w);
poly->getStroke().setColor(c);
poly->setFront(front);
for (const Point3 p : points) {
poly->add(K::GnuplotCoordinate3(p.x, p.y, p.z, K::GnuplotCoordinateSystem::FIRST));
}
splot.getObjects().add(poly);
}
void addPolygon(const std::vector<Point3>& points, const std::string& color, bool front = false, bool fill = true, const float alpha = 1) {
for (const Point3 p : points) {
if (p.z < settings.minZ) {return;}
@@ -216,6 +285,7 @@ public:
for (const Point3 p : points) {
poly->add(K::GnuplotCoordinate3(p.x, p.y, p.z, K::GnuplotCoordinateSystem::FIRST));
poly->setZIndex(p.z); // manual depth ordering
poly->getFill().setAlpha(alpha);
}
poly->setFront(front);
@@ -240,16 +310,16 @@ public:
}
void addFloorRect(const Point3 pos_m, const float size, Color c) {
void addFloorRect(const Point3 pos_m, const float size, Color c, float ratio = 1.0) {
const Point3 p1 = pos_m + Point3(-size, -size, 0);
const Point3 p2 = pos_m + Point3(+size, -size, 0);
const Point3 p3 = pos_m + Point3(+size, +size, 0);
const Point3 p4 = pos_m + Point3(-size, +size, 0);
const Point3 p1 = pos_m + Point3(-size, -size/ratio, 0);
const Point3 p2 = pos_m + Point3(+size, -size/ratio, 0);
const Point3 p3 = pos_m + Point3(+size, +size/ratio, 0);
const Point3 p4 = pos_m + Point3(-size, +size/ratio, 0);
std::vector<Point3> points = {p1,p2,p3,p4,p1};
addPolygon(points, c.toHEX());
addPolygon(points, c.toHEX(), false, true);
// gp << "set object polygon from ";
// for (size_t i = 0; i < points.size(); ++i) {
@@ -279,11 +349,12 @@ public:
}
void setView(const float degX, const float degY) {
gp << "set view " << degX << "," << degY << "\n";
//gp << "set view " << degX << "," << degY << "\n";
splot.getView().setCamera(degX, degY);
}
void setScale(const float x, const float y) {
gp << "set multiplot layout 1,1 scale " << x << "," << y << "\n";
void setScale(const float x, const float y, const float ox = 0, const float oy = 0) {
gp << "set multiplot layout 1,1 scale " << x << "," << y << " offset " << ox << "," << oy << "\n";
}
void writeCodeTo(const std::string& file) {
@@ -292,9 +363,12 @@ public:
void noFrame() {
gp << "unset border\n";
gp << "unset xtics\n";
gp << "unset ytics\n";
gp << "unset ztics\n";
// gp << "unset xtics\n";
// gp << "unset ytics\n";
// gp << "unset ztics\n";
splot.getAxisX().setTicsVisible(false);
splot.getAxisY().setTicsVisible(false);
splot.getAxisZ().setTicsVisible(false);
}
void writeEpsTex(const std::string file, K::GnuplotSize size = K::GnuplotSize(8.5, 5.1)) {
@@ -357,7 +431,9 @@ public:
// plot the floor's outline
if (settings.outline) {
for (Floorplan::FloorOutlinePolygon* poly : floor->outline) {
K::GnuplotColor color = (poly->outdoor) ? (K::GnuplotColor::fromRGB(200, 240, 200)) : (K::GnuplotColor::fromRGB(210,210,210));
K::GnuplotColor color = K::GnuplotColor::fromRGB(210,210,210);
if (poly->outdoor) {color = K::GnuplotColor::fromRGB(200, 240, 200);}
//if (poly->method == Floorplan::OutlineMethod::REMOVE) {color = K::GnuplotColor::fromRGB(245,245,245);}
K::GnuplotFill filler(K::GnuplotFillStyle::SOLID, color);
K::GnuplotObjectPolygon* gpol = new K::GnuplotObjectPolygon(filler, K::GnuplotStroke::NONE());
for (Point2 pt : poly->poly.points) {