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