ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
single3D.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/containers.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
15#include "detray/definitions/indexing.hpp"
16#include "detray/definitions/math.hpp"
17#include "detray/geometry/coordinates/cartesian2D.hpp"
18#include "detray/geometry/coordinates/cartesian3D.hpp"
19#include "detray/geometry/detail/shape_utils.hpp"
20
21// System include(s)
22#include <limits>
23#include <ostream>
24#include <stdexcept>
25#include <string_view>
26
27namespace detray {
28
33template <unsigned int kCheckIndex = 0u>
34class single3D {
35 public:
37 static constexpr std::string_view name = "single3D";
38
40 enum boundaries : unsigned int {
41 e_lower = 0u,
42 e_upper = 1u,
43 e_size = 2u,
44 };
45
47 template <concepts::scalar scalar_t>
49
51 template <concepts::algebra algebra_t>
53
55 template <typename bool_t>
56 using result_type = detail::boundary_check_result<bool_t>;
57
59 static constexpr std::size_t dim{1u};
60
70 template <concepts::scalar scalar_t, concepts::point point_t>
71 DETRAY_HOST_DEVICE inline scalar_t min_dist_to_boundary(
72 const bounds_type<scalar_t> &bounds, const point_t &loc_p) const {
73 return math::min(math::fabs(loc_p[kCheckIndex] - bounds[e_lower]),
74 math::fabs(bounds[e_upper] - loc_p[kCheckIndex]));
75 }
76
87 template <concepts::algebra algebra_t>
88 DETRAY_HOST_DEVICE constexpr result_type<dbool<algebra_t>> check_boundaries(
89 const bounds_type<dscalar<algebra_t>> &bounds,
90 const dtransform3D<algebra_t> &trf, const dpoint3D<algebra_t> &glob_p,
91 const dscalar<algebra_t> tol =
92 std::numeric_limits<dscalar<algebra_t>>::epsilon(),
93 const dscalar<algebra_t> edge_tol = 0.f) const {
94 // Get the full local position
95 const dpoint3D<algebra_t> loc_p =
97
98 return check_boundaries(bounds, loc_p, tol, edge_tol);
99 }
100
111 template <concepts::scalar scalar_t, concepts::point point_t>
112 DETRAY_HOST_DEVICE constexpr auto check_boundaries(
113 const bounds_type<scalar_t> &bounds, const point_t &loc_p,
114 const scalar_t tol = std::numeric_limits<scalar_t>::epsilon(),
115 const scalar_t edge_tol = 0.f) const {
116 auto inside_mask{(bounds[e_lower] - tol <= loc_p[kCheckIndex] &&
117 loc_p[kCheckIndex] <= bounds[e_upper] + tol)};
118
119 decltype(inside_mask) inside_edge{false};
120 if (detail::any_of(edge_tol > 0.f)) {
121 const scalar_t full_tol{tol + edge_tol};
122
123 inside_edge = (bounds[e_lower] - full_tol <= loc_p[kCheckIndex] &&
124 loc_p[kCheckIndex] <= bounds[e_upper] + full_tol);
125 }
126
127 return result_type<decltype(inside_mask)>{inside_mask, inside_edge};
128 }
129
130
136 template <concepts::scalar scalar_t>
137 DETRAY_HOST_DEVICE constexpr scalar_t measure(
138 const bounds_type<scalar_t> &bounds) const {
139 return area(bounds);
140 }
141
147 template <concepts::scalar scalar_t>
148 DETRAY_HOST_DEVICE constexpr scalar_t area(
149 const bounds_type<scalar_t> &bounds) const {
150 return math::fabs(bounds[e_upper] - bounds[e_lower]);
151 }
152
159 template <concepts::scalar scalar_t>
160 DETRAY_HOST_DEVICE constexpr bounds_type<scalar_t> merge(
161 const bounds_type<scalar_t> &bounds,
162 const bounds_type<scalar_t> &o_bounds) const {
163 bounds_type<scalar_t> new_bounds{};
164
165 new_bounds[e_lower] = math::min(bounds[e_lower], o_bounds[e_lower]);
166 new_bounds[e_upper] = math::max(bounds[e_upper], o_bounds[e_upper]);
167
168 return new_bounds;
169 }
170
180 template <concepts::algebra algebra_t>
181 DETRAY_HOST_DEVICE inline darray<dscalar<algebra_t>, 6> local_min_bounds(
182 const bounds_type<dscalar<algebra_t>> &bounds,
183 const dscalar<algebra_t> env =
184 std::numeric_limits<dscalar<algebra_t>>::epsilon()) const {
185 assert(env > 0.f);
186 darray<dscalar<algebra_t>, 6> o_bounds{-env, -env, -env, env, env, env};
187 o_bounds[kCheckIndex] += bounds[e_lower];
188 o_bounds[3u + kCheckIndex] += bounds[e_upper];
189 return o_bounds;
190 }
191
194 template <concepts::algebra algebra_t>
195 DETRAY_HOST_DEVICE auto centroid(
196 const bounds_type<dscalar<algebra_t>> &bounds) const {
197 using point3_t = dpoint3D<algebra_t>;
198
199 point3_t centr{0.f, 0.f, 0.f};
200 centr[kCheckIndex] = 0.5f * (bounds[e_lower] + bounds[e_upper]);
201
202 return centr;
203 }
204
210 template <concepts::algebra algebra_t>
212 const bounds_type<dscalar<algebra_t>> & /*unused*/,
213 dindex /*unused*/) const {
214 throw std::runtime_error(
215 "Vertex generation for single value shapes is not implemented");
216 return {};
217 }
218
225 template <concepts::scalar scalar_t>
226 DETRAY_HOST constexpr bool check_consistency(
227 const bounds_type<scalar_t> &bounds, std::ostream &os) const {
228 if (bounds[e_upper] < bounds[e_lower]) {
229 os << "DETRAY ERROR (HOST): Upper bounds must be smaller than "
230 "lower bounds ";
231 return false;
232 }
233
234 return true;
235 }
236};
237
238} // namespace detray
Underlying geometry for a single parameter bound mask.
Definition single3D.hpp:34
dvector< dpoint3D< algebra_t > > vertices(const bounds_type< dscalar< algebra_t > > &, dindex) const
Generate vertices in local cartesian frame.
Definition single3D.hpp:211
constexpr scalar_t area(const bounds_type< scalar_t > &bounds) const
The area of a the shape.
Definition single3D.hpp:148
scalar_t min_dist_to_boundary(const bounds_type< scalar_t > &bounds, const point_t &loc_p) const
Find the minimum distance to any boundary.
Definition single3D.hpp:71
static constexpr std::size_t dim
Dimension of the local coordinate system.
Definition single3D.hpp:59
darray< scalar_t, boundaries::e_size > bounds_type
Container definition for the shape boundary values.
Definition single3D.hpp:48
constexpr scalar_t measure(const bounds_type< scalar_t > &bounds) const
Measure of the shape: Range.
Definition single3D.hpp:137
detail::boundary_check_result< bool_t > result_type
Result type of a boundary check.
Definition single3D.hpp:56
auto centroid(const bounds_type< dscalar< algebra_t > > &bounds) const
Definition single3D.hpp:195
constexpr auto check_boundaries(const bounds_type< scalar_t > &bounds, const point_t &loc_p, const scalar_t tol=std::numeric_limits< scalar_t >::epsilon(), const scalar_t edge_tol=0.f) const
Definition single3D.hpp:112
constexpr result_type< dbool< algebra_t > > check_boundaries(const bounds_type< dscalar< algebra_t > > &bounds, const dtransform3D< algebra_t > &trf, const dpoint3D< algebra_t > &glob_p, const dscalar< algebra_t > tol=std::numeric_limits< dscalar< algebra_t > >::epsilon(), const dscalar< algebra_t > edge_tol=0.f) const
Check boundary values for a local point.
Definition single3D.hpp:88
boundaries
Indices describing the entries in the shape boundary array.
Definition single3D.hpp:40
cartesian2D< algebra_t > local_frame_type
Local coordinate frame for boundary checks.
Definition single3D.hpp:52
constexpr bool check_consistency(const bounds_type< scalar_t > &bounds, std::ostream &os) const
Check consistency of boundary values.
Definition single3D.hpp:226
darray< dscalar< algebra_t >, 6 > local_min_bounds(const bounds_type< dscalar< algebra_t > > &bounds, const dscalar< algebra_t > env=std::numeric_limits< dscalar< algebra_t > >::epsilon()) const
Lower and upper point for minimal axis aligned bounding box.
Definition single3D.hpp:181
static constexpr std::string_view name
The name for this shape.
Definition single3D.hpp:37
constexpr bounds_type< scalar_t > merge(const bounds_type< scalar_t > &bounds, const bounds_type< scalar_t > &o_bounds) const
Merge two 'single' shapes.
Definition single3D.hpp:160
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
vecmem::vector< value_t > dvector
Vector container backed by vecmem.
Definition containers.hpp:34
unsigned int dindex
Default index type.
Definition indexing.hpp:18
std::array< value_t, kDIM > darray
Fixed-size array container.
Definition containers.hpp:30
get_transform3D_t< A, T > dtransform3D
Three-dimensional transform type for algebra A and value type T.
Definition algebra.hpp:84
get_point3D_t< A, T > dpoint3D
Three-dimensional point type for algebra A and value type T.
Definition algebra.hpp:72
Projection into a 2D cartesian coordinate frame.
Definition cartesian2D.hpp:19
static loc_point global_to_local(const transform3_type &trf, const point3_type &p, const vector3_type &)
This method transforms a point from a global cartesian 3D frame to a local 3D cartesian point Convert...
Definition cartesian3D.hpp:57