Unify drawing of layers and interactions into "drawables".
This commit is contained in:
@@ -38,14 +38,16 @@ ActivityAnimation::ActivityAnimation(
|
|||||||
startingPos.reserve(bufferLength);
|
startingPos.reserve(bufferLength);
|
||||||
vector<float> endPos;
|
vector<float> endPos;
|
||||||
endPos.reserve(bufferLength);
|
endPos.reserve(bufferLength);
|
||||||
colorBuf.reserve(interactions.size());
|
transform(interactions.begin(), interactions.end(), back_inserter(colorBuffer), [&coloring](auto e) {
|
||||||
|
return coloring(e.first);
|
||||||
|
});
|
||||||
|
colorBuffer.reserve(interactions.size());
|
||||||
|
|
||||||
|
|
||||||
for (auto &entry : interactions) {
|
for (auto &entry : interactions) {
|
||||||
auto *aPos = &aPositions[3 * entry.second.first];
|
auto *aPos = &aPositions[3 * entry.second.first];
|
||||||
auto *bPos = &bPositions[3 * entry.second.second];
|
auto *bPos = &bPositions[3 * entry.second.second];
|
||||||
|
|
||||||
colorBuf.push_back(coloring(entry.first));
|
|
||||||
|
|
||||||
for (auto i : Range(3)) {
|
for (auto i : Range(3)) {
|
||||||
startingPos.emplace_back(aPos[i]);
|
startingPos.emplace_back(aPos[i]);
|
||||||
endPos.emplace_back(bPos[i] + (i % 3 ? 0 : LAYER_X_OFFSET));
|
endPos.emplace_back(bPos[i] + (i % 3 ? 0 : LAYER_X_OFFSET));
|
||||||
@@ -59,7 +61,7 @@ ActivityAnimation::ActivityAnimation(
|
|||||||
lineIndices.push_back(i + interactions.size());
|
lineIndices.push_back(i + interactions.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
patchTransparancy(colorBuf.begin(), colorBuf.end());
|
patchTransparancy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActivityAnimation::draw(float timeScale)
|
void ActivityAnimation::draw(float timeScale)
|
||||||
@@ -68,7 +70,7 @@ void ActivityAnimation::draw(float timeScale)
|
|||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
glColorPointer(std::tuple_size<Color>::value, GL_FLOAT, 0, colorBuf.data());
|
glColorPointer(std::tuple_size<Color>::value, GL_FLOAT, 0, colorBuffer.data());
|
||||||
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);
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ namespace fmri
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t bufferLength;
|
std::size_t bufferLength;
|
||||||
std::vector<Color> colorBuf;
|
|
||||||
std::vector<float> startingPos;
|
std::vector<float> startingPos;
|
||||||
std::vector<float> delta;
|
std::vector<float> delta;
|
||||||
std::vector<int> lineIndices;
|
std::vector<int> lineIndices;
|
||||||
|
|||||||
@@ -2,31 +2,16 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
#include "Drawable.hpp"
|
||||||
|
|
||||||
namespace fmri
|
namespace fmri
|
||||||
{
|
{
|
||||||
class Animation
|
class Animation : public Drawable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Animation() = default;
|
virtual ~Animation() = default;
|
||||||
|
|
||||||
virtual void draw(float step) = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
static float getAlpha();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<typename It>
|
float getAlpha() override;
|
||||||
void patchTransparancy(It begin, It end)
|
|
||||||
{
|
|
||||||
if constexpr (std::tuple_size<Color>::value >= 4) {
|
|
||||||
const auto alpha = getAlpha();
|
|
||||||
for (; begin != end; ++begin) {
|
|
||||||
Color &color = *begin;
|
|
||||||
color[3] = alpha;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/fmri/Drawable.cpp
Normal file
16
src/fmri/Drawable.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "Drawable.hpp"
|
||||||
|
|
||||||
|
void fmri::Drawable::patchTransparancy()
|
||||||
|
{
|
||||||
|
if constexpr (std::tuple_size<Color>::value < 4) {
|
||||||
|
// Not compiling with alpha support
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto alpha = getAlpha();
|
||||||
|
const auto end = colorBuffer.end();
|
||||||
|
|
||||||
|
for (auto it = colorBuffer.begin(); it != end; ++it) {
|
||||||
|
(*it)[3] = alpha;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/fmri/Drawable.hpp
Normal file
22
src/fmri/Drawable.hpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "utils.hpp"
|
||||||
|
|
||||||
|
namespace fmri
|
||||||
|
{
|
||||||
|
|
||||||
|
class Drawable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~Drawable() = default;
|
||||||
|
|
||||||
|
virtual void draw(float time) = 0;
|
||||||
|
virtual void patchTransparancy();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::vector<Color> colorBuffer;
|
||||||
|
|
||||||
|
virtual float getAlpha() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ namespace fmri
|
|||||||
class DummyLayerVisualisation : public LayerVisualisation
|
class DummyLayerVisualisation : public LayerVisualisation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void render() override
|
void draw(float time) override
|
||||||
{};
|
{};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering
|
|||||||
LayerVisualisation(layer.numEntries()),
|
LayerVisualisation(layer.numEntries()),
|
||||||
ordering(ordering),
|
ordering(ordering),
|
||||||
vertexBuffer(layer.numEntries() * NODE_FACES.size()),
|
vertexBuffer(layer.numEntries() * NODE_FACES.size()),
|
||||||
colorBuffer(layer.numEntries() * VERTICES_PER_NODE),
|
|
||||||
indexBuffer(layer.numEntries() * NODE_FACES.size())
|
indexBuffer(layer.numEntries() * NODE_FACES.size())
|
||||||
{
|
{
|
||||||
auto &shape = layer.shape();
|
auto &shape = layer.shape();
|
||||||
@@ -45,7 +44,7 @@ FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering
|
|||||||
|
|
||||||
auto scalingMax = std::max(abs(*minElem), abs(*maxElem));
|
auto scalingMax = std::max(abs(*minElem), abs(*maxElem));
|
||||||
|
|
||||||
auto colorPos = colorBuffer.begin();
|
auto colorPos = std::back_inserter(colorBuffer);
|
||||||
auto indexPos = indexBuffer.begin();
|
auto indexPos = indexBuffer.begin();
|
||||||
|
|
||||||
for (int i : Range(limit)) {
|
for (int i : Range(limit)) {
|
||||||
@@ -67,12 +66,10 @@ FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert(indexPos == indexBuffer.end());
|
assert(indexPos == indexBuffer.end());
|
||||||
assert(colorPos == colorBuffer.end());
|
patchTransparancy();
|
||||||
|
|
||||||
patchTransparancy(colorBuffer.begin(), colorBuffer.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatLayerVisualisation::render()
|
void FlatLayerVisualisation::draw(float time)
|
||||||
{
|
{
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
glEnableClientState(GL_COLOR_ARRAY);
|
||||||
@@ -85,7 +82,7 @@ void FlatLayerVisualisation::render()
|
|||||||
glDisableClientState(GL_COLOR_ARRAY);
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
// Now draw wireframe
|
// Now draw wireframe
|
||||||
glColor4f(0, 0, 0, 1);
|
glColor4f(0, 0, 0, getAlpha());
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, indices.data());
|
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, indices.data());
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
|||||||
@@ -12,12 +12,11 @@ namespace fmri
|
|||||||
public:
|
public:
|
||||||
explicit FlatLayerVisualisation(const LayerData &layer, Ordering ordering);
|
explicit FlatLayerVisualisation(const LayerData &layer, Ordering ordering);
|
||||||
|
|
||||||
void render() override;
|
void draw(float time) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ordering ordering;
|
Ordering ordering;
|
||||||
std::vector<float> vertexBuffer;
|
std::vector<float> vertexBuffer;
|
||||||
std::vector<Color> colorBuffer;
|
|
||||||
std::vector<int> indexBuffer;
|
std::vector<int> indexBuffer;
|
||||||
std::vector<int> activeIndexBuffer;
|
std::vector<int> activeIndexBuffer;
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ InputLayerVisualisation::InputLayerVisualisation(const LayerData &data)
|
|||||||
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_FLOAT, imageData.data());
|
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_FLOAT, imageData.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputLayerVisualisation::render()
|
void InputLayerVisualisation::draw(float time)
|
||||||
{
|
{
|
||||||
const float vertices[] = {
|
const float vertices[] = {
|
||||||
0, 0, 0,
|
0, 0, 0,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace fmri
|
|||||||
public:
|
public:
|
||||||
explicit InputLayerVisualisation(const LayerData &data);
|
explicit InputLayerVisualisation(const LayerData &data);
|
||||||
|
|
||||||
void render() override;
|
void draw(float time) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Texture texture;
|
Texture texture;
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
#include "Drawable.hpp"
|
||||||
|
|
||||||
namespace fmri
|
namespace fmri
|
||||||
{
|
{
|
||||||
class LayerVisualisation
|
class LayerVisualisation
|
||||||
|
: public Drawable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Ordering {
|
enum class Ordering {
|
||||||
@@ -17,28 +19,15 @@ namespace fmri
|
|||||||
explicit LayerVisualisation(size_t numNodes);
|
explicit LayerVisualisation(size_t numNodes);
|
||||||
virtual ~LayerVisualisation() = default;
|
virtual ~LayerVisualisation() = default;
|
||||||
|
|
||||||
virtual void render() = 0;
|
|
||||||
virtual const std::vector<float>& nodePositions() const;
|
virtual const std::vector<float>& nodePositions() const;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
static float getAlpha();
|
float getAlpha() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::vector<float> nodePositions_;
|
std::vector<float> nodePositions_;
|
||||||
|
|
||||||
template<Ordering Order>
|
template<Ordering Order>
|
||||||
void initNodePositions(size_t n, float spacing);
|
void initNodePositions(size_t n, float spacing);
|
||||||
|
|
||||||
template<typename It>
|
|
||||||
void patchTransparancy(It begin, It end)
|
|
||||||
{
|
|
||||||
if constexpr (std::tuple_size<Color>::value >= 4) {
|
|
||||||
const auto alpha = getAlpha();
|
|
||||||
for (; begin != end; ++begin) {
|
|
||||||
Color &color = *begin;
|
|
||||||
color[3] = alpha;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ MultiImageVisualisation::MultiImageVisualisation(const fmri::LayerData &layer)
|
|||||||
texCoordBuffer = getTexCoords(channels);
|
texCoordBuffer = getTexCoords(channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiImageVisualisation::render()
|
void MultiImageVisualisation::draw(float time)
|
||||||
{
|
{
|
||||||
float alpha = RenderingState::instance().layerAlpha();
|
float alpha = RenderingState::instance().layerAlpha();
|
||||||
drawImageTiles(vertexBuffer.size() / 3, vertexBuffer.data(), texCoordBuffer.data(), texture, alpha);
|
drawImageTiles(vertexBuffer.size() / 3, vertexBuffer.data(), texCoordBuffer.data(), texture, alpha);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace fmri
|
|||||||
|
|
||||||
explicit MultiImageVisualisation(const LayerData&);
|
explicit MultiImageVisualisation(const LayerData&);
|
||||||
|
|
||||||
void render() override;
|
void draw(float time) override;
|
||||||
|
|
||||||
static vector<float> getVertices(const std::vector<float> &nodePositions, float scaling = 1);
|
static vector<float> getVertices(const std::vector<float> &nodePositions, float scaling = 1);
|
||||||
static std::vector<float> getTexCoords(int n);
|
static std::vector<float> getTexCoords(int n);
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ void RenderingState::render(float time) const
|
|||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
renderLayerName(currentData->at(i).name());
|
renderLayerName(currentData->at(i).name());
|
||||||
if (options.renderLayers) {
|
if (options.renderLayers) {
|
||||||
layerVisualisations[i]->render();
|
layerVisualisations[i]->draw(time);
|
||||||
}
|
}
|
||||||
if (options.renderInteractions && i < interactionAnimations.size() && interactionAnimations[i]) {
|
if (options.renderInteractions && i < interactionAnimations.size() && interactionAnimations[i]) {
|
||||||
interactionAnimations[i]->draw(time);
|
interactionAnimations[i]->draw(time);
|
||||||
|
|||||||
Reference in New Issue
Block a user