Forráskód Böngészése

Merge branch 'ctkVTKScalarsToColorsView-exclude-firstandlast'

* ctkVTKScalarsToColorsView-exclude-firstandlast:
  Fix threshold unique points
  Fix the computed range of ctkVTKVolumePropertyWidget
  Add dontMoveFirstAndLast to ctkVTKScalarsToColorsView::MovePoints
Julien Finet 13 éve
szülő
commit
b249566af6

+ 6 - 8
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.cpp

@@ -587,24 +587,22 @@ void ctkVTKScalarsToColorsView::boundAxesToChartBounds()
 }
 
 // ----------------------------------------------------------------------------
-void ctkVTKScalarsToColorsView::moveAllPoints(double xOffset, double yOffset)
+void ctkVTKScalarsToColorsView::moveAllPoints(double xOffset, double yOffset,
+                                              bool dontMoveFirstAndLast)
 {
   vtkVector2f offset(xOffset, yOffset);
   foreach(vtkControlPointsItem* controlPointsItem, this->controlPointsItems())
     {
-    vtkSmartPointer<vtkIdTypeArray> ids;
-    ids.TakeReference(controlPointsItem->GetControlPointsIds());
-    controlPointsItem->MovePoints(offset, ids.GetPointer());
+    controlPointsItem->MovePoints(offset, dontMoveFirstAndLast);
     }
 }
 
 // ----------------------------------------------------------------------------
-void ctkVTKScalarsToColorsView::spreadAllPoints(double factor)
+void ctkVTKScalarsToColorsView::spreadAllPoints(double factor,
+                                                bool dontSpreadFirstAndLast)
 {
   foreach(vtkControlPointsItem* controlPointsItem, this->controlPointsItems())
     {
-    vtkSmartPointer<vtkIdTypeArray> ids;
-    ids.TakeReference(controlPointsItem->GetControlPointsIds());\
-    controlPointsItem->SpreadPoints(factor, ids.GetPointer());
+    controlPointsItem->SpreadPoints(factor, dontSpreadFirstAndLast);
     }
 }

+ 4 - 2
Libs/Visualization/VTK/Widgets/ctkVTKScalarsToColorsView.h

@@ -98,13 +98,15 @@ public slots:
 
   /// Move all the control points by a given offset.
   /// \sa vtkControlPoints::movePoints()
-  void moveAllPoints(double xOffset, double yOffset = 0.);
+  void moveAllPoints(double xOffset, double yOffset = 0.,
+                     bool dontMoveFirstAndLast = false);
 
   /// Spread all the control points by a given offset.
   /// A value >0 will space the control points, a value <0. will contract
   /// them.
   /// \sa vtkControlPoints::spreadPoints()
-  void spreadAllPoints(double factor = 1.);
+  void spreadAllPoints(double factor = 1.,
+                       bool dontMoveFirstAndLast = false);
 
 protected slots:
   void onBoundsChanged();

+ 16 - 1
Libs/Visualization/VTK/Widgets/ctkVTKThresholdWidget.cpp

@@ -57,6 +57,7 @@ protected:
   void setNodes(double nodeValues[][4], const int nodeCount);
   void setNodeValue(int index, double* nodeValue);
   double safeX(double value, double& previous)const;
+  static double nextHigher(double value);
 };
 
 // ----------------------------------------------------------------------------
@@ -139,6 +140,20 @@ void ctkVTKThresholdWidgetPrivate::setRange(double min, double max)
   this->ThresholdSliderWidget->blockSignals(wasBlocking);
 }
 
+//----------------------------------------------------------------------------
+double ctkVTKThresholdWidgetPrivate::nextHigher(double value)
+{
+  // Increment the value by the smallest offset possible
+  typedef union {
+      long long i64;
+      double d64;
+    } dbl_64;
+  dbl_64 d;
+  d.d64 = value;
+  d.i64 += (value >= 0) ? 1 : -1;
+  return d.d64;
+}
+
 // ----------------------------------------------------------------------------
 double ctkVTKThresholdWidgetPrivate::safeX(double value, double& previous)const
 {
@@ -148,7 +163,7 @@ double ctkVTKThresholdWidgetPrivate::safeX(double value, double& previous)const
     }
   if (value == previous && !this->PiecewiseFunction->GetAllowDuplicateScalars())
     {
-    value += 0.00000000000001;
+    value = this->nextHigher(value);
     }
   previous = value;
   return value;

+ 21 - 11
Libs/Visualization/VTK/Widgets/ctkVTKVolumePropertyWidget.cpp

