some refactoring
hopefully improved rendering speed added support to add .obj obstacles
This commit is contained in:
134
mapview/2D/MV2DElementFloorObstacleObject.cpp
Normal file
134
mapview/2D/MV2DElementFloorObstacleObject.cpp
Normal 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() {
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user