Browse Source

ctkVTKChartView was not supporting user bounds correctly

Julien Finet 14 years ago
parent
commit
ce7c5a020a

+ 12 - 2
Libs/Visualization/VTK/Widgets/ctkVTKChartView.cpp

@@ -215,6 +215,7 @@ void ctkVTKChartView::addPlot(vtkPlot* plot)
 // ----------------------------------------------------------------------------
 void ctkVTKChartView::onChartUpdated()
 {
+  emit boundsChanged();
 }
 
 // ----------------------------------------------------------------------------
@@ -223,6 +224,7 @@ void ctkVTKChartView::chartBounds(double* bounds)const
   Q_D(const ctkVTKChartView);
   if (d->UserBounds[1] < d->UserBounds[0])
     {
+    // Invalid user bounds, return the real chart bounds
     d->chartBounds(bounds);
     return;
     }
@@ -237,7 +239,7 @@ void ctkVTKChartView::setChartUserBounds(double* userBounds)
     {
     d->UserBounds[i] = userBounds[i];
     }
-  emit boundsChanged();
+  this->onChartUpdated();
 }
 
 // ----------------------------------------------------------------------------
@@ -280,7 +282,15 @@ void ctkVTKChartView::boundAxesToChartBounds()
       chart->GetAxis(i)->SetMaximumLimit(bounds[2*i + 1]);
       }
     }
-  emit boundsChanged();
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKChartView::chartBoundsToPlotBounds(double bounds[8], double plotBounds[4])const
+{
+  plotBounds[0] = bounds[vtkAxis::BOTTOM*2];
+  plotBounds[1] = bounds[vtkAxis::BOTTOM*2 + 1];
+  plotBounds[2] = bounds[vtkAxis::LEFT*2];
+  plotBounds[3] = bounds[vtkAxis::LEFT*2+1];
 }
 
 // ----------------------------------------------------------------------------

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

@@ -64,7 +64,7 @@ public:
 
   /// 
   virtual void setAxesToChartBounds();
-  void boundAxesToChartBounds();
+  virtual void boundAxesToChartBounds();
 
 signals:
   void plotAdded(vtkPlot* plot);
@@ -72,8 +72,10 @@ signals:
 
 protected:
   QScopedPointer<ctkVTKChartViewPrivate> d_ptr;
+
   virtual void mouseDoubleClickEvent(QMouseEvent* event);
   virtual void onChartUpdated();
+  void chartBoundsToPlotBounds(double bounds[8], double plotBounds[4])const;
 
 private:
   Q_DECLARE_PRIVATE(ctkVTKChartView);

+ 10 - 7
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.cpp

@@ -108,9 +108,9 @@ void ctkVTKScalarsToColorsView::addPlot(vtkPlot* plot)
 // ----------------------------------------------------------------------------
 void ctkVTKScalarsToColorsView::onChartUpdated()
 {
-  this->Superclass::onChartUpdated();
   this->boundAxesToChartBounds();
   this->setAxesToChartBounds();
+  this->Superclass::onChartUpdated();
 }
 
 // ----------------------------------------------------------------------------
@@ -436,17 +436,19 @@ void ctkVTKScalarsToColorsView
 
 // ----------------------------------------------------------------------------
 void ctkVTKScalarsToColorsView
-::setUserBoundsToPlots(double* bounds)
+::setPlotsUserBounds(double* bounds)
 {
+  double plotBounds[4];
+  this->chartBoundsToPlotBounds(bounds, plotBounds);
   foreach(vtkScalarsToColorsItem* plot,
           this->plots<vtkScalarsToColorsItem>())
     {
-    plot->SetUserBounds(bounds);
+    plot->SetUserBounds(plotBounds);
     }
   foreach(vtkControlPointsItem* plot,
           this->plots<vtkControlPointsItem>())
     {
-    plot->SetUserBounds(bounds);
+    plot->SetUserBounds(plotBounds);
     }
 }
 
@@ -484,13 +486,14 @@ void ctkVTKScalarsToColorsView::editPoint(vtkObject* caller, void* callData)
 }
 
 // ----------------------------------------------------------------------------
-void ctkVTKScalarsToColorsView::setAxesToChartBounds()
+void ctkVTKScalarsToColorsView::boundAxesToChartBounds()
 {
-  vtkChartXY* chart = this->chart();
+  this->Superclass::boundAxesToChartBounds();
+  /// We only set the plot user bounds if the chart is using User bounds.
   double userBounds[8];
   this->chartUserBounds(userBounds);
   if (userBounds[0] < userBounds[1])
     {
-    this->setUserBoundsToPlots(userBounds);
+    this->setPlotsUserBounds(userBounds);
     }
 }

+ 3 - 3
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.h

@@ -75,11 +75,11 @@ public:
   void setColorTransferFunctionToPlots(vtkColorTransferFunction* colorTF);
   void setOpacityFunctionToPlots(vtkPiecewiseFunction* opacityTF);
   void setPiecewiseFunctionToPlots(vtkPiecewiseFunction* piecewiseTF);
-  
-  void setUserBoundsToPlots(double* bounds);
+
+  void setPlotsUserBounds(double* bounds);
 
   /// Reimplemented to set the bounds to the plots as well
-  virtual void setAxesToChartBounds();
+  virtual void boundAxesToChartBounds();
 public slots:
   void editPoint(vtkObject* plot, void * pointId);
 

+ 5 - 4
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsWidget.cpp

@@ -208,10 +208,11 @@ void ctkVTKScalarsToColorsWidget::onBoundsChanged()
   Q_D(ctkVTKScalarsToColorsWidget);
   double bounds[8];
   d->View->chartBounds(bounds);
-  d->XRangeSlider->setMinimum(bounds[vtkAxis::BOTTOM * 2]);
-  d->XRangeSlider->setMaximum(bounds[vtkAxis::BOTTOM * 2 + 1]);
-  d->YRangeSlider->setMinimum(bounds[vtkAxis::LEFT * 2]);
-  d->YRangeSlider->setMaximum(bounds[vtkAxis::LEFT * 2 + 1]);
+  /// The bounds have already been set to the axes in ctkVTKChartView::boundAxesToChartBounds()
+  d->XRangeSlider->setRange(bounds[vtkAxis::BOTTOM * 2],
+                            bounds[vtkAxis::BOTTOM * 2 + 1]);
+  d->YRangeSlider->setRange(bounds[vtkAxis::LEFT * 2],
+                            bounds[vtkAxis::LEFT * 2 + 1]);
 }
 
 // ----------------------------------------------------------------------------