new helper methods

improved elememt-selection
changed some parameters
show length for selected obstacles/doors
minor fixes
This commit is contained in:
2017-01-05 09:41:47 +01:00
parent 535e410ae9
commit 2297a76c53
17 changed files with 160 additions and 56 deletions

View File

@@ -65,6 +65,7 @@ HEADERS += MainWindow.h \
mapview/2D/MV2DElementBeacon.h \ mapview/2D/MV2DElementBeacon.h \
mapview/2D/MV2DElementAccessPoint.h \ mapview/2D/MV2DElementAccessPoint.h \
mapview/2D/MV2DElementFloorObstacleCircle.h \ mapview/2D/MV2DElementFloorObstacleCircle.h \
mapview/2D/MV2DElementFloorObstacleDoor.h \
mapview/2D/MapViewElementHelper.h \ mapview/2D/MapViewElementHelper.h \
mapview/2D/MV2DElementFloorUnderlay.h \ mapview/2D/MV2DElementFloorUnderlay.h \
mapview/2D/MV2DElementPOI.h \ mapview/2D/MV2DElementPOI.h \
@@ -128,7 +129,8 @@ HEADERS += MainWindow.h \
mapview/model/MMFloorElevators.h \ mapview/model/MMFloorElevators.h \
mapview/model/MMFloorElevator.h \ mapview/model/MMFloorElevator.h \
params/LayerTree.h \ params/LayerTree.h \
params/EditFields.h params/EditFields.h \
mapview/2D/ClickDist.h
FORMS += MainWindow.ui FORMS += MainWindow.ui

View File

@@ -94,7 +94,8 @@ MainController::MainController() {
//mapModel->load("/mnt/data/workspaces/Indoor/tests/data/WalkHeadingMap.xml"); //mapModel->load("/mnt/data/workspaces/Indoor/tests/data/WalkHeadingMap.xml");
//mapModel->load("/mnt/data/workspaces/IPIN2016/IPIN2016/competition/maps/test.xml"); //mapModel->load("/mnt/data/workspaces/IPIN2016/IPIN2016/competition/maps/test.xml");
//mapModel->load("/mnt/vm/workspace/IRGame/IndoorServer/maps/map6.xml"); //mapModel->load("/mnt/vm/workspace/IRGame/IndoorServer/maps/map6.xml");
//mapModel->load("/mnt/vm/workspace/IRGame/IndoorServer/maps/keller.xml"); //mapModel->load("/mnt/vm/workspace/IRGame/IndoorServer/maps/keller1.xml");
mapModel->load("/mnt/vm/workspace/IRGame/IndoorServer/maps/wohnung3.xml");
//mapModel->startEmpty(); //mapModel->startEmpty();

59
mapview/2D/ClickDist.h Normal file
View File

@@ -0,0 +1,59 @@
#ifndef CLICKDIST_H
#define CLICKDIST_H
enum class ClickDistType {
UNKNOWN,
DIRECT, // e.g. distance between cursor and an edge-point, POI, AP, Beacon, ...
CUT, // e.g. distance between cursor and an obstacle-line
};
/** describes distances between mouse-cursor and objects within the 2D view */
struct ClickDist {
/** distance in pixels */
float dst_px;
/** distance type */
ClickDistType type;
/** ctor */
ClickDist(const float dst_px, const ClickDistType type) : dst_px(dst_px), type(type) {;}
/** max-dummy */
static ClickDist max() {return ClickDist(9999999, ClickDistType::UNKNOWN);}
/** distance comparison */
bool operator < (const ClickDist o) const {
return (this->dst_px * this->mod()) < (o.dst_px * o.mod());
}
/** multiply by constant */
ClickDist operator * (const float val) const {return ClickDist(dst_px*val, type);}
// /** weighted distance comparison based on ClickDistType */
// bool compare(const ClickDist o) const {
// return ((*this)*mod()) < (o*o.mod());
// }
private:
/**
* artificially modify the distance based on the given type.
* this enhances the selection in cases of equal distance
* like a POI residing dirctly one a line
*/
float mod() const {
switch (type) {
case ClickDistType::UNKNOWN: return 1.1;
case ClickDistType::CUT: return 1.0;
case ClickDistType::DIRECT: return 0.7;
default: throw "code error";
}
}
};
#endif // CLICKDIST_H

View File

@@ -9,6 +9,8 @@
#include <Indoor/geo/BBox2.h> #include <Indoor/geo/BBox2.h>
#include <Indoor/geo/Line2.h> #include <Indoor/geo/Line2.h>
#include "ClickDist.h"
/** /**
* represents one drawable, selectable, editable, ... * represents one drawable, selectable, editable, ...
* element shown within the MapView2D * element shown within the MapView2D
@@ -29,7 +31,7 @@ public:
virtual BBox2 getBoundingBox() const = 0; virtual BBox2 getBoundingBox() const = 0;
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
virtual float getMinDistanceXY(const Point2 p) const = 0; virtual ClickDist getMinDistanceXY(const Point2 p) const = 0;
/** repaint me */ /** repaint me */
virtual void paint(Painter& p) = 0; virtual void paint(Painter& p) = 0;

View File

@@ -31,8 +31,8 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
return p.getDistance(ap->pos.xy()); return ClickDist(p.getDistance(ap->pos.xy()), ClickDistType::DIRECT);
} }
/** repaint me */ /** repaint me */
@@ -61,7 +61,7 @@ public:
p.setPenBrush(Qt::black, Qt::NoBrush); p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawDot(ap->pos.xy()); p.drawDot(ap->pos.xy());
if (p.getScaler().getScale() >= 25) { if (p.getScaler().getScale() >= 25) {
const std::string str = ap->name + " (" + ap->name + ")"; const std::string str = ap->name + " (" + ap->mac + ")";
p.p->drawText(p.getScaler().xms(ap->pos.x) + 10, p.getScaler().yms(ap->pos.y) + 5, str.c_str()); p.p->drawText(p.getScaler().xms(ap->pos.x) + 10, p.getScaler().yms(ap->pos.y) + 5, str.c_str());
} else if (p.getScaler().getScale() >= 10) { } else if (p.getScaler().getScale() >= 10) {
const std::string str = ap->name; const std::string str = ap->name;

View File

@@ -29,8 +29,8 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
return p.getDistance(b->pos.xy()); return ClickDist(p.getDistance(b->pos.xy()), ClickDistType::DIRECT);
} }
/** repaint me */ /** repaint me */

