Browse Source

Add visibility button for threshold in ctkVTKVolumePropertyWidget

Julien Finet 13 years ago
parent
commit
16834dc0aa

+ 1 - 1
Libs/Visualization/VTK/Widgets/CMakeLists.txt

@@ -76,7 +76,7 @@ SET(KIT_UI_FORMS
 
 # Resources
 SET(KIT_resources
-
+  Resources/ctkVTKWidgets.qrc
 )
 
 # Set VTK_LIBRARIES variable

BIN
Libs/Visualization/VTK/Widgets/Resources/Icons/threshold.png


+ 5 - 0
Libs/Visualization/VTK/Widgets/Resources/ctkVTKWidgets.qrc

@@ -0,0 +1,5 @@
+<!DOCTYPE RCC><RCC version="1.0">
+  <qresource>
+    <file>Icons/threshold.png</file>
+  </qresource>
+</RCC>

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

@@ -60,6 +60,15 @@ public:
   void xRange(double* range)const;
   void yRange(double* range)const;
 
+  ///
+  /// Return the top-left corner widget if any.
+  QWidgetList extraWidgets()const;
+
+  ///
+  /// Add a widget in the top-left corner.
+  /// ctkVTKScalarsToColorsWidget takes ownership of the widget
+  void addExtraWidget(QWidget* extraWidget);
+
 public slots:
   void setCurrentControlPointsItem(vtkControlPointsItem* item);
   void setCurrentPoint(int pointId);

+ 38 - 4
Libs/Visualization/VTK/Widgets/ctkVTKVolumePropertyWidget.cpp

@@ -20,6 +20,7 @@
 
 // Qt includes
 #include <QDebug>
+#include <QToolButton>
 
 // CTK includes
 #include "ctkLogger.h"
@@ -61,6 +62,7 @@ public:
   
   vtkVolumeProperty* VolumeProperty;
   int                CurrentComponent;
+  QToolButton*       ShowOpacityThresholdWidgetButton;
 };
 
 // ----------------------------------------------------------------------------
@@ -95,6 +97,17 @@ void ctkVTKVolumePropertyWidgetPrivate::setupUi(QWidget* widget)
   composite->SetPointsFunction(vtkCompositeControlPointsItem::OpacityPointsFunction);
   this->ScalarColorWidget->view()->addColorTransferFunction(0);
   this->GradientWidget->view()->addPiecewiseFunction(0);
+
+  this->ShowOpacityThresholdWidgetButton = new QToolButton;
+  this->ShowOpacityThresholdWidgetButton->setIcon(
+    QIcon(":Icons/threshold.png"));
+  this->ShowOpacityThresholdWidgetButton->setCheckable(true);
+  this->ShowOpacityThresholdWidgetButton->setAutoRaise(true);
+  QObject::connect(this->ShowOpacityThresholdWidgetButton,
+                   SIGNAL(toggled(bool)),
+                   q, SLOT(onThresholdOpacityToggled(bool)));
+  this->ScalarOpacityWidget->addExtraWidget(
+    this->ShowOpacityThresholdWidgetButton);
   this->ScalarOpacityThresholdWidget->setVisible(false);
 
   QObject::connect(this->ScalarOpacityWidget, SIGNAL(axesModified()),
@@ -226,7 +239,7 @@ void ctkVTKVolumePropertyWidget::updateFromVolumeProperty()
       d->VolumeProperty->GetGradientOpacity() : 0;
     }
 
-  d->ScalarOpacityThresholdWidget->setPiecewiseFunction(this->useThresholdSlider() ? opacityFunction : 0);
+  d->ScalarOpacityThresholdWidget->setPiecewiseFunction(this->isThresholdVisible() ? opacityFunction : 0);
   
   d->ScalarOpacityWidget->view()->setOpacityFunctionToPlots(opacityFunction);
   d->ScalarOpacityWidget->view()->setColorTransferFunctionToPlots(colorTransferFunction);
