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);
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include <cstddef>
#include <functional>
#include <memory>
#include <vector>
#include "Animation.hpp"
@@ -30,5 +31,6 @@ namespace fmri
std::vector<std::array<float, 3>> colorBuf;
std::vector<float> startingPos;
std::vector<float> delta;
std::vector<int> lineIndices;
};
}

View File

@@ -94,6 +94,10 @@ void RenderingState::handleKey(unsigned char x)
reset();
break;
case 'p':
toggle(options.renderInteractionPaths);
break;
case 'o':
toggle(options.activatedOnly);
break;
@@ -254,6 +258,7 @@ void RenderingState::renderOverlayText() const
"l: toggle layers visible\n"
"i: toggle interactions visible\n"
"o: toggle activated nodes only\n"
"p: toggle interaction paths visible\n"
"q: quit\n";
}
@@ -312,3 +317,8 @@ bool RenderingState::renderActivatedOnly() const
{
return options.activatedOnly;
}
bool RenderingState::renderInteractionPaths() const
{
return options.renderInteractionPaths;
}

View File

@@ -43,6 +43,7 @@ namespace fmri
* @return Whether the network should only render activated nodes, rather than all of them.
*/
bool renderActivatedOnly() const;
bool renderInteractionPaths() const;
static RenderingState& instance();
@@ -53,6 +54,7 @@ namespace fmri
bool renderLayers = true;
bool renderInteractions = true;
bool activatedOnly = false;
bool renderInteractionPaths = false;
} options;
std::array<float, 3> pos;
std::array<float, 2> angle;

View File

@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
google::InstallFailureSignalHandler();
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
glutCreateWindow(argv[0]);
// Prepare data for simulations
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_DST_ALPHA,GL_ONE_MINUS_DST_ALPHA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Start visualisation
glutMainLoop();

View File

@@ -21,7 +21,7 @@ const std::vector<float> & fmri::animate(const std::vector<float> &start, const
static std::vector<float> vertexBuffer;
vertexBuffer = delta;
caffe::caffe_scal(vertexBuffer.size(), time, vertexBuffer.data());
caffe::caffe_add(start.size(), vertexBuffer.data(), start.data(), vertexBuffer.data());
caffe::caffe_add(vertexBuffer.size(), vertexBuffer.data(), start.data(), vertexBuffer.data());
return vertexBuffer;
}