Explorar o código

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 %!s(int64=13) %!d(string=hai) anos
pai
achega
6861053239
Modificáronse 1 ficheiros con 16 adicións e 1 borrados
  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;