Commit 45d930bc authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Clean and update many things

- uniform coloring is available for all vector decorators
- no more side effect between touch and draw
   - touch() enables to update decorator state
   - draw() tells the view to redraw itself

Management of color map can be enhanced especially to include opacity
management for volume rendering.
parent 98224870
......@@ -78,10 +78,6 @@ public:
void dtkVisualizationDecoratorIsocontours::updateContours(void)
{
if (!d_func()->show_actor_cb->isChecked()) {
return;
}
auto field_name = d_func()->current_field_name;
if (field_name.isEmpty() || !d_func()->dataset) {
......@@ -142,25 +138,28 @@ dtkVisualizationDecoratorIsocontours::dtkVisualizationDecoratorIsocontours(void)
//////////
// Inspectors connections
connect(d_func()->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
this->saveSettings("visibility",state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
connect(d->isolines_counts_sb, QOverload<int>::of(&QSpinBox::valueChanged), [=] (int value) {
this->saveSettings("isolines_count", value);
this->setCurrentIsolinesCount(value);
this->touch();
this->draw();
});
connect(d->isolines_width_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double value) {
this->saveSettings("isolines_line_width", value);
d->actor->GetProperty()->SetLineWidth(value);
d->actor->Modified();
this->draw();
});
connect(d_func()->show_actor_cb, &QCheckBox::stateChanged, [=] (int state)
{
this->saveSettings("visibility", state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
connect(d->isolines_counts_sb, QOverload<int>::of(&QSpinBox::valueChanged), [=] (int value)
{
this->saveSettings("isolines_count", value);
this->setCurrentIsolinesCount(value);
this->touch();
this->draw();
});
connect(d->isolines_width_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [=] (double value)
{
this->saveSettings("isolines_line_width", value);
d->actor->GetProperty()->SetLineWidth(value);
d->actor->Modified();
this->draw();
});
this->setObjectName("Isocontours");
......
......@@ -214,16 +214,16 @@ dtkVisualizationDecoratorSlices::dtkVisualizationDecoratorSlices(void): dtkVisua
});
connect(d->enable_slicing_x, &dtkVisualizationWidgetsSliceControls::reset, [=] ()
{
double *origin = d->input_image->GetOrigin();
d->volume_slice_x->SetPlaneOrientationToXAxes();
d->volume_slice_x->SetSlicePosition(origin[0]);
this->draw();
double *origin = d->input_image->GetOrigin();
d->volume_slice_x->SetPlaneOrientationToXAxes();
d->volume_slice_x->SetSlicePosition(origin[0]);
this->draw();
});
connect(d->enable_slicing_x, &dtkVisualizationWidgetsSliceControls::valueChanged, [=] (double value)
{
double *origin = d->input_image->GetOrigin();
d->volume_slice_x->SetSlicePosition(value + origin[0]);
this->draw();
double *origin = d->input_image->GetOrigin();
d->volume_slice_x->SetSlicePosition(value + origin[0]);
this->draw();
});
connect(d->enable_slicing_y, &dtkVisualizationWidgetsSliceControls::toggled, [=] (bool checked)
......@@ -233,16 +233,16 @@ dtkVisualizationDecoratorSlices::dtkVisualizationDecoratorSlices(void): dtkVisua
});
connect(d->enable_slicing_y, &dtkVisualizationWidgetsSliceControls::reset, [=] ()
{
double *origin = d->input_image->GetOrigin();
d->volume_slice_y->SetPlaneOrientationToYAxes();
d->volume_slice_y->SetSlicePosition(origin[1]);
this->draw();
double *origin = d->input_image->GetOrigin();
d->volume_slice_y->SetPlaneOrientationToYAxes();
d->volume_slice_y->SetSlicePosition(origin[1]);
this->draw();
});
connect(d->enable_slicing_y, &dtkVisualizationWidgetsSliceControls::valueChanged, [=] (double value)
{
double *origin = d->input_image->GetOrigin();
d->volume_slice_y->SetSlicePosition(value + origin[1]);
this->draw();
double *origin = d->input_image->GetOrigin();
d->volume_slice_y->SetSlicePosition(value + origin[1]);
this->draw();
});
connect(d->enable_slicing_z, &dtkVisualizationWidgetsSliceControls::toggled, [=] (bool checked)
......@@ -252,16 +252,16 @@ dtkVisualizationDecoratorSlices::dtkVisualizationDecoratorSlices(void): dtkVisua
});
connect(d->enable_slicing_z, &dtkVisualizationWidgetsSliceControls::reset, [=] ()
{
double *origin = d->input_image->GetOrigin();
d->volume_slice_z->SetPlaneOrientationToZAxes();
d->volume_slice_z->SetSlicePosition(origin[2]);
this->draw();
double *origin = d->input_image->GetOrigin();
d->volume_slice_z->SetPlaneOrientationToZAxes();
d->volume_slice_z->SetSlicePosition(origin[2]);
this->draw();
});
connect(d->enable_slicing_z, &dtkVisualizationWidgetsSliceControls::valueChanged, [=] (double value)
{
double *origin = d->input_image->GetOrigin();
d->volume_slice_z->SetSlicePosition((value + origin[2]));
this->draw();
double *origin = d->input_image->GetOrigin();
d->volume_slice_z->SetSlicePosition((value + origin[2]));
this->draw();
});
......
......@@ -109,6 +109,7 @@ dtkVisualizationDecoratorVectorGlyphs::dtkVisualizationDecoratorVectorGlyphs(voi
{
this->saveSettings("scaling_mode", component_id);
this->touch();
this->draw();
});
connect(d->glyphs_stride_sb, QOverload<int>::of(&QSpinBox::valueChanged), [=] (int value)
......
......@@ -647,10 +647,12 @@ void dtkVisualizationDecoratorVectorStreamTracer::setVisibility(bool visible)
{
dtkVisualizationDecoratorWithClut::setVisibility(visible);
d->actor->SetVisibility(visible);
if (d->cb_seed_type->currentText() == "Sphere") {
d->source_sphere_widget->SetEnabled(visible);
} else {
d->source_line_widget->SetEnabled(visible);
if (d->cb_show_seed->isChecked()) {
if (d->cb_seed_type->currentText() == "Sphere") {
d->source_sphere_widget->SetEnabled(visible);
} else {
d->source_line_widget->SetEnabled(visible);
}
}
}
......
......@@ -19,6 +19,7 @@
#include "dtkVisualizationView2D.h"
#include <dtkVisualizationWidgets/dtkVisualizationWidgetsCategory>
#include <dtkVisualizationWidgets/dtkVisualizationWidgetsColorDialog>
#include <dtkVisualizationWidgets/dtkVisualizationWidgetsColorMapEditor>
#include <dtkFonts/dtkFontAwesome>
......@@ -31,6 +32,7 @@
#include <vtkCellData.h>
#include <vtkDataArray.h>
#include <vtkDataSet.h>
#include <vtkLookupTable.h>
#include <vtkPiecewiseFunction.h>
#include <vtkPointData.h>
#include <vtkRenderer.h>
......@@ -70,14 +72,18 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
this->colormap_editor = new dtkVisualizationWidgetsColorMapEditor;
this->colormap_editor->setObjectName("Color Map");
// Color dialog
this->col_dialog = new dtkVisualizationWidgetsColorDialog;
this->col_dialog->setObjectName("Color");
// Display Data
show_actor_cb = new QCheckBox;
show_actor_cb->setObjectName("Data");
// Range
QHBoxLayout *h_layout_range = new QHBoxLayout;
QWidget *range_widget = new QWidget;
range_widget->setObjectName("Range");
this->range_widget = new QWidget;
this->range_widget->setObjectName("Range");
this->min_range = new QLineEdit;
this->max_range = new QLineEdit;
......@@ -96,7 +102,7 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
h_layout_range->addWidget(this->max_range);
h_layout_range->addWidget(this->reset_range);
range_widget->setLayout(h_layout_range);
this->range_widget->setLayout(h_layout_range);
// Opacity
this->opacity_widget = new QWidget;
......@@ -137,8 +143,10 @@ dtkVisualizationDecoratorWithClutPrivate::dtkVisualizationDecoratorWithClutPriva
this->show_scalar_bar } )
<< new dtkVisualizationWidgetsCategory("Colors", {
this->field_components,
colormap_editor,
range_widget } );
this->colormap_editor,
this->range_widget,
this->col_dialog
});
}
void dtkVisualizationDecoratorWithClutPrivate::clear(void)
......@@ -338,6 +346,18 @@ void dtkVisualizationDecoratorWithClutPrivate::updateColorTransferFunction(void)
// to extract in the GetRange method for the vector case.
int component_id = this->field_components->currentIndex() - 2;
dtkVisualizationWidgetsCategory *category = dynamic_cast<dtkVisualizationWidgetsCategory *>(this->inspectorItem("Colors"));
Q_ASSERT_X(category, Q_FUNC_INFO, "Category Colors should exist.");
category->setVisible(this->col_dialog, false);
category->setVisible(this->colormap_editor, true);
category->setVisible(this->range_widget, true);
this->colormap_editor->blockSignals(true);
this->colormap_editor->setValue(this->color_transfer_functions[this->current_field_name]);
this->colormap_editor->blockSignals(false);
QMap<double, QColor> color_map = this->colormap_editor->value();
switch (this->kinds[this->current_field_name]) {
case Kind::Vector:
switch(component_id) {
......@@ -357,7 +377,13 @@ void dtkVisualizationDecoratorWithClutPrivate::updateColorTransferFunction(void)
this->color_function->SetVectorComponent(2);
break;
default:
category->setVisible(this->col_dialog, true);
category->setVisible(this->colormap_editor, false);
category->setVisible(this->range_widget, false);
this->color_function->SetVectorModeToMagnitude();
color_map.clear();
auto&& range = this->ranges[this->current_field_name];
color_map[range[0]] = this->col_dialog->currentColor();
break;
}
break;
......@@ -365,9 +391,7 @@ void dtkVisualizationDecoratorWithClutPrivate::updateColorTransferFunction(void)
break;
}
this->colormap_editor->blockSignals(true);
this->colormap_editor->setValue(this->color_transfer_functions[this->current_field_name]);
this->colormap_editor->blockSignals(false);
q->setColorMap(color_map);
}
QWidget *dtkVisualizationDecoratorWithClutPrivate::inspectorItem(const QString& name) const
......@@ -386,31 +410,33 @@ QWidget *dtkVisualizationDecoratorWithClutPrivate::inspectorItem(const QString&
dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkVisualizationDecorator(), d(new dtkVisualizationDecoratorWithClutPrivate)
{
d->q = this;
//////////
// Inspectors connections
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state) {
this->saveSettings("visibility", state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
connect(d->show_actor_cb, &QCheckBox::stateChanged, [=] (int state)
{
this->saveSettings("visibility", state == Qt::Checked);
this->setVisibility(state == Qt::Checked);
this->draw();
});
connect(d->fields_box, &QComboBox::currentTextChanged, [=] (const QString& field_name)
{
this->setCurrentFieldName(field_name);
this->saveSettings("field_name", field_name);
this->touch();
this->draw();
});
connect(d->field_components, QOverload<int>::of(&QComboBox::currentIndexChanged), [=] (int component_id)
{
//
// if (d->current_field_component != component_id) {
// d->original_range = false;
// }
d->current_field_component = component_id;
this->saveSettings("field_component", component_id);
this->saveSettings("original_range", d->original_range);
this->touch();
this->draw();
});
connect(d->min_range, &QLineEdit::editingFinished, [=] ()
......@@ -421,6 +447,7 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkV
this->saveSettings("range_max", d->max_range->text().toDouble());
this->saveSettings("original_range", false);
this->touch();
this->draw();
});
connect(d->max_range, &QLineEdit::editingFinished, [=] ()
{
......@@ -430,6 +457,7 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkV
this->saveSettings("range_max", d->max_range->text().toDouble());
this->saveSettings("original_range", false);
this->touch();
this->draw();
});
// Restores default ranges
connect(d->reset_range, QOverload<>::of(&QPushButton::released), [=] ()
......@@ -437,18 +465,26 @@ dtkVisualizationDecoratorWithClut::dtkVisualizationDecoratorWithClut(void): dtkV
d->original_range = true;
this->saveSettings("original_range", true);
this->touch();
this->draw();
});
connect(d->colormap_editor, &dtkVisualizationWidgetsColorMapEditor::valueChanged, [=] (const QMap<double, QColor>& val)
{
d->color_transfer_functions[d->current_field_name] = d->colormap_editor->name();
d->colormap_editor->blockSignals(true);
this->setColorMap(val);
this->saveSettings("colormap", d->colormap_editor->name());
d->colormap_editor->blockSignals(false);
this->draw();
});
connect(d->col_dialog, &dtkVisualizationWidgetsColorDialog::colorChanged, [=] (QColor c)
{
if (c.isValid()) {
this->saveSettings("color", c);
this->touchColorMap();
this->draw();
}
});
connect(d->show_scalar_bar, &QCheckBox::stateChanged, [=] (int state)
{
d->scalar_bar->SetVisibility(state == Qt::Checked);
......@@ -490,24 +526,27 @@ void dtkVisualizationDecoratorWithClut::restoreSettings(void)
QSettings settings;
settings.beginGroup("canvas");
d->default_visibility = settings.value(name+"_visibility", true).toBool();
d->default_field_name = settings.value(name+"_field_name").toString();
if(!d->eligible_field_names.contains(d->default_field_name)) {
d->default_field_name = QString();
}
d->default_visibility = settings.value(name+"_visibility", true).toBool();
d->default_show_scalar_bar = settings.value(name+"_show_scalarbar", false).toBool();
d->default_field_component = settings.value(name+"_field_component").toInt();
d->field_components->blockSignals(true);
d->field_components->setCurrentIndex(d->default_field_component);
d->field_components->blockSignals(false);
d->default_color_map = settings.value(name+"_colormap", "inferno").toString();
d->default_show_scalar_bar = settings.value(name+"_show_scalarbar", false).toBool();
d->default_color_map = settings.value(name+"_colormap", "jet").toString();
double range_min = settings.value(name+"_range_min", -1.).toDouble();
double range_max = settings.value(name+"_range_max", -1.).toDouble();
bool original_range = settings.value(name+"_original_range", true).toBool();
QColor color = QColor(settings.value(name+"_color", "#000000").toString());
double opacity = settings.value(name+"_opacity", 1.).toDouble();
settings.endGroup();
......@@ -521,7 +560,13 @@ void dtkVisualizationDecoratorWithClut::restoreSettings(void)
d->colormap_editor->blockSignals(true);
d->colormap_editor->setValue(d->default_color_map);
d->colormap_editor->blockSignals(false);
this->setColorMap(d->colormap_editor->value());
d->col_dialog->blockSignals(true);
d->col_dialog->setColor(color);
d->col_dialog->blockSignals(false);
this->touchColorMap();
d->show_scalar_bar->blockSignals(true);
d->show_scalar_bar->setChecked(d->default_show_scalar_bar);
......@@ -570,7 +615,6 @@ void dtkVisualizationDecoratorWithClut::touchRange(void)
void dtkVisualizationDecoratorWithClut::touchColorMap(void)
{
d->updateColorTransferFunction();
this->setColorMap(d->colormap_editor->value());
}
void dtkVisualizationDecoratorWithClut::setVisibility(bool visible)
......@@ -657,7 +701,9 @@ void dtkVisualizationDecoratorWithClut::setColorMap(const QMap<double, QColor>&
// If there is no new colormap, take the previous one.
if (new_colormap.isEmpty()) {
QString colormap_name = d->color_transfer_functions[d->current_field_name];
d->colormap_editor->blockSignals(true);
d->colormap_editor->setValue(colormap_name);
d->colormap_editor->blockSignals(false);
colormap_map = d->colormap_editor->value();
}
......@@ -674,9 +720,6 @@ void dtkVisualizationDecoratorWithClut::setColorMap(const QMap<double, QColor>&
color.green() / 255.,
color.blue() / 255.);
}
d->colormap_editor->setValue(new_colormap);
d->color_function->ClampingOn();
d->color_function->Modified();
......
......@@ -69,6 +69,7 @@ protected:
virtual void setOpacity(double);
protected:
friend class dtkVisualizationDecoratorWithClutPrivate;
class dtkVisualizationDecoratorWithClutPrivate *d;
dtkVisualizationDecoratorWithClutPrivate *d_func(void);
const dtkVisualizationDecoratorWithClutPrivate *d_func(void) const;
......
......@@ -23,6 +23,7 @@
#include <array>
class dtkVisualizationView2D;
class dtkVisualizationWidgetsColorDialog;
class dtkVisualizationWidgetsColorMapEditor;
class QCheckBox;
......@@ -35,6 +36,7 @@ class QSlider;
class vtkColorTransferFunction;
class vtkDataSet;
class vtkDataSetAttributes;
class vtkLookupTable;
class vtkPiecewiseFunction;
class vtkPiecewiseFunction;
class vtkScalarBarActor;
......@@ -42,6 +44,9 @@ class vtkTransform;
class DTKVISUALIZATION_EXPORT dtkVisualizationDecoratorWithClutPrivate
{
public:
class dtkVisualizationDecoratorWithClut *q = nullptr;
public:
enum Support {
Unknown = 0,
......@@ -68,19 +73,21 @@ public:
QComboBox *fields_box = nullptr;
QComboBox *field_components = nullptr;
QWidget *range_widget = nullptr;
QPushButton *reset_range = nullptr;
QLineEdit *min_range = nullptr;
QLineEdit *max_range = nullptr;
bool original_range = true;
QCheckBox *show_scalar_bar = nullptr;
QCheckBox *show_actor_cb = nullptr;
public:
QWidget *opacity_widget = nullptr;
QSlider *opacity_slider = nullptr;
QDoubleSpinBox *opacity_val_sp = nullptr;
public:
dtkVisualizationWidgetsColorDialog *col_dialog = nullptr;
dtkVisualizationWidgetsColorMapEditor *colormap_editor = nullptr;
public:
......@@ -95,8 +102,8 @@ public:
public:
vtkSmartPointer<vtkColorTransferFunction> color_function;
vtkSmartPointer<vtkPiecewiseFunction> opacity;
vtkSmartPointer<vtkTransform> transform;
vtkSmartPointer<vtkPiecewiseFunction> opacity;
vtkSmartPointer<vtkTransform> transform;
vtkSmartPointer<vtkScalarBarActor> scalar_bar;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment