diff --git a/IndoorMap.pro b/IndoorMap.pro index 78b9e78..1ebcd6b 100644 --- a/IndoorMap.pro +++ b/IndoorMap.pro @@ -155,7 +155,11 @@ HEADERS += MainWindow.h \ mapview/2D/tools/ToolNewWall.h \ mapview/2D/tools/ToolNewStair.h \ mapview/2D/tools/ToolNewElevator.h \ - mapview/2D/tools/ToolNewOutline.h + mapview/2D/tools/ToolNewOutline.h \ + mapview/model/MMRegistration.h \ + mapview/model/MMRegistrationPoint.h \ + mapview/2D/MV2DElementRegistrationPoint.h \ + mapview/3D/MV3DElementRegistrationPoint.h FORMS += MainWindow.ui diff --git a/MainController.cpp b/MainController.cpp index 8c05b98..a737696 100644 --- a/MainController.cpp +++ b/MainController.cpp @@ -95,7 +95,7 @@ MainController::MainController() { connect(mw, &MainWindow::onGridShowEdges, [&] (const bool show) {mw->getMapView3D()->getGridRenderer()->setShowEdges(show);} ); - mapModel->load("../IndoorMap/maps/SHL35.xml"); + mapModel->load("../IndoorMap/maps/SHL36.xml"); //mapModel->resize(0.983, 0.983, 1, -0.2, -0.3, 0); diff --git a/mapview/2D/MV2DElementRegistrationPoint.h b/mapview/2D/MV2DElementRegistrationPoint.h new file mode 100644 index 0000000..9e70f30 --- /dev/null +++ b/mapview/2D/MV2DElementRegistrationPoint.h @@ -0,0 +1,107 @@ +#ifndef MV2DELEMENTREGISTRATIONPOINT_H +#define MV2DELEMENTREGISTRATIONPOINT_H + + +#include "MV2DElement.h" +#include "HasMoveableNodes.h" + +#include "MapViewElementHelper.h" +#include + +#include "../../UIHelper.h" + +/** one earth <-> map correspondence */ +class MV2DElementRegistrationPoint : public MV2DElement, public HasMoveableNodes { + +private: + + //bool sel = false; + Floorplan::EarthPosMapPos* reg; + +public: + + /** ctor with the AP to render/edit */ + MV2DElementRegistrationPoint(Floorplan::EarthPosMapPos* reg) : reg(reg) {;} + + + /** get the element's 3D bounding box */ + BBox2 getBoundingBox() const override { + BBox2 bbox; + bbox.add(Point2(reg->posOnMap_m.x, reg->posOnMap_m.y)); + bbox.grow(Point2(0.1, 0.1)); + return bbox; + } + + /** get the element's minimal distance (nearest whatsoever) to the given point */ + ClickDist getMinDistanceXY(const Point2 p) const override { + return ClickDist(p.getDistance(reg->posOnMap_m.xy()), ClickDistType::DIRECT); + } + + /** repaint me */ + void paint(Painter& p) override { + + 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); + + + if (selectedUserIdx == 0) { + p.drawPixmap(reg->posOnMap_m.xy(), pixmapSel); + } else if (hasFocus()) { + p.drawPixmap(reg->posOnMap_m.xy(), pixmapFocused); + } else { + p.drawPixmap(reg->posOnMap_m.xy(), pixmapUnfocused); + } + + // label + p.setPenBrush(Qt::black, Qt::NoBrush); + //p.drawDot(ap->pos.xy()); + if (p.getScaler().getScale() >= 10) { + const std::string str = std::to_string(reg->posOnEarth.lat) + " " + std::to_string(reg->posOnEarth.lon); + p.p->drawText(p.getScaler().xms(reg->posOnMap_m.x) + 10, p.getScaler().yms(reg->posOnMap_m.y) + 5, str.c_str()); + } + + } + + virtual std::vector getMoveableNodes() const override { + return { MoveableNode(0, reg->posOnMap_m.xy()) }; + } + + virtual void onNodeMove(MapView2D* v, const int userIdx, const Point2 newPos) override { + (void) v; + if (userIdx == 0) {reg->posOnMap_m.x = newPos.x; reg->posOnMap_m.y = newPos.y;} + } + + + virtual void mousePressed(MapView2D* v, const Point2 p) override { + (void) v; + (void) p; + } + + virtual void mouseMove(MapView2D* v, const Point2 p) override { + (void) v; + (void) p; + } + + virtual void mouseReleased(MapView2D* v, const Point2 p) override { + (void) v; + (void) p; + } + + virtual bool keyPressEvent(MapView2D* v, QKeyEvent *e) override { + (void) v; + (void) e; + return false; + } + + virtual void onFocus() override { + ; + } + + virtual void onUnfocus() override { + ; + } + +}; + +#endif // MV2DELEMENTREGISTRATIONPOINT_H diff --git a/mapview/3D/MV3DElementRegistrationPoint.h b/mapview/3D/MV3DElementRegistrationPoint.h new file mode 100644 index 0000000..9232a7a --- /dev/null +++ b/mapview/3D/MV3DElementRegistrationPoint.h @@ -0,0 +1,34 @@ +#ifndef MV3DELEMENTREGISTRATIONPOINT_H +#define MV3DELEMENTREGISTRATIONPOINT_H + +#include + +#include "misc/Cube.h" +#include "MV3DElement.h" + +class MV3DElementRegistrationPoint : public MV3DElement { + + Floorplan::EarthPosMapPos* reg; + +public: + + /** ctor */ + MV3DElementRegistrationPoint(Floorplan::EarthPosMapPos* reg) : reg(reg) { + ; + } + +protected: + + + /** repaint me */ + void paintGL() override { + + Cube cube(reg->posOnMap_m, 0.5); + glColor3f(0,0,0); + cube.paintGL(); + + } + +}; + +#endif // MV3DELEMENTREGISTRATIONPOINT_H diff --git a/mapview/model/IHasParams.h b/mapview/model/IHasParams.h index 296e526..f266cab 100644 --- a/mapview/model/IHasParams.h +++ b/mapview/model/IHasParams.h @@ -10,6 +10,7 @@ enum class ParamType { BOOL, INT, FLOAT, + DOUBLE, STRING, FILE, POINT2, @@ -23,6 +24,7 @@ private: bool _bool; int _int; float _float; + double _double; float _arr[3]; }; std::string _str; @@ -35,6 +37,7 @@ public: void setValue(const std::string& val) {_str = val;} void setValue(const float val) {_float = val;} + void setValue(const double val) {_double = val;} void setValue(const int val) {_int = val;} void setValue(const bool val) {_bool = val;} void setValue(const Point2 p) {_arr[0] = p.x; _arr[1] = p.y;} @@ -44,6 +47,7 @@ public: Point3 toPoint3() const {return Point3(_arr[0], _arr[1], _arr[2]);} std::string toString() const {return _str;} float toFloat() const {return _float;} + double toDouble() const {return _double;} int toInt() const {return _int;} bool toBool() const {return _bool;} diff --git a/mapview/model/MMRegistration.h b/mapview/model/MMRegistration.h new file mode 100644 index 0000000..bf9c450 --- /dev/null +++ b/mapview/model/MMRegistration.h @@ -0,0 +1,48 @@ +#ifndef MMREGISTRATION_H +#define MMREGISTRATION_H + + +#include "MMRegistrationPoint.h" + +#include + +/** + * layer that contains registriation points: earth <-> map + */ +class MMRegistration : public MapLayer { + +private: + + Floorplan::IndoorMap* map; + +public: + + /** ctor */ + MMRegistration(MapLayer* parent, Floorplan::IndoorMap* map) : MapLayer(parent, MapLayerType::REGISTRATION), map(map) { + + // the registered points + for (Floorplan::EarthPosMapPos* reg : map->earthReg.correspondences) { + addElement(new MMRegistrationPoint(this, map, reg)); + } + + } + + //TODO: check + MMRegistrationPoint* create(Floorplan::EarthPosMapPos* reg) { + + // add to underlying model + map->earthReg.correspondences.push_back(reg); + + // add to myself as element + MMRegistrationPoint* mm = new MMRegistrationPoint(this, map, reg); + addElement(mm); + return mm; + + } + + virtual std::string getLayerName() const override {return "registration";} + +}; + + +#endif // MMREGISTRATION_H diff --git a/mapview/model/MMRegistrationPoint.h b/mapview/model/MMRegistrationPoint.h new file mode 100644 index 0000000..a40f7fc --- /dev/null +++ b/mapview/model/MMRegistrationPoint.h @@ -0,0 +1,78 @@ +#ifndef MMREGISTRATIONPOINT_H +#define MMREGISTRATIONPOINT_H + + +#include "IHasParams.h" +#include "MapModelElement.h" + +#include "../2D/MV2DElementRegistrationPoint.h" +#include "../3D/MV3DElementRegistrationPoint.h" + +#include + +/** + * one earth <-> map correspondcen + */ +class MMRegistrationPoint : public MapModelElement, public IHasParams { + +private: + + Floorplan::IndoorMap* map; + Floorplan::EarthPosMapPos* reg; + MV2DElementRegistrationPoint mv2d; + MV3DElementRegistrationPoint mv3d; + + std::string fileName; + +public: + + /** ctor */ + MMRegistrationPoint(MapLayer* parent, Floorplan::IndoorMap* map, Floorplan::EarthPosMapPos* reg) : + MapModelElement(parent), map(map), reg(reg), mv2d(reg), mv3d(reg) { + ; + } + + MV2DElement* getMV2D() const override {return (MV2DElement*) &mv2d;} + MV3DElement* getMV3D() const override {return (MV3DElement*) &mv3d;} + + void deleteMe() const override { + ; + } + + int getNumParams() const override { + return 4; + } + + virtual Param getParamDesc(const int idx) const override { + switch (idx) { + case 0: return Param("map", ParamType::POINT3); + case 1: return Param("lat", ParamType::DOUBLE); + case 2: return Param("lon", ParamType::DOUBLE); + case 3: return Param("alt", ParamType::FLOAT); + default: throw 1; + } + } + + virtual ParamValue getParamValue(const int idx) const override { + switch(idx) { + case 0: return ParamValue(reg->posOnMap_m); + case 1: return ParamValue(reg->posOnEarth.lat); + case 2: return ParamValue(reg->posOnEarth.lon); + case 3: return ParamValue(reg->posOnEarth.height); + default: throw 1; + } + } + + virtual void setParamValue(const int idx, const ParamValue& val) override { + switch (idx) { + case 0: reg->posOnMap_m = val.toPoint3(); break; + case 1: reg->posOnEarth.lat = val.toDouble(); break; + case 2: reg->posOnEarth.lon = val.toDouble(); break; + case 3: reg->posOnEarth.height = val.toFloat(); break; + default: throw 1; + } + } + +}; + +#endif // MMREGISTRATIONPOINT_H diff --git a/mapview/model/MMRoot.h b/mapview/model/MMRoot.h index b79b487..bf1e33f 100644 --- a/mapview/model/MMRoot.h +++ b/mapview/model/MMRoot.h @@ -3,6 +3,7 @@ #include "MapLayer.h" #include "MMFloors.h" +#include "MMRegistration.h" #include @@ -23,6 +24,7 @@ public: MMRoot(MapLayer* parent, Floorplan::IndoorMap* map) : MapLayer(parent), map(map) { // all floors + new MMRegistration(this, map); new MMFloors(this, map); } diff --git a/mapview/model/MapLayer.h b/mapview/model/MapLayer.h index 72331f7..c8a30fb 100644 --- a/mapview/model/MapLayer.h +++ b/mapview/model/MapLayer.h @@ -13,6 +13,7 @@ class MapModelElement; enum class MapLayerType { UNKNOWN, ROOT, + REGISTRATION, FLOORS, FLOOR, FLOOR_GROUND, diff --git a/params/ElementParamWidget.cpp b/params/ElementParamWidget.cpp index a6cff09..c3fa772 100644 --- a/params/ElementParamWidget.cpp +++ b/params/ElementParamWidget.cpp @@ -195,6 +195,21 @@ void ElementParamWidget::refresh() { break; } + case ParamType::DOUBLE: { + const std::string str = std::to_string(value.toDouble()); + if (param.readOnly) { + lay->addWidget(new QLabel(str.c_str()),r,1); + } else { + QLineEdit* le = new QLineEdit( str.c_str() ); + connect(le, &QLineEdit::textChanged, [i,elem] (const QString& str) { + const double val = str.toDouble(); + elem->setParamValue(i, ParamValue(val)); + }); + lay->addWidget(le,r,1); + } + break; + } + case ParamType::INT: { const std::string str = std::to_string(value.toInt()); QLineEdit* le = new QLineEdit( str.c_str() ); diff --git a/params/ToolBox.cpp b/params/ToolBox.cpp index a992565..9ecb132 100644 --- a/params/ToolBox.cpp +++ b/params/ToolBox.cpp @@ -13,6 +13,7 @@ #include "../mapview/model/MMFloorAccessPoint.h" #include "../mapview/model/MMFloorBeacon.h" #include "../mapview/model/MMFloorGroundTruthPoints.h" +#include "../mapview/model/MMRegistration.h" #include "../mapview/2D/tools/ToolMeasure.h" #include "../mapview/2D/tools/ToolSelector.h" @@ -133,6 +134,15 @@ ToolBoxWidget::ToolBoxWidget(MapView2D* view, QWidget *parent) : QWidget(parent) + + // EARTH REGISTRATION + btnEarthReg = new QPushButton(UIHelper::getIcon("registration"), ""); + btnEarthReg->setMinimumSize(s,s); + lay->addWidget(btnEarthReg, r++, 0, 1,1,Qt::AlignTop); + connect(btnEarthReg, SIGNAL(clicked(bool)), this, SLOT(onNewEarthReg())); + + + // what to do when the main-tool is changed connect(&view->getTools(), SIGNAL(mainToolChanged()), this, SLOT(onMainToolChanged())); @@ -187,6 +197,8 @@ void ToolBoxWidget::setSelectedLayer(MapLayer *ml) { btnImage->setEnabled(ml && (ml->getLayerType() == MapLayerType::FLOOR_UNDERLAYS)); + btnEarthReg->setEnabled(ml && (ml->getLayerType() == MapLayerType::REGISTRATION)); + } @@ -340,6 +352,18 @@ void ToolBoxWidget::onNewGTP() { } +void ToolBoxWidget::onNewEarthReg() { + + const Point2 center = view->getScaler().getCenter(); + Floorplan::EarthPosMapPos* reg = new Floorplan::EarthPosMapPos( + EarthPos(50, 10, 300), Point3(center.x, center.y, 0) + ); + + MMRegistration* mmreg = (MMRegistration*) curLayer; + mmreg->create(reg); + +} + void ToolBoxWidget::onNewImage() { const Point2 center = view->getScaler().getCenter(); diff --git a/params/ToolBoxWidget.h b/params/ToolBoxWidget.h index c8642c7..59014d4 100644 --- a/params/ToolBoxWidget.h +++ b/params/ToolBoxWidget.h @@ -47,7 +47,9 @@ private: QPushButton* btnBeacon; QPushButton* btnFingerprintLocation; QPushButton* btnPOI; - QPushButton* btnGTP; + QPushButton* btnGTP; + + QPushButton* btnEarthReg; QPushButton* btnImage; @@ -71,6 +73,8 @@ private slots: void onNewImage(); + void onNewEarthReg(); + void onMainToolChanged(); diff --git a/res.qrc b/res.qrc index 4900f24..6489553 100644 --- a/res.qrc +++ b/res.qrc @@ -19,5 +19,6 @@ res/icons/ruler.svg res/icons/fingerprint.svg res/icons/gtp.svg + res/icons/registration.svg diff --git a/res/icons/registration.svg b/res/icons/registration.svg new file mode 100644 index 0000000..8cdb582 --- /dev/null +++ b/res/icons/registration.svg @@ -0,0 +1,6 @@ + + + + + +