Fix an issue with casting a float to an int too soon

There was a case of bad casting where a Float32 that should be in the
range between 0 and 1 was cast to an Id and then multiplied by the size
of an array. The intention is to get a proportional index into the
array, but because the float was cast to an int first, you get either
the first or last index.

Instead, first cast the size of the array to a Float32, multiply it by
the fraction, and then cast back to an Id. That should give the desired
effect.
This commit is contained in:
Kenneth Moreland 2016-11-22 15:34:56 -07:00
parent 719a8bd35d
commit 02e37f4bc5

@ -221,7 +221,8 @@ public:
//normalize scalar //normalize scalar
finalScalar = (finalScalar - MinScalar) * InverseDeltaScalar; finalScalar = (finalScalar - MinScalar) * InverseDeltaScalar;
vtkm::Id colorIndex = static_cast<vtkm::Id>(finalScalar) * ColorMapSize; vtkm::Id colorIndex = static_cast<vtkm::Id>(
finalScalar * static_cast<vtkm::Float32>(ColorMapSize));
//colorIndex = vtkm::Min(ColorMapSize, vtkm::Max(0,colorIndex)); //colorIndex = vtkm::Min(ColorMapSize, vtkm::Max(0,colorIndex));
vtkm::Vec<vtkm::Float32,4> sampleColor = ColorMap.Get(colorIndex); vtkm::Vec<vtkm::Float32,4> sampleColor = ColorMap.Get(colorIndex);
//sampleColor[3] = .05f; //sampleColor[3] = .05f;