Implement interaciton paths for labels.

This commit is contained in:
2018-04-30 13:40:12 +02:00
parent 4f370a4bbd
commit c434c2b62c
5 changed files with 45 additions and 7 deletions

View File

@@ -75,7 +75,7 @@ void ActivityAnimation::draw(float timeScale)
glDrawArrays(GL_POINTS, 0, bufferLength / 3);
glDisableClientState(GL_COLOR_ARRAY);
if (RenderingState::instance().renderInteractionPaths()) {
glColor4fv(RenderingState::instance().pathColor().data());
setGlColor(RenderingState::instance().pathColor());
glVertexPointer(3, GL_FLOAT, 0, startingPos.data());
glDrawElements(GL_LINES, lineIndices.size(), GL_UNSIGNED_INT, lineIndices.data());
}

View File

@@ -1,22 +1,27 @@
#include <GL/gl.h>
#include "LabelVisualisation.hpp"
#include "glutils.hpp"
#include "RenderingState.hpp"
using namespace fmri;
void LabelVisualisation::draw(float)
{
if (RenderingState::instance().renderInteractionPaths()) {
setGlColor(RenderingState::instance().pathColor());
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, nodePositions_.data());
glDrawElements(GL_LINES, nodeIndices.size(), GL_UNSIGNED_INT, nodeIndices.data());
glDisableClientState(GL_VERTEX_ARRAY);
}
glPushMatrix();
glTranslatef(LAYER_X_OFFSET, 0, 0);
for (auto i = 0u; i < nodeLabels.size(); ++i) {
glPushMatrix();
glTranslatef(nodePositions_[3 * i], nodePositions_[3 * i + 1], nodePositions_[3 * i + 2]);
if constexpr (alphaEnabled()) {
glColor4fv(colorBuffer[i].data());
} else {
glColor3fv(colorBuffer[i].data());
}
setGlColor(colorBuffer[i]);
renderText(nodeLabels[i]);
glPopMatrix();
}
@@ -32,6 +37,7 @@ LabelVisualisation::LabelVisualisation(const std::vector<float> &positions, cons
auto nodeInserter = std::back_inserter(nodePositions_);
// First, determine all nodes elegible to be rendered.
for (auto i = 0u; i < limit; ++i) {
if (prevData[i] < DISPLAY_LIMIT) {
continue;
@@ -42,5 +48,19 @@ LabelVisualisation::LabelVisualisation(const std::vector<float> &positions, cons
nodeLabels.emplace_back(labels[i]);
}
// Now fix the points for the interaction paths.
nodeIndices.reserve(2 * nodeLabels.size());
for (auto i = 0u; i < nodeLabels.size(); ++i) {
nodeIndices.push_back(i);
nodeIndices.push_back(i + nodeLabels.size());
}
// Make sure the end positions exist.
std::copy_n(nodePositions_.begin(), nodePositions_.size(), nodeInserter);
for (auto i = nodePositions_.size() / 2; i < nodePositions_.size(); i += 3) {
nodePositions_[i] = LAYER_X_OFFSET;
}
patchTransparancy();
}

View File

@@ -16,5 +16,6 @@ namespace fmri
std::vector<std::string> nodeLabels;
std::vector<float> nodePositions_;
std::vector<int> nodeIndices;
};
}

View File

@@ -136,3 +136,12 @@ void fmri::registerErrorCallbacks()
LOG(INFO) << "Compiled without freeglut, error handlers not available.";
#endif
}
void fmri::setGlColor(const Color &c)
{
if constexpr (alphaEnabled()) {
glColor4fv(c.data());
} else {
glColor3fv(c.data());
}
}

View File

@@ -52,7 +52,15 @@ namespace fmri {
drawImageTiles(int n, const float *vertexBuffer, const float *textureCoords, const Texture &texture, float alpha);
/**
* Attempmt to register
* Attempt to register error handlers in GLUT.
*
* Only works in Freeglut.
*/
void registerErrorCallbacks();
/**
* Set GL drawing color from internal color.
* @param c
*/
void setGlColor(const Color& c);
}