ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
cuboid_intersector.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/definitions/algebra.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
14#include "detray/tracks/ray.hpp"
15#include "detray/utils/invalid_values.hpp"
16
17namespace detray {
18
38 template <concepts::algebra algebra_t, typename mask_t>
39 DETRAY_HOST_DEVICE bool operator()(
40 const detail::ray<algebra_t> &ray, const mask_t &box,
41 const dscalar<algebra_t> /*mask_tolerance*/ = 0.f) const {
42 using scalar_type = dscalar<algebra_t>;
43 using point3_type = dpoint3D<algebra_t>;
44 using vector3_type = dvector3D<algebra_t>;
45 using boundaries = typename mask_t::boundaries;
46
47 const point3_type &ro = ray.pos();
48 const vector3_type &rd = ray.dir();
49 // @TODO: put vector-vector operator/ in algebra-plugins
50 constexpr scalar_type inv{detail::invalid_value<scalar_type>()};
51 const vector3_type inv_dir{rd[0] == 0.f ? inv : 1.f / rd[0],
52 rd[1] == 0.f ? inv : 1.f / rd[1],
53 rd[2] == 0.f ? inv : 1.f / rd[2]};
54
55 // This is prob. slow -> @todo refactor masks to hold custom mask values
56 const vector3_type min{box[boundaries::e_min_x], box[boundaries::e_min_y],
57 box[boundaries::e_min_z]};
58 const vector3_type max{box[boundaries::e_max_x], box[boundaries::e_max_y],
59 box[boundaries::e_max_z]};
60 // Find tmin and tmax, which define the segment of the ray that
61 // intersects the box
62 vector3_type t1 = (min - ro);
63 vector3_type t2 = (max - ro);
64
66 for (unsigned int i{0u}; i < 3u; ++i) {
67 t1[i] *= inv_dir[i];
68 t2[i] *= inv_dir[i];
69 }
70
71 const bool t_comp = t1[0] > t2[0];
72 scalar_type tmin{t_comp ? t2[0] : t1[0]};
73 scalar_type tmax{t_comp ? t1[0] : t2[0]};
74
75 for (unsigned int i{0u}; i < 2u; ++i) {
76 if (t1[i] > t2[i]) {
77 tmin = t2[i] < tmin ? tmin : t2[i];
78 tmax = t1[i] > tmax ? tmax : t1[i];
79 } else {
80 tmin = t1[i] < tmin ? tmin : t1[i];
81 tmax = t2[i] > tmax ? tmax : t2[i];
82 }
83 }
84
85 // Was a valid intersection found ?
86 return tmin < tmax;
87 }
88};
89
90} // namespace detray
describes a straight-line trajectory
Definition ray.hpp:22
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
get_vector3D_t< A, T > dvector3D
Three-dimensional vector type for algebra A and value type T.
Definition algebra.hpp:80
get_point3D_t< A, T > dpoint3D
Three-dimensional point type for algebra A and value type T.
Definition algebra.hpp:72
Checks if a cuboid bonuding box is intersected by a ray.
Definition cuboid_intersector.hpp:27
bool operator()(const detail::ray< algebra_t > &ray, const mask_t &box, const dscalar< algebra_t >=0.f) const
Operator to find intersections between ray and a cuboid aabb.
Definition cuboid_intersector.hpp:39