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

119 lines
2.7 KiB
C++

#ifndef MV3DELEMENTFLOOROUTLINE_H
#define MV3DELEMENTFLOOROUTLINE_H
#include <Indoor/floorplan/v2/Floorplan.h>
#include <Indoor/geo/GPCPolygon2.h>
#include "misc/Cube.h"
#include "MV3DElement.h"
#include "misc/Outline.h"
class MV3DElementFloorOutline : public MV3DElement {
Floorplan::Floor* f;
Floorplan::FloorOutline* out;
struct Temp {
Point2 cacheSum;
GPCPolygon2* 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 GPCPolygon2();
// all to-be-added polygons (filter!)
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: break;
default: throw 1;
}
}
// all to-be-removed polygons (NO filter!)
for (Floorplan::FloorOutlinePolygon* poly : polys) {
switch (poly->method) {
case Floorplan::OutlineMethod::REMOVE: tmp.pol->remove(poly->poly); break;
case Floorplan::OutlineMethod::ADD: 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