ソースを参照

Fix threshold unique points

The epsilon added to values in order to ensure uniqueness depends of the
fraction part of the double value.
The higher the number is, the higher the epsilon must be to be represented
in the fraction.
Julien Finet 13 年 前
コミット
6861053239
共有1 個のファイルを変更した16 個の追加1 個の削除を含む
  1. 16 1
      Libs/Visualization/VTK/Widgets/ctkVTKThresholdWidget.cpp

+ 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;