View File

@@ -30,11 +30,11 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
// std::vector<Point2> points = elevator->getPoints().points; // std::vector<Point2> points = elevator->getPoints().points;
// points.push_back(elevator->center); // points.push_back(elevator->center);
// auto it minEl = std::min_element(points.begin(), points.end(), // auto it minEl = std::min_element(points.begin(), points.end(),
return p.getDistance(elevator->center); return ClickDist(p.getDistance(elevator->center), ClickDistType::DIRECT);
} }
/** repaint me */ /** repaint me */

View File

@@ -27,8 +27,11 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
return std::min(p.getDistance(getSelPoints()[0]), p.getDistance(getSelPoints()[1])); const ClickDist d1(p.getDistance(getSelPoints()[0]), ClickDistType::DIRECT);
const ClickDist d2(p.getDistance(getSelPoints()[1]), ClickDistType::DIRECT);
return std::min(d1, d2);
//return std::min(p.getDistance(getSelPoints()[0]), p.getDistance(getSelPoints()[1]));
} }

View File

@@ -27,7 +27,7 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p); return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p);
} }
@@ -69,6 +69,12 @@ public:
p.drawCircle(fo->to); p.drawCircle(fo->to);
} }
// obstacle length
if (hasFocus()) {
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to));
}
} }

View File

