Quellcode durchsuchen

Fix the guess threshold in ctkVTKThresholdWidget

If the function was a threshold, guessThreshold returned different values
for the min, max and opacity.
min: the point before the first non null opacity point
max: the first point with an opacity lower than the previous point
opacity: the max  opacity between min and max.
Julien Finet vor 13 Jahren
Ursprung
Commit
a0cdf0514b
1 geänderte Dateien mit 10 neuen und 16 gelöschten Zeilen
  1. 10 16
      Libs/Visualization/VTK/Widgets/ctkVTKThresholdWidget.cpp

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

@@ -90,42 +90,36 @@ void ctkVTKThresholdWidgetPrivate::guessThreshold(double& min, double& max, doub
     {
     return;
     }
-  int minIndex; 
+  int minIndex;
+  // The min index is the point before the opacity is >0
   for (minIndex=0; minIndex < this->PiecewiseFunction->GetSize(); ++minIndex)
     {
     double node[4];
     this->PiecewiseFunction->GetNodeValue(minIndex, node);
     if (node[1] > 0.)
       {
-      min = node[0];
       opacity = node[1];
+      max = node[0];
       break;
       }
+    min = node[0];
     }
   if (minIndex == this->PiecewiseFunction->GetSize())
     {
     return;
     }
-  int maxIndex;
-  for (maxIndex = minIndex + 1;
-       maxIndex < this->PiecewiseFunction->GetSize();
-       ++maxIndex)
+  int maxIndex = minIndex + 1;
+  for (;maxIndex < this->PiecewiseFunction->GetSize(); ++maxIndex)
     {
     double node[4];
     this->PiecewiseFunction->GetNodeValue(maxIndex, node);
-    // average the opacities
-    opacity += node[1];
-    if (node[1] == 0.)
+    // use the max opacity
+    opacity = std::max(opacity, node[1]);
+    if (node[1] < opacity)
       {
-      max = node[0];
-      opacity /= maxIndex - minIndex + 1;
       break;
       }
-    }
-  // couldn't find the upper threshold value, use the upper range
-  if (maxIndex == this->PiecewiseFunction->GetSize())
-    {
-    opacity /= maxIndex - minIndex;
+    max = node[0];
     }
 }