134 lines
2.8 KiB
C++
134 lines
2.8 KiB
C++
#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) {
|
|
|
|
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
|