From 0b0db2b7064cc60092ab832fa68f2327975b75e8 Mon Sep 17 00:00:00 2001 From: Markus Bullmann Date: Tue, 27 Mar 2018 14:04:31 +0200 Subject: [PATCH] VS fixes --- IndoorMap.pro | 9 +- MainController.cpp | 2 +- mapview/2D/tools/ToolSelector.h | 2 +- mapview/3D/MV3DElementFloorOutline.h | 6 +- mapview/3D/MapView3D.cpp | 6 +- mapview/3D/floorplan/RenderTriangle.h | 6 +- mapview/3D/misc/Polygon.h | 170 +++++++++++++------------- tree/MapTreeModel.h | 7 +- 8 files changed, 109 insertions(+), 99 deletions(-) diff --git a/IndoorMap.pro b/IndoorMap.pro index 692ea49..59635a4 100644 --- a/IndoorMap.pro +++ b/IndoorMap.pro @@ -6,7 +6,7 @@ QT += core gui opengl -CONFIG += c++11 -g3 -O0 +CONFIG += c++17 -g3 -O0 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets svg @@ -16,13 +16,18 @@ TEMPLATE = app DEFINES += WITH_ASSERTIONS DEFINES += WITH_DEBUG_LOG +win32 { + DEFINES += _USE_MATH_DEFINES + + LIBS+= -llibGLESV2d +} + INCLUDEPATH += \ ../ SOURCES += \ - lib/gpc/gpc.cpp \ main.cpp \ MainWindow.cpp \ MainController.cpp \ diff --git a/MainController.cpp b/MainController.cpp index b609756..08544cc 100644 --- a/MainController.cpp +++ b/MainController.cpp @@ -103,7 +103,7 @@ MainController::MainController() { connect(mw, &MainWindow::onGridNodeColorType, [&] () {mw->getMapView3D()->getGridRenderer()->setNodeColorMode(GridRendererColorMode::SHOW_NODE_TYPE);} ); connect(mw, &MainWindow::onGridShowEdges, [&] (const bool show) {mw->getMapView3D()->getGridRenderer()->setShowEdges(show);} ); - Ray3D::OBJPool::get().init("/mnt/vm/paper/diss/code/IndoorMap/res/mdl/"); + Ray3D::OBJPool::get().init("C:/Temp/"); //mapModel->load("../IndoorMap/maps/SHL36_noel.xml"); //mapModel->load("../IndoorMap/maps/SHL38_no_elev.xml"); diff --git a/mapview/2D/tools/ToolSelector.h b/mapview/2D/tools/ToolSelector.h index 82e1f5a..5fa19bb 100644 --- a/mapview/2D/tools/ToolSelector.h +++ b/mapview/2D/tools/ToolSelector.h @@ -232,7 +232,7 @@ private: const float g = m->getScaler().sm(15); // increase each BBox by 15 px (needed mainly for hor/ver lines) -#warning "which elements to select? among all currently visible? or only among the selected layer?" +#pragma message "which elements to select? among all currently visible? or only among the selected layer?" // get all elements with bounding-box matchings std::vector possible; // for (MapModelElement* el : m->getModel()->getSelectedLayerElements()) { diff --git a/mapview/3D/MV3DElementFloorOutline.h b/mapview/3D/MV3DElementFloorOutline.h index c397476..420e3e9 100644 --- a/mapview/3D/MV3DElementFloorOutline.h +++ b/mapview/3D/MV3DElementFloorOutline.h @@ -2,12 +2,12 @@ #define MV3DELEMENTFLOOROUTLINE_H #include +#include #include "misc/Cube.h" #include "MV3DElement.h" #include "../../lib/gpc/gpc.h" -#include "misc/Polygon.h" #include "misc/Outline.h" class MV3DElementFloorOutline : public MV3DElement { @@ -17,7 +17,7 @@ class MV3DElementFloorOutline : public MV3DElement { struct Temp { Point2 cacheSum; - Polygon* pol = nullptr; + Ray3D::Polygon* pol = nullptr; std::vector> trias; }; @@ -80,7 +80,7 @@ protected: std::vector add; std::vector rem; if (tmp.pol) {delete tmp.pol;} - tmp.pol = new Polygon(); + tmp.pol = new Ray3D::Polygon(); // all to-be-added polygons (filter!) for (Floorplan::FloorOutlinePolygon* poly : polys) { diff --git a/mapview/3D/MapView3D.cpp b/mapview/3D/MapView3D.cpp index 5695fd2..760e4b9 100644 --- a/mapview/3D/MapView3D.cpp +++ b/mapview/3D/MapView3D.cpp @@ -295,7 +295,7 @@ void MapView3D::draw() { V.rotate(rot.z, 0.0, 0.0, 1.0); V.translate(center.x, center.y, center.z); - float far = 200; // TODO + float farPlane = 200; // TODO // projection QMatrix4x4 P; @@ -306,14 +306,14 @@ void MapView3D::draw() { float h = height() / 30; viewport.size.x = w; viewport.size.y = h; - P.perspective(45.0f, aspect, 0.01, far); + P.perspective(45.0f, aspect, 0.01, farPlane); } else { // default size: 50 * 50/aspect meters float w = 50.0f; float h = 50.0f * height() / width(); viewport.size.x = w; viewport.size.y = h; - P.ortho(-w, +w, -h, +h, 0.1f, +far); + P.ortho(-w, +w, -h, +h, 0.1f, +farPlane); } rs.shader->bind(); diff --git a/mapview/3D/floorplan/RenderTriangle.h b/mapview/3D/floorplan/RenderTriangle.h index 36fe82f..c229705 100644 --- a/mapview/3D/floorplan/RenderTriangle.h +++ b/mapview/3D/floorplan/RenderTriangle.h @@ -10,17 +10,17 @@ class RenderTriangle { struct Vertex{ float x,y,z; Vertex(const float x, const float y, const float z) : x(x), y(y), z(z) {;} - } __attribute__((packed)); + }; struct Normal { float x,y,z; Normal(const float x, const float y, const float z) : x(x), y(y), z(z) {;} - } __attribute__((packed)); + }; struct RGBA { float r,g,b,a; RGBA(const float r, const float g, const float b, const float a) : r(r), g(g), b(b), a(a) {;} - } __attribute__((packed)); + }; std::vector vertices; std::vector normals; diff --git a/mapview/3D/misc/Polygon.h b/mapview/3D/misc/Polygon.h index 8b5536c..d24939a 100644 --- a/mapview/3D/misc/Polygon.h +++ b/mapview/3D/misc/Polygon.h @@ -1,110 +1,112 @@ -#ifndef POLYGON_H -#define POLYGON_H +// Duplicated file with Indoor/wifi/estimate/ray3/ModelFactoryHelper.h + +//#ifndef POLYGON_H +//#define POLYGON_H -#include -#include "../../../lib/gpc/gpc.h" +//#include +//#include "../../../lib/gpc/gpc.h" -class Polygon { +//class Polygon_ { - struct GPCPolygon : gpc_polygon { - GPCPolygon() { -// contour = (gpc_vertex_list*) calloc(0, 1024); -// contour->num_vertices = 0; -// contour->vertex = (gpc_vertex*) calloc(0, 1024); -// hole = (int*) calloc(0, 1024); - num_contours = 0; - contour = nullptr; - hole = nullptr; - } - ~GPCPolygon() { - if (contour) { - gpc_free_polygon(this); - //free(contour->vertex); contour->vertex = nullptr; - } - free(contour); contour = nullptr; - free(hole); hole = nullptr; +// struct GPCPolygon : gpc_polygon { +// GPCPolygon() { +//// contour = (gpc_vertex_list*) calloc(0, 1024); +//// contour->num_vertices = 0; +//// contour->vertex = (gpc_vertex*) calloc(0, 1024); +//// hole = (int*) calloc(0, 1024); +// num_contours = 0; +// contour = nullptr; +// hole = nullptr; +// } +// ~GPCPolygon() { +// if (contour) { +// gpc_free_polygon(this); +// //free(contour->vertex); contour->vertex = nullptr; +// } +// free(contour); contour = nullptr; +// free(hole); hole = nullptr; - } - GPCPolygon& operator = (const GPCPolygon& o) = delete; - GPCPolygon& operator = (GPCPolygon& o) { - this->contour = o.contour; - this->hole = o.hole; - this->num_contours = o.num_contours; - o.contour = nullptr; - o.hole = nullptr; - return *this; - } - }; +// } +// GPCPolygon& operator = (const GPCPolygon& o) = delete; +// GPCPolygon& operator = (GPCPolygon& o) { +// this->contour = o.contour; +// this->hole = o.hole; +// this->num_contours = o.num_contours; +// o.contour = nullptr; +// o.hole = nullptr; +// return *this; +// } +// }; -private: +//private: - GPCPolygon state; +// GPCPolygon state; -public: +//public: - void add(const Floorplan::Polygon2& poly) { - GPCPolygon cur = toGPC(poly); - //GPCPolygon out; - gpc_polygon_clip(GPC_UNION, &state, &cur, &state); - //state = out; - } +// void add(const Floorplan::Polygon2& poly) { +// GPCPolygon cur = toGPC(poly); +// //GPCPolygon out; +// gpc_polygon_clip(GPC_UNION, &state, &cur, &state); +// //state = out; +// } - void remove(const Floorplan::Polygon2& poly) { - GPCPolygon cur = toGPC(poly); - //GPCPolygon out; - gpc_polygon_clip(GPC_DIFF, &state, &cur, &state); - //state = out; - } +// void remove(const Floorplan::Polygon2& poly) { +// GPCPolygon cur = toGPC(poly); +// //GPCPolygon out; +// gpc_polygon_clip(GPC_DIFF, &state, &cur, &state); +// //state = out; +// } - std::vector> get(float z) { +// std::vector> get(float z) { - gpc_tristrip res; - res.num_strips = 0; - res.strip = nullptr; +// gpc_tristrip res; +// res.num_strips = 0; +// res.strip = nullptr; - //res.strip = (gpc_vertex_list*) malloc(1024); - gpc_polygon_to_tristrip(&state, &res); +// //res.strip = (gpc_vertex_list*) malloc(1024); +// gpc_polygon_to_tristrip(&state, &res); - std::vector> trias; +// std::vector> trias; - for (int i = 0; i < res.num_strips; ++i) { - gpc_vertex_list lst = res.strip[i]; - std::vector tria; - for (int j = 0; j < lst.num_vertices; ++j) { - gpc_vertex& vert = lst.vertex[j]; - Point3 p3(vert.x, vert.y, z); - tria.push_back(p3); - } - trias.push_back(tria); - } +// for (int i = 0; i < res.num_strips; ++i) { +// gpc_vertex_list lst = res.strip[i]; +// std::vector tria; +// for (int j = 0; j < lst.num_vertices; ++j) { +// gpc_vertex& vert = lst.vertex[j]; +// Point3 p3(vert.x, vert.y, z); +// tria.push_back(p3); +// } +// trias.push_back(tria); +// } - gpc_free_tristrip(&res); +// gpc_free_tristrip(&res); - return std::move(trias); +// return std::move(trias); - } +// } -private: +//private: - GPCPolygon toGPC(Floorplan::Polygon2 poly) { +// GPCPolygon toGPC(Floorplan::Polygon2 poly) { - std::vector verts; - for (Point2 p2 : poly.points) { - gpc_vertex vert; vert.x = p2.x; vert.y = p2.y; - verts.push_back(vert); - } +// std::vector verts; +// for (Point2 p2 : poly.points) { +// gpc_vertex vert; vert.x = p2.x; vert.y = p2.y; +// verts.push_back(vert); +// } - GPCPolygon gpol; - gpc_vertex_list list; - list.num_vertices = verts.size(); - list.vertex = verts.data(); - gpc_add_contour(&gpol, &list, 0); +// GPCPolygon gpol; +// gpc_vertex_list list; +// list.num_vertices = verts.size(); +// list.vertex = verts.data(); +// gpc_add_contour(&gpol, &list, 0); - return gpol; +// return gpol; - } +// } -}; +//}; -#endif // POLYGON_H +//#endif // POLYGON_H diff --git a/tree/MapTreeModel.h b/tree/MapTreeModel.h index bc8a6af..3095847 100644 --- a/tree/MapTreeModel.h +++ b/tree/MapTreeModel.h @@ -41,8 +41,11 @@ public: _parent = static_cast(parent.internalPointer()); } - return createIndex(row, column, _parent->getSubLayers().at(row)); - + if (_parent->getSubLayers().size() > 0) { + return createIndex(row, column, _parent->getSubLayers().at(row)); + } else { + return createIndex(0, 0, nullptr); + } } virtual QModelIndex parent(const QModelIndex& child) const override {