Browse Source

Expose chartsExtent and chartsBounds to ctkVTKChartView

The extent is the current viewed area on the chart
Julien Finet 13 years ago
parent
commit
b598e3c64c

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

@@ -88,6 +88,12 @@ void ctkVTKChartViewPrivate::init()
 #endif
 #endif
   this->Chart->SetActionToButton(vtkChart::PAN, vtkContextMouseEvent::MIDDLE_BUTTON);
   this->Chart->SetActionToButton(vtkChart::PAN, vtkContextMouseEvent::MIDDLE_BUTTON);
   this->Chart->SetActionToButton(vtkChart::SELECT, vtkContextMouseEvent::RIGHT_BUTTON);
   this->Chart->SetActionToButton(vtkChart::SELECT, vtkContextMouseEvent::RIGHT_BUTTON);
+
+  q->qvtkConnect(q->chart()->GetAxis(vtkAxis::BOTTOM),vtkCommand::ModifiedEvent,
+                    q, SIGNAL(extentChanged()));
+  q->qvtkConnect(q->chart()->GetAxis(vtkAxis::LEFT),vtkCommand::ModifiedEvent,
+                    q, SIGNAL(extentChanged()));
+
 }
 }
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
@@ -239,6 +245,28 @@ void ctkVTKChartView::onChartUpdated()
     }
     }
 }
 }
 
 
