some refactoring

hopefully improved rendering speed
added support to add .obj obstacles
This commit is contained in:
2018-02-17 17:39:18 +01:00
parent 839401edb7
commit 52ab71fac5
25 changed files with 538 additions and 12 deletions

View File

@@ -38,6 +38,11 @@ public:
/** repaint me */
void paint(Painter& p) override {
// invisible? -> leave
if (!p.isVisible(ap->pos.xy())) {
return;
}
static const QPixmap& pixmapUnfocused = UIHelper::getPixmapColored("wifi", CFG::UNFOCUS_COLOR, 16);
static const QPixmap& pixmapFocused = UIHelper::getPixmapColored("wifi", CFG::FOCUS_COLOR, 16);
static const QPixmap& pixmapSel = UIHelper::getPixmapColored("wifi", CFG::SEL_COLOR, 16);

View File

@@ -38,6 +38,11 @@ public:
/** repaint me */
void paint(Painter& p) override {
// invisible? -> leave
if (!p.isVisible(fpl->posOnFloor)) {
return;
}
static const QPixmap& pixmapUnfocused = UIHelper::getPixmapColored("fingerprint", CFG::UNFOCUS_COLOR, 16);
static const QPixmap& pixmapFocused = UIHelper::getPixmapColored("fingerprint", CFG::FOCUS_COLOR, 16);
static const QPixmap& pixmapSel = UIHelper::getPixmapColored("fingerprint", CFG::SEL_COLOR, 16);

View File

@@ -23,6 +23,11 @@ ClickDist MV2DElementFloorObstacleDoor::getMinDistanceXY(const Point2 p) const {
void MV2DElementFloorObstacleDoor::paint(Painter& p) {
// invisible? -> leave
if (!p.isVisible( (fo->from+fo->to)/2 )) {
return;
}
// selected endpoints?
if (hasFocus()) {
p.setPenBrush(Qt::NoPen, CFG::SEL_COLOR);

View File

@@ -0,0 +1,134 @@
#include "MV2DElementFloorObstacleObject.h"
#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h>
#include <Indoor/wifi/estimate/ray3/OBJPool.h>
#include "../../UIHelper.h"
MV2DElementFloorObstacleObject::MV2DElementFloorObstacleObject(Floorplan::FloorObstacleObject* fo) : fo(fo) {
;
}
BBox2 MV2DElementFloorObstacleObject::getBoundingBox() const {
BBox2 bbox;
bbox.add(Point2(fo->pos.x, fo->pos.y));
bbox.grow(Point2(0.1, 0.1));
return bbox;
}
ClickDist MV2DElementFloorObstacleObject::getMinDistanceXY(const Point2 p) const {
return ClickDist(p.getDistance(fo->pos.xy()), ClickDistType::DIRECT);
}
//#include <unordered_map>
//struct Cache {
// struct Line {
// Point2 p1;
// Point2 p2;
// Line(Point2 p1, Point2 p2) : p1(p1), p2(p2) {;}
// };
// struct Entry {
// const Floorplan::FloorObstacleObject* obj = nullptr;
// std::vector<Line> lines;
// };
// Entry e;
// const Entry& get(const Floorplan::FloorObstacleObject* obj) {
// if (e.obj == nullptr || e.obj->file != obj->file || e.obj->pos != obj->pos || e.obj->rot != obj->rot) {
// e.obj = obj;
// e.lines.clear();
// const Ray3D::Obstacle3D obs = Ray3D::OBJPool::get().getObject(obj->file).rotated_deg(obj->rot).translated(obj->pos);
// for (const Triangle3& tria : obs.triangles) {
// if (tria.p1.xy() != tria.p2.xy()) {
// e.lines.push_back( Line (tria.p1.xy(), tria.p2.xy()) );
// }
// }
// return e;
// }
// }
//} cache;
void MV2DElementFloorObstacleObject::paint(Painter& p) {
static const QPixmap& pixmapUnfocused = UIHelper::getPixmapColored("objects", CFG::UNFOCUS_COLOR, 16);
static const QPixmap& pixmapFocused = UIHelper::getPixmapColored("objects", CFG::FOCUS_COLOR, 16);
static const QPixmap& pixmapSel = UIHelper::getPixmapColored("objects", CFG::SEL_COLOR, 16);
// invisible? -> leave
if (!p.isVisible(fo->pos.xy())) {
return;
}
if (p.getScaler().getScale() >= 40) {
// TODO: quite costly... cache??
p.setPenBrush(Qt::black, Qt::NoBrush);
// const Cache::Entry& e = cache.get(fo);
// for (const Cache::Line& l : e.lines) {
// p.drawLine(l.p1, l.p2);
// }
const Ray3D::Obstacle3D obs = Ray3D::OBJPool::get().getObject(fo->file).rotated_deg(fo->rot).translated(fo->pos);
for (const Triangle3& tria : obs.triangles) {
if (tria.p1.xy() != tria.p2.xy()) {
p.drawLine( tria.p1.xy(), tria.p2.xy() );
}
}
}
if (p.getScaler().getScale() >= 20) {
if (selectedUserIdx == 0) {
p.drawPixmap(fo->pos.xy(), pixmapSel);
} else if (hasFocus()) {
p.drawPixmap(fo->pos.xy(), pixmapFocused);
} else {
p.drawPixmap(fo->pos.xy(), pixmapUnfocused);
}
}
//p.setPenBrush(Qt::black, Qt::NoBrush);
//p.drawDot(fo->pos.xy());
}
std::vector<MoveableNode> MV2DElementFloorObstacleObject::getMoveableNodes() const {
return { MoveableNode(0, fo->pos.xy()) };
}
void MV2DElementFloorObstacleObject::onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) {
(void) v;
if (userIdx == 0) {fo->pos.x = newPos.x; fo->pos.y = newPos.y;}
}
void MV2DElementFloorObstacleObject::mousePressed(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
void MV2DElementFloorObstacleObject::mouseMove(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
void MV2DElementFloorObstacleObject::mouseReleased(MapView2D* v, const Point2 p) {
(void) v;
(void) p;
}
bool MV2DElementFloorObstacleObject::keyPressEvent(MapView2D* v, QKeyEvent *e) {
(void) v;
(void) e;
return false;
}
void MV2DElementFloorObstacleObject::onFocus() {
;
}
void MV2DElementFloorObstacleObject::onUnfocus() {
;
}

View File

@@ -0,0 +1,51 @@
#ifndef MV2DELEMENTFLOOROBSTACLEOBJECT_H
#define MV2DELEMENTFLOOROBSTACLEOBJECT_H
#include "MV2DElement.h"
#include "HasMoveableNodes.h"
//#include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h>
//#include <stdio.h>
//#include "../../UIHelper.h"
class MV2DElementFloorObstacleObject : public MV2DElement, public HasMoveableNodes {
private:
//bool sel = false;
Floorplan::FloorObstacleObject* fo;
public:
/** ctor with the AP to render/edit */
MV2DElementFloorObstacleObject(Floorplan::FloorObstacleObject* fo);
BBox2 getBoundingBox() const override;
/** get the element's minimal distance (nearest whatsoever) to the given point */
ClickDist getMinDistanceXY(const Point2 p) const override;
/** repaint me */
void paint(Painter& p) override;
virtual std::vector<MoveableNode> getMoveableNodes() const override;
virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override;
virtual void mousePressed(MapView2D* v, const Point2 p) override;
virtual void mouseMove(MapView2D* v, const Point2 p) override;
virtual void mouseReleased(MapView2D* v, const Point2 p) override;
virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override;
virtual void onFocus() override;
virtual void onUnfocus() override;
};
#endif // MV2DELEMENTFLOOROBSTACLELINE_H

View File

@@ -37,6 +37,11 @@ public:
/** repaint me */
void paint(Painter& p) override {
// invisible? -> leave
if (!p.isVisible(gtp->pos.xy())) {
return;
}
static const QPixmap& pixmapUnfocused = UIHelper::getPixmapColored("gtp", CFG::UNFOCUS_COLOR, 16);
static const QPixmap& pixmapFocused = UIHelper::getPixmapColored("gtp", CFG::FOCUS_COLOR, 16);
static const QPixmap& pixmapSel = UIHelper::getPixmapColored("gtp", CFG::SEL_COLOR, 16);

View File

@@ -37,6 +37,11 @@ public:
/** repaint me */
void paint(Painter& p) override {
// invisible? -> leave
if (!p.isVisible(poi->pos)) {
return;
}
static const QPixmap& pixmapUnfocused = UIHelper::getPixmapColored("poi", CFG::UNFOCUS_COLOR, 16);
static const QPixmap& pixmapFocused = UIHelper::getPixmapColored("poi", CFG::FOCUS_COLOR, 16);
static const QPixmap& pixmapSel = UIHelper::getPixmapColored("poi", CFG::SEL_COLOR, 16);

View File

@@ -40,6 +40,11 @@ public:
/** repaint me */
void paint(Painter& p) override {
// invisible? -> leave
if (!p.isVisible(reg->posOnMap_m.xy())) {
return;
}
static const QPixmap& pixmapUnfocused = UIHelper::getPixmapColored("registration", CFG::UNFOCUS_COLOR, 16);
static const QPixmap& pixmapFocused = UIHelper::getPixmapColored("registration", CFG::FOCUS_COLOR, 16);
static const QPixmap& pixmapSel = UIHelper::getPixmapColored("registration", CFG::SEL_COLOR, 16);

View File

@@ -95,6 +95,18 @@ public:
std::vector<Floorplan::StairPart> parts = stair->getParts();
std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(parts, floor);
// skip drawing?
BBox2 bbox;
for (const Floorplan::Quad3& q : quads) {
bbox.add(q.p1.xy());
bbox.add(q.p2.xy());
bbox.add(q.p3.xy());
bbox.add(q.p4.xy());
}
if (!p.isVisible(bbox)) {
return;
}
for (int i = 0; i < (int) parts.size(); ++i) {
const Floorplan::StairPart& part = parts[i];

View File

@@ -6,6 +6,7 @@
#include <Indoor/geo/Point2.h>
#include <Indoor/geo/Point3.h>
#include <Indoor/geo/BBox2.h>
#include "Scaler.h"
@@ -30,6 +31,22 @@ public:
int height() {return h;}
/** is the given point visible on screen? */
bool isVisible(const Point2 p) {
const float x = s.xms(p.x);
const float y = s.yms(p.y);
return (x >= 0 && y >= 0 && x < w && y < h);
}
/** is the given volume visible on screen? */
bool isVisible(const BBox2 bb) {
const BBox2 bbt(0,0,w,h);
BBox2 bbs;
bbs.add(s.xms(bb.getMin().x), s.yms(bb.getMin().y)); // y might be inverted! -> use the add() method to address this
bbs.add(s.xms(bb.getMax().x), s.yms(bb.getMax().y)); // y might be inverted! -> use the add() method to address this
return bbt.intersects(bbs);
}
void drawLine(const Point2 p1, const Point2 p2) {
p->drawLine(s.xms(p1.x), s.yms(p1.y), s.xms(p2.x), s.yms(p2.y));
}

View File

@@ -0,0 +1,49 @@
#ifndef TOOLNEWOBJECT_H
#define TOOLNEWOBJECT_H
#include "ToolNewElement.h"
#include "../../model/MMFloorObstacles.h"
#include "../../model/MMFloorObstacleObject.h"
class ToolNewObject : public ToolNewElement<Floorplan::FloorObstacleObject, MMFloorObstacleObject> {
public:
ToolNewObject(Tools& tools, MapLayer* layer) : ToolNewElement(tools, layer) {
;
}
void becomesActive() override {
emit onHelpTextChange("left-click where to place a new object. right-click to end.");
}
void becomesInactive() override {
;
}
const std::string getName() const override {
return "new Object/Furniture/...";
}
void moving(const Point2 mapPoint) override {
(void) mapPoint;
}
/** next point */
void leftMouse(const Point2 mapPoint) override {
foEL = new Floorplan::FloorObstacleObject("", Point3(mapPoint.x, mapPoint.y, 0.0), Point3(0,0,0));
MMFloorObstacles* obs = (MMFloorObstacles*)layer;
mmEL = obs->createObject(foEL);
}
void rightMouse(const Point2 mapPoint) override {
(void) mapPoint;
finalizeCurrent();
disableMe();
}
};
#endif // TOOLNEWOBJECT_H