Skip to content

Commit

Permalink
BUG: Fixed scalars to colors widget range issues
Browse files Browse the repository at this point in the history
Fixes both bugs described in https://issues.slicer.org/view.php?id=4526
  • Loading branch information
cpinter authored and lassoan committed Apr 26, 2018
1 parent 773c7ce commit 9ca8734
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
1 change: 0 additions & 1 deletion Libs/Visualization/VTK/Widgets/ctkVTKChartView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ void ctkVTKChartView::setAxesToChartBounds()
if (bounds[2*i] != VTK_DOUBLE_MAX)
{
chart->GetAxis(i)->SetRange(bounds[2*i], bounds[2*i+1]);
//chart->GetAxis(i)->SetBehavior(2);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Libs/Visualization/VTK/Widgets/ctkVTKChartView.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Q_SLOTS:
Q_SIGNALS:
void plotAdded(vtkPlot* plot);
void plotRemoved(vtkPlot* plot);
/// Fired anytime the bound of a plot modifies the overal bounds
/// Fired anytime the bound of a plot modifies the overall bounds
void boundsChanged();
/// Fired anytime an axis is modified.
void extentChanged();
Expand Down
4 changes: 4 additions & 0 deletions Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ void ctkVTKScalarsToColorsView::setLookuptTableToPlots(vtkLookupTable* lut)
plot->SetLookupTable(lut);
}
this->onChartUpdated();
emit functionChanged();
}

// ----------------------------------------------------------------------------
Expand All @@ -459,6 +460,7 @@ ::setColorTransferFunctionToPlots(vtkColorTransferFunction* colorTF)
plot->SetColorTransferFunction(colorTF);
}
this->onChartUpdated();
emit functionChanged();
}

// ----------------------------------------------------------------------------
Expand All @@ -477,6 +479,7 @@ ::setOpacityFunctionToPlots(vtkPiecewiseFunction* opacityTF)
plot->SetOpacityFunction(opacityTF);
}
this->onChartUpdated();
emit functionChanged();
}

// ----------------------------------------------------------------------------
Expand All @@ -494,6 +497,7 @@ ::setPiecewiseFunctionToPlots(vtkPiecewiseFunction* piecewiseTF)
plot->SetPiecewiseFunction(piecewiseTF);
}
this->onChartUpdated();
emit functionChanged();
}

// ----------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKScalarsToColorsView
/// Reimplemented to set the bounds to the plots as well
virtual void boundAxesToChartBounds();

Q_SIGNALS:
/// Emitted when a new function is set to the view
/// \sa setLookuptTableToPlots, \sa setColorTransferFunctionToPlots,
/// \sa setOpacityFunctionToPlots, \sa setPiecewiseFunctionToPlots
void functionChanged();

public Q_SLOTS:
void editPoint(vtkObject* plot, void * pointId);

Expand Down
34 changes: 33 additions & 1 deletion Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ void ctkVTKScalarsToColorsWidgetPrivate::setupUi(QWidget* widget)
q, SLOT(onPlotAdded(vtkPlot*)));
QObject::connect(this->View, SIGNAL(boundsChanged()),
q, SLOT(onBoundsChanged()));
QObject::connect(this->View, SIGNAL(functionChanged()),
q, SLOT(resetRange()));

this->PointIdSpinBox->setSpecialValueText("None");
QObject::connect(this->PointIdSpinBox, SIGNAL(valueChanged(int)),
Expand Down Expand Up @@ -385,9 +387,20 @@ void ctkVTKScalarsToColorsWidget::updateCurrentPoint()
return;
}

double point[4];
double point[4] = {0.0};
d->CurrentControlPointsItem->GetControlPoint(pointId, point);

vtkAxis* xAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
Q_ASSERT(xAxis);
if (xAxis && xAxis->GetMinimumLimit() > point[0] || xAxis->GetMaximumLimit() < point[0])
{
xAxis->SetMinimumLimit(qMin(xAxis->GetMinimumLimit(), point[0]));
xAxis->SetMaximumLimit(qMax(xAxis->GetMaximumLimit(), point[0]));
d->View->boundAxesToChartBounds();
this->onAxesModified();
}

bool oldBlock = d->blockSignals(true);
d->XSpinBox->setValue(point[0]);
d->OpacitySpinBox->setValue(point[1]);
Expand Down Expand Up @@ -549,6 +562,25 @@ void ctkVTKScalarsToColorsWidget::setYRange(double min, double max)
}
}

// ----------------------------------------------------------------------------
void ctkVTKScalarsToColorsWidget::resetRange()
{
Q_D(ctkVTKScalarsToColorsWidget);
vtkAxis* xAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetXAxis() : d->View->chart()->GetAxis(vtkAxis::BOTTOM);
if (xAxis)
{
this->setXRange(xAxis->GetMinimumLimit(), xAxis->GetMaximumLimit());
}

vtkAxis* yAxis = d->CurrentControlPointsItem ?
d->CurrentControlPointsItem->GetYAxis() : d->View->chart()->GetAxis(vtkAxis::LEFT);
if (yAxis)
{
this->setYRange(yAxis->GetMinimumLimit(), yAxis->GetMaximumLimit());
}
}

// ----------------------------------------------------------------------------
void ctkVTKScalarsToColorsWidget::onAxesModified()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public Q_SLOTS:
void setCurrentPoint(int pointId);
void setXRange(double min, double max);
void setYRange(double min, double max);
void resetRange();

Q_SIGNALS:
/// Be carefull, axesModified() can be fired inside the Render() function
Expand Down

0 comments on commit 9ca8734

Please sign in to comment.