10 #ifndef vtk_m_rendering_raytracing_TriangleIntersections_h
11 #define vtk_m_rendering_raytracing_TriangleIntersections_h
25 template <
typename Precision>
41 p[0] = dir[1] * e2[2] - dir[2] * e2[1];
42 p[1] = dir[2] * e2[0] - dir[0] * e2[2];
43 p[2] = dir[0] * e2[1] - dir[1] * e2[0];
44 Precision dot = e1[0] * p[0] + e1[1] * p[1] + e1[2] * p[2];
51 u = (t[0] * p[0] + t[1] * p[1] + t[2] * p[2]) * dot;
52 if (u >= (0.f - EPSILON2) && u <= (1.f + EPSILON2))
56 q[0] = t[1] * e1[2] - t[2] * e1[1];
57 q[1] = t[2] * e1[0] - t[0] * e1[2];
58 q[2] = t[0] * e1[1] - t[1] * e1[0];
59 v = (dir[0] * q[0] + dir[1] * q[1] + dir[2] * q[2]) * dot;
60 if (v >= (0.f - EPSILON2) && v <= (1.f + EPSILON2) && !(u + v > 1.f))
62 distance = (e2[0] * q[0] + e2[1] * q[1] + e2[2] * q[2]) * dot;
80 template <
typename Precision>
87 if (vtkm::Abs(dir[0]) > vtkm::Abs(dir[1]))
89 if (vtkm::Abs(dir[0]) > vtkm::Abs(dir[2]))
96 if (vtkm::Abs(dir[1]) > vtkm::Abs(dir[2]))
116 s[0] = dir[k[0]] / dir[k[2]];
117 s[1] = dir[k[1]] / dir[k[2]];
118 s[2] = 1.f / dir[k[2]];
121 template <
typename Precision>
135 if (vtkm::Abs(dir[0]) > vtkm::Abs(dir[1]))
137 if (vtkm::Abs(dir[0]) > vtkm::Abs(dir[2]))
144 if (vtkm::Abs(dir[1]) > vtkm::Abs(dir[2]))
164 s[0] = dir[k[0]] / dir[k[2]];
165 s[1] = dir[k[1]] / dir[k[2]];
166 s[2] = 1.f / dir[k[2]];
173 const Precision Ax = A[k[0]] - s[0] * A[k[2]];
174 const Precision Ay = A[k[1]] - s[1] * A[k[2]];
175 const Precision Bx = B[k[0]] - s[0] * B[k[2]];
176 const Precision By = B[k[1]] - s[1] * B[k[2]];
177 const Precision Cx = C[k[0]] - s[0] * C[k[2]];
178 const Precision Cy = C[k[1]] - s[1] * C[k[2]];
181 u = Cx * By - Cy * Bx;
182 v = Ax * Cy - Ay * Cx;
183 Precision w = Bx * Ay - By * Ax;
184 if (u == 0.f || v == 0.f || w == 0.f)
198 Precision low = vtkm::Min(u, vtkm::Min(v, w));
199 Precision high = vtkm::Max(u, vtkm::Max(v, w));
201 Precision det = u + v + w;
203 if (!((low < 0.) && (high > 0.)) && (det != 0.))
206 const Precision Az = s[2] * A[k[2]];
207 const Precision Bz = s[2] * B[k[2]];
208 const Precision Cz = s[2] * C[k[2]];
215 distance = (u * Az + v * Bz + w * det * Cz);
226 template <
typename Precision>
242 const Precision Ax = A[k[0]] - s[0] * A[k[2]];
243 const Precision Ay = A[k[1]] - s[1] * A[k[2]];
244 const Precision Bx = B[k[0]] - s[0] * B[k[2]];
245 const Precision By = B[k[1]] - s[1] * B[k[2]];
246 const Precision Cx = C[k[0]] - s[0] * C[k[2]];
247 const Precision Cy = C[k[1]] - s[1] * C[k[2]];
250 u = Cx * By - Cy * Bx;
251 v = Ax * Cy - Ay * Cx;
252 Precision w = Bx * Ay - By * Ax;
253 if (u == 0.f || v == 0.f || w == 0.f)
268 Precision low = vtkm::Min(u, vtkm::Min(v, w));
269 Precision high = vtkm::Max(u, vtkm::Max(v, w));
271 Precision det = u + v + w;
273 if (!((low < 0.) && (high > 0.)) && (det != 0.))
276 const Precision Az = s[2] * A[k[2]];
277 const Precision Bz = s[2] * B[k[2]];
278 const Precision Cz = s[2] * C[k[2]];
285 distance = (u * Az + v * Bz + w * det * Cz);
309 if (vtkm::Abs(dir[0]) > vtkm::Abs(dir[1]))
311 if (vtkm::Abs(dir[0]) > vtkm::Abs(dir[2]))
318 if (vtkm::Abs(dir[1]) > vtkm::Abs(dir[2]))
357 u = Cx * By - Cy * Bx;
358 v = Ax * Cy - Ay * Cx;
367 if (!((low < 0.) && (high > 0.)) && (det != 0.))
379 distance = (u * Az + v * Bz + w * det * Cz);
392 #endif //vtk_m_rendering_raytracing_TriagnleIntersections_h