Implement some kind of animation.
The animation is still all wrong, but it is there at least.
This commit is contained in:
@@ -16,11 +16,11 @@ static inline float correct_timescale(float original)
|
|||||||
|
|
||||||
ActivityAnimation::ActivityAnimation(std::size_t count, const float *aPos, const float *bPos, const float xDist) :
|
ActivityAnimation::ActivityAnimation(std::size_t count, const float *aPos, const float *bPos, const float xDist) :
|
||||||
bufferLength(3 * count),
|
bufferLength(3 * count),
|
||||||
startingPos(new float[bufferLength]),
|
startingPos(bufferLength),
|
||||||
delta(new float[bufferLength]),
|
delta(bufferLength),
|
||||||
offset(new float[count])
|
offset(bufferLength)
|
||||||
{
|
{
|
||||||
memcpy(startingPos.get(), aPos, sizeof(aPos[0]) * bufferLength);
|
memcpy(startingPos.data(), aPos, sizeof(aPos[0]) * bufferLength);
|
||||||
for (auto i : Range(bufferLength)) {
|
for (auto i : Range(bufferLength)) {
|
||||||
delta[i] = bPos[i] - aPos[i];
|
delta[i] = bPos[i] - aPos[i];
|
||||||
}
|
}
|
||||||
@@ -38,12 +38,12 @@ void ActivityAnimation::draw(float timeScale) const
|
|||||||
std::unique_ptr<float[]> vertexBuffer(new float[bufferLength]);
|
std::unique_ptr<float[]> vertexBuffer(new float[bufferLength]);
|
||||||
|
|
||||||
for (auto i : Range(bufferLength)) {
|
for (auto i : Range(bufferLength)) {
|
||||||
vertexBuffer[i] = startingPos[i] + correct_timescale(offset[i/3] + timeScale) * delta[i];
|
vertexBuffer[i] = startingPos[i] + timeScale * delta[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
glColor3f(1, 1, 1);
|
glColor3f(1, 1, 1);
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.get());
|
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.get());
|
||||||
glDrawArrays(GL_POINTS, bufferLength / 3, bufferLength);
|
glDrawArrays(GL_POINTS, 0, bufferLength / 3);
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace fmri
|
namespace fmri
|
||||||
{
|
{
|
||||||
@@ -13,8 +14,8 @@ namespace fmri
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t bufferLength;
|
std::size_t bufferLength;
|
||||||
std::unique_ptr<float[]> startingPos;
|
std::vector<float> startingPos;
|
||||||
std::unique_ptr<float[]> delta;
|
std::vector<float> delta;
|
||||||
std::unique_ptr<float[]> offset;
|
std::vector<float> offset;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -82,6 +82,9 @@ static void render()
|
|||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
renderLayerName(dataSet[i]);
|
renderLayerName(dataSet[i]);
|
||||||
rendererData.layerVisualisations[i]->render();
|
rendererData.layerVisualisations[i]->render();
|
||||||
|
if (i < rendererData.animations.size() && rendererData.animations[i]) {
|
||||||
|
rendererData.animations[i]->draw(rendererData.animationStep);
|
||||||
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glTranslatef(-10, 0, 0);
|
glTranslatef(-10, 0, 0);
|
||||||
|
|||||||
@@ -39,8 +39,10 @@ computeActivityStrengths(const LayerData &prevState, const LayerInfo &layer)
|
|||||||
|
|
||||||
const auto shape = layer.parameters()[0]->shape();
|
const auto shape = layer.parameters()[0]->shape();
|
||||||
auto weights = layer.parameters()[0]->cpu_data();
|
auto weights = layer.parameters()[0]->cpu_data();
|
||||||
|
const auto numEntries = accumulate(shape.begin(), shape.end(), 1u, multiplies<void>());
|
||||||
|
result.reserve(numEntries);
|
||||||
|
|
||||||
for (auto i : Range(accumulate(shape.begin(), shape.end(), 1, multiplies<void>()))) {
|
for (auto i : Range(numEntries)) {
|
||||||
result.emplace_back(weights[i] * data[i % shape[0]], make_pair(i % shape[0], i / shape[0]));
|
result.emplace_back(weights[i] * data[i % shape[0]], make_pair(i % shape[0], i / shape[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +82,5 @@ fmri::ActivityAnimation *fmri::getActivityAnimation(const fmri::LayerData &prevS
|
|||||||
memcpy(endingPositions.get() + 3 * i, curPositions.data() + 3 * entries[i].second.second, 3 * sizeof(float));
|
memcpy(endingPositions.get() + 3 * i, curPositions.data() + 3 * entries[i].second.second, 3 * sizeof(float));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: actually do something
|
|
||||||
return new ActivityAnimation(entries.size(), startingPositions.get(), endingPositions.get(), 2.0);
|
return new ActivityAnimation(entries.size(), startingPositions.get(), endingPositions.get(), 2.0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user