@@ -6,6 +6,7 @@
#include "MapViewElementHelper.h" #include "MapViewElementHelper.h"
#include <Indoor/floorplan/v2/Floorplan.h> #include <Indoor/floorplan/v2/Floorplan.h>
#include <stdio.h>
class MV2DElementFloorObstacleLine : public MV2DElement, public HasMoveableNodes { class MV2DElementFloorObstacleLine : public MV2DElement, public HasMoveableNodes {
@@ -27,7 +28,7 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p); return MapElementHelper::getLineDistanceXY(fo->from, fo->to, p);
} }
@@ -60,36 +61,48 @@ public:
p.setPenBrush(Qt::black, Qt::NoBrush); p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawCircle(fo->from); p.drawCircle(fo->from);
p.drawCircle(fo->to); p.drawCircle(fo->to);
// obstacle length
p.setPenBrush(Qt::black, Qt::NoBrush);
p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to));
} else { } else {
//p.setPenBrush(Qt::NoPen, Qt::black); //p.setPenBrush(Qt::NoPen, Qt::black);
p.drawCircle(fo->from, 0.1); p.drawCircle_px(fo->from, 3);
p.drawCircle(fo->to, 0.1); p.drawCircle_px(fo->to, 3);
} }
} }
void paintDoor(Painter& p) { // void paintDoor(Painter& p) {
QPen pen; // QPen pen;
pen.setColor(QColor(0.5,0.5,0.5)); // pen.setColor(QColor(0.5,0.5,0.5));
pen.setStyle(Qt::PenStyle::DotLine); // pen.setStyle(Qt::PenStyle::DotLine);
p.setPenBrush(pen, Qt::NoBrush); // p.setPenBrush(pen, Qt::NoBrush);
// opening indicator // // opening indicator
const float open = M_PI / 4; // const float open = M_PI / 4;
const float len = (fo->to - fo->from).length(); // const float len = (fo->to - fo->from).length();
const float angle1 = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x); // const float angle1 = std::atan2(fo->to.y-fo->from.y, fo->to.x-fo->from.x);
const float angle2 = angle1 + open; // const float angle2 = angle1 + open;
const Point2 pOpen = Point2( std::cos(angle2) * len, std::sin(angle2) * len ) + fo->from; // const Point2 pOpen = Point2( std::cos(angle2) * len, std::sin(angle2) * len ) + fo->from;
p.drawLine(fo->from, fo->to); // p.drawLine(fo->from, fo->to);
p.drawLine(fo->from, pOpen); // p.drawLine(fo->from, pOpen);
p.drawArc(fo->from, len, angle1, open); // p.drawArc(fo->from, len, angle1, open);
//p.drawLine(fo->to, pOpen); // //p.drawLine(fo->to, pOpen);
} // // obstacle length
// p.setPenBrush(Qt::black, Qt::NoBrush);
// p.drawLength(fo->from, fo->to, fo->from.getDistance(fo->to));
// }
void onFocus() override { void onFocus() override {
; ;

View File

@@ -26,12 +26,12 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
float min = 999999; ClickDist min = ClickDist::max();
for (int i = 0; i < (int)fo.poly.points.size()-1; ++i) { for (int i = 0; i < (int)fo.poly.points.size()-1; ++i) {
const Point2 p1 = fo.poly.points[i]; const Point2 p1 = fo.poly.points[i];
const Point2 p2 = fo.poly.points[i+1]; const Point2 p2 = fo.poly.points[i+1];
const float dst = MapElementHelper::getLineDistanceXY(p1, p2, p); const ClickDist dst = MapElementHelper::getLineDistanceXY(p1, p2, p);
if (dst < min) {min = dst;} if (dst < min) {min = dst;}
} }
return min; return min;

View File

@@ -42,9 +42,9 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
(void) p; (void) p;
return CFG::SEL_THRESHOLD_SIZE_PX; // we do not know the distance from the image return ClickDist(CFG::SEL_THRESHOLD_SIZE_PX, ClickDistType::UNKNOWN); // we do not know the distance from the image
} }
virtual void onFocus() override { virtual void onFocus() override {

View File

@@ -30,8 +30,8 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
return p.getDistance(poi->pos); return ClickDist(p.getDistance(poi->pos), ClickDistType::DIRECT);
} }
/** repaint me */ /** repaint me */

View File

