mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-08 03:18:58 +00:00
Merge topic 'avoid-fpe'
1b541bdd3 Avoid floating point exceptions in rendering code Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Manish Mathai <mmathai@uoregon.edu> Merge-request: !3154
This commit is contained in:
commit
7523f841b0
10
docs/changelog/avoid-rendering-fpe.md
Normal file
10
docs/changelog/avoid-rendering-fpe.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# Avoid floating point exceptions in rendering code
|
||||||
|
|
||||||
|
There were some places in the rendering code where floating point
|
||||||
|
exceptions (FPE) could happen under certain circumstances. Often we do not
|
||||||
|
care about invalid floating point operation in rendering as they often
|
||||||
|
occur in degenerate cases that don't contribute anyway. However,
|
||||||
|
simulations that might include VTK-m might turn on FPE to check their own
|
||||||
|
operations. In such cases, we don't want errant rendering arithmetic
|
||||||
|
causing an exception and bringing down the whole code. Thus, we turn on FPE
|
||||||
|
in some of our test platforms and avoid such operations in general.
|
@ -234,7 +234,9 @@ public:
|
|||||||
|
|
||||||
vtkm::Float32 dx = x2 - x1;
|
vtkm::Float32 dx = x2 - x1;
|
||||||
vtkm::Float32 dy = y2 - y1;
|
vtkm::Float32 dy = y2 - y1;
|
||||||
vtkm::Float32 gradient = (dx == 0.0) ? 1.0f : (dy / dx);
|
if (dx == 0.0)
|
||||||
|
dx = vtkm::Epsilon32(); // Avoid FPE
|
||||||
|
vtkm::Float32 gradient = dy / dx;
|
||||||
|
|
||||||
vtkm::Float32 xEnd = vtkm::Round(x1);
|
vtkm::Float32 xEnd = vtkm::Round(x1);
|
||||||
vtkm::Float32 yEnd = y1 + gradient * (xEnd - x1);
|
vtkm::Float32 yEnd = y1 + gradient * (xEnd - x1);
|
||||||
|
@ -418,7 +418,11 @@ public:
|
|||||||
normal[0] = (vtkm::Abs(vtkm::Abs(lp[0]) - 1.0f) <= eps) ? lp[0] : 0.0f;
|
normal[0] = (vtkm::Abs(vtkm::Abs(lp[0]) - 1.0f) <= eps) ? lp[0] : 0.0f;
|
||||||
normal[1] = (vtkm::Abs(vtkm::Abs(lp[1]) - 1.0f) <= eps) ? lp[1] : 0.0f;
|
normal[1] = (vtkm::Abs(vtkm::Abs(lp[1]) - 1.0f) <= eps) ? lp[1] : 0.0f;
|
||||||
normal[2] = (vtkm::Abs(vtkm::Abs(lp[2]) - 1.0f) <= eps) ? lp[2] : 0.0f;
|
normal[2] = (vtkm::Abs(vtkm::Abs(lp[2]) - 1.0f) <= eps) ? lp[2] : 0.0f;
|
||||||
vtkm::Normalize(normal);
|
Precision magSquared = vtkm::MagnitudeSquared(normal);
|
||||||
|
if (magSquared > eps)
|
||||||
|
{
|
||||||
|
normal = vtkm::RSqrt(magSquared) * normal;
|
||||||
|
}
|
||||||
|
|
||||||
// Flip normal if it is pointing the wrong way
|
// Flip normal if it is pointing the wrong way
|
||||||
if (vtkm::Dot(normal, rayDir) > 0.0f)
|
if (vtkm::Dot(normal, rayDir) > 0.0f)
|
||||||
|
Loading…
Reference in New Issue
Block a user