@@ -317,7 +330,7 @@ void ctkVTKVolumePropertyWidget::setSpecularPower(double value)
 }
 
 // ----------------------------------------------------------------------------
-bool ctkVTKVolumePropertyWidget::useThresholdSlider()const
+bool ctkVTKVolumePropertyWidget::isThresholdVisible()const
 {
   Q_D(const ctkVTKVolumePropertyWidget);
   return d->ScalarOpacityThresholdWidget->isVisibleTo(
@@ -325,15 +338,36 @@ bool ctkVTKVolumePropertyWidget::useThresholdSlider()const
 }
 
 // ----------------------------------------------------------------------------
-void ctkVTKVolumePropertyWidget::setUseThresholdSlider(bool enable)
+void ctkVTKVolumePropertyWidget::showThreshold(bool enable)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  d->ShowOpacityThresholdWidgetButton->setChecked(enable);
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::onThresholdOpacityToggled(bool enable)
 {
   Q_D(ctkVTKVolumePropertyWidget);
   d->ScalarOpacityThresholdWidget->setVisible(enable);
-  d->ScalarOpacityWidget->setVisible(!enable);
   this->updateFromVolumeProperty();
 }
 
 // ----------------------------------------------------------------------------
+bool ctkVTKVolumePropertyWidget::hasThresholdVisibilityToggle()const
+{
+  Q_D(const ctkVTKVolumePropertyWidget);
+  return d->ShowOpacityThresholdWidgetButton->isVisibleTo(
+    const_cast<ctkVTKVolumePropertyWidget*>(this));
+}
+
+// ----------------------------------------------------------------------------
+void ctkVTKVolumePropertyWidget::setThresholdVisibilityToggle(bool showToggle)
+{
+  Q_D(ctkVTKVolumePropertyWidget);
+  d->ShowOpacityThresholdWidgetButton->setVisible(showToggle);
+}
+
+// ----------------------------------------------------------------------------
 void ctkVTKVolumePropertyWidget::onAxesModified()
 {
   Q_D(ctkVTKVolumePropertyWidget);

+ 11 - 3
Libs/Visualization/VTK/Widgets/ctkVTKVolumePropertyWidget.h

@@ -40,7 +40,12 @@ class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKVolumePropertyWidget
   ///
   /// Control wether a range slider widget is used to edit the opacity
   /// function instead of a chart editor. False by default
-  Q_PROPERTY(bool useThresholdSlider READ useThresholdSlider WRITE setUseThresholdSlider)
+  Q_PROPERTY(bool thresholdVisibility READ isThresholdVisible WRITE showThreshold)
+
+  ///
+  /// Show or hide the opacity threshold slider toggle button.
+  /// True by default.
+  Q_PROPERTY(bool thresholdVisibilityToggle READ hasThresholdVisibilityToggle WRITE setThresholdVisibilityToggle)
 
 public:
   ctkVTKVolumePropertyWidget(QWidget* parent = 0);
@@ -48,9 +53,10 @@ public:
 
   vtkVolumeProperty* volumeProperty()const;
 
-  bool useThresholdSlider()const;
-  void setUseThresholdSlider(bool enable);
+  bool isThresholdVisible()const;
 
+  bool hasThresholdVisibilityToggle()const;
+  void setThresholdVisibilityToggle(bool showToggle);
 public slots:
   void setVolumeProperty(vtkVolumeProperty* volumeProperty);
 
@@ -66,6 +72,7 @@ public slots:
   /// \sa vtkControlPoints::spreadPoints()
   void spreadAllPoints(double factor = 1.);
 
+  void showThreshold(bool enable);
 protected slots:
   void updateFromVolumeProperty();
 
@@ -76,6 +83,7 @@ protected slots:
   void setSpecular(double value);
   void setSpecularPower(double value);
   
+  void onThresholdOpacityToggled(bool);
   /// Called whenever a view (opacity, colors or gradient) has one of its axis
   /// modified. It synchronize all the views to see the same.
   void onAxesModified();