Avoid divide by zero in rendering TriangleIntersections

This commit is contained in:
Kenneth Moreland 2021-07-12 11:23:24 -06:00
parent ede7756929
commit f883b5e036

@ -198,13 +198,11 @@ public:
Precision low = vtkm::Min(u, vtkm::Min(v, w));
Precision high = vtkm::Max(u, vtkm::Max(v, w));
bool invalid = (low < 0.) && (high > 0.);
Precision det = u + v + w;
if (det == 0.)
invalid = true;
if (!((low < 0.) && (high > 0.)) && (det != 0.))
{
// Intersection is valid
const Precision Az = s[2] * A[k[2]];
const Precision Bz = s[2] * B[k[2]];
const Precision Cz = s[2] * C[k[2]];
@ -217,9 +215,13 @@ public:
distance = (u * Az + v * Bz + w * det * Cz);
u = v;
v = w * det;
if (invalid)
}
else
{
// Intersection is invalid
distance = -1.;
}
}
template <typename Precision>
VTKM_EXEC inline void IntersectTriSn(const vtkm::Vec<Precision, 3>& a,
@ -266,13 +268,11 @@ public:
Precision low = vtkm::Min(u, vtkm::Min(v, w));
Precision high = vtkm::Max(u, vtkm::Max(v, w));
bool invalid = (low < 0.) && (high > 0.);
Precision det = u + v + w;
if (det == 0.)
invalid = true;
if (!((low < 0.) && (high > 0.)) && (det != 0.))
{
// Intersection is valid
const Precision Az = s[2] * A[k[2]];
const Precision Bz = s[2] * B[k[2]];
const Precision Cz = s[2] * C[k[2]];
@ -285,9 +285,13 @@ public:
distance = (u * Az + v * Bz + w * det * Cz);
u = v;
v = w * det;
if (invalid)
}
else
{
// Intersection is invalid
distance = -1.;
}
}
}; //WaterTight
template <>
@ -357,13 +361,12 @@ VTKM_EXEC inline void WaterTight::IntersectTri<vtkm::Float64>(const vtkm::Vec3f_
vtkm::Float64 low = vtkm::Min(u, vtkm::Min(v, w));
vtkm::Float64 high = vtkm::Max(u, vtkm::Max(v, w));
bool invalid = (low < 0.) && (high > 0.);
vtkm::Float64 det = u + v + w;
if (det == 0.)
invalid = true;
if (!((low < 0.) && (high > 0.)) && (det != 0.))
{
// Intersection is valid
const vtkm::Float64 Az = Sz * A[kz];
const vtkm::Float64 Bz = Sz * B[kz];
const vtkm::Float64 Cz = Sz * C[kz];
@ -376,10 +379,14 @@ VTKM_EXEC inline void WaterTight::IntersectTri<vtkm::Float64>(const vtkm::Vec3f_
distance = (u * Az + v * Bz + w * det * Cz);
u = v;
v = w * det;
if (invalid)
}
else
{
// Intersection is invalid
distance = -1.;
}
}
}
}
} //namespace vtkm::rendering::raytracing
#endif //vtk_m_rendering_raytracing_TriagnleIntersections_h