浏览代码

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;