Commit eb682c79 authored by Larsen, Matthew's avatar Larsen, Matthew Committed by Kitware Robot
Browse files

Merge topic 'wireframer_divide_by_zero_fix'

ffdb33f7 follow coding conventions
a778af8b make scalar normilization consistent across rendering
168952a0

 correct a potential divide by zero
Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarKenneth Moreland <kmorel@acm.org>
Merge-request: !2435
parents a42bb1b0 ffdb33f7
......@@ -181,8 +181,17 @@ public:
, FrameBuffer(frameBuffer.PrepareForExecution(DeviceTag(), token))
, FieldMin(vtkm::Float32(fieldRange.Min))
{
InverseFieldDelta = 1.0f / vtkm::Float32(fieldRange.Length());
Offset = vtkm::Max(0.03f / vtkm::Float32(clippingRange.Length()), 0.0001f);
vtkm::Float32 fieldLength = vtkm::Float32(fieldRange.Length());
if (fieldLength == 0.f)
{
// constant color
this->InverseFieldDelta = 0.f;
}
else
{
this->InverseFieldDelta = 1.0f / fieldLength;
}
this->Offset = vtkm::Max(0.03f / vtkm::Float32(clippingRange.Length()), 0.0001f);
}
template <typename CoordinatesPortalType, typename ScalarFieldPortalType>
......@@ -327,10 +336,11 @@ private:
VTKM_EXEC vtkm::Vec4f_32 GetColor(vtkm::Float64 fieldValue) const
{
vtkm::Int32 colorIdx =
vtkm::Int32((vtkm::Float32(fieldValue) - FieldMin) * ColorMapSize * InverseFieldDelta);
colorIdx = vtkm::Min(vtkm::Int32(ColorMap.GetNumberOfValues() - 1), vtkm::Max(0, colorIdx));
return ColorMap.Get(colorIdx);
vtkm::Int32 colorIdx = vtkm::Int32((vtkm::Float32(fieldValue) - FieldMin) * this->ColorMapSize *
this->InverseFieldDelta);
colorIdx =
vtkm::Min(vtkm::Int32(this->ColorMap.GetNumberOfValues() - 1), vtkm::Max(0, colorIdx));
return this->ColorMap.Get(colorIdx);
}
VTKM_EXEC
......
......@@ -370,7 +370,7 @@ class GetScalar : public vtkm::worklet::WorkletMapField
{
private:
Precision MinScalar;
Precision invDeltaScalar;
Precision InvDeltaScalar;
bool Normalize;
public:
......@@ -383,17 +383,13 @@ public:
{
// support the scalar renderer
Normalize = false;
MinScalar = 0;
invDeltaScalar = 1;
this->InvDeltaScalar = Precision(0.f);
}
else
{
//Make sure the we don't divide by zero on
//something like an iso-surface
if (maxScalar - MinScalar != 0.f)
invDeltaScalar = 1.f / (maxScalar - MinScalar);
else
invDeltaScalar = 1.f / minScalar;
this->InvDeltaScalar = 1.f / (maxScalar - this->MinScalar);
}
}
typedef void ControlSignature(FieldIn, FieldInOut, WholeArrayIn, WholeArrayIn);
......@@ -413,7 +409,7 @@ public:
scalar = Precision(scalars.Get(pointId[0]));
if (Normalize)
{
scalar = (scalar - MinScalar) * invDeltaScalar;
scalar = (scalar - this->MinScalar) * this->InvDeltaScalar;
}
}
}; //class GetScalar
......
......@@ -357,7 +357,7 @@ class GetScalar : public vtkm::worklet::WorkletMapField
{
private:
Precision MinScalar;
Precision invDeltaScalar;
Precision InvDeltaScalar;
bool Normalize;
public:
......@@ -370,17 +370,13 @@ public:
{
// support the scalar renderer
Normalize = false;
MinScalar = 0;
invDeltaScalar = 1;
this->InvDeltaScalar = Precision(0.f);
}
else
{
//Make sure the we don't divide by zero on
//something like an iso-surface
if (maxScalar - MinScalar != 0.f)
invDeltaScalar = 1.f / (maxScalar - MinScalar);
else
invDeltaScalar = 1.f / minScalar;
this->InvDeltaScalar = 1.f / (maxScalar - MinScalar);
}
}
typedef void ControlSignature(FieldIn, FieldOut, WholeArrayIn, WholeArrayIn);
......@@ -400,7 +396,7 @@ public:
scalar = Precision(scalars.Get(pointId[0]));
if (Normalize)
{
scalar = (scalar - MinScalar) * invDeltaScalar;
scalar = (scalar - MinScalar) * this->InvDeltaScalar;
}
}
}; //class GetScalar
......
......@@ -248,7 +248,7 @@ class GetScalar : public vtkm::worklet::WorkletMapField
{
private:
Precision MinScalar;
Precision invDeltaScalar;
Precision InvDeltaScalar;
bool Normalize;
public:
......@@ -261,17 +261,13 @@ public:
{
// support the scalar renderer
Normalize = false;
MinScalar = 0;
invDeltaScalar = 1;
this->InvDeltaScalar = Precision(0.f);
}
else
{
//Make sure the we don't divide by zero on
//something like an iso-surface
if (maxScalar - MinScalar != 0.f)
invDeltaScalar = 1.f / (maxScalar - MinScalar);
else
invDeltaScalar = 1.f / minScalar;
this->InvDeltaScalar = 1.f / (maxScalar - this->MinScalar);
}
}
typedef void ControlSignature(FieldIn, FieldOut, WholeArrayIn, WholeArrayIn);
......@@ -290,7 +286,7 @@ public:
scalar = Precision(scalars.Get(pointId));
if (Normalize)
{
scalar = (scalar - MinScalar) * invDeltaScalar;
scalar = (scalar - this->MinScalar) * this->InvDeltaScalar;
}
}
}; //class GetScalar
......
......@@ -242,7 +242,7 @@ public:
{
private:
Precision MinScalar;
Precision invDeltaScalar;
Precision InvDeltaScalar;
bool Normalize;
public:
......@@ -254,18 +254,14 @@ public:
if (minScalar >= maxScalar)
{
// support the scalar renderer
Normalize = false;
MinScalar = 0;
invDeltaScalar = 1;
this->Normalize = false;
this->InvDeltaScalar = 1;
}
else
{
//Make sure the we don't divide by zero on
//something like an iso-surface
if (maxScalar - MinScalar != 0.f)
invDeltaScalar = 1.f / (maxScalar - MinScalar);
else
invDeltaScalar = 1.f / minScalar;
this->InvDeltaScalar = 1.f / (maxScalar - this->MinScalar);
}
}
typedef void ControlSignature(FieldIn,
......@@ -296,7 +292,7 @@ public:
//normalize
if (Normalize)
{
lerpedScalar = (lerpedScalar - MinScalar) * invDeltaScalar;
lerpedScalar = (lerpedScalar - this->MinScalar) * this->InvDeltaScalar;
}
}
}; //class LerpScalar
......@@ -306,7 +302,7 @@ public:
{
private:
Precision MinScalar;
Precision invDeltaScalar;
Precision InvDeltaScalar;
bool Normalize;
public:
......@@ -319,17 +315,13 @@ public:
{
// support the scalar renderer
Normalize = false;
MinScalar = 0;
invDeltaScalar = 1;
this->InvDeltaScalar = Precision(0.f);
}
else
{
//Make sure the we don't divide by zero on
//something like an iso-surface
if (maxScalar - MinScalar != 0.f)
invDeltaScalar = 1.f / (maxScalar - MinScalar);
else
invDeltaScalar = 1.f / minScalar;
this->InvDeltaScalar = 1.f / (maxScalar - this->MinScalar);
}
}
......@@ -352,7 +344,7 @@ public:
if (Normalize)
{
scalar = (scalar - MinScalar) * invDeltaScalar;
scalar = (scalar - this->MinScalar) * this->InvDeltaScalar;
}
}
}; //class LerpScalar
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment