diff --git a/IndoorMap.pro b/IndoorMap.pro index f021e55..659ea41 100644 --- a/IndoorMap.pro +++ b/IndoorMap.pro @@ -68,7 +68,8 @@ SOURCES += \ mapview/3D/floorplan/FloorplanRenderer.cpp \ mapview/2D/MV2DElementStair.cpp \ mapview/2D/MV2DElementElevator.cpp \ - mapview/2D/MV2DElementFloorObstacleCircle.cpp + mapview/2D/MV2DElementFloorObstacleCircle.cpp \ + mapview/3D/floorplan/FloorplanRendererModel.cpp HEADERS += MainWindow.h \ diff --git a/MainController.cpp b/MainController.cpp index 4716bfb..6753aad 100644 --- a/MainController.cpp +++ b/MainController.cpp @@ -126,7 +126,8 @@ MainController::MainController() { //mapModel->load("/apps/paper/diss/data/maps/walkmodel_stairs3.xml"); //mapModel->load("/apps/paper/maps/museum/map43_svg.xml"); - mapModel->load("/apps/paper/maps/shl/SHL45_nm.xml"); + //mapModel->load("/apps/paper/maps/shl/SHL45_nm.xml"); + mapModel->load("/apps/paper/maps/test/polyMergeTest2.xml"); //mapModel->load("/mnt/sdcard/SHL41_nm.xml"); diff --git a/mapview/3D/MapView3D.cpp b/mapview/3D/MapView3D.cpp index e3e3a7c..d0db423 100644 --- a/mapview/3D/MapView3D.cpp +++ b/mapview/3D/MapView3D.cpp @@ -119,7 +119,7 @@ MapView3D::MapView3D(QWidget *parent) : QOpenGLWidget(parent) { //format.setSamples(2); //format.setProfile(QSurfaceFormat::CompatibilityProfile); //format.setOption(QSurfaceFormat::DebugContext); - format.setSamples(2); + format.setSamples(4); setFormat(format); diff --git a/mapview/3D/floorplan/FloorplanRendererModel.cpp b/mapview/3D/floorplan/FloorplanRendererModel.cpp new file mode 100644 index 0000000..3266e7a --- /dev/null +++ b/mapview/3D/floorplan/FloorplanRendererModel.cpp @@ -0,0 +1,109 @@ +#include "FloorplanRendererModel.h" + +#include +#include +#include +#include +#include + +#include "RenderTriangle.h" + +struct Material { + int r, g, b, a; + Material(int r, int g, int b, int a) : r(r), g(g), b(b), a(a) {;} +}; + +const std::vector mats = { + + Material(0,128,0,255), // ground outdoor + Material(64,64,64,255), // ground outdoor + Material(105,105,105,255), // stair + Material(220,220,220,255), // handrail + + Material(200,200,255,96), // door (glass) + Material(140,140,140,255), // door (wood) + + Material(135,135,135,255), // concrete + Material(240,240,255,96), // glass + Material(170,170,255,96), // glass (metallized) + Material(170,120,60,255), // wood + Material(200,200,200,255), // drywall + + Material(255,255,255,255), // object + + Material(235,235,235,255), // default + +}; + +int FloorplanRendererModel::getMaterial(const Ray3D::Obstacle3D& o) const { + + if (o.type == Ray3D::Obstacle3D::Type::GROUND_OUTDOOR) {return 0;} + if (o.type == Ray3D::Obstacle3D::Type::GROUND_INDOOR) {return 1;} + if (o.type == Ray3D::Obstacle3D::Type::STAIR) {return 2;} + if (o.type == Ray3D::Obstacle3D::Type::HANDRAIL) {return 3;} + if (o.type == Ray3D::Obstacle3D::Type::OBJECT) {return 11;} + + if (o.type == Ray3D::Obstacle3D::Type::DOOR && o.mat == Floorplan::Material::GLASS) {return 4;} + if (o.type == Ray3D::Obstacle3D::Type::DOOR) {return 5;} + + if (o.mat == Floorplan::Material::CONCRETE) {return 6;} + if (o.mat == Floorplan::Material::GLASS) {return 7;} + if (o.mat == Floorplan::Material::METALLIZED_GLAS) {return 8;} + + if (o.mat == Floorplan::Material::WOOD) {return 9;} + if (o.mat == Floorplan::Material::DRYWALL) {return 10;} + + return 12; + +} + + +FloorplanRendererModel::FloorplanRendererModel() { + ; +} + +Ray3D::FloorplanMesh& FloorplanRendererModel::getMesh() { + return mesh; +} + +const RenderTriangle& FloorplanRendererModel::getTriaSolid() { + return triaSolid; +} + +const RenderTriangle& FloorplanRendererModel::getTriaTransp() { + return triaTransp; +} + +void FloorplanRendererModel::rebuild(Floorplan::IndoorMap* im) { + + // rebuild the mesh + //Ray3D::ModelFactory fac(im); + + //mesh = fac.getMesh(); + + + triaTransp.clear(); + triaSolid.clear(); + + // rebuild the mesh + try { + Ray3D::ModelFactory fac(im); + fac.exportDoors = showDoors; + mesh = fac.getMesh(); + for (const Ray3D::Obstacle3D& obs : mesh.elements) { + const int matID = getMaterial(obs); + const Material& mat = mats[matID]; + for (const Triangle3& tria : obs.triangles) { + const Point3 n = cross(tria.p2-tria.p1, tria.p3-tria.p1).normalized(); + if (mat.a != 255) { + triaTransp.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f); + } else { + triaSolid.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f); + } + } + } + } + catch(const std::exception& e) { + std::cout << "Can't create 3D view. Failed to get mesh from model factory with error: '" << e.what() << "'" << std::endl; + } +} diff --git a/mapview/3D/floorplan/FloorplanRendererModel.h b/mapview/3D/floorplan/FloorplanRendererModel.h index e9382e9..6dc32f0 100644 --- a/mapview/3D/floorplan/FloorplanRendererModel.h +++ b/mapview/3D/floorplan/FloorplanRendererModel.h @@ -2,10 +2,7 @@ #define FLOORPLANRENDERERMODEL_H #include -#include -#include -#include -#include +#include #include "RenderTriangle.h" @@ -22,54 +19,7 @@ private: RenderTriangle triaSolid; RenderTriangle triaTransp; - struct Material { - int r, g, b, a; - Material(int r, int g, int b, int a) : r(r), g(g), b(b), a(a) {;} - }; - - const std::vector mats = { - - Material(0,128,0,255), // ground outdoor - Material(64,64,64,255), // ground outdoor - Material(105,105,105,255), // stair - Material(220,220,220,255), // handrail - - Material(200,200,255,96), // door (glass) - Material(140,140,140,255), // door (wood) - - Material(135,135,135,255), // concrete - Material(240,240,255,96), // glass - Material(170,170,255,96), // glass (metallized) - Material(170,120,60,255), // wood - Material(200,200,200,255), // drywall - - Material(255,255,255,255), // object - - Material(235,235,235,255), // default - - }; - - int getMaterial(const Ray3D::Obstacle3D& o) const { - - if (o.type == Ray3D::Obstacle3D::Type::GROUND_OUTDOOR) {return 0;} - if (o.type == Ray3D::Obstacle3D::Type::GROUND_INDOOR) {return 1;} - if (o.type == Ray3D::Obstacle3D::Type::STAIR) {return 2;} - if (o.type == Ray3D::Obstacle3D::Type::HANDRAIL) {return 3;} - if (o.type == Ray3D::Obstacle3D::Type::OBJECT) {return 11;} - - if (o.type == Ray3D::Obstacle3D::Type::DOOR && o.mat == Floorplan::Material::GLASS) {return 4;} - if (o.type == Ray3D::Obstacle3D::Type::DOOR) {return 5;} - - if (o.mat == Floorplan::Material::CONCRETE) {return 6;} - if (o.mat == Floorplan::Material::GLASS) {return 7;} - if (o.mat == Floorplan::Material::METALLIZED_GLAS) {return 8;} - - if (o.mat == Floorplan::Material::WOOD) {return 9;} - if (o.mat == Floorplan::Material::DRYWALL) {return 10;} - - return 12; - - } + int getMaterial(const Ray3D::Obstacle3D& o) const; public: @@ -77,55 +27,15 @@ public: bool showDoors = false; /** ctor */ - FloorplanRendererModel() { - ; - } + FloorplanRendererModel(); - Ray3D::FloorplanMesh& getMesh() { - return mesh; - } + Ray3D::FloorplanMesh& getMesh(); - const RenderTriangle& getTriaSolid() { - return triaSolid; - } + const RenderTriangle& getTriaSolid(); - const RenderTriangle& getTriaTransp() { - return triaTransp; - } + const RenderTriangle& getTriaTransp(); - void rebuild(Floorplan::IndoorMap* im) { - - // rebuild the mesh - //Ray3D::ModelFactory fac(im); - - //mesh = fac.getMesh(); - - - triaTransp.clear(); - triaSolid.clear(); - - // rebuild the mesh - try { - Ray3D::ModelFactory fac(im); - fac.exportDoors = showDoors; - mesh = fac.getMesh(); - for (const Ray3D::Obstacle3D& obs : mesh.elements) { - const int matID = getMaterial(obs); - const Material& mat = mats[matID]; - for (const Triangle3& tria : obs.triangles) { - const Point3 n = cross(tria.p2-tria.p1, tria.p3-tria.p1).normalized(); - if (mat.a != 255) { - triaTransp.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f); - } else { - triaSolid.addTriangle(tria.p1, tria.p2, tria.p3, n, mat.r/255.0f, mat.g/255.0f, mat.b/255.0f, mat.a/255.0f); - } - } - } - } - catch(const std::exception& e) { - std::cout << "Can't create 3D view. Failed to get mesh from model factory with error: '" << e.what() << "'" << std::endl; - } - } + void rebuild(Floorplan::IndoorMap* im); }; diff --git a/params/ToolBoxWidget.cpp b/params/ToolBoxWidget.cpp index 61bb300..d7cc601 100644 --- a/params/ToolBoxWidget.cpp +++ b/params/ToolBoxWidget.cpp @@ -186,7 +186,7 @@ void ToolBoxWidget::onMainToolChanged() { btnDoor->setStyleSheet( dynamic_cast(t) ? styleSel : styleNor ); btnWall->setStyleSheet( dynamic_cast(t) ? styleSel : styleNor ); - btnObject->setStyleSheet( dynamic_cast(t) ? styleSel : styleNor ); + btnObject->setStyleSheet( dynamic_cast(t) ? styleSel : styleNor ); btnElevator->setStyleSheet( dynamic_cast(t) ? styleSel : styleNor ); btnStair->setStyleSheet( dynamic_cast(t) ? styleSel : styleNor ); btnPillar->setStyleSheet( dynamic_cast(t) ? styleSel : styleNor );