Skip to content

Commit

Permalink
Merge pull request #2667 from MRtrix3/mrview_fix_tsf_custom_colour
Browse files Browse the repository at this point in the history
mrview: fix tsf custom colour
  • Loading branch information
bjeurissen authored Jul 1, 2023
2 parents 1320438 + ad39dc8 commit 5a0f40c
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 221 deletions.
16 changes: 11 additions & 5 deletions src/gui/mrview/colourmap_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ void ColourMapButton::init_special_colour_menu_items(bool create_shortcuts)

void ColourMapButton::init_customise_state_menu_items()
{
auto show_colour_bar = colourmap_menu->addAction(tr("Show colour bar"), this, SLOT(show_colour_bar_slot(bool)));
show_colour_bar->setCheckable(true);
show_colour_bar->setChecked(true);
addAction(show_colour_bar);
show_colour_bar_action = colourmap_menu->addAction(tr("Show colour bar"), this, SLOT(show_colour_bar_slot(bool)));
show_colour_bar_action->setCheckable(true);
show_colour_bar_action->setChecked(true);
addAction(show_colour_bar_action);

invert_scale_action = colourmap_menu->addAction(tr("Invert"), this, SLOT(invert_colourmap_slot(bool)));
invert_scale_action->setCheckable(true);
Expand Down Expand Up @@ -163,12 +163,18 @@ void ColourMapButton::set_colourmap_index(size_t index)
}
}

void ColourMapButton::set_scale_inverted(bool yesno)
void ColourMapButton::set_scale_inverted (bool yesno)
{
assert (invert_scale_action != nullptr);
invert_scale_action->setChecked (yesno);
}

void ColourMapButton::set_show_colourbar (bool yesno)
{
assert (invert_scale_action != nullptr);
show_colour_bar_action->setChecked (yesno);
}


void ColourMapButton::set_fixed_colour()
{
Expand Down
18 changes: 10 additions & 8 deletions src/gui/mrview/colourmap_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,25 @@ class ColourMapButton;
class ColourMapButtonObserver
{ NOMEMALIGN
public:
virtual void selected_colourmap(size_t, const ColourMapButton&) {}
virtual void selected_custom_colour(const QColor&, const ColourMapButton&) {}
virtual void toggle_show_colour_bar(bool, const ColourMapButton&) {}
virtual void toggle_invert_colourmap(bool, const ColourMapButton&) {}
virtual void reset_colourmap(const ColourMapButton&) {}
virtual void selected_colourmap (size_t, const ColourMapButton&) {}
virtual void selected_custom_colour (const QColor&, const ColourMapButton&) {}
virtual void toggle_show_colour_bar (bool, const ColourMapButton&) {}
virtual void toggle_invert_colourmap (bool, const ColourMapButton&) {}
virtual void reset_colourmap (const ColourMapButton&) {}
};


class ColourMapButton : public QToolButton
{ MEMALIGN(ColourMapButton)
Q_OBJECT
public:
ColourMapButton(QWidget* parent, ColourMapButtonObserver& obs,
ColourMapButton (QWidget* parent, ColourMapButtonObserver& obs,
bool use_shortcuts = false,
bool use_special_colourmaps = true,
bool use_customise_state_items = true);
void set_colourmap_index(size_t index);
void set_scale_inverted(bool yesno);
void set_colourmap_index (size_t index);
void set_scale_inverted (bool yesno);
void set_show_colourbar (bool yesno);
void set_fixed_colour();
vector<QAction*> colourmap_actions;
void open_menu (const QPoint& p) { colourmap_menu->exec (p); }
Expand All @@ -71,6 +72,7 @@ class ColourMapButton : public QToolButton
QMenu* colourmap_menu;
QAction* custom_colour_action;
QAction* invert_scale_action;
QAction* show_colour_bar_action;

size_t fixed_colour_index;

Expand Down
67 changes: 0 additions & 67 deletions src/gui/mrview/colourmap_menu.cpp

This file was deleted.

49 changes: 0 additions & 49 deletions src/gui/mrview/colourmap_menu.h

This file was deleted.

8 changes: 7 additions & 1 deletion src/gui/mrview/displayable.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,16 @@ namespace MR
flags_ = cmap;
}

void set_colour (std::array<GLubyte,3> &c) {
void set_colour (const std::array<GLubyte,3> &c) {
colour = c;
}

void set_colour (const QColor &c) {
colour[0] = c.red();
colour[1] = c.green();
colour[2] = c.blue();
}

void set_use_discard_lower (bool yesno) {
if (!discard_lower_enabled()) return;
set_bit (DiscardLower, yesno);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/mrview/tool/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ namespace MR
if (colourmap_index == -2)
colourmap_index = overlay->colourmap;
else
colourmap_index = -1;
colourmap_index = -1;
}
num_inverted += overlay->scale_inverted();
rate += overlay->scaling_rate();
Expand Down
76 changes: 21 additions & 55 deletions src/gui/mrview/tool/tractography/track_scalar_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "gui/mrview/tool/tractography/track_scalar_file.h"

#include "gui/dialog/file.h"
#include "gui/mrview/colourmap_menu.h"
#include "gui/mrview/tool/tractography/tractogram.h"


Expand Down Expand Up @@ -52,34 +51,7 @@ namespace MR
connect (intensity_file_button, SIGNAL (clicked()), this, SLOT (open_intensity_track_scalar_file_slot ()));
hlayout->addWidget (intensity_file_button);

// Colourmap menu:
colourmap_menu = new QMenu (tr ("Colourmap menu"), this);

MRView::create_colourmap_menu (this, colourmap_group, colourmap_menu, colourmap_actions, false, false);
connect (colourmap_group, SIGNAL (triggered (QAction*)), this, SLOT (select_colourmap_slot()));
colourmap_actions[1]->setChecked (true);

colourmap_menu->addSeparator();

show_colour_bar = colourmap_menu->addAction (tr ("Show colour bar"), this, SLOT (show_colour_bar_slot()));
show_colour_bar->setCheckable (true);
show_colour_bar->setChecked (true);
addAction (show_colour_bar);

invert_scale = colourmap_menu->addAction (tr ("Invert"), this, SLOT (invert_colourmap_slot()));
invert_scale->setCheckable (true);
addAction (invert_scale);

colourmap_menu->addSeparator();

QAction* reset_intensity = colourmap_menu->addAction (tr ("Reset intensity"), this, SLOT (reset_intensity_slot()));
addAction (reset_intensity);

colourmap_button = new QToolButton (this);
colourmap_button->setToolTip (tr ("Colourmap menu"));
colourmap_button->setIcon (QIcon (":/colourmap.svg"));
colourmap_button->setPopupMode (QToolButton::InstantPopup);
colourmap_button->setMenu (colourmap_menu);
colourmap_button = new ColourMapButton(this, *this, false, false, true);
hlayout->addWidget (colourmap_button);

vlayout->addLayout (hlayout);
Expand Down Expand Up @@ -159,7 +131,8 @@ namespace MR

window().colourbar_renderer.render (tractogram.colourmap, tractogram.scale_inverted(),
min_value, max_value,
tractogram.scaling_min(), tractogram.display_range, tractogram.colour);
tractogram.scaling_min(), tractogram.display_range,
{ tractogram.colour[0]/255.0f, tractogram.colour[1]/255.0f, tractogram.colour[2]/255.0f });
}


Expand All @@ -180,10 +153,10 @@ namespace MR
min_entry->setValue (tractogram->scaling_min());
max_entry->setValue (tractogram->scaling_max());

colourmap_menu->setEnabled (true);
colourmap_actions[tractogram->colourmap]->setChecked (true);
show_colour_bar->setChecked (tractogram->show_colour_bar);
invert_scale->setChecked (tractogram->scale_inverted());
colourmap_button->setEnabled (true);
colourmap_button->set_colourmap_index(tractogram->colourmap);
colourmap_button->set_scale_inverted (tractogram->scale_inverted());
colourmap_button->set_show_colourbar (tractogram->show_colour_bar);

assert (tractogram->intensity_scalar_filename.length());
intensity_file_button->setText (qstr (shorten (Path::basename (tractogram->intensity_scalar_filename), 35, 0)));
Expand Down Expand Up @@ -259,28 +232,30 @@ namespace MR
return scalar_file.size();
}

