浏览代码

Merge branch 'ctkvtkthresholdwidget-guessthreshold'

* ctkvtkthresholdwidget-guessthreshold:
  Fix the guess threshold in ctkVTKThresholdWidget
Julien Finet 13 年之前
父节点
当前提交
e6edd5b7a4
共有 1 个文件被更改,包括 10 次插入16 次删除
  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];
     }
 }