+
+// ----------------------------------------------------------------------------
+void ctkVTKChartView::chartExtent(double* extent)const
+{
+  Q_D(const ctkVTKChartView);
+  extent[0] = extent[2] = extent[4] = extent[6] = VTK_DOUBLE_MAX;
+  extent[1] = extent[3] = extent[5] = extent[7] = VTK_DOUBLE_MIN;
+  vtkChartXY* chart = this->chart();
+  vtkAxis* axis = chart->GetAxis(vtkAxis::BOTTOM);
+  extent[0] = qMin(axis->GetMinimum(), extent[0]);
+  extent[1] = qMax(axis->GetMaximum(), extent[1]);
+  axis = chart->GetAxis(vtkAxis::LEFT);
+  extent[2] = qMin(axis->GetMinimum(), extent[2]);
+  extent[3] = qMax(axis->GetMaximum(), extent[3]);
+  axis = chart->GetAxis(vtkAxis::TOP);
+  extent[4] = qMin(axis->GetMinimum(), extent[4]);
+  extent[5] = qMax(axis->GetMaximum(), extent[5]);
+  axis = chart->GetAxis(vtkAxis::RIGHT);
+  extent[6] = qMin(axis->GetMinimum(), extent[6]);
+  extent[7] = qMax(axis->GetMaximum(), extent[7]);
+}
+
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 void ctkVTKChartView::chartBounds(double* bounds)const
 void ctkVTKChartView::chartBounds(double* bounds)const
 {
 {

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

@@ -22,7 +22,7 @@
 #define __ctkVTKChartView_h
 #define __ctkVTKChartView_h
 
 
 // CTK includes
 // CTK includes
-#include <ctkPimpl.h>
+#include <ctkVTKObject.h>
 #include "ctkVisualizationVTKWidgetsExport.h"
 #include "ctkVisualizationVTKWidgetsExport.h"
 class ctkVTKChartViewPrivate;
 class ctkVTKChartViewPrivate;
 
 
@@ -36,6 +36,7 @@ class vtkPlot;
 class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKChartView : public QVTKWidget
 class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKChartView : public QVTKWidget
 {
 {
   Q_OBJECT
   Q_OBJECT
+  QVTK_OBJECT
   Q_PROPERTY(QString title READ title WRITE setTitle)
   Q_PROPERTY(QString title READ title WRITE setTitle)
 
 
 public:
 public:
@@ -55,11 +56,17 @@ public:
   QString title()const;
   QString title()const;
   void setTitle(const QString& title);
   void setTitle(const QString& title);
 
 
+  /// Return the chart extent for the 4 chart axes.
+  /// extent must be an array of 8 doubles
+  /// The current extent is the visible area on the chart.
+  /// it is equivalent to the Minimum/Maximum of the axes
+  void chartExtent(double bounds[8])const;
+
   /// Return the chart bounds for the 4 chart axes.
   /// Return the chart bounds for the 4 chart axes.
   /// bounds must be an array of 8 doubles.
   /// bounds must be an array of 8 doubles.
   /// If no bounds is provided by the user, compute the bounds for the 4 chart
   /// If no bounds is provided by the user, compute the bounds for the 4 chart
   /// axes from the vtkPlots bounds.
   /// axes from the vtkPlots bounds.
-  void chartBounds(double* bounds)const;
+  void chartBounds(double bounds[8])const;
   void setChartUserBounds(double* bounds);
   void setChartUserBounds(double* bounds);
   void chartUserBounds(double* bounds)const;
   void chartUserBounds(double* bounds)const;
 
 
@@ -69,7 +76,10 @@ public:
 
 
 signals:
 signals:
   void plotAdded(vtkPlot* plot);
   void plotAdded(vtkPlot* plot);
+  /// Fired anytime the bound of a plot modifies the overal bounds
   void boundsChanged();
   void boundsChanged();
+  /// Fired anytime an axis is modified.
+  void extentChanged();
 
 
 protected:
 protected:
   QScopedPointer<ctkVTKChartViewPrivate> d_ptr;
   QScopedPointer<ctkVTKChartViewPrivate> d_ptr;

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

@@ -119,10 +119,8 @@ void ctkVTKScalarsToColorsWidgetPrivate::setupUi(QWidget* widget)
   QObject::connect(this->YRangeSlider, SIGNAL(valuesChanged(double,double)),
   QObject::connect(this->YRangeSlider, SIGNAL(valuesChanged(double,double)),
                    q, SIGNAL(axesModified()));
                    q, SIGNAL(axesModified()));
 
 
-  q->qvtkConnect(this->View->chart()->GetAxis(0),vtkCommand::ModifiedEvent,
-                    q, SLOT(onAxesModified()));
-  q->qvtkConnect(this->View->chart()->GetAxis(1),vtkCommand::ModifiedEvent,
-                    q, SLOT(onAxesModified()));
+  QObject::connect(this->View, SIGNAL(extentChanged()),
+                   q, SLOT(onAxesModified()));
 
 
   this->ExpandButton->setMirrorOnExpand(true);
   this->ExpandButton->setMirrorOnExpand(true);
   QObject::connect(this->ExpandButton, SIGNAL(clicked(bool)),
   QObject::connect(this->ExpandButton, SIGNAL(clicked(bool)),

+ 41 - 0
Libs/Visualization/VTK/Widgets/ctkVTKVolumePropertyWidget.cpp

@@ -89,6 +89,9 @@ void ctkVTKVolumePropertyWidgetPrivate::setupUi(QWidget* widget)
   this->ScalarColorWidget->view()->setValidBounds(validBounds);
   this->ScalarColorWidget->view()->setValidBounds(validBounds);
   this->GradientWidget->view()->setValidBounds(validBounds);
   this->GradientWidget->view()->setValidBounds(validBounds);
 
 
+  QObject::connect(this->ScalarOpacityWidget->view(), SIGNAL(extentChanged()),
+                   q, SIGNAL(chartsExtentChanged()));
+
   this->ScalarOpacityWidget->view()->addCompositeFunction(0, 0, true, true);
   this->ScalarOpacityWidget->view()->addCompositeFunction(0, 0, true, true);
   vtkCompositeControlPointsItem* composite = 
   vtkCompositeControlPointsItem* composite = 
   vtkCompositeControlPointsItem::SafeDownCast(
   vtkCompositeControlPointsItem::SafeDownCast(
@@ -295,6 +298,44 @@ void ctkVTKVolumePropertyWidget::updateRange()
 }
 }
 
 
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::chartsBounds(double bounds[4])const
+{
+  Q_D(const ctkVTKVolumePropertyWidget);
+  double chartBounds[4];
+  d->ScalarOpacityWidget->view()->chartBounds(chartBounds);
+  memcpy(bounds, chartBounds, 4*sizeof(double));
+  d->ScalarColorWidget->view()->chartBounds(chartBounds);
+  bounds[0] = qMin(bounds[0], chartBounds[0]);
+  bounds[1] = qMax(bounds[1], chartBounds[1]);
+  bounds[2] = qMin(bounds[2], chartBounds[2]);
+  bounds[3] = qMax(bounds[3], chartBounds[3]);
+  //d->GradientWidget->view()->chartBounds(chartBounds);
+  //bounds[0] = qMin(bounds[0], chartBounds[0]);
+  //bounds[1] = qMax(bounds[1], chartBounds[1]);
+  //bounds[2] = qMin(bounds[2], chartBounds[2]);
+  //bounds[3] = qMax(bounds[3], chartBounds[3]);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::chartsExtent(double extent[4])const
+{
+  Q_D(const ctkVTKVolumePropertyWidget);
+  double chartExtent[8];
+  d->ScalarOpacityWidget->view()->chartExtent(chartExtent);
+  memcpy(extent, chartExtent, 4*sizeof(double));
+  d->ScalarColorWidget->view()->chartExtent(chartExtent);
+  extent[0] = qMin(extent[0], chartExtent[0]);
+  extent[1] = qMax(extent[1], chartExtent[1]);
+  extent[2] = qMin(extent[2], chartExtent[2]);
+  extent[3] = qMax(extent[3], chartExtent[3]);
+  //d->GradientWidget->view()->chartExtent(chartExtent);
+  //extent[0] = qMin(extent[0], chartExtent[0]);
+  //extent[1] = qMin(extent[1], chartExtent[1]);
+  //extent[2] = qMin(extent[2], chartExtent[2]);
+  //extent[3] = qMin(extent[3], chartExtent[3]);
+}
+
+// ----------------------------------------------------------------------------
 void ctkVTKVolumePropertyWidget::setInterpolationMode(int mode)
 void ctkVTKVolumePropertyWidget::setInterpolationMode(int mode)
 {
 {
   Q_D(ctkVTKVolumePropertyWidget);
   Q_D(ctkVTKVolumePropertyWidget);

+ 7 - 0
Libs/Visualization/VTK/Widgets/ctkVTKVolumePropertyWidget.h

@@ -57,6 +57,9 @@ public:
 
 
   bool hasThresholdVisibilityToggle()const;
   bool hasThresholdVisibilityToggle()const;
   void setThresholdVisibilityToggle(bool showToggle);
   void setThresholdVisibilityToggle(bool showToggle);
+
+  void chartsBounds(double bounds[4])const;
+  void chartsExtent(double extent[4])const;
 public slots:
 public slots:
   void setVolumeProperty(vtkVolumeProperty* volumeProperty);
   void setVolumeProperty(vtkVolumeProperty* volumeProperty);
 
 
@@ -73,6 +76,10 @@ public slots:
   void spreadAllPoints(double factor = 1.);
   void spreadAllPoints(double factor = 1.);
 
 
   void showThreshold(bool enable);
   void showThreshold(bool enable);
+
+signals:
+  void chartsExtentChanged();
+
 protected slots:
 protected slots:
   void updateFromVolumeProperty();
   void updateFromVolumeProperty();
   void updateRange();
   void updateRange();