current state

This commit is contained in:
2017-04-24 16:12:15 +02:00
parent 67a9f02d6d
commit 755f5662ae
15 changed files with 1211 additions and 329 deletions

View File

@@ -10,6 +10,9 @@
#include <KLib/misc/gnuplot/GnuplotSplotElementPoints.h>
#include <KLib/misc/gnuplot/GnuplotSplotElementColorPoints.h>
#include <KLib/misc/gnuplot/GnuplotSplotElementLines.h>
#include <KLib/misc/gnuplot/GnuplotSplotElementPM3D.h>
#include <KLib/misc/gnuplot/GnuplotSplotElementEmpty.h>
#include <KLib/misc/gnuplot/GnuplotPlot.h>
#include <KLib/misc/gnuplot/GnuplotPlotElementHistogram.h>
#include <KLib/misc/gnuplot/objects/GnuplotObjects.h>
@@ -103,6 +106,11 @@ public:
K::GnuplotSplotElementLines mapOutlineConcrete;
K::GnuplotSplotElementLines mapBBoxes;
K::GnuplotSplotElementEmpty emptyElem;
K::GnuplotSplotElementPM3D pm3doutline;
std::string codeFile;
struct Settings {
@@ -134,6 +142,9 @@ public:
mapOutlineDrywall.getStroke().getColor().setHexStr("#888888");
mapOutlineGlass.getStroke().getColor().setHexStr("#888888"); mapOutlineGlass.getStroke().setType(K::GnuplotDashtype::DASHED);
mapBBoxes.getStroke().setWidth(2);
splot.add(&emptyElem);
splot.add(&mapOutlineConcrete);
splot.add(&mapOutlineDrywall);
splot.add(&mapOutlineGlass);
@@ -144,6 +155,8 @@ public:
splot.add(&pathReal); pathReal.getStroke().setWidth(2); pathReal.getStroke().getColor().setHexStr("#000000");
splot.add(&pathEst); pathEst.getStroke().setWidth(2); pathEst.getStroke().getColor().setHexStr("#0000ff");
splot.add(&pm3doutline);
splot.add(&points);
points.setPointType(7);
points.setPointSize(0.5);
@@ -239,7 +252,8 @@ public:
}
void addLabel(const std::string& txt, const Point3 pos) {
gp << "set label '" << txt << "' at " << pos.x << "," << pos.y << "," << pos.z << "\n";
//gp << "set label '" << txt << "' at " << pos.x << "," << pos.y << "," << pos.z << "\n";
splot.getCustom() << "set label '" << txt << "' at " << pos.x << "," << pos.y << "," << pos.z << " front\n";
}
void addRectangle(const Point3 p1, const Point3 p2, const Color c, bool front = false, bool fill = true) {
@@ -271,11 +285,11 @@ public:
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) {
K::GnuplotObjectPolygon* 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;}
if (p.z > settings.maxZ) {return;}
if (p.z < settings.minZ) {return nullptr;}
if (p.z > settings.maxZ) {return nullptr;}
}
const K::GnuplotFill pfill = (fill) ? (K::GnuplotFill(K::GnuplotFillStyle::SOLID, K::GnuplotColor::fromHexStr(color))) : (K::GnuplotFill::NONE());
@@ -303,6 +317,8 @@ public:
// gp << " fc rgb " << "'" << color << "'";
// gp << "\n";
return poly;
}
void setZRange(const float min, const float max) {
@@ -310,7 +326,7 @@ public:
}
void addFloorRect(const Point3 pos_m, const float size, Color c, float ratio = 1.0) {
K::GnuplotObjectPolygon* addFloorRect(const Point3 pos_m, const float size, Color c, float ratio = 1.0) {
const Point3 p1 = pos_m + Point3(-size, -size/ratio, 0);
const Point3 p2 = pos_m + Point3(+size, -size/ratio, 0);
@@ -319,7 +335,7 @@ public:
std::vector<Point3> points = {p1,p2,p3,p4,p1};
addPolygon(points, c.toHEX(), false, true);
return addPolygon(points, c.toHEX(), false, true);
// gp << "set object polygon from ";
// for (size_t i = 0; i < points.size(); ++i) {
@@ -397,6 +413,8 @@ public:
std::vector<Floorplan::Floor*> floors;
BBox3 bbox = FloorplanHelper::getBBox(map);
// only some floors??
if (settings.floors.empty()) {
floors = map->floors;
@@ -406,33 +424,31 @@ public:
}
}
// mapOutlineDrywall.addSegment(
// K::GnuplotPoint3(bbox.getMin().x, bbox.getMin().y, bbox.getMin().z),
// K::GnuplotPoint3(bbox.getMax().x, bbox.getMax().y, bbox.getMax().z)
// );
splot.getAxisX().setRange(K::GnuplotAxis::Range(bbox.getMin().x, bbox.getMax().x));
splot.getAxisY().setRange(K::GnuplotAxis::Range(bbox.getMin().y, bbox.getMax().y));
splot.getAxisZ().setRange(K::GnuplotAxis::Range(0, 11));
// process each selected floor
for (Floorplan::Floor* floor : floors) {
// plot obstacles?
if (settings.obstacles) {
for (Floorplan::FloorObstacle* obs : floor->obstacles) {
Floorplan::FloorObstacleLine* line = dynamic_cast<Floorplan::FloorObstacleLine*>(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);
switch(line->material) {
case Floorplan::Material::CONCRETE: mapOutlineConcrete.addSegment(p1, p2); break;
case Floorplan::Material::GLASS: mapOutlineGlass.addSegment(p1, p2); break;
case Floorplan::Material::UNKNOWN:
case Floorplan::Material::DRYWALL: mapOutlineDrywall.addSegment(p1, p2); break;
}
}
}
}
const float vo = floor->atHeight * 4.5;
// plot the floor's outline
if (settings.outline) {
for (Floorplan::FloorOutlinePolygon* poly : floor->outline) {
K::GnuplotColor color = K::GnuplotColor::fromRGB(210,210,210);
if (poly->outdoor) {color = K::GnuplotColor::fromRGB(200, 240, 200);}
if (floor->atHeight < settings.minZ) {continue;}
if (floor->atHeight > settings.maxZ) {continue;}
const float v = 180 + vo;
K::GnuplotColor color = K::GnuplotColor::fromRGB(v,v,v);
if (poly->outdoor) {color = K::GnuplotColor::fromRGB(180, 240, 180);}
//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());
@@ -441,7 +457,56 @@ public:
gpol->add(coord);
}
gpol->close();
gpol->setZIndex(floor->atHeight-0.1); // below the lines
//gpol->setFront(true);
splot.getObjects().add(gpol);
}
}
// plot obstacles?
if (settings.obstacles) {
for (Floorplan::FloorObstacle* obs : floor->obstacles) {
Floorplan::FloorObstacleLine* line = dynamic_cast<Floorplan::FloorObstacleLine*>(obs);
if (line) {
if (floor->atHeight < settings.minZ) {continue;}
if (floor->atHeight > settings.maxZ) {continue;}
// const K::GnuplotPoint3 p1(line->from.x, line->from.y, floor->atHeight);
// const K::GnuplotPoint3 p2(line->to.x, line->to.y, floor->atHeight);
// switch(line->material) {
// case Floorplan::Material::CONCRETE: mapOutlineConcrete.addSegment(p1, p2); break;
// case Floorplan::Material::GLASS: mapOutlineGlass.addSegment(p1, p2); break;
// case Floorplan::Material::UNKNOWN:
// case Floorplan::Material::DRYWALL: mapOutlineDrywall.addSegment(p1, p2); break;
// }
// K::GnuplotObjectArrow* arrow = new K::GnuplotObjectArrow(
// K::GnuplotCoordinate3(line->from.x, line->from.y, floor->atHeight, K::GnuplotCoordinateSystem::FIRST),
// K::GnuplotCoordinate3(line->to.x, line->to.y, floor->atHeight, K::GnuplotCoordinateSystem::FIRST)
// );
// arrow->setHead(K::GnuplotObjectArrow::Head::NONE);
// splot.getObjects().add(arrow);
const float v = 140 + vo;
// drawing outlines as polygon is a hack for correct depth-order in gnuplot
K::GnuplotColor color = K::GnuplotColor::fromRGB(v,v,v);
K::GnuplotFill filler = K::GnuplotFill(K::GnuplotFillStyle::EMPTY_BORDER, color);
K::GnuplotStroke stroke(K::GnuplotDashtype::NONE, 1, color);
//K::GnuplotObjectPolygon* gpol = new K::GnuplotObjectPolygon(K::GnuplotFill::NONE(), stroke);
K::GnuplotObjectPolygon* gpol = new K::GnuplotObjectPolygon(filler, stroke);
//K::GnuplotObjectPolygon* gpol = new K::GnuplotObjectPolygon(K::GnuplotFill::NONE(), K::GnuplotStroke::NONE());
gpol->add(K::GnuplotCoordinate3(line->from.x, line->from.y, floor->atHeight, K::GnuplotCoordinateSystem::FIRST));
gpol->add(K::GnuplotCoordinate3(line->to.x, line->to.y, floor->atHeight, K::GnuplotCoordinateSystem::FIRST));
gpol->close();
gpol->setZIndex(floor->atHeight); // above the ground polygon
//gpol->setFront(true);
splot.getObjects().add(gpol);
}
}
}
@@ -450,7 +515,32 @@ public:
for (Floorplan::Stair* s : floor->stairs) {
std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(s->getParts(), floor);
for (const Floorplan::Quad3& q : quads) {
addPolygon({q.p1, q.p2, q.p3, q.p4, q.p1}, "#c0c0c0");
// K::GnuplotObjectPolygon* poly = addPolygon({q.p1, q.p2, q.p3, q.p4, q.p1}, "#c0c0c0");
// if (poly) {
// poly->setZIndex(floor->atHeight+1.5); // above the floor
// }
const float v1 = 180 + q.p1.z * 4.5;
const float v2 = 140 + q.p1.z * 4.5;
const float z = (q.p1.z + q.p2.z + q.p3.z + q.p4.z) / 4.0f;
if (z < settings.minZ) {continue;}
if (z > settings.maxZ) {continue;}
K::GnuplotColor color = K::GnuplotColor::fromRGB(v1,v1,v1);
K::GnuplotColor color2 = K::GnuplotColor::fromRGB(v2,v2,v2);
K::GnuplotFill filler(K::GnuplotFillStyle::SOLID, color);
K::GnuplotStroke stroke(K::GnuplotDashtype::SOLID, 1, color2);
K::GnuplotObjectPolygon* gpol = new K::GnuplotObjectPolygon(filler, stroke);
gpol->add(K::GnuplotCoordinate3(q.p1.x, q.p1.y, q.p1.z, K::GnuplotCoordinateSystem::FIRST));
gpol->add(K::GnuplotCoordinate3(q.p2.x, q.p2.y, q.p2.z, K::GnuplotCoordinateSystem::FIRST));
gpol->add(K::GnuplotCoordinate3(q.p3.x, q.p3.y, q.p3.z, K::GnuplotCoordinateSystem::FIRST));
gpol->add(K::GnuplotCoordinate3(q.p4.x, q.p4.y, q.p4.z, K::GnuplotCoordinateSystem::FIRST));
gpol->close();
gpol->setZIndex(z); // above the ground
splot.getObjects().add(gpol);
}
}
}