Support layer and interaction transparancy. Refs #1

This commit is contained in:
2018-04-05 16:08:58 +02:00
parent 21fdc45e65
commit 3e4452ca3a
12 changed files with 114 additions and 12 deletions

View File

@@ -58,6 +58,8 @@ ActivityAnimation::ActivityAnimation(
lineIndices.push_back(i);
lineIndices.push_back(i + interactions.size());
}
patchTransparancy(colorBuf.begin(), colorBuf.end());
}
void ActivityAnimation::draw(float timeScale)

View File

@@ -1,5 +1,7 @@
//
// Created by bert on 13/02/18.
//
#include "Animation.hpp"
#include "RenderingState.hpp"
float fmri::Animation::getAlpha()
{
return fmri::RenderingState::instance().interactionAlpha();
}

View File

@@ -1,6 +1,8 @@
#pragma once
#include "utils.hpp"
namespace fmri
{
class Animation
@@ -10,5 +12,21 @@ namespace fmri
virtual void draw(float step) = 0;
private:
static float getAlpha();
protected:
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;
}
}
}
};
}

View File

@@ -68,6 +68,8 @@ FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering
assert(indexPos == indexBuffer.end());
assert(colorPos == colorBuffer.end());
patchTransparancy(colorBuffer.begin(), colorBuffer.end());
}
void FlatLayerVisualisation::render()

View File

@@ -1,6 +1,7 @@
#include "LayerVisualisation.hpp"
#include "Range.hpp"
#include "utils.hpp"
#include "RenderingState.hpp"
const std::vector<float> &fmri::LayerVisualisation::nodePositions() const
{
@@ -25,6 +26,11 @@ void fmri::LayerVisualisation::initNodePositions<fmri::LayerVisualisation::Order
}
}
float fmri::LayerVisualisation::getAlpha()
{
return RenderingState::instance().layerAlpha();
}
template<>
void fmri::LayerVisualisation::initNodePositions<fmri::LayerVisualisation::Ordering::SQUARE>(size_t n, float spacing)
{

View File

@@ -1,6 +1,7 @@
#pragma once
#include <vector>
#include "utils.hpp"
namespace fmri
{
@@ -19,10 +20,25 @@ namespace fmri
virtual void render() = 0;
virtual const std::vector<float>& nodePositions() const;
private:
static float getAlpha();
protected:
std::vector<float> nodePositions_;
template<Ordering Order>
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;
}
}
}
};
}

View File

@@ -70,6 +70,8 @@ Options Options::parse(const int argc, char *const argv[])
("labels,l", value<std::string>(&options.labelsPath), "labels file")
("means,m", value<std::string>(&options.meansPath), "means file")
("path-color,p", value<std::string>(), "color for paths")
("layer-opacity", value<float>(&options.layerTransparancy_), "Opacity for layers")
("interaction-opacity", value<float>(&options.interactionTransparancy_), "Opacity for interactions")
("dump,d", value<std::string>(&options.dumpPath), "dump convolutional images in this directory");
options_description composed = desc;
@@ -92,12 +94,12 @@ Options Options::parse(const int argc, char *const argv[])
// Sanity checks
check_file(options.modelPath);
check_file(options.weightsPath);
check_file(options.meansPath);
if (!options.meansPath.empty()) check_file(options.meansPath);
if (!options.labelsPath.empty()) check_file(options.labelsPath);
std::for_each(options.inputPaths.begin(), options.inputPaths.end(), check_file);
return options;
} catch (required_option& e) {
std::cerr << e.get_option_name() << std::endl;
if (e.get_option_name() == "--input") {
std::cerr << "No input files specified" << std::endl;
} else {
@@ -149,6 +151,8 @@ std::optional<PNGDumper> Options::imageDumper() const
}
Options::Options() noexcept :
layerTransparancy_(1),
interactionTransparancy_(1),
pathColor_({1, 1, 1, 0.1})
{
}
@@ -157,3 +161,13 @@ const Color &Options::pathColor() const
{
return pathColor_;
}
float Options::layerTransparancy() const
{
return layerTransparancy_;
}
float Options::interactionTransparancy() const
{
return interactionTransparancy_;
}

View File

@@ -22,10 +22,14 @@ namespace fmri {
const Color& pathColor() const;
std::optional<vector<string>> labels() const;
std::optional<fmri::PNGDumper> imageDumper() const;
float layerTransparancy() const;
float interactionTransparancy() const;
const vector<string>& inputs() const;
private:
float layerTransparancy_;
float interactionTransparancy_;
Color pathColor_;
string modelPath;
string weightsPath;

View File

@@ -341,9 +341,11 @@ bool RenderingState::renderInteractionPaths() const
return options.renderInteractionPaths;
}
void RenderingState::loadOptions(const Options &options)
void RenderingState::loadOptions(const Options &programOptions)
{
this->options.pathColor = options.pathColor();
options.pathColor = programOptions.pathColor();
options.layerAlpha = programOptions.layerTransparancy();
options.interactionAlpha = programOptions.interactionTransparancy();
}
const Color &RenderingState::pathColor() const
@@ -369,3 +371,13 @@ RenderingState::RenderingState() noexcept
// Set initial point size
glPointSize(3);
}
float RenderingState::interactionAlpha() const
{
return options.interactionAlpha;
}
float RenderingState::layerAlpha() const
{
return options.layerAlpha;
}

View File

@@ -43,15 +43,17 @@ namespace fmri
/**
* Load rendering-specific options from the given options object.
*
* @param options
* @param programOptions
*/
void loadOptions(const Options& options);
void loadOptions(const Options& programOptions);
/**
* @return Whether the network should only render activated nodes, rather than all of them.
*/
bool renderActivatedOnly() const;
bool renderInteractionPaths() const;
const Color& pathColor() const;
float interactionAlpha() const;
float layerAlpha() const;
static RenderingState& instance();
@@ -63,6 +65,8 @@ namespace fmri
bool renderInteractions = true;
bool activatedOnly = false;
bool renderInteractionPaths = false;
float layerAlpha;
float interactionAlpha;
Color pathColor;
} options;
std::array<float, 3> pos;

View File

@@ -59,8 +59,8 @@ int main(int argc, char *argv[])
// Prepare data for simulations
Options options = Options::parse(argc, argv);
loadSimulationData(options);
RenderingState::instance().loadOptions(options);
loadSimulationData(options);
// Register callbacks
glutReshapeFunc(changeWindowSize);