174 lines
5.1 KiB
C++
174 lines
5.1 KiB
C++
#ifndef GNUPLOTEXPORT_H
|
|
#define GNUPLOTEXPORT_H
|
|
|
|
#include "fixC11.h"
|
|
|
|
#include <Indoor/floorplan/v2/Floorplan.h>
|
|
#include <Indoor/grid/Grid.h>
|
|
|
|
#include <KLib/misc/gnuplot/Gnuplot.h>
|
|
#include <KLib/misc/gnuplot/GnuplotSplot.h>
|
|
#include <KLib/misc/gnuplot/GnuplotSplotElementLines.h>
|
|
#include <KLib/misc/gnuplot/GnuplotSplotElementPoints.h>
|
|
#include <KLib/misc/gnuplot/GnuplotSplotElementColorPoints.h>
|
|
#include <KLib/misc/gnuplot/GnuplotSplotElementMesh.h>
|
|
|
|
#include <set>
|
|
#include <fstream>
|
|
|
|
class GnuplotExport {
|
|
|
|
|
|
public:
|
|
|
|
|
|
// template <typename T> static void exp(const Floorplan::IndoorMap& map, Grid<T>& grid) {
|
|
|
|
// K::GnuplotSplotElementLines* walls =getWalls(map);
|
|
// write("/tmp/walls.dat", walls);
|
|
|
|
|
|
// K::GnuplotSplotElementPoints* nodesFloor = getNodes(grid, true, false);
|
|
// write("/tmp/nodesFloor.dat", nodesFloor);
|
|
|
|
// K::GnuplotSplotElementPoints* nodesStair = getNodes(grid, false, true);
|
|
// write("/tmp/nodesStair.dat", nodesStair);
|
|
|
|
// K::GnuplotSplotElementPoints* nodesAll = getNodes(grid, true, true);
|
|
// write("/tmp/nodesAll.dat", nodesAll);
|
|
|
|
|
|
// K::GnuplotSplotElementColorPoints* nodesAllImp = getColorNodes(grid, true, true);
|
|
// write("/tmp/nodesAllImp.dat", nodesAllImp);
|
|
// const std::string xxx = getColorNodes2(grid, true, true);
|
|
// write("/tmp/nodesAllImpPoly.dat", xxx);
|
|
// const std::string yyy = getColorNodes2(grid, true, false);
|
|
// write("/tmp/nodesFloorImpPoly.dat", yyy);
|
|
|
|
|
|
// K::GnuplotSplotElementLines* edgesFloor = getEdges(grid, true, false);
|
|
// write("/tmp/edgesFloor.dat", edgesFloor);
|
|
|
|
// K::GnuplotSplotElementLines* edgesStair= getEdges(grid, false, true);
|
|
// write("/tmp/edgesStair.dat", edgesStair);
|
|
|
|
// K::GnuplotSplotElementLines* edgesAll = getEdges(grid, true, true);
|
|
// write("/tmp/edgesAll.dat", edgesAll);
|
|
|
|
|
|
// }
|
|
|
|
|
|
template <typename T> static void write(const std::string& file, const T* elem) {
|
|
std::ofstream os(file.c_str());
|
|
if (!os.good()) {throw "error!";}
|
|
elem->addDataTo(os);
|
|
os.close();
|
|
}
|
|
|
|
static void write(const std::string& file, const std::string& str) {
|
|
std::ofstream os(file.c_str());
|
|
if (!os.good()) {throw "error!";}
|
|
os << str;
|
|
os.close();
|
|
}
|
|
|
|
static K::GnuplotSplotElementLines* getWalls(const Floorplan::IndoorMap& map) {
|
|
|
|
K::GnuplotSplotElementLines* lines = new K::GnuplotSplotElementLines();
|
|
for (const Floorplan::Floor* f : map.floors) {
|
|
for (const Floorplan::FloorObstacle* o : f->obstacles) {
|
|
if (dynamic_cast<const Floorplan::FloorObstacleLine*>(o)) {
|
|
Floorplan::FloorObstacleLine* l = (Floorplan::FloorObstacleLine*) o;
|
|
K::GnuplotPoint3 p1(l->from.x, l->from.y, f->atHeight);
|
|
K::GnuplotPoint3 p2(l->to.x, l->to.y, f->atHeight);
|
|
lines->addSegment(p1*100, p2*100);
|
|
}
|
|
}
|
|
}
|
|
return lines;
|
|
|
|
}
|
|
|
|
template <typename T> static K::GnuplotSplotElementPoints* getNodes(Grid<T>& grid, bool addFloor, bool addStair) {
|
|
|
|
K::GnuplotSplotElementPoints* points = new K::GnuplotSplotElementPoints();
|
|
for (const T& n : grid) {
|
|
if (n.getType() == GridNode::TYPE_STAIR && !addStair) {continue;}
|
|
if (n.getType() == GridNode::TYPE_FLOOR && !addFloor) {continue;}
|
|
|
|
K::GnuplotPoint3 p(n.x_cm, n.y_cm, n.z_cm);
|
|
points->add(p);
|
|
}
|
|
return points;
|
|
|
|
}
|
|
|
|
|
|
template <typename T> static std::string getColorNodes2(Grid<T>& grid, bool addFloor, bool addStair) {
|
|
|
|
std::stringstream ss;
|
|
for (const T& n : grid) {
|
|
if (n.getType() == GridNode::TYPE_STAIR && !addStair) {continue;}
|
|
if (n.getType() == GridNode::TYPE_FLOOR && !addFloor) {continue;}
|
|
|
|
int s = 15;
|
|
ss << "set object polygon from ";
|
|
ss << n.x_cm-s << "," << n.y_cm-s << "," << n.z_cm << " to ";
|
|
ss << n.x_cm+s << "," << n.y_cm-s << "," << n.z_cm << " to ";
|
|
ss << n.x_cm+s << "," << n.y_cm+s << "," << n.z_cm << " to ";
|
|
ss << n.x_cm-s << "," << n.y_cm+s << "," << n.z_cm << " ";
|
|
ss << "fs solid fc palette cb " << n.imp << "\n";
|
|
}
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
template <typename T> static K::GnuplotSplotElementColorPoints* getColorNodes(Grid<T>& grid, bool addFloor, bool addStair) {
|
|
|
|
K::GnuplotSplotElementColorPoints* points = new K::GnuplotSplotElementColorPoints();
|
|
for (const T& n : grid) {
|
|
if (n.getType() == GridNode::TYPE_STAIR && !addStair) {continue;}
|
|
if (n.getType() == GridNode::TYPE_FLOOR && !addFloor) {continue;}
|
|
|
|
K::GnuplotPoint3 p(n.x_cm, n.y_cm, n.z_cm);
|
|
points->add(p, n.imp);
|
|
}
|
|
return points;
|
|
|
|
}
|
|
|
|
template <typename T> static K::GnuplotSplotElementLines* getEdges(Grid<T>& grid, bool addFloor, bool addStair) {
|
|
|
|
std::set<uint64_t> filter;
|
|
K::GnuplotSplotElementLines* lines = new K::GnuplotSplotElementLines();
|
|
for (const T& n1 : grid) {
|
|
if (n1.getType() == GridNode::TYPE_STAIR && !addStair) {continue;}
|
|
if (n1.getType() == GridNode::TYPE_FLOOR && !addFloor) {continue;}
|
|
|
|
for (const T& n2 : grid.neighbors(n1)) {
|
|
|
|
const uint64_t i1 = std::min(n1.getIdx(), n2.getIdx());
|
|
const uint64_t i2 = std::max(n1.getIdx(), n2.getIdx());
|
|
const uint64_t idx = i2 << 32 | i1;
|
|
|
|
if (filter.find(idx) == filter.end()) {
|
|
|
|
filter.insert(idx);
|
|
K::GnuplotPoint3 p1(n1.x_cm, n1.y_cm, n1.z_cm);
|
|
K::GnuplotPoint3 p2(n2.x_cm, n2.y_cm, n2.z_cm);
|
|
lines->addSegment(p1, p2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
return lines;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // GNUPLOTEXPORT_H
|