@@ -35,11 +35,11 @@ public:
} }
/** get the element's minimal distance (nearest whatsoever) to the given point */ /** get the element's minimal distance (nearest whatsoever) to the given point */
float getMinDistanceXY(const Point2 p) const override { ClickDist getMinDistanceXY(const Point2 p) const override {
auto comp = [p] (const Floorplan::StairPart& p1, const Floorplan::StairPart& p2) { auto comp = [p] (const Floorplan::StairPart& p1, const Floorplan::StairPart& p2) {
const float d1 = MapElementHelper::getLineDistanceXY(p1.start.xy(), p1.end.xy(), p); const ClickDist d1 = MapElementHelper::getLineDistanceXY(p1.start.xy(), p1.end.xy(), p);
const float d2 = MapElementHelper::getLineDistanceXY(p2.start.xy(), p2.end.xy(), p); const ClickDist d2 = MapElementHelper::getLineDistanceXY(p2.start.xy(), p2.end.xy(), p);
return d1 < d2; return d1 < d2;
}; };

View File

@@ -11,6 +11,8 @@
#include <Indoor/floorplan/v2/Floorplan.h> #include <Indoor/floorplan/v2/Floorplan.h>
#include "ClickDist.h"
/** configuration */ /** configuration */
namespace CFG { namespace CFG {
const float MOVE_SNAP_SIZE_M = 0.1f; // in meter (= map-space) const float MOVE_SNAP_SIZE_M = 0.1f; // in meter (= map-space)
@@ -33,7 +35,7 @@ public:
* move l into dst * move l into dst
* and calculate the cut-point between l and (p1, p2) * and calculate the cut-point between l and (p1, p2)
*/ */
static float getLineDistanceXY(Point2 p1, Point2 p2, Point2 dst) { static ClickDist getLineDistanceXY(Point2 p1, Point2 p2, Point2 dst) {
// the line (p1, p2) // the line (p1, p2)
const Line2 line(p1, p2); const Line2 line(p1, p2);
@@ -46,20 +48,21 @@ public:
// calculate the cut betwen L and (p1,p2) (if any) // calculate the cut betwen L and (p1,p2) (if any)
Point2 cut(0,0); Point2 cut(0,0);
ClickDist cutDist(99999999, ClickDistType::CUT);
if (line.getSegmentIntersection(perb, cut)) { if (line.getSegmentIntersection(perb, cut)) {
// distance between cut-point and mouse // distance between cut-point and mouse
return cut.getDistance(dst); cutDist.dst_px = cut.getDistance(dst);
} else {
// no cut detected
const float d1 = p1.getDistance(dst);
const float d2 = p2.getDistance(dst);
return std::min(d1, d2);
} }
// distance from endpoints
const ClickDist d1(p1.getDistance(dst), ClickDistType::DIRECT);
const ClickDist d2(p2.getDistance(dst), ClickDistType::DIRECT);
// return the nearest possibility:
return std::min(d1, std::min(d2, cutDist));
} }
static QPen getPen(Floorplan::Material mat, Floorplan::ObstacleType type, bool focus) { static QPen getPen(Floorplan::Material mat, Floorplan::ObstacleType type, bool focus) {

View File

@@ -69,6 +69,11 @@ public:
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r); p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
} }
void drawCircle_px(const Point2 center, const float size_px) {
int r = size_px;
p->drawEllipse(s.xms(center.x)-r, s.yms(center.y)-r, 2*r, 2*r);
}
void drawLine(const float x1, const float y1, const float x2, const float y2) { void drawLine(const float x1, const float y1, const float x2, const float y2) {
p->drawLine(s.xms(x1), s.yms(y1), s.xms(x2), s.yms(y2)); p->drawLine(s.xms(x1), s.yms(y1), s.xms(x2), s.yms(y2));
} }
@@ -115,6 +120,16 @@ public:
p->drawImage(s.xms(pt.x)-img.width()/2, s.yms(pt.y)-img.height()/2, img); p->drawImage(s.xms(pt.x)-img.width()/2, s.yms(pt.y)-img.height()/2, img);
} }
void drawLength(Point2 p1, Point2 p2, const float len) {
if (p1.x < p2.x) {swap(p1, p2);}
const Point2 center_m = (p1 + p2) / 2;
Point2 dir_px = (p2 - p1).perpendicular().normalized() * 5;
if (dir_px.x <= 0) {dir_px = -dir_px;}
const Point2 pos_m = center_m + dir_px / getScaler().getScale();
char buf[64]; sprintf(buf, "%.1f", len);
drawText(pos_m, buf);
}
void setBrush(const QBrush& brush) { p->setBrush(brush); } void setBrush(const QBrush& brush) { p->setBrush(brush); }
void setBrush(const Qt::BrushStyle& brush) { p->setBrush(brush); } void setBrush(const Qt::BrushStyle& brush) { p->setBrush(brush); }

View File

@@ -24,7 +24,7 @@ protected:
/** repaint me */ /** repaint me */
void paintGL() override { void paintGL() override {
Cube cube(ap->getPos(f), 0.5); Cube cube(ap->getPos(f), 0.25);
cube.paintGL(); cube.paintGL();
} }