Implement showing interaction paths.
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
#include <caffe/util/math_functions.hpp>
|
#include <caffe/util/math_functions.hpp>
|
||||||
#include "Range.hpp"
|
#include "Range.hpp"
|
||||||
#include "ActivityAnimation.hpp"
|
#include "ActivityAnimation.hpp"
|
||||||
|
#include "RenderingState.hpp"
|
||||||
|
#include "glutils.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace fmri;
|
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 std::vector<std::pair<DType, std::pair<std::size_t, std::size_t>>> &interactions,
|
||||||
const float *aPositions, const float *bPositions, ColoringFunction coloring)
|
const float *aPositions, const float *bPositions, ColoringFunction coloring)
|
||||||
:
|
:
|
||||||
bufferLength(3 * interactions.size())
|
bufferLength(3 * interactions.size()),
|
||||||
|
delta(bufferLength)
|
||||||
{
|
{
|
||||||
CHECK(coloring) << "Invalid coloring function passed.";
|
CHECK(coloring) << "Invalid coloring function passed.";
|
||||||
startingPos.reserve(bufferLength);
|
startingPos.reserve(bufferLength);
|
||||||
delta.reserve(bufferLength);
|
vector<float> endPos;
|
||||||
|
endPos.reserve(bufferLength);
|
||||||
colorBuf.reserve(interactions.size());
|
colorBuf.reserve(interactions.size());
|
||||||
|
|
||||||
for (auto &entry : interactions) {
|
for (auto &entry : interactions) {
|
||||||
@@ -44,9 +48,16 @@ ActivityAnimation::ActivityAnimation(
|
|||||||
|
|
||||||
for (auto i : Range(3)) {
|
for (auto i : Range(3)) {
|
||||||
startingPos.emplace_back(aPos[i]);
|
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)
|
void ActivityAnimation::draw(float timeScale)
|
||||||
@@ -60,5 +71,11 @@ void ActivityAnimation::draw(float timeScale)
|
|||||||
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.data());
|
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.data());
|
||||||
glDrawArrays(GL_POINTS, 0, bufferLength / 3);
|
glDrawArrays(GL_POINTS, 0, bufferLength / 3);
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
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);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Animation.hpp"
|
#include "Animation.hpp"
|
||||||
@@ -30,5 +31,6 @@ namespace fmri
|
|||||||
std::vector<std::array<float, 3>> colorBuf;
|
std::vector<std::array<float, 3>> colorBuf;
|
||||||
std::vector<float> startingPos;
|
std::vector<float> startingPos;
|
||||||
std::vector<float> delta;
|
std::vector<float> delta;
|
||||||
|
std::vector<int> lineIndices;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ void RenderingState::handleKey(unsigned char x)
|
|||||||
reset();
|
reset();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
toggle(options.renderInteractionPaths);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
toggle(options.activatedOnly);
|
toggle(options.activatedOnly);
|
||||||
break;
|
break;
|
||||||
@@ -254,6 +258,7 @@ void RenderingState::renderOverlayText() const
|
|||||||
"l: toggle layers visible\n"
|
"l: toggle layers visible\n"
|
||||||
"i: toggle interactions visible\n"
|
"i: toggle interactions visible\n"
|
||||||
"o: toggle activated nodes only\n"
|
"o: toggle activated nodes only\n"
|
||||||
|
"p: toggle interaction paths visible\n"
|
||||||
"q: quit\n";
|
"q: quit\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,3 +317,8 @@ bool RenderingState::renderActivatedOnly() const
|
|||||||
{
|
{
|
||||||
return options.activatedOnly;
|
return options.activatedOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RenderingState::renderInteractionPaths() const
|
||||||
|
{
|
||||||
|
return options.renderInteractionPaths;
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ namespace fmri
|
|||||||
* @return Whether the network should only render activated nodes, rather than all of them.
|
* @return Whether the network should only render activated nodes, rather than all of them.
|
||||||
*/
|
*/
|
||||||
bool renderActivatedOnly() const;
|
bool renderActivatedOnly() const;
|
||||||
|
bool renderInteractionPaths() const;
|
||||||
|
|
||||||
static RenderingState& instance();
|
static RenderingState& instance();
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ namespace fmri
|
|||||||
bool renderLayers = true;
|
bool renderLayers = true;
|
||||||
bool renderInteractions = true;
|
bool renderInteractions = true;
|
||||||
bool activatedOnly = false;
|
bool activatedOnly = false;
|
||||||
|
bool renderInteractionPaths = false;
|
||||||
} options;
|
} options;
|
||||||
std::array<float, 3> pos;
|
std::array<float, 3> pos;
|
||||||
std::array<float, 2> angle;
|
std::array<float, 2> angle;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
|
|||||||
google::InstallFailureSignalHandler();
|
google::InstallFailureSignalHandler();
|
||||||
|
|
||||||
glutInit(&argc, argv);
|
glutInit(&argc, argv);
|
||||||
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
|
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
|
||||||
glutCreateWindow(argv[0]);
|
glutCreateWindow(argv[0]);
|
||||||
|
|
||||||
// Prepare data for simulations
|
// Prepare data for simulations
|
||||||
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
|
|||||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||||
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
|
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_DST_ALPHA,GL_ONE_MINUS_DST_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// Start visualisation
|
// Start visualisation
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const std::vector<float> & fmri::animate(const std::vector<float> &start, const
|
|||||||
static std::vector<float> vertexBuffer;
|
static std::vector<float> vertexBuffer;
|
||||||
vertexBuffer = delta;
|
vertexBuffer = delta;
|
||||||
caffe::caffe_scal(vertexBuffer.size(), time, vertexBuffer.data());
|
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;
|
return vertexBuffer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user