Pārlūkot izejas kodu

BUG: ctkVTKTransferFunction... fix optimization issue.
The next value was used to know if the sharpness is 0

Julien Finet 15 gadi atpakaļ
vecāks
revīzija
cabbd58f8b

+ 14 - 17
Libs/Visualization/VTK/Core/ctkVTKColorTransferFunction.cpp

@@ -177,23 +177,21 @@ ctkControlPoint* ctkVTKColorTransferFunction::controlPoint(int index)const
   ctkNonLinearControlPoint* cp = new ctkNonLinearControlPoint();
   cp->P.X = values[0];
   cp->P.Value = rgb;
+  double nextValues[6];
+  d->ColorTransferFunction->GetNodeValue(index + 1, nextValues);
+  Q_ASSERT(nextValues[0] >= d->ColorTransferFunction->GetRange()[0] &&
+           nextValues[0] <= d->ColorTransferFunction->GetRange()[1] &&
+           nextValues[1] >= 0. && nextValues[1] <= 1. &&  // Red
+           nextValues[2] >= 0. && nextValues[2] <= 1. &&  // Green
+           nextValues[3] >= 0. && nextValues[3] <= 1. &&  // Blue
+           nextValues[4] >= 0. && nextValues[4] <= 1. &&  // MidPoint
+           nextValues[5] >= 0. && nextValues[5] <= 1.);   // Sharpness
   // Optimization: don't use SubPoints when the sharpness is 0.
   if (values[5] == 0.)
     {
     cp->SubPoints << ctkPoint(values[0], rgb);
-    } 
-  d->ColorTransferFunction->GetNodeValue(index + 1, values);
-  Q_ASSERT(values[0] >= d->ColorTransferFunction->GetRange()[0] &&
-           values[0] <= d->ColorTransferFunction->GetRange()[1] &&
-           values[1] >= 0. && values[1] <= 1. &&  // Red
-           values[2] >= 0. && values[2] <= 1. &&  // Green
-           values[3] >= 0. && values[3] <= 1. &&  // Blue
-           values[4] >= 0. && values[4] <= 1. &&  // MidPoint
-           values[5] >= 0. && values[5] <= 1.);   // Sharpness
-  // Optimization: don't use SubPoints when the sharpness is 0.
-  if (values[5] == 0.)
-    {
-    cp->SubPoints << ctkPoint(values[0], rgb);
+    rgb = QColor::fromRgbF(nextValues[1], nextValues[2], nextValues[3]);
+    cp->SubPoints << ctkPoint(nextValues[0], rgb);
     return cp;
     } 
   double subPoints[30];
@@ -201,10 +199,9 @@ ctkControlPoint* ctkVTKColorTransferFunction::controlPoint(int index)const
   qreal interval = (values[0] - cp->x()) / 9.;
   for(int i = 0; i < 10; ++i)
     {
-    
-    QColor rgb = QColor::fromRgbF(subPoints[3*i], 
-                                  subPoints[3*i+1],
-                                  subPoints[3*i+2]);
+    rgb = QColor::fromRgbF(subPoints[3*i], 
+                           subPoints[3*i+1],
+                           subPoints[3*i+2]);
     cp->SubPoints << ctkPoint(cp->x() + interval*i, rgb);
     }
   return cp;

+ 9 - 8
Libs/Visualization/VTK/Core/ctkVTKPiecewiseFunction.cpp

@@ -168,21 +168,22 @@ ctkControlPoint* ctkVTKPiecewiseFunction::controlPoint(int index)const
     {
     cp->SubPoints << ctkPoint(values[0], values[1]);
     } 
-  d->PiecewiseFunction->GetNodeValue(index + 1, values);
+  double nextValues[4];
+  d->PiecewiseFunction->GetNodeValue(index + 1, nextValues);
 
-  Q_ASSERT(values[0] >= range[0] && values[0] <= range[1]  &&  // X
-           values[1] >= rangeY[0].toDouble() && values[1] <= rangeY[1].toDouble()  &&  // Y
-           values[2] >= 0. && values[2] <= 1. &&                // Midpoint
-           values[3] >= 0. && values[3] <= 1. );                // Sharpness
+  Q_ASSERT(nextValues[0] >= range[0] && nextValues[0] <= range[1]  &&  // X
+           nextValues[1] >= rangeY[0].toDouble() && nextValues[1] <= rangeY[1].toDouble()  &&  // Y
+           nextValues[2] >= 0. && nextValues[2] <= 1. &&                // Midpoint
+           nextValues[3] >= 0. && nextValues[3] <= 1. );                // Sharpness
   // Optimization: Don't use Subpoints if sharpness == 0
   if (values[3] == 0.)
     {
-    cp->SubPoints << ctkPoint(values[0], values[1]);
+    cp->SubPoints << ctkPoint(nextValues[0], nextValues[1]);
     return cp;
     }
   double subPoints[100];
-  d->PiecewiseFunction->GetTable(cp->x(), values[0], 100, subPoints);
-  qreal interval = (values[0] - cp->x()) / 99.;
+  d->PiecewiseFunction->GetTable(cp->x(), nextValues[0], 100, subPoints);
+  qreal interval = (nextValues[0] - cp->x()) / 99.;
 
   // subPoints[i] since value varies (not like in color transfer function widget)
   for(int i = 0; i < 100; ++i)