Configurable colors.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
#include <glog/logging.h>
|
#include <glog/logging.h>
|
||||||
|
#include <GL/gl.h>
|
||||||
#include "Options.hpp"
|
#include "Options.hpp"
|
||||||
#include "visualisations.hpp"
|
#include "visualisations.hpp"
|
||||||
|
|
||||||
@@ -67,6 +68,17 @@ static void parse_color(const char *input, Color &targetColor)
|
|||||||
throw std::invalid_argument(errorBuf);
|
throw std::invalid_argument(errorBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void parse_color(const std::string& input, Color& targetColor)
|
||||||
|
{
|
||||||
|
parse_color(input.c_str(), targetColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void use_color(const boost::program_options::variables_map& vm, const char* key, Color& target) {
|
||||||
|
if (vm.count(key)) {
|
||||||
|
parse_color(vm[key].as<std::string>(), target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Options::Options(int argc, char * const argv[]):
|
Options::Options(int argc, char * const argv[]):
|
||||||
layerTransparancy_(1),
|
layerTransparancy_(1),
|
||||||
interactionTransparancy_(1),
|
interactionTransparancy_(1),
|
||||||
@@ -94,6 +106,10 @@ Options::Options(int argc, char * const argv[]):
|
|||||||
("interaction-opacity", value_for(interactionTransparancy_), "Opacity for interactions")
|
("interaction-opacity", value_for(interactionTransparancy_), "Opacity for interactions")
|
||||||
("layer-distance", value_for(LAYER_X_OFFSET), "Distance between layers")
|
("layer-distance", value_for(LAYER_X_OFFSET), "Distance between layers")
|
||||||
("interaction-limit", value_for(INTERACTION_LIMIT), "Maximum number of interactions per layer")
|
("interaction-limit", value_for(INTERACTION_LIMIT), "Maximum number of interactions per layer")
|
||||||
|
("neutral-color", value<std::string>(), "Color for showing neutral states")
|
||||||
|
("positive-color", value<std::string>(), "Color for showing positive states")
|
||||||
|
("negative-color", value<std::string>(), "Color for showing negative states")
|
||||||
|
("background-color", value<std::string>()->default_value("#00000000"), "Color for showing neutral states")
|
||||||
("dump,d", value<std::string>(&dumpPath), "dump convolutional images in this directory");
|
("dump,d", value<std::string>(&dumpPath), "dump convolutional images in this directory");
|
||||||
|
|
||||||
options_description composed = desc;
|
options_description composed = desc;
|
||||||
@@ -109,8 +125,15 @@ Options::Options(int argc, char * const argv[]):
|
|||||||
|
|
||||||
notify(vm);
|
notify(vm);
|
||||||
|
|
||||||
if (vm.count("path-color")) {
|
use_color(vm, "path-color", pathColor_);
|
||||||
parse_color(vm["path-color"].as<std::string>().c_str(), pathColor_);
|
use_color(vm, "neutral-color", NEUTRAL_COLOR);
|
||||||
|
use_color(vm, "positive-color", POSITIVE_COLOR);
|
||||||
|
use_color(vm, "negative-color", NEGATIVE_COLOR);
|
||||||
|
|
||||||
|
if (vm.count("background-color")) {
|
||||||
|
Color bg;
|
||||||
|
parse_color(vm["background-color"].as<std::string>(), bg);
|
||||||
|
glClearColor(bg[0], bg[1], bg[2], bg[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sanity checks
|
// Sanity checks
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
int rows;
|
int rows;
|
||||||
|
|
||||||
|
Gtk::Box box;
|
||||||
|
Gtk::ScrolledWindow scrolledWindow;
|
||||||
Gtk::Grid grid;
|
Gtk::Grid grid;
|
||||||
Gtk::FileChooserButton fmriChooser;
|
Gtk::FileChooserButton fmriChooser;
|
||||||
Gtk::FileChooserButton modelChooser;
|
Gtk::FileChooserButton modelChooser;
|
||||||
@@ -106,6 +108,10 @@ private:
|
|||||||
Gtk::FileChooserButton meansChooser;
|
Gtk::FileChooserButton meansChooser;
|
||||||
Gtk::FileChooserButton inputChooser;
|
Gtk::FileChooserButton inputChooser;
|
||||||
Gtk::ColorButton pathColor;
|
Gtk::ColorButton pathColor;
|
||||||
|
Gtk::ColorButton bgColor;
|
||||||
|
Gtk::ColorButton neutralColor;
|
||||||
|
Gtk::ColorButton positiveColor;
|
||||||
|
Gtk::ColorButton negativeColor;
|
||||||
Gtk::Scale layerDistance;
|
Gtk::Scale layerDistance;
|
||||||
Gtk::Scale layerTransparancy;
|
Gtk::Scale layerTransparancy;
|
||||||
Gtk::Scale interactionTransparancy;
|
Gtk::Scale interactionTransparancy;
|
||||||
@@ -118,12 +124,14 @@ private:
|
|||||||
Gtk::Label* getManagedLabel(const std::string& contents);
|
Gtk::Label* getManagedLabel(const std::string& contents);
|
||||||
void findExecutable();
|
void findExecutable();
|
||||||
void addRowWithLabel(const std::string& label, Gtk::Widget& widget);
|
void addRowWithLabel(const std::string& label, Gtk::Widget& widget);
|
||||||
|
void addHeaderRow(const std::string& header);
|
||||||
};
|
};
|
||||||
|
|
||||||
Launcher::Launcher()
|
Launcher::Launcher()
|
||||||
:
|
:
|
||||||
Gtk::Window(),
|
Gtk::Window(),
|
||||||
rows(0),
|
rows(0),
|
||||||
|
box(Gtk::Orientation::ORIENTATION_VERTICAL),
|
||||||
fmriChooser("Select FMRI executable"),
|
fmriChooser("Select FMRI executable"),
|
||||||
modelChooser("Select caffe model prototxt"),
|
modelChooser("Select caffe model prototxt"),
|
||||||
weightsChooser("Select caffe model weights"),
|
weightsChooser("Select caffe model weights"),
|
||||||
@@ -131,15 +139,22 @@ Launcher::Launcher()
|
|||||||
meansChooser("Select means file"),
|
meansChooser("Select means file"),
|
||||||
inputChooser("Select input directory", Gtk::FileChooserAction::FILE_CHOOSER_ACTION_SELECT_FOLDER),
|
inputChooser("Select input directory", Gtk::FileChooserAction::FILE_CHOOSER_ACTION_SELECT_FOLDER),
|
||||||
pathColor(Gdk::RGBA("rgba(255, 255, 255, 0.1)")),
|
pathColor(Gdk::RGBA("rgba(255, 255, 255, 0.1)")),
|
||||||
|
bgColor(Gdk::RGBA("rgba(0, 0, 0, 0)")),
|
||||||
|
neutralColor(Gdk::RGBA("rgba(255, 255, 255, 1)")),
|
||||||
|
positiveColor(Gdk::RGBA("rgba(0, 0, 255, 1)")),
|
||||||
|
negativeColor(Gdk::RGBA("rgba(255, 0, 0, 1)")),
|
||||||
layerDistance(Gtk::Adjustment::create(10, 0, 100, 0, 0.1, 0)),
|
layerDistance(Gtk::Adjustment::create(10, 0, 100, 0, 0.1, 0)),
|
||||||
layerTransparancy(Gtk::Adjustment::create(1, 0, 1, 0.0, 1.f / 256)),
|
layerTransparancy(Gtk::Adjustment::create(1, 0, 1, 0.0, 1.f / 256)),
|
||||||
interactionTransparancy(Gtk::Adjustment::create(1, 0, 1, 0.0, 1.f / 256)),
|
interactionTransparancy(Gtk::Adjustment::create(1, 0, 1, 0.0, 1.f / 256)),
|
||||||
interactionLimit(Gtk::Adjustment::create(10000, 4096, std::numeric_limits<int>::max()), 10000),
|
interactionLimit(Gtk::Adjustment::create(10000, 4096, std::numeric_limits<int>::max()), 10000),
|
||||||
startButton("Start FMRI")
|
startButton("Start FMRI")
|
||||||
{
|
{
|
||||||
set_default_size(400, -1);
|
set_default_size(480, 320);
|
||||||
//set_size_request(400, -1);
|
add(box);
|
||||||
add(grid);
|
box.add(scrolledWindow);
|
||||||
|
scrolledWindow.set_vexpand(true);
|
||||||
|
box.add(startButton);
|
||||||
|
scrolledWindow.add(grid);
|
||||||
|
|
||||||
// Configure all widgets
|
// Configure all widgets
|
||||||
fmriChooser.set_hexpand(true);
|
fmriChooser.set_hexpand(true);
|
||||||
@@ -168,14 +183,20 @@ Launcher::Launcher()
|
|||||||
addRowWithLabel("Labels (optional)", labelChooser);
|
addRowWithLabel("Labels (optional)", labelChooser);
|
||||||
addRowWithLabel("Input directory", inputChooser);
|
addRowWithLabel("Input directory", inputChooser);
|
||||||
addRowWithLabel("Means (optional)", meansChooser);
|
addRowWithLabel("Means (optional)", meansChooser);
|
||||||
|
addHeaderRow("Color settings");
|
||||||
addRowWithLabel("Path color", pathColor);
|
addRowWithLabel("Path color", pathColor);
|
||||||
|
addRowWithLabel("Background color", bgColor);
|
||||||
|
addRowWithLabel("Neutral color", neutralColor);
|
||||||
|
addRowWithLabel("Positive color", positiveColor);
|
||||||
|
addRowWithLabel("Negative color", negativeColor);
|
||||||
|
addHeaderRow("Misc settings");
|
||||||
addRowWithLabel("Layer distance", layerDistance);
|
addRowWithLabel("Layer distance", layerDistance);
|
||||||
addRowWithLabel("Layer transparancy", layerTransparancy);
|
addRowWithLabel("Layer transparancy", layerTransparancy);
|
||||||
addRowWithLabel("Interaction transparancy", interactionTransparancy);
|
addRowWithLabel("Interaction transparancy", interactionTransparancy);
|
||||||
addRowWithLabel("Interaction limit", interactionLimit);
|
addRowWithLabel("Interaction limit", interactionLimit);
|
||||||
|
|
||||||
startButton.signal_clicked().connect(sigc::mem_fun(*this, &Launcher::start));
|
startButton.signal_clicked().connect(sigc::mem_fun(*this, &Launcher::start));
|
||||||
grid.attach_next_to(startButton, Gtk::PositionType::POS_BOTTOM, 2, 1);
|
//grid.attach_next_to(startButton, Gtk::PositionType::POS_BOTTOM, 2, 1);
|
||||||
show_all_children(true);
|
show_all_children(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,6 +228,14 @@ void Launcher::start()
|
|||||||
wrap_string(weights),
|
wrap_string(weights),
|
||||||
wrap_string("-p"),
|
wrap_string("-p"),
|
||||||
color_string(pathColor),
|
color_string(pathColor),
|
||||||
|
wrap_string("--background-color"),
|
||||||
|
color_string(bgColor),
|
||||||
|
wrap_string("--neutral-color"),
|
||||||
|
color_string(neutralColor),
|
||||||
|
wrap_string("--positive-color"),
|
||||||
|
color_string(positiveColor),
|
||||||
|
wrap_string("--negative-color"),
|
||||||
|
color_string(negativeColor)
|
||||||
};
|
};
|
||||||
|
|
||||||
float_parameter(argv, "--layer-opacity", layerTransparancy.get_value());
|
float_parameter(argv, "--layer-opacity", layerTransparancy.get_value());
|
||||||
@@ -309,6 +338,14 @@ void Launcher::addRowWithLabel(const std::string &label, Gtk::Widget &widget)
|
|||||||
grid.attach_next_to(*getManagedLabel(label), widget, Gtk::PositionType::POS_LEFT, 1, 1);
|
grid.attach_next_to(*getManagedLabel(label), widget, Gtk::PositionType::POS_LEFT, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Launcher::addHeaderRow(const std::string &header)
|
||||||
|
{
|
||||||
|
int currentRow = rows++;
|
||||||
|
auto label = getManagedLabel(header);
|
||||||
|
label->set_markup("<b>" + header + "</b>");
|
||||||
|
grid.attach(*label, 0, currentRow, 2, 1);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
auto app = Gtk::Application::create(argc, argv);
|
auto app = Gtk::Application::create(argc, argv);
|
||||||
|
|||||||
Reference in New Issue
Block a user