Unify interpolation function.
This commit is contained in:
@@ -51,17 +51,13 @@ ActivityAnimation::ActivityAnimation(
|
||||
|
||||
void ActivityAnimation::draw(float timeScale)
|
||||
{
|
||||
std::unique_ptr<float[]> vertexBuffer(new float[bufferLength]);
|
||||
caffe::caffe_copy(bufferLength, delta.data(), vertexBuffer.get());
|
||||
caffe::caffe_scal(bufferLength, timeScale, vertexBuffer.get());
|
||||
caffe::caffe_add(bufferLength, startingPos.data(), vertexBuffer.get(), vertexBuffer.get());
|
||||
|
||||
const auto vertexBuffer = animate(startingPos, delta, timeScale);
|
||||
glPointSize(5);
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glColorPointer(3, GL_FLOAT, 0, colorBuf.data());
|
||||
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.get());
|
||||
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.data());
|
||||
glDrawArrays(GL_POINTS, 0, bufferLength / 3);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
@@ -8,9 +8,7 @@ using namespace fmri;
|
||||
|
||||
void ImageInteractionAnimation::draw(float step)
|
||||
{
|
||||
auto vertexBuffer = deltas;
|
||||
caffe::caffe_scal(deltas.size(), step, vertexBuffer.data());
|
||||
caffe::caffe_add(vertexBuffer.size(), vertexBuffer.data(), startingPositions.data(), vertexBuffer.data());
|
||||
auto vertexBuffer = animate(startingPositions, deltas, step);
|
||||
|
||||
drawImageTiles(vertexBuffer.size() / 3, vertexBuffer.data(), textureCoordinates.data(), texture);
|
||||
}
|
||||
|
||||
@@ -30,9 +30,7 @@ PoolingLayerAnimation::PoolingLayerAnimation(const LayerData &prevData, const La
|
||||
|
||||
void PoolingLayerAnimation::draw(float timeStep)
|
||||
{
|
||||
vector<float> vertexBuffer(deltas);
|
||||
caffe::caffe_scal(vertexBuffer.size(), timeStep, vertexBuffer.data());
|
||||
caffe::caffe_add(startingPositions.size(), startingPositions.data(), vertexBuffer.data(), vertexBuffer.data());
|
||||
auto vertexBuffer = animate(startingPositions, deltas, timeStep);
|
||||
|
||||
drawImageTiles(vertexBuffer.size() / 3, vertexBuffer.data(), textureCoordinates.data(), original);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <caffe/util/math_functions.hpp>
|
||||
#include "utils.hpp"
|
||||
|
||||
const float fmri::LAYER_X_OFFSET = -10;
|
||||
@@ -14,3 +15,12 @@ std::default_random_engine &fmri::rng()
|
||||
|
||||
return rng;
|
||||
}
|
||||
|
||||
std::vector<float> fmri::animate(const std::vector<float> &start, const std::vector<float> &delta, float time)
|
||||
{
|
||||
auto vertexBuffer = delta;
|
||||
caffe::caffe_scal(vertexBuffer.size(), time, vertexBuffer.data());
|
||||
caffe::caffe_add(start.size(), vertexBuffer.data(), start.data(), vertexBuffer.data());
|
||||
|
||||
return vertexBuffer;
|
||||
}
|
||||
|
||||
@@ -229,4 +229,14 @@ namespace fmri
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Animate a list of floats.
|
||||
*
|
||||
* @param start Starting values for all floats
|
||||
* @param delta Value to be added at the end of the animation
|
||||
* @param time 0..1 where in the animation are we?
|
||||
* @return Resulting list of floats.
|
||||
*/
|
||||
std::vector<float> animate(const std::vector<float>& start, const std::vector<float>& delta, float time);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user