worked on 3D viz
scaling, moving by finger some fixes / improvement
This commit is contained in:
72
mapview/3D/floorplan/FloorplanRenderer.h
Normal file
72
mapview/3D/floorplan/FloorplanRenderer.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef FLOORPLANRENDERER_H
|
||||
#define FLOORPLANRENDERER_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"
|
||||
|
||||
#include <Indoor/wifi/estimate/ray3/ModelFactory.h>
|
||||
|
||||
#include "RenderTriangle.h"
|
||||
|
||||
class FloorplanRenderer {
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
FloorplanRenderer() {
|
||||
;
|
||||
}
|
||||
|
||||
/** render the given grid using GL commands */
|
||||
void renderSolid(const RenderSettings& rs, const RenderTriangle& rt) {
|
||||
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
|
||||
rs.shader->setVertices(rt.getVertices().data());
|
||||
rs.shader->setNormals(rt.getNormals().data());
|
||||
rs.shader->setVertexColor(rt.getRGBA().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.getVertices().size()/3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetNormals();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
rs.shader->release();
|
||||
|
||||
}
|
||||
|
||||
/** render the given grid using GL commands */
|
||||
void renderTransp(const RenderSettings& rs, const RenderTriangle& rt) {
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
rs.shader->bind();
|
||||
rs.shader->setModelMatrix(QMatrix4x4());
|
||||
|
||||
rs.shader->setVertices(rt.getVertices().data());
|
||||
rs.shader->setNormals(rt.getNormals().data());
|
||||
rs.shader->setVertexColor(rt.getRGBA().data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, rt.getVertices().size()/3);
|
||||
rs.shader->unsetVertices();
|
||||
rs.shader->unsetNormals();
|
||||
rs.shader->unsetVertexColor();
|
||||
|
||||
rs.shader->release();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // FLOORPLANRENDERER_H
|
||||
110
mapview/3D/floorplan/FloorplanRendererModel.h
Normal file
110
mapview/3D/floorplan/FloorplanRendererModel.h
Normal file
@@ -0,0 +1,110 @@
|
||||
#ifndef FLOORPLANRENDERERMODEL_H
|
||||
#define FLOORPLANRENDERERMODEL_H
|
||||
|
||||
#include <Indoor/floorplan/v2/Floorplan.h>
|
||||
#include <Indoor/navMesh/NavMesh.h>
|
||||
#include <Indoor/navMesh/NavMeshFactory.h>
|
||||
#include <Indoor/navMesh/NavMeshFactoryListener.h>
|
||||
#include <Indoor/wifi/estimate/ray3/ModelFactory.h>
|
||||
|
||||
#include "RenderTriangle.h"
|
||||
|
||||
/**
|
||||
* model for rendering the floorplan
|
||||
*/
|
||||
class FloorplanRendererModel {
|
||||
|
||||
private:
|
||||
|
||||
Floorplan::IndoorMap* im;
|
||||
Ray3D::FloorplanMesh mesh;
|
||||
|
||||
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<Material> mats = {
|
||||
|
||||
Material(0,128,0,255), // ground outdoor
|
||||
Material(64,64,64,255), // ground outdoor
|
||||
Material(255,96,96,255), // stair
|
||||
Material(220,220,220,255), // handrail
|
||||
|
||||
Material(200,200,255,96), // door (glass)
|
||||
Material(200,160,150,255), // door (wood)
|
||||
|
||||
Material(128,128,128,255), // concrete
|
||||
Material(200,200,255,96), // glass
|
||||
|
||||
Material(200,200,200,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::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;}
|
||||
|
||||
return 8;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/** ctor */
|
||||
FloorplanRendererModel() {
|
||||
;
|
||||
}
|
||||
|
||||
Ray3D::FloorplanMesh& getMesh() {
|
||||
return mesh;
|
||||
}
|
||||
|
||||
const RenderTriangle& getTriaSolid() {
|
||||
return triaSolid;
|
||||
}
|
||||
|
||||
const RenderTriangle& getTriaTransp() {
|
||||
return triaTransp;
|
||||
}
|
||||
|
||||
void rebuild(Floorplan::IndoorMap* im) {
|
||||
|
||||
// rebuild the mesh
|
||||
Ray3D::ModelFactory fac(im);
|
||||
mesh = fac.getMesh();
|
||||
|
||||
triaTransp.clear();
|
||||
triaSolid.clear();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // FLOORPLANRENDERERMODEL_H
|
||||
78
mapview/3D/floorplan/RenderTriangle.h
Normal file
78
mapview/3D/floorplan/RenderTriangle.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#ifndef RENDERTRIANGLE_H
|
||||
#define RENDERTRIANGLE_H
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <Indoor/geo/Point3.h>
|
||||
|
||||
class RenderTriangle {
|
||||
|
||||
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});
|
||||
|
||||
}
|
||||
|
||||
|
||||
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() const {return vertices;}
|
||||
|
||||
const std::vector<float>& getNormals() const {return normals;}
|
||||
|
||||
const std::vector<float>& getRGBA() const {return rgba;}
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // RENDERTRIANGLE_H
|
||||
Reference in New Issue
Block a user