changed 3D rendering
added pan/zoom gesture
This commit is contained in:
@@ -82,11 +82,21 @@ protected:
|
||||
if (tmp.pol) {delete tmp.pol;}
|
||||
tmp.pol = new Polygon();
|
||||
|
||||
// all to-be-added polygons (filter!)
|
||||
for (Floorplan::FloorOutlinePolygon* poly : polys) {
|
||||
if (!include(poly)) {continue;}
|
||||
switch (poly->method) {
|
||||
case Floorplan::OutlineMethod::ADD: tmp.pol->add(poly->poly); break;
|
||||
case Floorplan::OutlineMethod::REMOVE: break;
|
||||
default: throw 1;
|
||||
}
|
||||
}
|
||||
|
||||
// all to-be-removed polygons (NO filter!)
|
||||
for (Floorplan::FloorOutlinePolygon* poly : polys) {
|
||||
switch (poly->method) {
|
||||
case Floorplan::OutlineMethod::REMOVE: tmp.pol->remove(poly->poly); break;
|
||||
case Floorplan::OutlineMethod::ADD: break;
|
||||
default: throw 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
#ifndef MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
||||
#define MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
||||
|
||||
//#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
|
||||
//#include "misc/Cube.h"
|
||||
//#include "MV3DElement.h"
|
||||
|
||||
//class MV3DElementFloorOutlinePolygon : public MV3DElement {
|
||||
|
||||
// Floorplan::Floor* f;
|
||||
// Floorplan::FloorOutlinePolygon* poly;
|
||||
|
||||
//public:
|
||||
|
||||
// /** ctor */
|
||||
// MV3DElementFloorOutlinePolygon(Floorplan::Floor* f, Floorplan::FloorOutlinePolygon* poly) : f(f), poly(poly) {
|
||||
// ;
|
||||
// }
|
||||
|
||||
//protected:
|
||||
|
||||
|
||||
// /** repaint me */
|
||||
// void paintGL() override {
|
||||
|
||||
// throw "deprecated!!!";
|
||||
|
||||
// glDisable(GL_CULL_FACE);
|
||||
|
||||
//// switch (poly->method) {
|
||||
//// case Floorplan::OutlineMethod::ADD:
|
||||
//// glColor3f(1,1,1);
|
||||
//// break;
|
||||
//// case Floorplan::OutlineMethod::REMOVE:
|
||||
//// glColor3f(0.3, 0.3, 0.3);
|
||||
//// break;
|
||||
//// }
|
||||
|
||||
// if (poly->outdoor) {
|
||||
// glColor3f(0, 0, 0.5);
|
||||
// } else {
|
||||
// glColor3f(0.3, 0.3, 0.3);
|
||||
// }
|
||||
|
||||
// glBegin(GL_POLYGON);
|
||||
// glNormal3f(0,1,0);
|
||||
// for (Point2 p2 : poly->poly.points) {
|
||||
// Point3 p3(p2.x, p2.y, f->atHeight);
|
||||
// glVertex3f(p3.x, p3.z, p3.y);
|
||||
// }
|
||||
// glEnd();
|
||||
|
||||
// glEnable(GL_CULL_FACE);
|
||||
|
||||
// }
|
||||
|
||||
//};
|
||||
|
||||
#endif // MV3DELEMENTFLOOROUTLINEPOLYGON_H
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "misc/Cube.h"
|
||||
#include "MV3DElement.h"
|
||||
#include "misc/Shader.h"
|
||||
#include "misc/TriangleData.h"
|
||||
|
||||
class MV3DElementStair : public MV3DElement {
|
||||
|
||||
@@ -25,11 +26,7 @@ protected:
|
||||
/** repaint me */
|
||||
void render(const RenderSettings& rs) override {
|
||||
|
||||
//glDisable(GL_CULL_FACE);
|
||||
|
||||
|
||||
std::vector<float> vertices;
|
||||
std::vector<float> normals;
|
||||
TriangleData data;
|
||||
|
||||
const std::vector<Floorplan::StairPart> parts = stair->getParts();
|
||||
const std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(parts, floor);
|
||||
@@ -46,66 +43,26 @@ protected:
|
||||
Point3 n = Math::normal(p1,p2);
|
||||
if (n.z < 0) {n = -n;}
|
||||
|
||||
vertices.insert(vertices.end(), {quad.p1.x, quad.p1.y, quad.p1.z});
|
||||
vertices.insert(vertices.end(), {quad.p2.x, quad.p2.y, quad.p2.z});
|
||||
vertices.insert(vertices.end(), {quad.p3.x, quad.p3.y, quad.p3.z});
|
||||
// upper side
|
||||
data.addTriangle(quad.p1, quad.p2, quad.p3, n);
|
||||
data.addTriangle(quad.p3, quad.p4, quad.p1, n);
|
||||
|
||||
vertices.insert(vertices.end(), {quad.p3.x, quad.p3.y, quad.p3.z});
|
||||
vertices.insert(vertices.end(), {quad.p4.x, quad.p4.y, quad.p4.z});
|
||||
vertices.insert(vertices.end(), {quad.p1.x, quad.p1.y, quad.p1.z});
|
||||
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
// lower side
|
||||
data.addTriangle(quad.p2, quad.p1, quad.p3, -n);
|
||||
data.addTriangle(quad.p4, quad.p3, quad.p1, -n);
|
||||
|
||||
}
|
||||
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
rs.shader->setColor(1.0, 0.55, 0.55);
|
||||
rs.shader->setVertices(vertices.data());
|
||||
rs.shader->setNormals(normals.data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size()/3);
|
||||
rs.shader->setVertices(data.getVertices().data());
|
||||
rs.shader->setNormals(data.getNormals().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, data.getVertices().size()/3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetNormals();
|
||||
rs.shader->release();
|
||||
|
||||
/*
|
||||
TODO_GL
|
||||
//glColor3f(1.0, 0.55, 0.55);
|
||||
glColor3f(0.3, 0.3, 0.3);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
const std::vector<Floorplan::StairPart> parts = stair->getParts();
|
||||
const std::vector<Floorplan::Quad3> quads = Floorplan::getQuads(parts, floor);
|
||||
|
||||
for (int i = 0; i < (int) parts.size(); ++i) {
|
||||
|
||||
//const Floorplan::StairPart& part = parts[i];
|
||||
const Floorplan::Quad3& quad = quads[i];
|
||||
|
||||
//const Floorplan::Quad3 quad = part.getQuad(floor);
|
||||
const Point3 p1 = quad.p2-quad.p1;
|
||||
const Point3 p2 = quad.p4-quad.p1;
|
||||
|
||||
Point3 n = Math::normal(p1,p2);
|
||||
if (n.z < 0) {n = -n;}
|
||||
|
||||
glNormal3f(n.x, n.z, n.z);
|
||||
glVertex3f(quad.p1.x, quad.p1.z, quad.p1.y);
|
||||
glVertex3f(quad.p2.x, quad.p2.z, quad.p2.y);
|
||||
glVertex3f(quad.p3.x, quad.p3.z, quad.p3.y);
|
||||
glVertex3f(quad.p4.x, quad.p4.z, quad.p4.y);
|
||||
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
*/
|
||||
}
|
||||
|
||||
bool isTransparent() const override {
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
#include "../model/MapModelElement.h"
|
||||
#include "../model/MapModel.h"
|
||||
|
||||
#include "../3DGrid/GridModel.h"
|
||||
#include "../3DGrid/GridRenderer.h"
|
||||
#include "../3D/grid/GridModel.h"
|
||||
#include "../3D/grid/GridRenderer.h"
|
||||
|
||||
#include "../3DNavMesh/NavMeshModel.h"
|
||||
#include "../3DNavMesh/NavMeshRenderer.h"
|
||||
#include "../3D/navMesh/NavMeshModel.h"
|
||||
#include "../3D/navMesh/NavMeshRenderer.h"
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
95
mapview/3D/grid/GridModel.h
Normal file
95
mapview/3D/grid/GridModel.h
Normal file
@@ -0,0 +1,95 @@
|
||||
#ifndef GRIDMODEL_H
|
||||
#define GRIDMODEL_H
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
#include <Indoor/grid/Grid.h>
|
||||
#include <Indoor/grid/factory/v2/GridFactory.h>
|
||||
#include <Indoor/grid/factory/v2/Importance.h>
|
||||
|
||||
#include <QProgressDialog>
|
||||
#include <QApplication>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QProgressBar>
|
||||
|
||||
#include "MyNode.h"
|
||||
|
||||
/**
|
||||
* used for 3D grid rendering
|
||||
*/
|
||||
class GridModel {
|
||||
|
||||
private:
|
||||
|
||||
const int gridSize_cm = 30; // TODO
|
||||
|
||||
Grid<MyNode> grid;
|
||||
Floorplan::IndoorMap* im;
|
||||
|
||||
public:
|
||||
|
||||
GridModel() : grid(gridSize_cm) {
|
||||
;
|
||||
}
|
||||
|
||||
Grid<MyNode>* getGrid() {return &grid;}
|
||||
|
||||
|
||||
class Listener : public GridFactoryListener {
|
||||
|
||||
private:
|
||||
QDialog dlg;
|
||||
QLabel* lbl1;
|
||||
QLabel* lbl2;
|
||||
QProgressBar* bar1;
|
||||
QProgressBar* bar2;
|
||||
|
||||
public:
|
||||
Listener() {
|
||||
QVBoxLayout* lay = new QVBoxLayout(&dlg);
|
||||
lbl1 = new QLabel(); lay->addWidget(lbl1);
|
||||
bar1 = new QProgressBar(); lay->addWidget(bar1);
|
||||
lbl2 = new QLabel(); lay->addWidget(lbl2);
|
||||
bar2 = new QProgressBar(); lay->addWidget(bar2);
|
||||
dlg.resize(350, 120);
|
||||
dlg.show();
|
||||
}
|
||||
~Listener() {
|
||||
dlg.close();
|
||||
}
|
||||
|
||||
void onGridBuildUpdateMajor(const std::string& what) override {
|
||||
lbl1->setText(what.c_str());
|
||||
QApplication::processEvents();
|
||||
}
|
||||
void onGridBuildUpdateMajor(const int cnt, const int cur) override {
|
||||
bar1->setValue(cur*100/cnt);
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void onGridBuildUpdateMinor(const std::string& what) override {
|
||||
lbl2->setText(what.c_str());
|
||||
QApplication::processEvents();
|
||||
}
|
||||
void onGridBuildUpdateMinor(const int cnt, const int cur) override {
|
||||
bar2->setValue(cur*100/cnt);
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void rebuild(Floorplan::IndoorMap* im) {
|
||||
|
||||
Listener l;
|
||||
|
||||
GridFactory<MyNode> fac(grid);
|
||||
fac.build(im, &l);
|
||||
|
||||
Importance::addImportance(grid, &l);
|
||||
//Importance::addImportance(grid, 400);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // GRIDMODEL_H
|
||||
141
mapview/3D/grid/GridRenderer.h
Normal file
141
mapview/3D/grid/GridRenderer.h
Normal file
@@ -0,0 +1,141 @@
|
||||
#ifndef GRIDRENDERER_H
|
||||
#define GRIDRENDERER_H
|
||||
|
||||
#include "MyNode.h"
|
||||
|
||||
#include <unordered_set>
|
||||
#include <Indoor/grid/Grid.h>
|
||||
|
||||
enum class GridRendererColorMode {
|
||||
SHOW_NODE_TYPE,
|
||||
SHOW_NODE_IMPORTANCE,
|
||||
};
|
||||
|
||||
class GridRenderer {
|
||||
|
||||
private:
|
||||
|
||||
// settings
|
||||
GridRendererColorMode colorMode = GridRendererColorMode::SHOW_NODE_IMPORTANCE;
|
||||
bool showEdges = false;
|
||||
|
||||
struct Color {
|
||||
float r,g,b;
|
||||
Color() : r(1), g(0), b(0) {;}
|
||||
Color(float r, float g, float b) : r(r), g(g), b(b) {;}
|
||||
};
|
||||
|
||||
/** node color depending on the node's type. see ctor */
|
||||
Color colors[200];
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
GridRenderer() {
|
||||
|
||||
colors[GridNode::TYPE_FLOOR] = Color(0.4, 0.4, 0.4);
|
||||
colors[GridNode::TYPE_STAIR] = Color(0,0,1);
|
||||
colors[GridNode::TYPE_ELEVATOR] = Color(0,0,1);
|
||||
colors[GridNode::TYPE_DOOR] = Color(0.0, 0.0, 0.0);
|
||||
|
||||
colors[GridNode::TYPE_OUTDOOR] = Color(0.0, 0.5, 0.0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void setNodeColorMode(const GridRendererColorMode mode) {this->colorMode = mode;}
|
||||
void setShowEdges(const bool show) {this->showEdges = show;}
|
||||
|
||||
|
||||
/** render the given grid using GL commands */
|
||||
void paintGL(Grid<MyNode>* grid) {
|
||||
|
||||
/*
|
||||
|
||||
TODO_GL
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
const float sz = 1.0f; // scale-z: more/less z-spacing
|
||||
const float oz = 0.1f; // z-offset
|
||||
|
||||
if (showEdges) {
|
||||
std::unordered_set<uint64_t> used;
|
||||
glBegin(GL_LINES);
|
||||
for (MyNode& n1 : *grid) {
|
||||
glColor3f(0.5, 0.5, 0.5);
|
||||
for (MyNode& n2 : grid->neighbors(n1)) {
|
||||
uint64_t min = std::min(n1.getIdx(), n2.getIdx());
|
||||
uint64_t max = std::max(n1.getIdx(), n2.getIdx());
|
||||
uint64_t idx = max << 32 | min;
|
||||
if (used.find(idx) == used.end()) {
|
||||
glVertex3f(n1.x_cm/100.0f, n1.z_cm/100.0f*sz+oz, n1.y_cm/100.0f);
|
||||
glVertex3f(n2.x_cm/100.0f, n2.z_cm/100.0f*sz+oz, n2.y_cm/100.0f);
|
||||
used.insert(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
glPointSize(3.0f);
|
||||
glBegin(GL_POINTS);
|
||||
for (MyNode& n : *grid) {
|
||||
|
||||
// get the color to use
|
||||
switch(colorMode) {
|
||||
case GridRendererColorMode::SHOW_NODE_TYPE: {
|
||||
const Color c = colors[n.getType()];
|
||||
glColor3f(c.r, c.g, c.b);
|
||||
break;
|
||||
}
|
||||
|
||||
case GridRendererColorMode::SHOW_NODE_IMPORTANCE: {
|
||||
const float xx = n.navImportance - 0.6;
|
||||
glColor3f(xx, xx, xx);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
glVertex3f(n.x_cm/100.0f, n.z_cm/100.0f*sz+oz, n.y_cm/100.0f);
|
||||
|
||||
}
|
||||
glEnd();
|
||||
|
||||
|
||||
|
||||
// std::vector<MyNode> vec = lint();
|
||||
// glPointSize(4.0f);
|
||||
// glBegin(GL_POINTS);
|
||||
// glColor3f(1,0,0);
|
||||
// for (MyNode& n : vec) {
|
||||
// glVertex3f(n.x_cm/100.0f, n.z_cm/100.0f*s, n.y_cm/100.0f);
|
||||
// }
|
||||
// glEnd();
|
||||
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
// std::vector<MyNode> lint() {
|
||||
// std::vector<MyNode> vec;
|
||||
// lintStair(vec);
|
||||
// return vec;
|
||||
// }
|
||||
|
||||
// void lintStair(std::vector<MyNode>& vec) {
|
||||
// for (MyNode& n1 : *grid) {
|
||||
// if (n1.getNumNeighbors() <= 5) { vec.push_back(n1);}
|
||||
// }
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
#endif // GRIDRENDERER_H
|
||||
15
mapview/3D/grid/MyNode.h
Normal file
15
mapview/3D/grid/MyNode.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef MYNODE_H
|
||||
#define MYNODE_H
|
||||
|
||||
#include <Indoor/grid/Grid.h>
|
||||
#include <Indoor/grid/factory/v2/GridNodeImportance.h>
|
||||
|
||||
struct MyNode : public GridNode, public GridPoint, public GridNodeImportance {
|
||||
|
||||
MyNode(float x, float y, float z) : GridPoint(x,y,z) {;}
|
||||
|
||||
float walkImportance;
|
||||
|
||||
};
|
||||
|
||||
#endif // MYNODE_H
|
||||
@@ -47,8 +47,6 @@ static float cube_normals[] = {
|
||||
};
|
||||
|
||||
|
||||
//static Shader* shader = nullptr;
|
||||
|
||||
Cube::Cube(Point3 pos, float size) : pos(pos), size(size,size,size), rot(0,0,0) {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef CUBE_H
|
||||
#define CUBE_H
|
||||
|
||||
#include "../../../fixC11.h"
|
||||
#include <Indoor/geo/Point3.h>
|
||||
#include "Renderable3D.h"
|
||||
|
||||
@@ -26,82 +27,6 @@ public:
|
||||
|
||||
void render(const RenderSettings& rs) override;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
void paintGL(Shader* shader);
|
||||
|
||||
TODO_GL
|
||||
|
||||
glColor3f(color.x, color.y, color.z);
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
// 3) move to destination
|
||||
glTranslatef(pos.x, pos.z, pos.y); // swap yz
|
||||
|
||||
// 2) rotate
|
||||
glRotatef(rot.x, 1, 0, 0);
|
||||
glRotatef(rot.y, 0, 0, 1); // swap yz
|
||||
glRotatef(rot.z, 0, 1, 0);
|
||||
|
||||
// 1) scale
|
||||
glScalef(size.x, size.z, size.y); // swap yz
|
||||
|
||||
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
// bottom
|
||||
glNormal3f(0,-1,0);
|
||||
glVertex3f(+s, -s, -s);
|
||||
glVertex3f(+s, -s, +s);
|
||||
glVertex3f(-s, -s, +s);
|
||||
glVertex3f(-s, -s, -s);
|
||||
|
||||
// top
|
||||
glNormal3f(0,+1,0);
|
||||
glVertex3f(-s, +s, -s);
|
||||
glVertex3f(-s, +s, +s);
|
||||
glVertex3f(+s, +s, +s);
|
||||
glVertex3f(+s, +s, -s);
|
||||
|
||||
// left
|
||||
glNormal3f(-1,0,0);
|
||||
glVertex3f(-s, -s, -s);
|
||||
glVertex3f(-s, -s, +s);
|
||||
glVertex3f(-s, +s, +s);
|
||||
glVertex3f(-s, +s, -s);
|
||||
|
||||
// right
|
||||
glNormal3f(+1,0,0);
|
||||
glVertex3f(+s, +s, -s);
|
||||
glVertex3f(+s, +s, +s);
|
||||
glVertex3f(+s, -s, +s);
|
||||
glVertex3f(+s, -s, -s);
|
||||
|
||||
// front
|
||||
glNormal3f(0,0,+1);
|
||||
glVertex3f(+s, +s, +s);
|
||||
glVertex3f(-s, +s, +s);
|
||||
glVertex3f(-s, -s, +s);
|
||||
glVertex3f(+s, -s, +s);
|
||||
|
||||
// rear
|
||||
glNormal3f(0,0,-1);
|
||||
glVertex3f(+s, -s, -s);
|
||||
glVertex3f(-s, -s, -s);
|
||||
glVertex3f(-s, +s, -s);
|
||||
glVertex3f(+s, +s, -s);
|
||||
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
*/
|
||||
|
||||
};
|
||||
|
||||
#endif // CUBE_H
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "../../../fixC11.h"
|
||||
|
||||
#include "Handrail.h"
|
||||
|
||||
#include <Indoor/geo/Point3.h>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "../../../fixC11.h"
|
||||
|
||||
#include "Outline.h"
|
||||
|
||||
#include <QMatrix4x4>
|
||||
@@ -19,17 +21,15 @@ void Outline::render(const RenderSettings& rs) {
|
||||
|
||||
// show both sides
|
||||
//glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
|
||||
rs.shader->setColor(color.x, color.y, color.z);
|
||||
rs.shader->setVertices(vertices.data());
|
||||
rs.shader->setNormals(normals.data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size() / 3);
|
||||
rs.shader->setVertices(triangles.getVertices().data());
|
||||
rs.shader->setNormals(triangles.getNormals().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, triangles.getVertices().size() / 3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetNormals();
|
||||
|
||||
|
||||
|
||||
rs.shader->release();
|
||||
|
||||
}
|
||||
@@ -39,8 +39,7 @@ void Outline::setColor(float r, float g, float b) {
|
||||
}
|
||||
|
||||
void Outline::clear() {
|
||||
normals.clear();
|
||||
vertices.clear();
|
||||
triangles.clear();
|
||||
}
|
||||
|
||||
void Outline::add(std::vector<std::vector<Point3>>& triangles) {
|
||||
@@ -54,18 +53,22 @@ void Outline::add(std::vector<std::vector<Point3>>& triangles) {
|
||||
|
||||
const Point3 n = cross(p2-p1, p3-p1);
|
||||
if (n.z < 0) {
|
||||
vertices.push_back(p1.x); vertices.push_back(p1.y); vertices.push_back(p1.z);
|
||||
vertices.push_back(p3.x); vertices.push_back(p3.y); vertices.push_back(p3.z);
|
||||
vertices.push_back(p2.x); vertices.push_back(p2.y); vertices.push_back(p2.z);
|
||||
} else {
|
||||
vertices.push_back(p1.x); vertices.push_back(p1.y); vertices.push_back(p1.z);
|
||||
vertices.push_back(p2.x); vertices.push_back(p2.y); vertices.push_back(p2.z);
|
||||
vertices.push_back(p3.x); vertices.push_back(p3.y); vertices.push_back(p3.z);
|
||||
}
|
||||
|
||||
normals.push_back(0); normals.push_back(0); normals.push_back(1);
|
||||
normals.push_back(0); normals.push_back(0); normals.push_back(1);
|
||||
normals.push_back(0); normals.push_back(0); normals.push_back(1);
|
||||
// upper side (floor)
|
||||
this->triangles.addTriangle(p1, p3, p2, Point3(0,0,+1));
|
||||
|
||||
// facing downwards (ceiling)
|
||||
this->triangles.addTriangle(p1, p2, p3, Point3(0,0,-1));
|
||||
|
||||
} else {
|
||||
|
||||
// upper side (floor)
|
||||
this->triangles.addTriangle(p1, p2, p3, Point3(0,0,+1));
|
||||
|
||||
// facing downwards (ceiling)
|
||||
this->triangles.addTriangle(p1, p3, p2, Point3(0,0,-1));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
#include "Renderable3D.h"
|
||||
#include <vector>
|
||||
#include <Indoor/geo/Point3.h>
|
||||
#include "TriangleData.h"
|
||||
|
||||
class Outline : public Renderable3D {
|
||||
|
||||
private:
|
||||
|
||||
std::vector<float> vertices;
|
||||
std::vector<float> normals;
|
||||
TriangleData triangles;
|
||||
Point3 color;
|
||||
|
||||
public:
|
||||
|
||||
77
mapview/3D/misc/TriangleData.h
Normal file
77
mapview/3D/misc/TriangleData.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef TRIANGLEDATA_H
|
||||
#define TRIANGLEDATA_H
|
||||
|
||||
#include <vector>
|
||||
#include <Indoor/geo/Point3.h>
|
||||
|
||||
class TriangleData {
|
||||
|
||||
std::vector<float> vertices;
|
||||
std::vector<float> normals;
|
||||
std::vector<float> rgba;
|
||||
|
||||
public:
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
|
||||
}
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
|
||||
}
|
||||
|
||||
void addTriangle(Point3 p1, Point3 p2, Point3 p3, const Point3 n, const float r, const float g, const float b, const float a) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
vertices.insert(vertices.end(), {p3.x, p3.y, p3.z});
|
||||
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
normals.insert(normals.end(), {n.x, n.y, n.z});
|
||||
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
|
||||
}
|
||||
|
||||
|
||||
void addLine(Point3 p1, Point3 p2, const float r, const float g, const float b, const float a) {
|
||||
|
||||
vertices.insert(vertices.end(), {p1.x, p1.y, p1.z});
|
||||
vertices.insert(vertices.end(), {p2.x, p2.y, p2.z});
|
||||
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
rgba.insert(rgba.end(), {r,g,b,a});
|
||||
|
||||
}
|
||||
|
||||
void clear() {
|
||||
vertices.clear();
|
||||
normals.clear();
|
||||
rgba.clear();
|
||||
}
|
||||
|
||||
const std::vector<float>& getVertices() {return vertices;}
|
||||
|
||||
const std::vector<float>& getNormals() {return normals;}
|
||||
|
||||
const std::vector<float>& getRGBA() {return rgba;}
|
||||
|
||||
};
|
||||
|
||||
#endif // TRIANGLEDATA_H
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "../../../fixC11.h"
|
||||
|
||||
#include "Window.h"
|
||||
#include "Shader.h"
|
||||
|
||||
|
||||
85
mapview/3D/navMesh/NavMeshModel.h
Normal file
85
mapview/3D/navMesh/NavMeshModel.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#ifndef NAVMESHMODEL_H
|
||||
#define NAVMESHMODEL_H
|
||||
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
#include <Indoor/navMesh/NavMesh.h>
|
||||
#include <Indoor/navMesh/NavMeshFactory.h>
|
||||
#include <Indoor/navMesh/NavMeshFactoryListener.h>
|
||||
|
||||
#include <QProgressDialog>
|
||||
#include <QApplication>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QProgressBar>
|
||||
#include "QNavMeshSettings.h"
|
||||
|
||||
/**
|
||||
* used for 3D NavMesh rendering
|
||||
*/
|
||||
class NavMeshModel {
|
||||
|
||||
private:
|
||||
|
||||
NM::NavMesh<NM::NavMeshTriangle> navMesh;
|
||||
NM::NavMeshSettings settings;
|
||||
Floorplan::IndoorMap* im;
|
||||
|
||||
public:
|
||||
|
||||
NavMeshModel() : navMesh() {
|
||||
;
|
||||
}
|
||||
|
||||
NM::NavMesh<NM::NavMeshTriangle>* getNavMesh() {return &navMesh;}
|
||||
|
||||
|
||||
class Listener : public NM::NavMeshFactoryListener {
|
||||
|
||||
private:
|
||||
QDialog dlg;
|
||||
QLabel* lbl1;
|
||||
QProgressBar* bar1;
|
||||
|
||||
public:
|
||||
Listener() {
|
||||
QVBoxLayout* lay = new QVBoxLayout(&dlg);
|
||||
lbl1 = new QLabel(); lay->addWidget(lbl1);
|
||||
bar1 = new QProgressBar(); lay->addWidget(bar1);
|
||||
dlg.resize(350, 90);
|
||||
dlg.setWindowTitle("NavMesh building");
|
||||
dlg.show();
|
||||
}
|
||||
~Listener() {
|
||||
dlg.close();
|
||||
}
|
||||
|
||||
void onNavMeshBuildUpdateMajor(const std::string& what) override {
|
||||
lbl1->setText(what.c_str());
|
||||
QApplication::processEvents();
|
||||
}
|
||||
void onNavMeshBuildUpdateMajor(const int cnt, const int cur) override {
|
||||
bar1->setValue(cur*100/cnt);
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void rebuild(Floorplan::IndoorMap* im) {
|
||||
|
||||
Listener l;
|
||||
|
||||
QNavMeshSettings qs(&settings);
|
||||
qs.exec();
|
||||
|
||||
if (qs.ok) {
|
||||
NM::NavMeshFactory<NM::NavMeshTriangle> fac(&navMesh, settings);
|
||||
fac.build(im, &l);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // NAVMESHMODEL_H
|
||||
157
mapview/3D/navMesh/NavMeshRenderer.h
Normal file
157
mapview/3D/navMesh/NavMeshRenderer.h
Normal file
@@ -0,0 +1,157 @@
|
||||
#ifndef NAVMESHRENDERER_H
|
||||
#define NAVMESHRENDERER_H
|
||||
|
||||
|
||||
|
||||
#include <unordered_set>
|
||||
#include <Indoor/navMesh/NavMesh.h>
|
||||
#include <Indoor/navMesh/NavMeshTriangle.h>
|
||||
#include <Indoor/navMesh/NavMeshType.h>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QOpenGLWidget>
|
||||
|
||||
#include "../misc/Renderable3D.h"
|
||||
#include "../misc/Shader.h"
|
||||
#include "../misc/TriangleData.h"
|
||||
|
||||
class NavMeshRenderer {
|
||||
|
||||
private:
|
||||
|
||||
// settings
|
||||
//GridRendererColorMode colorMode = GridRendererColorMode::SHOW_NODE_IMPORTANCE;
|
||||
bool showEdges = false;
|
||||
|
||||
struct Color {
|
||||
float r,g,b;
|
||||
Color() : r(1), g(0), b(0) {;}
|
||||
Color(float r, float g, float b) : r(r), g(g), b(b) {;}
|
||||
};
|
||||
|
||||
/** node color depending on the node's type. see ctor */
|
||||
Color colors[200];
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
NavMeshRenderer() {
|
||||
|
||||
colors[GridNode::TYPE_FLOOR] = Color(0.4, 0.4, 0.4);
|
||||
colors[GridNode::TYPE_STAIR] = Color(0,0,1);
|
||||
colors[GridNode::TYPE_ELEVATOR] = Color(0,0,1);
|
||||
colors[GridNode::TYPE_DOOR] = Color(0.0, 0.0, 0.0);
|
||||
|
||||
colors[GridNode::TYPE_OUTDOOR] = Color(0.0, 0.5, 0.0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// void setNodeColorMode(const GridRendererColorMode mode) {this->colorMode = mode;}
|
||||
void setShowEdges(const bool show) {this->showEdges = show;}
|
||||
|
||||
|
||||
/** render the given grid using GL commands */
|
||||
void render(const RenderSettings& rs, NM::NavMesh<NM::NavMeshTriangle>* navMesh, QOpenGLWidget* dst) {
|
||||
|
||||
if (navMesh == nullptr) {return;}
|
||||
|
||||
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
|
||||
TriangleData data;
|
||||
|
||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
||||
|
||||
Point3 color;
|
||||
|
||||
switch (tria->getType()) {
|
||||
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.8, 0.8, 0.8); break;
|
||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.1, 0.8, 0.1); break;
|
||||
case (int) NM::NavMeshType::DOOR: color = Point3(0.7, 0.7, 0.8); break;
|
||||
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.5, 0.5, 0.5); break;
|
||||
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.6, 0.6, 0.6); break;
|
||||
}
|
||||
|
||||
data.addTriangle(tria->getP1(), tria->getP3(), tria->getP2(), Point3(0,0,1), color.x, color.y, color.z, 1.0f);
|
||||
|
||||
// vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z});
|
||||
// vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z});
|
||||
// vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z});
|
||||
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
|
||||
}
|
||||
|
||||
rs.shader->setVertices(data.getVertices().data());
|
||||
rs.shader->setVertexColor(data.getRGBA().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, data.getVertices().size()/3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
data.clear();
|
||||
|
||||
|
||||
for (const NM::NavMeshTriangle* tria : *navMesh) {
|
||||
|
||||
Point3 color;
|
||||
|
||||
switch (tria->getType()) {
|
||||
case (int) NM::NavMeshType::FLOOR_INDOOR: color = Point3(0.6, 0.6, 0.6); break;
|
||||
case (int) NM::NavMeshType::FLOOR_OUTDOOR: color = Point3(0.0, 0.6, 0.0); break;
|
||||
case (int) NM::NavMeshType::DOOR: color = Point3(0.5, 0.5, 0.6); break;
|
||||
case (int) NM::NavMeshType::STAIR_LEVELED: color = Point3(0.4, 0.4, 0.4); break;
|
||||
case (int) NM::NavMeshType::STAIR_SKEWED: color = Point3(0.4, 0.4, 0.4); break;
|
||||
}
|
||||
|
||||
const float o = 0.001f;
|
||||
data.addLine(tria->getP1(), tria->getP2(), color.x, color.y, color.z, 1);
|
||||
data.addLine(tria->getP2(), tria->getP3(), color.x, color.y, color.z, 1);
|
||||
data.addLine(tria->getP3(), tria->getP1(), color.x, color.y, color.z, 1);
|
||||
|
||||
// vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z+o});
|
||||
// vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z+o});
|
||||
|
||||
// vertices.insert(vertices.end(), {tria->getP2().x, tria->getP2().y, tria->getP2().z+o});
|
||||
// vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z+o});
|
||||
|
||||
// vertices.insert(vertices.end(), {tria->getP3().x, tria->getP3().y, tria->getP3().z+o});
|
||||
// vertices.insert(vertices.end(), {tria->getP1().x, tria->getP1().y, tria->getP1().z+o});
|
||||
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
// colors.insert(colors.end(), {color.x, color.y, color.z, 1});
|
||||
|
||||
}
|
||||
|
||||
rs.shader->setVertices(data.getVertices().data());
|
||||
rs.shader->setVertexColor(data.getRGBA().data());
|
||||
glDrawArrays(GL_LINES, 0, data.getVertices().size()/3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
rs.shader->release();
|
||||
|
||||
}
|
||||
|
||||
// std::vector<MyNode> lint() {
|
||||
// std::vector<MyNode> vec;
|
||||
// lintStair(vec);
|
||||
// return vec;
|
||||
// }
|
||||
|
||||
// void lintStair(std::vector<MyNode>& vec) {
|
||||
// for (MyNode& n1 : *grid) {
|
||||
// if (n1.getNumNeighbors() <= 5) { vec.push_back(n1);}
|
||||
// }
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
#endif // NAVMESHRENDERER_H
|
||||
102
mapview/3D/navMesh/QNavMeshSettings.cpp
Normal file
102
mapview/3D/navMesh/QNavMeshSettings.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include "QNavMeshSettings.h"
|
||||
|
||||
#include <Indoor/navMesh/NavMeshSettings.h>
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QLabel>
|
||||
#include <QSlider>
|
||||
#include <QSlider>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
QNavMeshSettings::QNavMeshSettings(NM::NavMeshSettings* settings, QWidget* parent) : QDialog(parent) {
|
||||
|
||||
QGridLayout* lay = new QGridLayout(this);
|
||||
this->setLayout(lay);
|
||||
int row = 0;
|
||||
|
||||
this->setWindowTitle("NavMesh Settings");
|
||||
this->setMinimumWidth(350);
|
||||
|
||||
// MAX QUALITY
|
||||
{
|
||||
lay->addWidget(new QLabel("smallest element"), row, 0);
|
||||
QLabel* lblQuality = new QLabel("");
|
||||
lay->addWidget(lblQuality, row, 2);
|
||||
QSlider* sldQuality = new QSlider(Qt::Orientation::Horizontal); sldQuality->setMinimum(10); sldQuality->setMaximum(30);
|
||||
connect(sldQuality, &QSlider::valueChanged, [settings, sldQuality, lblQuality] () {
|
||||
settings->maxQuality_m = sldQuality->value() / 100.0f;
|
||||
lblQuality->setText(QString("%1 m").arg(settings->maxQuality_m, 5, 'f', 2, 0));
|
||||
});
|
||||
sldQuality->setValue(settings->maxQuality_m * 100.0f);
|
||||
lay->addWidget(sldQuality, row, 1);
|
||||
++row;
|
||||
}
|
||||
|
||||
// AGENT HEIGHT
|
||||
{
|
||||
lay->addWidget(new QLabel("agent height"), row, 0);
|
||||
QLabel* lblHeight = new QLabel("");
|
||||
lay->addWidget(lblHeight, row, 2);
|
||||
QSlider* sldHeight = new QSlider(Qt::Orientation::Horizontal); sldHeight->setMinimum(10); sldHeight->setMaximum(200);
|
||||
connect(sldHeight, &QSlider::valueChanged, [settings, sldHeight, lblHeight] () {
|
||||
settings->agentHeight = sldHeight->value() / 100.0f;
|
||||
lblHeight->setText(QString("%1 m").arg(settings->agentHeight, 5, 'f', 2, 0));
|
||||
});
|
||||
sldHeight->setValue(settings->agentHeight * 100.0f);
|
||||
lay->addWidget(sldHeight, row, 1);
|
||||
++row;
|
||||
}
|
||||
|
||||
// AGENT RADIUS
|
||||
{
|
||||
lay->addWidget(new QLabel("agent radius"), row, 0);
|
||||
QLabel* lblRadius = new QLabel("");
|
||||
lay->addWidget(lblRadius, row, 2);
|
||||
QSlider* sldRadius = new QSlider(Qt::Orientation::Horizontal); sldRadius->setMinimum(5); sldRadius->setMaximum(60);
|
||||
connect(sldRadius, &QSlider::valueChanged, [settings, sldRadius, lblRadius] () {
|
||||
settings->agentRadius = sldRadius->value() / 100.0f;
|
||||
lblRadius->setText(QString("%1 m").arg(settings->agentRadius, 5, 'f', 2, 0));
|
||||
});
|
||||
sldRadius->setValue(settings->agentRadius * 100.0f);
|
||||
lay->addWidget(sldRadius, row, 1);
|
||||
++row;
|
||||
}
|
||||
|
||||
|
||||
// MAX EDGE LENGTH
|
||||
{
|
||||
lay->addWidget(new QLabel("max edge length"), row, 0);
|
||||
QLabel* lblMaxEdgeLength = new QLabel("");
|
||||
lay->addWidget(lblMaxEdgeLength, row, 2);
|
||||
QSlider* sdlMaxEdgeLength = new QSlider(Qt::Orientation::Horizontal); sdlMaxEdgeLength->setMinimum(300); sdlMaxEdgeLength->setMaximum(2000);
|
||||
connect(sdlMaxEdgeLength, &QSlider::valueChanged, [settings, sdlMaxEdgeLength, lblMaxEdgeLength] () {
|
||||
settings->edgeMaxLen = sdlMaxEdgeLength->value() / 100.0f;
|
||||
lblMaxEdgeLength->setText(QString("%1 m").arg(settings->edgeMaxLen, 5, 'f', 2, 0));
|
||||
});
|
||||
sdlMaxEdgeLength->setValue(settings->edgeMaxLen * 100.0f);
|
||||
lay->addWidget(sdlMaxEdgeLength, row, 1);
|
||||
++row;
|
||||
}
|
||||
|
||||
// MIN REGION SIZE
|
||||
{
|
||||
lay->addWidget(new QLabel("min region size"), row, 0);
|
||||
QLabel* lblMinRegionSize = new QLabel("");
|
||||
lay->addWidget(lblMinRegionSize, row, 2);
|
||||
QSlider* sldRegionMinSize = new QSlider(Qt::Orientation::Horizontal); sldRegionMinSize->setMinimum(400); sldRegionMinSize->setMaximum(10000);
|
||||
connect(sldRegionMinSize, &QSlider::valueChanged, [settings, sldRegionMinSize, lblMinRegionSize] () {
|
||||
settings->regionMinSize = sldRegionMinSize->value() / 100.0f;
|
||||
lblMinRegionSize->setText(QString("%1 m").arg(settings->regionMinSize, 5, 'f', 2, 0));
|
||||
});
|
||||
sldRegionMinSize->setValue(settings->regionMinSize * 100.0f);
|
||||
lay->addWidget(sldRegionMinSize, row, 1);
|
||||
++row;
|
||||
}
|
||||
|
||||
QDialogButtonBox* box = new QDialogButtonBox(QDialogButtonBox::StandardButton::Ok | QDialogButtonBox::StandardButton::Close);
|
||||
lay->addWidget(box, row, 0, 1, 3);
|
||||
|
||||
connect(box, &QDialogButtonBox::accepted, [&] () {ok = true; close();});
|
||||
connect(box, &QDialogButtonBox::rejected, [&] () {ok = false; close();});
|
||||
|
||||
}
|
||||
24
mapview/3D/navMesh/QNavMeshSettings.h
Normal file
24
mapview/3D/navMesh/QNavMeshSettings.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef QNAVMESHSETTINGS_H
|
||||
#define QNAVMESHSETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDialog>
|
||||
|
||||
namespace NM {
|
||||
class NavMeshSettings;
|
||||
}
|
||||
|
||||
class QNavMeshSettings : public QDialog {
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
|
||||
QNavMeshSettings(NM::NavMeshSettings* settings, QWidget* parent = nullptr);
|
||||
|
||||
bool ok = false;
|
||||
|
||||
};
|
||||
|
||||
#endif // QNAVMESHSETTINGS_H
|
||||
Reference in New Issue
Block a user