Commit 2af0aaa2 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud

Fix the problem of changing field in slice decorator.

The underlying vtkImageMapToColors contained in the vtkImagePlaneWidget
only considers the active scalar of the input.

The trick is to use a shallow copy of the input image to set the active
scalar on its fields without corrupt other decorators.

Paraview has not such a problem since it does not use the
vtkImagePlaneWidget.

Simplifications have also been made to avoid spurious calls to set the
positions of the slices.
parent 4db817d3
......@@ -36,6 +36,7 @@
#include <vtkDataSetMapper.h>
#include <vtkImageMapToColors.h>
#include <vtkImagePlaneWidget.h>
#include <vtkImageReslice.h>
#include <vtkLookupTable.h>
#include <vtkOutlineFilter.h>
#include <vtkPiecewiseFunction.h>
......@@ -91,6 +92,9 @@ public:
class dtkVisualizationDecoratorSlicesPrivate
{
public:
vtkSmartPointer<vtkImageData> input_image;
public:
vtkSmartPointer<vtkImagePlaneWidget> volume_slice_x;
vtkSmartPointer<vtkImagePlaneWidget> volume_slice_y;
......@@ -121,7 +125,7 @@ public slots:
void dtkVisualizationDecoratorSlicesPrivate::setupSlices(void)
{
double *origin;
origin = vtkImageData::SafeDownCast(this->volume_slice_z->GetInput())->GetOrigin();
origin = vtkImageData::SafeDownCast(this->volume_slice_x->GetInput())->GetOrigin();
this->volume_slice_x->PlaceWidget();
this->volume_slice_x->SetPlaneOrientationToXAxes();
......@@ -148,6 +152,11 @@ void dtkVisualizationDecoratorSlicesPrivate::setupSlices(void)
void dtkVisualizationDecoratorSlicesPrivate::setVisibility(bool visible)
{
if (!this->volume_slice_x->GetInteractor()) {
// Interactor must be set before enabling vtkImagePlaneWidget.
return;
}
if (visible) {
this->volume_slice_x->On();
this->volume_slice_x->InteractionOn();
......@@ -170,7 +179,10 @@ void dtkVisualizationDecoratorSlicesPrivate::setVisibility(bool visible)
dtkVisualizationDecoratorSlices::dtkVisualizationDecoratorSlices(void): dtkVisualizationDecoratorWithClut(), d(new dtkVisualizationDecoratorSlicesPrivate())
{
d->input_image = vtkSmartPointer<vtkImageData>::New();
d->c2p_filter = vtkSmartPointer<vtkCellDataToPointData>::New();
d->c2p_filter->SetInputData(d->input_image);
d->volume_slice_x = vtkImagePlaneWidget::New();
d->volume_slice_y = vtkImagePlaneWidget::New();
......@@ -195,56 +207,59 @@ dtkVisualizationDecoratorSlices::dtkVisualizationDecoratorSlices(void): dtkVisua
//////////
// Inspectors connections
connect(d->enable_slicing_x, &dtkVisualizationWidgetsSliceControls::toggled, [=] (bool checked) {
connect(d->enable_slicing_x, &dtkVisualizationWidgetsSliceControls::toggled, [=] (bool checked)
{
d->volume_slice_x->SetEnabled(checked);
this->draw();
});
connect(d->enable_slicing_x, &dtkVisualizationWidgetsSliceControls::reset, [=] () {
double *origin;
origin = vtkImageData::SafeDownCast(d_func()->dataset)->GetOrigin();
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();
});
connect(d->enable_slicing_x, &dtkVisualizationWidgetsSliceControls::valueChanged, [=] (double value) {
double *origin;
origin = vtkImageData::SafeDownCast(d_func()->dataset)->GetOrigin();
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();
});
connect(d->enable_slicing_y, &dtkVisualizationWidgetsSliceControls::toggled, [=] (bool checked) {
connect(d->enable_slicing_y, &dtkVisualizationWidgetsSliceControls::toggled, [=] (bool checked)
{
d->volume_slice_y->SetEnabled(checked);
this->draw();
});
connect(d->enable_slicing_y, &dtkVisualizationWidgetsSliceControls::reset, [=] () {
double *origin;
origin = vtkImageData::SafeDownCast(d_func()->dataset)->GetOrigin();
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();
});
connect(d->enable_slicing_y, &dtkVisualizationWidgetsSliceControls::valueChanged, [=] (double value) {
double *origin;
origin = vtkImageData::SafeDownCast(d_func()->dataset)->GetOrigin();
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();
});
connect(d->enable_slicing_z, &dtkVisualizationWidgetsSliceControls::toggled, [=] (bool checked) {
connect(d->enable_slicing_z, &dtkVisualizationWidgetsSliceControls::toggled, [=] (bool checked)
{
d->volume_slice_z->SetEnabled(checked);
this->draw();
});
connect(d->enable_slicing_z, &dtkVisualizationWidgetsSliceControls::reset, [=] () {
double *origin;
origin = vtkImageData::SafeDownCast(d_func()->dataset)->GetOrigin();
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();
});
connect(d->enable_slicing_z, &dtkVisualizationWidgetsSliceControls::valueChanged, [=] (double value) {
double *origin;
origin = vtkImageData::SafeDownCast(d_func()->dataset)->GetOrigin();
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();
});
......@@ -303,7 +318,8 @@ void dtkVisualizationDecoratorSlices::setData(const QVariant& data)
d_func()->clear();
return;
}
d->c2p_filter->SetInputData(dataset);
d->input_image->ShallowCopy(dataset);
this->restoreSettings();
d_func()->sortEligibleFields();
......@@ -343,8 +359,8 @@ void dtkVisualizationDecoratorSlices::setCanvas(dtkVisualizationCanvas *canvas)
void dtkVisualizationDecoratorSlices::unsetCanvas(void)
{
if (d_func()->view) {
// d_func()->view->renderer()->RemoveActor(d->actor);
if (!d_func()->view) {
return;
}
d->volume_slice_x->SetInteractor(nullptr);
......@@ -376,6 +392,12 @@ void dtkVisualizationDecoratorSlices::restoreSettings(void)
void dtkVisualizationDecoratorSlices::touch(void)
{
// Need to update slices positions before calling parent touch to ensure drawing slices at the right positions.
double *origin = d->input_image->GetOrigin();
d->volume_slice_x->SetSlicePosition(d->enable_slicing_x->value() + origin[0]);
d->volume_slice_y->SetSlicePosition(d->enable_slicing_y->value() + origin[1]);
d->volume_slice_z->SetSlicePosition(d->enable_slicing_z->value() + origin[2]);
dtkVisualizationDecoratorWithClut::touch();
}
......@@ -393,29 +415,25 @@ bool dtkVisualizationDecoratorSlices::setCurrentFieldName(const QString& field_n
if(!d_func()->eligible_field_names.contains(field_name)) {
dtkWarn() << Q_FUNC_INFO << "The field name :" << field_name << "that was specified doesn't match any of the eligible scalar field names";
return false;
}
using Support = dtkVisualizationDecoratorWithClut::Support;
int support = d_func()->supports[field_name];
if(support == Support::Point) {
d->volume_slice_x->SetInputData(d_func()->dataset);
d->volume_slice_y->SetInputData(d_func()->dataset);
d->volume_slice_z->SetInputData(d_func()->dataset);
d->input_image->GetPointData()->SetActiveScalars(qPrintable(field_name));
d->volume_slice_x->SetInputData(d->input_image);
d->volume_slice_y->SetInputData(d->input_image);
d->volume_slice_z->SetInputData(d->input_image);
} else if(support == Support::Cell) {
d->c2p_filter->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_CELLS, qPrintable(field_name));
d->volume_slice_x->SetInputConnection(d->c2p_filter->GetOutputPort());
d->volume_slice_y->SetInputConnection(d->c2p_filter->GetOutputPort());
d->volume_slice_z->SetInputConnection(d->c2p_filter->GetOutputPort());
d->c2p_filter->Modified();
}
d->volume_slice_x->SetSlicePosition(d->enable_slicing_x->value());
d->volume_slice_y->SetSlicePosition(d->enable_slicing_y->value());
d->volume_slice_z->SetSlicePosition(d->enable_slicing_z->value());
return dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name);
d->input_image->GetCellData()->SetActiveScalars(qPrintable(field_name));
d->c2p_filter->Modified();
d->volume_slice_x->SetInputConnection(d->c2p_filter->GetOutputPort());
d->volume_slice_y->SetInputConnection(d->c2p_filter->GetOutputPort());
d->volume_slice_z->SetInputConnection(d->c2p_filter->GetOutputPort());
}
return dtkVisualizationDecoratorWithClut::setCurrentFieldName(field_name);
}
void dtkVisualizationDecoratorSlices::setColorMap(const QMap<double, QColor>& new_colormap)
......@@ -423,8 +441,13 @@ void dtkVisualizationDecoratorSlices::setColorMap(const QMap<double, QColor>& ne
dtkVisualizationDecoratorWithClut::setColorMap(new_colormap);
d->volume_slice_x->GetColorMap()->SetLookupTable(d_func()->color_function);
d->volume_slice_x->GetColorMap()->Modified();
d->volume_slice_y->GetColorMap()->SetLookupTable(d_func()->color_function);
d->volume_slice_y->GetColorMap()->Modified();
d->volume_slice_z->GetColorMap()->SetLookupTable(d_func()->color_function);
d->volume_slice_z->GetColorMap()->Modified();
}
//
......
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