10 #ifndef vtk_m_rendering_raytracing_BVH_Traverser_h
11 #define vtk_m_rendering_raytracing_BVH_Traverser_h
26 #define END_FLAG -1000000000
28 template <
typename BVHPortalType,
typename Precision>
33 const Precision& closestDistance,
36 const Precision& minDistance)
42 Precision xmin0 = first4[0] * invDir[0] - originDir[0];
43 Precision ymin0 = first4[1] * invDir[1] - originDir[1];
44 Precision zmin0 = first4[2] * invDir[2] - originDir[2];
45 Precision xmax0 = first4[3] * invDir[0] - originDir[0];
46 Precision ymax0 = second4[0] * invDir[1] - originDir[1];
47 Precision zmax0 = second4[1] * invDir[2] - originDir[2];
49 Precision min0 = vtkm::Max(
50 vtkm::Max(vtkm::Max(vtkm::Min(ymin0, ymax0), vtkm::Min(xmin0, xmax0)), vtkm::Min(zmin0, zmax0)),
52 Precision max0 = vtkm::Min(
53 vtkm::Min(vtkm::Min(vtkm::Max(ymin0, ymax0), vtkm::Max(xmin0, xmax0)), vtkm::Max(zmin0, zmax0)),
55 hitLeftChild = (max0 >= min0);
57 Precision xmin1 = second4[2] * invDir[0] - originDir[0];
58 Precision ymin1 = second4[3] * invDir[1] - originDir[1];
59 Precision zmin1 = third4[0] * invDir[2] - originDir[2];
60 Precision xmax1 = third4[1] * invDir[0] - originDir[0];
61 Precision ymax1 = third4[2] * invDir[1] - originDir[1];
62 Precision zmax1 = third4[3] * invDir[2] - originDir[2];
64 Precision min1 = vtkm::Max(
65 vtkm::Max(vtkm::Max(vtkm::Min(ymin1, ymax1), vtkm::Min(xmin1, xmax1)), vtkm::Min(zmin1, zmax1)),
67 Precision max1 = vtkm::Min(
68 vtkm::Min(vtkm::Min(vtkm::Max(ymin1, ymax1), vtkm::Max(xmin1, xmax1)), vtkm::Max(zmin1, zmax1)),
70 hitRightChild = (max1 >= min1);
85 return rcp((vtkm::Abs(f) < 1e-8f) ? 1e-8f : f);
92 return rcp((vtkm::Abs(f) < 1e-8f) ? 1e-8f : f);
107 ExecObject leafIntersector,
110 using ExecutionSignature = void(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12);
113 template <
typename PointPortalType,
116 typename InnerNodePortalType,
117 typename LeafPortalType>
121 const Precision& minDistance,
122 const Precision& maxDistance,
126 const PointPortalType& points,
127 LeafType& leafIntersector,
128 const InnerNodePortalType& flatBVH,
129 const LeafPortalType& leafs)
const
131 Precision closestDistance = maxDistance;
132 distance = maxDistance;
146 todo[stackptr] = barrier;
152 if (currentNode > -1)
156 bool hitLeftChild, hitRightChild;
166 if (!hitLeftChild && !hitRightChild)
168 currentNode = todo[stackptr];
175 memcpy(&leftChild, &children[0], 4);
177 memcpy(&rightChild, &children[1], 4);
178 currentNode = (hitLeftChild) ? leftChild : rightChild;
179 if (hitLeftChild && hitRightChild)
183 currentNode = rightChild;
185 todo[stackptr] = leftChild;
190 todo[stackptr] = rightChild;
196 if (currentNode < 0 && currentNode != barrier)
198 currentNode = -currentNode - 1;
199 leafIntersector.IntersectLeaf(currentNode,
209 currentNode = todo[stackptr];
216 distance = closestDistance;
221 template <
typename Precision,
typename LeafIntersectorType>
224 LeafIntersectorType& leafIntersector,
228 intersectDispatch.Invoke(rays.
Dir,
246 #endif //vtk_m_rendering_raytracing_BVHTraverser_h