This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/mapview/3D/MV3DElementFloorOutline.h
kazu 3b62f23c0e worked on 3D display
some ui changes
refactoring
new icons
2018-02-03 23:30:55 +01:00

110 lines
2.4 KiB
C++

#ifndef MV3DELEMENTFLOOROUTLINE_H
#define MV3DELEMENTFLOOROUTLINE_H
#include <Indoor/floorplan/v2/Floorplan.h>
#include "misc/Cube.h"
#include "MV3DElement.h"
#include "../../lib/gpc/gpc.h"
#include "misc/Polygon.h"
#include "misc/Outline.h"
class MV3DElementFloorOutline : public MV3DElement {
Floorplan::Floor* f;
Floorplan::FloorOutline* out;
struct Temp {
Point2 cacheSum;
Polygon* pol = nullptr;
std::vector<std::vector<Point3>> trias;
};
Temp tempIndoor;
Temp tempOutdoor;
Outline outlineIndoor;
Outline outlineOutdoor;
public:
/** ctor */
MV3DElementFloorOutline(Floorplan::Floor* f, Floorplan::FloorOutline* out) : f(f), out(out) {
outlineOutdoor.setColor(0.0, 0.5, 0.0);
outlineIndoor.setColor(0.2, 0.2, 0.2);
}
protected:
/** repaint me */
void render(const RenderSettings& rs) override {
rebuildIfNeeded();
outlineIndoor.render(rs);
outlineOutdoor.render(rs);
}
void rebuildIfNeeded() {
auto filterIndoor = [] (const Floorplan::FloorOutlinePolygon* p) {return p->outdoor == false;};
auto filterOutdoor = [] (const Floorplan::FloorOutlinePolygon* p) {return p->outdoor == true;};
rebuildIfNeeded(filterIndoor, outlineIndoor, tempIndoor);
rebuildIfNeeded(filterOutdoor, outlineOutdoor, tempOutdoor);
}
template <typename Filter> void rebuildIfNeeded(Filter include, Outline& dst, Temp& tmp) {
const std::vector<Floorplan::FloorOutlinePolygon*>& polys = *out;
// get number of points for rebuild-check
Point2 cacheSum(0,0);
for (Floorplan::FloorOutlinePolygon* poly : polys) {
if (!include(poly)) {continue;}
for (Point2 pt : poly->poly.points) {
cacheSum += pt;
}
}
// already up to date?
if (cacheSum == tmp.cacheSum) {return;}
tmp.cacheSum = cacheSum;
// rebuild
std::vector<gpc_polygon> add;
std::vector<gpc_polygon> rem;
if (tmp.pol) {delete tmp.pol;}
tmp.pol = new Polygon();
for (Floorplan::FloorOutlinePolygon* poly : polys) {
if (!include(poly)) {continue;}
switch (poly->method) {
case Floorplan::OutlineMethod::ADD: tmp.pol->add(poly->poly); break;
case Floorplan::OutlineMethod::REMOVE: tmp.pol->remove(poly->poly); break;
default: throw 1;
}
}
//dst->trias = dst->pol->get(f->atHeight);
std::vector<std::vector<Point3>> trias = tmp.pol->get(f->atHeight);
dst.clear();
dst.add(trias);
}
bool isTransparent() const override {
return false;
}
};
#endif // MV3DELEMENTFLOOROUTLINE_H