Implement showing interaction paths.

This commit is contained in:
2018-04-03 14:06:38 +02:00
parent c0032aa688
commit d76c067489
6 changed files with 37 additions and 6 deletions

View File

@@ -5,6 +5,8 @@
#include <caffe/util/math_functions.hpp>
#include "Range.hpp"
#include "ActivityAnimation.hpp"
#include "RenderingState.hpp"
#include "glutils.hpp"
using namespace std;
using namespace fmri;
@@ -29,11 +31,13 @@ ActivityAnimation::ActivityAnimation(
const std::vector<std::pair<DType, std::pair<std::size_t, std::size_t>>> &interactions,
const float *aPositions, const float *bPositions, ColoringFunction coloring)
:
bufferLength(3 * interactions.size())
bufferLength(3 * interactions.size()),
delta(bufferLength)
{
CHECK(coloring) << "Invalid coloring function passed.";
startingPos.reserve(bufferLength);
delta.reserve(bufferLength);
vector<float> endPos;
endPos.reserve(bufferLength);
colorBuf.reserve(interactions.size());
for (auto &entry : interactions) {
@@ -44,9 +48,16 @@ ActivityAnimation::ActivityAnimation(
for (auto i : Range(3)) {
startingPos.emplace_back(aPos[i]);
delta.emplace_back(bPos[i] - aPos[i] + (i % 3 ? 0 : LAYER_X_OFFSET));
endPos.emplace_back(bPos[i] + (i % 3 ? 0 : LAYER_X_OFFSET));
}
}
caffe::caffe_sub(endPos.size(), endPos.data(), startingPos.data(), delta.data());
startingPos.insert(startingPos.end(), endPos.begin(), endPos.end());
for (auto i : Range(interactions.size())) {
lineIndices.push_back(i);
lineIndices.push_back(i + interactions.size());
}
}
void ActivityAnimation::draw(float timeScale)
@@ -60,5 +71,11 @@ void ActivityAnimation::draw(float timeScale)
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.data());
glDrawArrays(GL_POINTS, 0, bufferLength / 3);
glDisableClientState(GL_COLOR_ARRAY);
if (RenderingState::instance().renderInteractionPaths()) {
glColor4f(1, 1, 1, 0.1);
glVertexPointer(3, GL_FLOAT, 0, startingPos.data());
glDrawElements(GL_LINES, lineIndices.size(), GL_UNSIGNED_INT, lineIndices.data());
checkGLErrors();
}
glDisableClientState(GL_VERTEX_ARRAY);
}