-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathbvh2_extra_kernels.h
More file actions
79 lines (69 loc) · 2.64 KB
/
bvh2_extra_kernels.h
File metadata and controls
79 lines (69 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
// Sandro Wenzel 2026
#ifndef ROOT_GEOM_BVH2_EXTRA
namespace bvh::v2::extra
{
// reusable geometry kernels used in multiple places
// for interaction with BVH2 structures
// determines if a point is inside the bounding box
template <typename T>
bool contains(bvh::v2::BBox<T, 3> const& box, bvh::v2::Vec<T, 3> const& p)
{
auto min = box.min;
auto max = box.max;
return (p[0] >= min[0] && p[0] <= max[0]) && (p[1] >= min[1] && p[1] <= max[1]) &&
(p[2] >= min[2] && p[2] <= max[2]);
}
// determines the largest squared distance of point to any of the bounding box corners
template <typename T>
auto RmaxSqToNode(bvh::v2::BBox<T, 3> const& box, bvh::v2::Vec<T, 3> const& p)
{
// construct the 8 corners to get the maximal distance
const auto minCorner = box.min;
const auto maxCorner = box.max;
using Vec3 = bvh::v2::Vec<T, 3>;
// these are the corners of the bounding box
const std::array<bvh::v2::Vec<T, 3>, 8> corners{
Vec3{minCorner[0], minCorner[1], minCorner[2]}, Vec3{minCorner[0], minCorner[1], maxCorner[2]},
Vec3{minCorner[0], maxCorner[1], minCorner[2]}, Vec3{minCorner[0], maxCorner[1], maxCorner[2]},
Vec3{maxCorner[0], minCorner[1], minCorner[2]}, Vec3{maxCorner[0], minCorner[1], maxCorner[2]},
Vec3{maxCorner[0], maxCorner[1], minCorner[2]}, Vec3{maxCorner[0], maxCorner[1], maxCorner[2]}};
T Rmax_sq{0};
for (const auto& corner : corners) {
float R_sq = 0.;
const auto dx = corner[0] - p[0];
R_sq += dx * dx;
const auto dy = corner[1] - p[1];
R_sq += dy * dy;
const auto dz = corner[2] - p[2];
R_sq += dz * dz;
Rmax_sq = std::max(Rmax_sq, R_sq);
}
return Rmax_sq;
};
// determines the minimum squared distance of point to a bounding box ("safey square")
template <typename T>
auto SafetySqToNode(bvh::v2::BBox<T, 3> const& box, bvh::v2::Vec<T, 3> const& p)
{
T sqDist{0.0};
for (int i = 0; i < 3; i++) {
T v = p[i];
if (v < box.min[i]) {
sqDist += (box.min[i] - v) * (box.min[i] - v);
} else if (v > box.max[i]) {
sqDist += (v - box.max[i]) * (v - box.max[i]);
}
}
return sqDist;
};
} // namespace bvh::v2::extra
#endif