Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
bvh2_extra_kernels.h
Go to the documentation of this file.
1#ifndef ROOT_GEOM_BVH2_EXTRA
2
3namespace bvh::v2::extra {
4
5// reusable geometry kernels used in multiple places
6// for interaction with BVH2 structures
7
8// determines if a point is inside the bounding box
9template <typename T>
11{
12 auto min = box.min;
13 auto max = box.max;
14 return (p[0] >= min[0] && p[0] <= max[0]) && (p[1] >= min[1] && p[1] <= max[1]) &&
15 (p[2] >= min[2] && p[2] <= max[2]);
16}
17
18// determines the largest squared distance of point to any of the bounding box corners
19template <typename T>
21{
22 // construct the 8 corners to get the maximal distance
23 const auto minCorner = box.min;
24 const auto maxCorner = box.max;
26 // these are the corners of the bounding box
27 const std::array<bvh::v2::Vec<T, 3>, 8> corners{
32
33 T Rmax_sq{0};
34 for (const auto &corner : corners) {
35 float R_sq = 0.;
36 const auto dx = corner[0] - p[0];
37 R_sq += dx * dx;
38 const auto dy = corner[1] - p[1];
39 R_sq += dy * dy;
40 const auto dz = corner[2] - p[2];
41 R_sq += dz * dz;
42 Rmax_sq = std::max(Rmax_sq, R_sq);
43 }
44 return Rmax_sq;
45};
46
47// determines the minimum squared distance of point to a bounding box ("safey square")
48template <typename T>
50{
51 T sqDist{0.0};
52 for (int i = 0; i < 3; i++) {
53 T v = p[i];
54 if (v < box.min[i]) {
55 sqDist += (box.min[i] - v) * (box.min[i] - v);
56 } else if (v > box.max[i]) {
57 sqDist += (v - box.max[i]) * (v - box.max[i]);
58 }
59 }
60 return sqDist;
61};
62
63} // namespace bvh::v2::extra
64
65#endif
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
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)