@@ -140,13 +140,15 @@ void ctkVTKVolumePropertyWidgetPrivate::setupUi(QWidget* widget)
 // ----------------------------------------------------------------------------
 void ctkVTKVolumePropertyWidgetPrivate::computeRange(double* range)
 {
-  range[0] = 0.;
-  range[1] = 1.;
-
   if (!this->VolumeProperty)
     {
+    range[0] = 0.;
+    range[1] = 1.;
     return;
     }
+  range[0] = VTK_DOUBLE_MAX;
+  range[1] = VTK_DOUBLE_MIN;
+
   Q_ASSERT(this->VolumeProperty->GetRGBTransferFunction(this->CurrentComponent));
   Q_ASSERT(this->VolumeProperty->GetScalarOpacity(this->CurrentComponent));
   Q_ASSERT(this->VolumeProperty->GetGradientOpacity(this->CurrentComponent));
@@ -470,16 +472,20 @@ void ctkVTKVolumePropertyWidget::onAxesModified()
 }
 
 // ----------------------------------------------------------------------------
-void ctkVTKVolumePropertyWidget::moveAllPoints(double xOffset, double yOffset)
+void ctkVTKVolumePropertyWidget::moveAllPoints(double xOffset, double yOffset,
+                                               bool dontMoveFirstAndLast)
 {
   Q_D(ctkVTKVolumePropertyWidget);
   if (d->VolumeProperty)
     {
     d->VolumeProperty->InvokeEvent(vtkCommand::StartEvent);
     }
-  d->ScalarOpacityWidget->view()->moveAllPoints(xOffset, yOffset);
-  d->ScalarColorWidget->view()->moveAllPoints(xOffset, yOffset);
-  d->GradientWidget->view()->moveAllPoints(xOffset, yOffset);
+  d->ScalarOpacityWidget->view()
+    ->moveAllPoints(xOffset, yOffset, dontMoveFirstAndLast);
+  d->ScalarColorWidget->view()
+    ->moveAllPoints(xOffset, yOffset, dontMoveFirstAndLast);
+  d->GradientWidget->view()
+    ->moveAllPoints(xOffset, yOffset, dontMoveFirstAndLast);
   if (d->VolumeProperty)
     {
     d->VolumeProperty->InvokeEvent(vtkCommand::EndEvent);
@@ -487,12 +493,16 @@ void ctkVTKVolumePropertyWidget::moveAllPoints(double xOffset, double yOffset)
 }
 
 // ----------------------------------------------------------------------------
-void ctkVTKVolumePropertyWidget::spreadAllPoints(double factor)
+void ctkVTKVolumePropertyWidget::spreadAllPoints(double factor,
+                                                 bool dontSpreadFirstAndLast)
 {
   Q_D(ctkVTKVolumePropertyWidget);
   d->VolumeProperty->InvokeEvent(vtkCommand::StartEvent);
-  d->ScalarOpacityWidget->view()->spreadAllPoints(factor);
-  d->ScalarColorWidget->view()->spreadAllPoints(factor);
-  d->GradientWidget->view()->spreadAllPoints(factor);
+  d->ScalarOpacityWidget->view()
+    ->spreadAllPoints(factor, dontSpreadFirstAndLast);
+  d->ScalarColorWidget->view()
+    ->spreadAllPoints(factor, dontSpreadFirstAndLast);
+  d->GradientWidget->view()
+    ->spreadAllPoints(factor, dontSpreadFirstAndLast);
   d->VolumeProperty->InvokeEvent(vtkCommand::EndEvent);
 }

+ 4 - 2
Libs/Visualization/VTK/Widgets/ctkVTKVolumePropertyWidget.h

@@ -66,14 +66,16 @@ public slots:
   /// Move all the control points of the opacity, colors and gradient
   /// of a give offset.
   /// \sa vtkControlPoints::movePoints()
-  void moveAllPoints(double xOffset, double yOffset = 0.);
+  void moveAllPoints(double xOffset, double yOffset = 0.,
+                     bool dontSpreadFirstAndLast = false);
 
   /// Spread all the control points of the opacity, colors and gradient
   /// by a given offset.
   /// A value >0 will space the control points, a value <0. will contract
   /// them.
   /// \sa vtkControlPoints::spreadPoints()
-  void spreadAllPoints(double factor = 1.);
+  void spreadAllPoints(double factor = 1.,
+                       bool dontSpreadFirstAndLast = false);
 
   void showThreshold(bool enable);