Implement visualisation of the labels, if available.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
void fmri::Drawable::patchTransparancy()
|
void fmri::Drawable::patchTransparancy()
|
||||||
{
|
{
|
||||||
if constexpr (std::tuple_size<Color>::value < 4) {
|
if constexpr (!alphaEnabled()) {
|
||||||
// Not compiling with alpha support
|
// Not compiling with alpha support
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ static inline void computeColor(float intensity, float limit, Color& destination
|
|||||||
destination[1] = saturation;
|
destination[1] = saturation;
|
||||||
destination[2] = saturation;
|
destination[2] = saturation;
|
||||||
}
|
}
|
||||||
if constexpr (std::tuple_size<Color>::value >= 4) {
|
if constexpr (alphaEnabled()) {
|
||||||
// We have an alpha channel, set it to 1.
|
// We have an alpha channel, set it to 1.
|
||||||
destination[3] = 1;
|
destination[3] = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
46
src/fmri/LabelVisualisation.cpp
Normal file
46
src/fmri/LabelVisualisation.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include <GL/gl.h>
|
||||||
|
#include "LabelVisualisation.hpp"
|
||||||
|
#include "glutils.hpp"
|
||||||
|
|
||||||
|
using namespace fmri;
|
||||||
|
|
||||||
|
void LabelVisualisation::draw(float)
|
||||||
|
{
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(LAYER_X_OFFSET, 0, 0);
|
||||||
|
|
||||||
|
for (auto i = 0u; i < nodeLabels.size(); ++i) {
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(nodePositions_[3 * i], nodePositions_[3 * i + 1], nodePositions_[3 * i + 2]);
|
||||||
|
if constexpr (alphaEnabled()) {
|
||||||
|
glColor4fv(colorBuffer[i].data());
|
||||||
|
} else {
|
||||||
|
glColor3fv(colorBuffer[i].data());
|
||||||
|
}
|
||||||
|
renderText(nodeLabels[i]);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
LabelVisualisation::LabelVisualisation(const std::vector<float> &positions, const LayerData &prevData,
|
||||||
|
const std::vector<std::string> &labels)
|
||||||
|
{
|
||||||
|
const auto limit = std::min(prevData.numEntries(), labels.size());
|
||||||
|
const auto maxVal = *std::max_element(prevData.data(), prevData.data() + prevData.numEntries());
|
||||||
|
|
||||||
|
auto nodeInserter = std::back_inserter(nodePositions_);
|
||||||
|
|
||||||
|
for (auto i = 0u; i < limit; ++i) {
|
||||||
|
if (prevData[i] < DISPLAY_LIMIT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
colorBuffer.emplace_back(Color{1 - prevData[i] / maxVal, 1 - prevData[i] / maxVal, 1});
|
||||||
|
std::copy_n(positions.begin() + 3 * i, 3, nodeInserter);
|
||||||
|
nodeLabels.emplace_back(labels[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
patchTransparancy();
|
||||||
|
}
|
||||||
20
src/fmri/LabelVisualisation.hpp
Normal file
20
src/fmri/LabelVisualisation.hpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "LayerData.hpp"
|
||||||
|
#include "Animation.hpp"
|
||||||
|
|
||||||
|
namespace fmri
|
||||||
|
{
|
||||||
|
class LabelVisualisation : public Animation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LabelVisualisation(const std::vector<float>& positions, const LayerData& prevData, const std::vector<std::string>& labels);
|
||||||
|
void draw(float time) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr float DISPLAY_LIMIT = 0.01;
|
||||||
|
|
||||||
|
std::vector<std::string> nodeLabels;
|
||||||
|
std::vector<float> nodePositions_;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -42,6 +42,11 @@ DType const * LayerData::data() const
|
|||||||
return data_.get();
|
return data_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DType &LayerData::operator[](std::size_t i) const
|
||||||
|
{
|
||||||
|
return data_[i];
|
||||||
|
}
|
||||||
|
|
||||||
ostream& operator<< (ostream& o, const LayerData& layer)
|
ostream& operator<< (ostream& o, const LayerData& layer)
|
||||||
{
|
{
|
||||||
o << layer.name() << '(';
|
o << layer.name() << '(';
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ namespace fmri
|
|||||||
const string &name() const;
|
const string &name() const;
|
||||||
const vector<int> &shape() const;
|
const vector<int> &shape() const;
|
||||||
DType const *data() const;
|
DType const *data() const;
|
||||||
size_t numEntries() const;
|
std::size_t numEntries() const;
|
||||||
|
|
||||||
|
const DType& operator[] (std::size_t i) const;
|
||||||
private:
|
private:
|
||||||
string name_;
|
string name_;
|
||||||
vector<int> shape_;
|
vector<int> shape_;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "Range.hpp"
|
#include "Range.hpp"
|
||||||
#include "glutils.hpp"
|
#include "glutils.hpp"
|
||||||
#include "Simulator.hpp"
|
#include "Simulator.hpp"
|
||||||
|
#include "LabelVisualisation.hpp"
|
||||||
|
|
||||||
using namespace fmri;
|
using namespace fmri;
|
||||||
|
|
||||||
@@ -68,6 +69,8 @@ static VisualisationList loadVisualisations(const Options& options)
|
|||||||
|
|
||||||
auto [layerInfo, layerData] = Simulator::loadSimulationData(options);
|
auto [layerInfo, layerData] = Simulator::loadSimulationData(options);
|
||||||
|
|
||||||
|
auto labels = options.labels();
|
||||||
|
|
||||||
VisualisationList result;
|
VisualisationList result;
|
||||||
|
|
||||||
for (auto &&item : layerData) {
|
for (auto &&item : layerData) {
|
||||||
@@ -89,6 +92,10 @@ static VisualisationList loadVisualisations(const Options& options)
|
|||||||
|
|
||||||
VisualisationList::value_type dataSet;
|
VisualisationList::value_type dataSet;
|
||||||
|
|
||||||
|
if (labels) {
|
||||||
|
animations.emplace_back(new LabelVisualisation(layers.rbegin()->get()->nodePositions(), *prevData, labels.value()));
|
||||||
|
}
|
||||||
|
|
||||||
for (auto i = 0u; i < layers.size(); ++i) {
|
for (auto i = 0u; i < layers.size(); ++i) {
|
||||||
auto interaction = i < animations.size() ? move(animations[i]) : nullptr;
|
auto interaction = i < animations.size() ? move(animations[i]) : nullptr;
|
||||||
dataSet.emplace_back(move(layers[i]), move(interaction));
|
dataSet.emplace_back(move(layers[i]), move(interaction));
|
||||||
|
|||||||
@@ -246,4 +246,11 @@ namespace fmri
|
|||||||
* @return Resulting list of floats.
|
* @return Resulting list of floats.
|
||||||
*/
|
*/
|
||||||
const std::vector<float> & animate(const std::vector<float> &start, const std::vector<float> &delta, float time);
|
const std::vector<float> & animate(const std::vector<float> &start, const std::vector<float> &delta, float time);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Whether alpha support is enabled, compile time.
|
||||||
|
*/
|
||||||
|
constexpr bool alphaEnabled() {
|
||||||
|
return std::tuple_size<Color>::value >= 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user