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/cartesian3D.hpp"
18#include "detray/geometry/detail/shape_utils.hpp"
35 static constexpr std::string_view
name =
"cuboid3D";
49 template <concepts::scalar scalar_t>
53 template <concepts::algebra algebra_t>
57 template <
typename bool_t>
61 static constexpr std::size_t
dim{3u};
72 template <concepts::scalar scalar_t, concepts::po
int po
int_t>
75 const scalar_t min_x_dist =
76 math::min(math::fabs(loc_p[0] - bounds[e_min_x]),
77 math::fabs(bounds[e_max_x] - loc_p[0]));
78 const scalar_t min_y_dist =
79 math::min(math::fabs(loc_p[1] - bounds[e_min_y]),
80 math::fabs(bounds[e_max_y] - loc_p[1]));
81 const scalar_t min_z_dist =
82 math::min(math::fabs(loc_p[2] - bounds[e_min_z]),
83 math::fabs(bounds[e_max_z] - loc_p[2]));
86 return math::min(math::min(min_x_dist, min_y_dist), min_z_dist);
97 template <concepts::algebra algebra_t>
121 template <concepts::scalar scalar_t, concepts::po
int3D po
int_t>
124 const scalar_t tol = std::numeric_limits<scalar_t>::epsilon(),
125 const scalar_t = 0.f)
const {
126 return ((bounds[e_min_x] - tol) <= loc_p[0] &&
127 (bounds[e_min_y] - tol) <= loc_p[1] &&
128 (bounds[e_min_x] - tol) <= loc_p[2] &&
129 loc_p[0] <= (bounds[e_max_x] + tol) &&
130 loc_p[1] <= (bounds[e_max_y] + tol) &&
131 loc_p[2] <= (bounds[e_max_z] + tol));
140 template <concepts::scalar scalar_t>
141 DETRAY_HOST_DEVICE
constexpr scalar_t
measure(
151 template <concepts::scalar scalar_t>
152 DETRAY_HOST_DEVICE
constexpr scalar_t
volume(
154 return (bounds[e_max_x] - bounds[e_min_x]) *
155 (bounds[e_max_y] - bounds[e_min_y]) *
156 (bounds[e_max_z] - bounds[e_min_z]);
165 template <concepts::scalar scalar_t>
171 new_bounds[e_min_x] = math::min(bounds[e_min_x], o_bounds[e_min_x]);
172 new_bounds[e_min_y] = math::min(bounds[e_min_y], o_bounds[e_min_y]);
173 new_bounds[e_min_z] = math::min(bounds[e_min_z], o_bounds[e_min_z]);
174 new_bounds[e_max_x] = math::max(bounds[e_max_x], o_bounds[e_max_x]);
175 new_bounds[e_max_y] = math::max(bounds[e_max_y], o_bounds[e_max_y]);
176 new_bounds[e_max_z] = math::max(bounds[e_max_z], o_bounds[e_max_z]);
190 template <concepts::algebra algebra_t>
197 for (
unsigned int i{0}; i < 3u; ++i) {
199 o_bounds[i + 3u] += env;
206 template <concepts::algebra algebra_t>
210 bounds[e_min_y] + bounds[e_max_y],
211 bounds[e_min_z] + bounds[e_max_z]};
220 template <concepts::algebra algebra_t>
224 throw std::runtime_error(
225 "Vertex generation for cuboids is not implemented");
235 template <concepts::scalar scalar_t>
238 constexpr auto tol{10.f * std::numeric_limits<scalar_t>::epsilon()};
240 if (bounds[e_min_x] >= bounds[e_max_x] ||
241 math::fabs(bounds[e_min_x] - bounds[e_max_x]) < tol) {
242 os <<
"DETRAY ERROR (HOST): Min x must be smaller than max x.";
245 if (bounds[e_min_y] >= bounds[e_max_y] ||
246 math::fabs(bounds[e_min_y] - bounds[e_max_y]) < tol) {
247 os <<
"DETRAY ERROR (HOST): Min y must be smaller than max y.";
250 if (bounds[e_min_z] >= bounds[e_max_z] ||
251 math::fabs(bounds[e_min_z] - bounds[e_max_z]) < tol) {
252 os <<
"DETRAY ERROR (HOST): Min z must be smaller than max z.";
Geometrical shape of a full 3D cuboid.
Definition cuboid3D.hpp:32
dpoint3D< algebra_t > centroid(const bounds_type< dscalar< algebra_t > > &bounds) const
Definition cuboid3D.hpp:207
constexpr bool check_consistency(const bounds_type< scalar_t > &bounds, std::ostream &os) const
Check consistency of boundary values.
Definition cuboid3D.hpp:236
static constexpr std::string_view name
The name for this shape.
Definition cuboid3D.hpp:35
constexpr scalar_t measure(const bounds_type< scalar_t > &bounds) const
Measure of the shape: Volume.
Definition cuboid3D.hpp:141
bool_t result_type
Result type of a boundary check.
Definition cuboid3D.hpp:58
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 cuboid3D.hpp:73
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=0.f) const
Definition cuboid3D.hpp:122
dvector< dpoint3D< algebra_t > > vertices(const bounds_type< dscalar< algebra_t > > &, dindex) const
Generate vertices in local cartesian frame.
Definition cuboid3D.hpp:221
darray< scalar_t, boundaries::e_size > bounds_type
Container definition for the shape boundary values.
Definition cuboid3D.hpp:50
boundaries
Indices describing the entries in the shape boundary array.
Definition cuboid3D.hpp:38
cartesian3D< algebra_t > local_frame_type
Local coordinate frame for boundary checks.
Definition cuboid3D.hpp:54
static constexpr std::size_t dim
Dimension of the local coordinate system.
Definition cuboid3D.hpp:61
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 >=0.f) const
Check boundary values for a local point.
Definition cuboid3D.hpp:98
constexpr bounds_type< scalar_t > merge(const bounds_type< scalar_t > &bounds, const bounds_type< scalar_t > &o_bounds) const
Merge two 3D cuboid shapes.
Definition cuboid3D.hpp:166
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 cuboid3D.hpp:191
constexpr scalar_t volume(const bounds_type< scalar_t > &bounds) const
The volume of a the shape.
Definition cuboid3D.hpp:152
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 3D cartesian coordinate frame.
Definition cartesian3D.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