55 {
56 static constexpr int other_coordinate = (coordinate + 1) % 2;
57 using Scalar = typename LineType::Scalar;
58 using Floating = typename std::conditional<std::is_floating_point<Scalar>::value, Scalar, double>::type;
59 const auto& node = tree.node(node_idx);
60 assert(node.is_valid());
61 if (node.is_leaf()) {
62 const LineType& line = lines[node.idx];
63 if (ray_origin[other_coordinate] < std::min(line.a[other_coordinate], line.b[other_coordinate]) || ray_origin[other_coordinate] >= std::max(line.a[other_coordinate], line.b[other_coordinate])) {
64
65
66 return { 0, 0 };
67 }
68
69 Scalar line_max = std::max(line.a[coordinate], line.b[coordinate]);
70 Scalar line_min = std::min(line.a[coordinate], line.b[coordinate]);
71 if (ray_origin[coordinate] > line_max) {
72 return { 1, 0 };
73 } else if (ray_origin[coordinate] < line_min) {
74 return { 0, 1 };
75 } else {
76
77
78
79
80
81
82
83 Floating distance_oc = line.b[other_coordinate] - line.a[other_coordinate];
84 Floating t = (ray_origin[other_coordinate] - line.a[other_coordinate]) / distance_oc;
85 Floating val_c = line.a[coordinate] + t * (line.b[coordinate] - line.a[coordinate]);
86 if (ray_origin[coordinate] > val_c) {
87 return { 1, 0 };
88 } else if (ray_origin[coordinate] < val_c) {
89 return { 0, 1 };
90 } else {
91 return { -1, -1 };
92 }
93 }
94 } else {
95 int intersections_above = 0;
96 int intersections_below = 0;
97 size_t left_node_idx = node_idx * 2 + 1;
98 size_t right_node_idx = left_node_idx + 1;
99 const auto& node_left = tree.node(left_node_idx);
100 const auto& node_right = tree.node(right_node_idx);
101 assert(node_left.is_valid());
102 assert(node_right.is_valid());
103
104 if (node_left.bbox.min()[other_coordinate] <= ray_origin[other_coordinate] && node_left.bbox.max()[other_coordinate] >= ray_origin[other_coordinate]) {
106 ray_origin);
107 if (above < 0 || below < 0)
108 return { -1, -1 };
109 intersections_above += above;
110 intersections_below += below;
111 }
112
113 if (node_right.bbox.min()[other_coordinate] <= ray_origin[other_coordinate] && node_right.bbox.max()[other_coordinate] >= ray_origin[other_coordinate]) {
115 ray_origin);
116 if (above < 0 || below < 0)
117 return { -1, -1 };
118 intersections_above += above;
119 intersections_below += below;
120 }
121 return { intersections_above, intersections_below };
122 }
123 }
std::tuple< int, int > coordinate_aligned_ray_hit_count(size_t node_idx, const TreeType &tree, const std::vector< LineType > &lines, const VectorType &ray_origin)
Definition AABBTreeLines.hpp:51