From c434c2b62c911c082a52e0ef757dd573e3bb60c8 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 30 Apr 2018 13:40:12 +0200 Subject: [PATCH] Implement interaciton paths for labels. --- src/fmri/ActivityAnimation.cpp | 2 +- src/fmri/LabelVisualisation.cpp | 30 +++++++++++++++++++++++++----- src/fmri/LabelVisualisation.hpp | 1 + src/fmri/glutils.cpp | 9 +++++++++ src/fmri/glutils.hpp | 10 +++++++++- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/fmri/ActivityAnimation.cpp b/src/fmri/ActivityAnimation.cpp index 8b58b0f..4d60d13 100644 --- a/src/fmri/ActivityAnimation.cpp +++ b/src/fmri/ActivityAnimation.cpp @@ -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()); } diff --git a/src/fmri/LabelVisualisation.cpp b/src/fmri/LabelVisualisation.cpp index d73ba37..831402c 100644 --- a/src/fmri/LabelVisualisation.cpp +++ b/src/fmri/LabelVisualisation.cpp @@ -1,22 +1,27 @@ #include #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 &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 &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(); } diff --git a/src/fmri/LabelVisualisation.hpp b/src/fmri/LabelVisualisation.hpp index a429322..dd84afc 100644 --- a/src/fmri/LabelVisualisation.hpp +++ b/src/fmri/LabelVisualisation.hpp @@ -16,5 +16,6 @@ namespace fmri std::vector nodeLabels; std::vector nodePositions_; + std::vector nodeIndices; }; } diff --git a/src/fmri/glutils.cpp b/src/fmri/glutils.cpp index 9d30cd4..585e169 100644 --- a/src/fmri/glutils.cpp +++ b/src/fmri/glutils.cpp @@ -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()); + } +} diff --git a/src/fmri/glutils.hpp b/src/fmri/glutils.hpp index 8286d2e..63bb723 100644 --- a/src/fmri/glutils.hpp +++ b/src/fmri/glutils.hpp @@ -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); }