Sfoglia il codice sorgente

BUG: Fixed scalars to colors widget range issues

Fixes both bugs described in https://issues.slicer.org/view.php?id=4526
Csaba Pinter 7 anni fa
parent
commit
9ca8734881

+ 0 - 1
Libs/Visualization/VTK/Widgets/ctkVTKChartView.cpp

@@ -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);
       }
     }
 }

+ 1 - 1
Libs/Visualization/VTK/Widgets/ctkVTKChartView.h

@@ -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();

+ 4 - 0
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.cpp

@@ -442,6 +442,7 @@ void ctkVTKScalarsToColorsView::setLookuptTableToPlots(vtkLookupTable* lut)
     plot->SetLookupTable(lut);
     }
   this->onChartUpdated();
+  emit functionChanged();
 }
 
 // ----------------------------------------------------------------------------
@@ -459,6 +460,7 @@ void ctkVTKScalarsToColorsView
     plot->SetColorTransferFunction(colorTF);
     }
   this->onChartUpdated();
+  emit functionChanged();
 }
 
 // ----------------------------------------------------------------------------
@@ -477,6 +479,7 @@ void ctkVTKScalarsToColorsView
     plot->SetOpacityFunction(opacityTF);
     }
   this->onChartUpdated();
+  emit functionChanged();
 }
 
 // ----------------------------------------------------------------------------
@@ -494,6 +497,7 @@ void ctkVTKScalarsToColorsView
     plot->SetPiecewiseFunction(piecewiseTF);
     }
   this->onChartUpdated();
+  emit functionChanged();
 }
 
 // ----------------------------------------------------------------------------

+ 6 - 0
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.h

@@ -93,6 +93,12 @@ public:
   /// 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);
 

+ 33 - 1
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsWidget.cpp

@@ -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)),
@@ -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]);
@@ -550,6 +563,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()
 {
   Q_D(ctkVTKScalarsToColorsWidget);

+ 1 - 0
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsWidget.h

@@ -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