void TrackScalarFileOptions::show_colour_bar_slot ()
void TrackScalarFileOptions::toggle_show_colour_bar(bool show_colour_bar, const ColourMapButton&)
{
if (tractogram) {
tractogram->show_colour_bar = show_colour_bar->isChecked();
tractogram->show_colour_bar = show_colour_bar;
window().updateGL();
}
}


void TrackScalarFileOptions::select_colourmap_slot ()
void TrackScalarFileOptions::selected_colourmap (size_t cmap, const ColourMapButton&)
{
if (tractogram) {
QAction* action = colourmap_group->checkedAction();
size_t n = 0;
while (action != colourmap_actions[n])
++n;
tractogram->colourmap = n;
tractogram->colourmap = cmap;
window().updateGL();
}
}


void TrackScalarFileOptions::selected_custom_colour (const QColor& c, const ColourMapButton&)
{
if (tractogram) {
tractogram->set_colour (c);
window().updateGL();
}
}

void TrackScalarFileOptions::set_threshold(GUI::MRView::Tool::TrackThresholdType dataSource, default_type min, default_type max)//TrackThresholdType dataSource
{
Expand Down Expand Up @@ -429,7 +404,7 @@ namespace MR
}


void TrackScalarFileOptions::reset_intensity_slot ()
void TrackScalarFileOptions::reset_colourmap (const ColourMapButton&)
{
if (tractogram) {
tractogram->reset_windowing();
Expand All @@ -439,19 +414,10 @@ namespace MR
}


void TrackScalarFileOptions::invert_colourmap_slot ()
void TrackScalarFileOptions::toggle_invert_colourmap (bool invert, const ColourMapButton&)
{
if (tractogram) {
tractogram->set_invert_scale (invert_scale->isChecked());
window().updateGL();
}
}

void TrackScalarFileOptions::set_colourmap (int colourmap_index)
{
if (tractogram) {
tractogram->colourmap = colourmap_index;
update_UI();
tractogram->set_invert_scale (invert);
window().updateGL();
}
}
Expand Down
Loading

0 comments on commit 5a0f40c

Please sign in to comment.