Skip to content

Commit 151356c

Browse files
authored
Merge pull request #738 from niermann999/fix-navigation
fix: navigation and make mask tolerance scaling configurable
2 parents b8e4396 + 73b2ac2 commit 151356c

26 files changed

+198
-86
lines changed

core/include/detray/definitions/detail/math.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ inline decltype(auto) copysign(T &&mag, S &&sgn) {
111111
return Vc::copysign(std::forward<T>(mag), std::forward<S>(sgn));
112112
}
113113

114+
template <typename T,
115+
std::enable_if_t<Vc::Traits::is_simd_vector<T>::value, bool> = true>
116+
inline decltype(auto) min(T &&vec) {
117+
return Vc::min(std::forward<T>(vec));
118+
}
119+
120+
template <typename T,
121+
std::enable_if_t<Vc::Traits::is_simd_vector<T>::value, bool> = true>
122+
inline decltype(auto) max(T &&vec) {
123+
return Vc::max(std::forward<T>(vec));
124+
}
125+
114126
template <typename T,
115127
std::enable_if_t<Vc::Traits::is_simd_vector<T>::value, bool> = true>
116128
inline decltype(auto) signbit(T &&vec) {

core/include/detray/navigation/intersection/helix_cylinder_intersector.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct helix_intersector_impl<cylindrical2D<algebra_t>, algebra_t>
6565
const std::array<scalar_type, 2u> mask_tolerance =
6666
{detail::invalid_value<scalar_type>(),
6767
detail::invalid_value<scalar_type>()},
68-
const scalar_type = 0.f) const {
68+
const scalar_type = 0.f, const scalar_type = 0.f) const {
6969

7070
assert((mask_tolerance[0] == mask_tolerance[1]) &&
7171
"Helix intersectors use only one mask tolerance value");
@@ -194,7 +194,7 @@ struct helix_intersector_impl<cylindrical2D<algebra_t>, algebra_t>
194194
DETRAY_HOST_DEVICE inline std::array<intersection_type<surface_descr_t>, 2>
195195
operator()(const helix_type &h, const surface_descr_t &sf_desc,
196196
const mask_t &mask, const transform3_type &trf,
197-
const scalar_type mask_tolerance,
197+
const scalar_type mask_tolerance, const scalar_type = 0.f,
198198
const scalar_type = 0.f) const {
199199
return this->operator()(h, sf_desc, mask, trf, {mask_tolerance, 0.f},
200200
0.f);

core/include/detray/navigation/intersection/helix_line_intersector.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct helix_intersector_impl<line2D<algebra_t>, algebra_t> {
5858
const std::array<scalar_type, 2u> mask_tolerance =
5959
{detail::invalid_value<scalar_type>(),
6060
detail::invalid_value<scalar_type>()},
61-
const scalar_type = 0.f) const {
61+
const scalar_type = 0.f, const scalar_type = 0.f) const {
6262

6363
assert((mask_tolerance[0] == mask_tolerance[1]) &&
6464
"Helix intersectors use only one mask tolerance value");
@@ -180,7 +180,7 @@ struct helix_intersector_impl<line2D<algebra_t>, algebra_t> {
180180
DETRAY_HOST_DEVICE inline intersection_type<surface_descr_t> operator()(
181181
const helix_type &h, const surface_descr_t &sf_desc, const mask_t &mask,
182182
const transform3_type &trf, const scalar_type mask_tolerance,
183-
const scalar_type = 0.f) const {
183+
const scalar_type = 0.f, const scalar_type = 0.f) const {
184184
return this->operator()(h, sf_desc, mask, trf, {mask_tolerance, 0.f},
185185
0.f);
186186
}

core/include/detray/navigation/intersection/helix_plane_intersector.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct helix_intersector_impl<cartesian2D<algebra_t>, algebra_t> {
6060
const std::array<scalar_type, 2u> mask_tolerance =
6161
{detail::invalid_value<scalar_type>(),
6262
detail::invalid_value<scalar_type>()},
63-
const scalar_type = 0.f) const {
63+
const scalar_type = 0.f, const scalar_type = 0.f) const {
6464

6565
assert((mask_tolerance[0] == mask_tolerance[1]) &&
6666
"Helix intersectors use only one mask tolerance value");
@@ -134,7 +134,7 @@ struct helix_intersector_impl<cartesian2D<algebra_t>, algebra_t> {
134134
DETRAY_HOST_DEVICE inline intersection_type<surface_descr_t> operator()(
135135
const helix_type &h, const surface_descr_t &sf_desc, const mask_t &mask,
136136
const transform3_type &trf, const scalar_type mask_tolerance,
137-
const scalar_type = 0.f) const {
137+
const scalar_type = 0.f, const scalar_type = 0.f) const {
138138
return this->operator()(h, sf_desc, mask, trf, {mask_tolerance, 0.f},
139139
0.f);
140140
}

core/include/detray/navigation/intersection/intersection.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ struct intersection2D {
7676
/// @param rhs is the left hand side intersection for comparison
7777
DETRAY_HOST_DEVICE
7878
bool_t operator==(const intersection2D &rhs) const {
79-
return math::fabs(path - rhs.path) < std::numeric_limits<T>::epsilon();
79+
return math::fabs(path - rhs.path) <
80+
std::numeric_limits<float>::epsilon();
8081
}
8182

8283
DETRAY_HOST_DEVICE

core/include/detray/navigation/intersection/ray_concentric_cylinder_intersector.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct ray_concentric_cylinder_intersector {
5858
const transform3_type & /*trf*/,
5959
const std::array<scalar_type, 2u> mask_tolerance =
6060
{0.f, 1.f * unit<scalar_type>::mm},
61+
const scalar_type mask_tol_scalor = 0.f,
6162
const scalar_type overstep_tol = 0.f) const {
6263

6364
intersection_type<surface_descr_t> is;
@@ -114,9 +115,10 @@ struct ray_concentric_cylinder_intersector {
114115
// for the r-check
115116
// Tolerance: per mille of the distance
116117
is.status = mask.is_inside(
117-
is.local, math::max(mask_tolerance[0],
118-
math::min(mask_tolerance[1],
119-
1e-3f * math::abs(is.path))));
118+
is.local,
119+
math::max(mask_tolerance[0],
120+
math::min(mask_tolerance[1],
121+
mask_tol_scalor * math::abs(is.path))));
120122

121123
// prepare some additional information in case the intersection
122124
// is valid
@@ -141,7 +143,7 @@ struct ray_concentric_cylinder_intersector {
141143
const ray_type &ray, const surface_descr_t &sf, const mask_t &mask,
142144
const transform3_type &trf, const scalar_type mask_tolerance,
143145
const scalar_type overstep_tol = 0.f) const {
144-
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f},
146+
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f}, 0.f,
145147
overstep_tol);
146148
}
147149

@@ -162,9 +164,10 @@ struct ray_concentric_cylinder_intersector {
162164
const mask_t &mask, const transform3_type &trf,
163165
const std::array<scalar_type, 2u> &mask_tolerance =
164166
{0.f, 1.f * unit<scalar_type>::mm},
167+
const scalar_type mask_tol_scalor = 0.f,
165168
const scalar_type overstep_tol = 0.f) const {
166169
sfi = this->operator()(ray, sfi.sf_desc, mask, trf, mask_tolerance,
167-
overstep_tol)[0];
170+
mask_tol_scalor, overstep_tol)[0];
168171
}
169172
};
170173

core/include/detray/navigation/intersection/ray_cylinder_intersector.hpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, false> {
5959
const mask_t &mask, const transform3_type &trf,
6060
const std::array<scalar_type, 2u> mask_tolerance =
6161
{0.f, 100.f * unit<scalar_type>::um},
62+
const scalar_type mask_tol_scalor = 0.f,
6263
const scalar_type overstep_tol = 0.f) const {
6364

6465
// One or both of these solutions might be invalid
@@ -68,15 +69,17 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, false> {
6869
switch (qe.solutions()) {
6970
case 2:
7071
ret[1] = build_candidate<surface_descr_t>(
71-
ray, mask, trf, qe.larger(), mask_tolerance, overstep_tol);
72+
ray, mask, trf, qe.larger(), mask_tolerance,
73+
mask_tol_scalor, overstep_tol);
7274
ret[1].sf_desc = sf;
7375
// If there are two solutions, reuse the case for a single
7476
// solution to setup the intersection with the smaller path
7577
// in ret[0]
7678
[[fallthrough]];
7779
case 1:
7880
ret[0] = build_candidate<surface_descr_t>(
79-
ray, mask, trf, qe.smaller(), mask_tolerance, overstep_tol);
81+
ray, mask, trf, qe.smaller(), mask_tolerance,
82+
mask_tol_scalor, overstep_tol);
8083
ret[0].sf_desc = sf;
8184
break;
8285
case 0:
@@ -97,7 +100,7 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, false> {
97100
const mask_t &mask, const transform3_type &trf,
98101
const scalar_type mask_tolerance,
99102
const scalar_type overstep_tol = 0.f) const {
100-
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f},
103+
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f}, 0.f,
101104
overstep_tol);
102105
}
103106

@@ -117,6 +120,7 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, false> {
117120
const mask_t &mask, const transform3_type &trf,
118121
const std::array<scalar_type, 2u> mask_tolerance =
119122
{0.f, 1.f * unit<scalar_type>::mm},
123+
const scalar_type mask_tol_scalor = 0.f,
120124
const scalar_type overstep_tol = 0.f) const {
121125

122126
// One or both of these solutions might be invalid
@@ -125,7 +129,8 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, false> {
125129
switch (qe.solutions()) {
126130
case 1:
127131
sfi = build_candidate<surface_descr_t>(
128-
ray, mask, trf, qe.smaller(), mask_tolerance, overstep_tol);
132+
ray, mask, trf, qe.smaller(), mask_tolerance,
133+
mask_tol_scalor, overstep_tol);
129134
break;
130135
case 0:
131136
sfi.status = false;
@@ -169,6 +174,7 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, false> {
169174
build_candidate(const ray_type &ray, mask_t &mask,
170175
const transform3_type &trf, const scalar_type path,
171176
const std::array<scalar_type, 2u> mask_tolerance,
177+
const scalar_type mask_tol_scalor,
172178
const scalar_type overstep_tol) const {
173179

174180
assert((mask_tolerance[0] <= mask_tolerance[1]) &&
@@ -189,9 +195,10 @@ struct ray_intersector_impl<cylindrical2D<algebra_t>, algebra_t, false> {
189195
is.local = mask.to_local_frame(trf, p3);
190196
// Tolerance: per mille of the distance
191197
is.status = mask.is_inside(
192-
is.local, math::max(mask_tolerance[0],
193-
math::min(mask_tolerance[1],
194-
1e-3f * math::fabs(is.path))));
198+
is.local,
199+
math::max(mask_tolerance[0],
200+
math::min(mask_tolerance[1],
201+
mask_tol_scalor * math::fabs(is.path))));
195202

196203
// prepare some additional information in case the intersection
197204
// is valid

core/include/detray/navigation/intersection/ray_cylinder_portal_intersector.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,
6666
const transform3_type &trf,
6767
const std::array<scalar_type, 2u> mask_tolerance =
6868
{0.f, 1.f * unit<scalar_type>::mm},
69+
const scalar_type mask_tol_scalor = 0.f,
6970
const scalar_type overstep_tol = 0.f) const {
7071

7172
intersection_type<surface_descr_t> is;
@@ -81,7 +82,8 @@ struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,
8182
const scalar_type t{(qe.smaller() > overstep_tol) ? qe.smaller()
8283
: qe.larger()};
8384
is = this->template build_candidate<surface_descr_t>(
84-
ray, mask, trf, t, mask_tolerance, overstep_tol);
85+
ray, mask, trf, t, mask_tolerance, mask_tol_scalor,
86+
overstep_tol);
8587
is.sf_desc = sf;
8688
} else {
8789
is.status = false;
@@ -96,7 +98,7 @@ struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,
9698
const ray_type &ray, const surface_descr_t &sf, const mask_t &mask,
9799
const transform3_type &trf, const scalar_type mask_tolerance,
98100
const scalar_type overstep_tol = 0.f) const {
99-
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f},
101+
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f}, 0.f,
100102
overstep_tol);
101103
}
102104

@@ -116,9 +118,10 @@ struct ray_intersector_impl<concentric_cylindrical2D<algebra_t>, algebra_t,
116118
const mask_t &mask, const transform3_type &trf,
117119
const std::array<scalar_type, 2u> &mask_tolerance =
118120
{0.f, 1.f * unit<scalar_type>::mm},
121+
const scalar_type mask_tol_scalor = 0.f,
119122
const scalar_type overstep_tol = 0.f) const {
120123
sfi = this->operator()(ray, sfi.sf_desc, mask, trf, mask_tolerance,
121-
overstep_tol);
124+
mask_tol_scalor, overstep_tol);
122125
}
123126
};
124127

core/include/detray/navigation/intersection/ray_line_intersector.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct ray_intersector_impl<line2D<algebra_t>, algebra_t, false> {
5454
const transform3_type &trf,
5555
const std::array<scalar_type, 2u> mask_tolerance =
5656
{0.f, 1.f * unit<scalar_type>::mm},
57+
const scalar_type mask_tol_scalor = 0.f,
5758
const scalar_type overstep_tol = 0.f) const {
5859

5960
assert((mask_tolerance[0] <= mask_tolerance[1]) &&
@@ -107,9 +108,10 @@ struct ray_intersector_impl<line2D<algebra_t>, algebra_t, false> {
107108
is.local = mask.to_local_frame(trf, m, _d);
108109
// Tolerance: per mille of the distance
109110
is.status = mask.is_inside(
110-
is.local, math::max(mask_tolerance[0],
111-
math::min(mask_tolerance[1],
112-
1e-3f * math::fabs(is.path))));
111+
is.local,
112+
math::max(mask_tolerance[0],
113+
math::min(mask_tolerance[1],
114+
mask_tol_scalor * math::fabs(is.path))));
113115

114116
// prepare some additional information in case the intersection
115117
// is valid
@@ -131,7 +133,7 @@ struct ray_intersector_impl<line2D<algebra_t>, algebra_t, false> {
131133
const ray_type &ray, const surface_descr_t &sf, const mask_t &mask,
132134
const transform3_type &trf, const scalar_type mask_tolerance,
133135
const scalar_type overstep_tol = 0.f) const {
134-
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f},
136+
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f}, 0.f,
135137
overstep_tol);
136138
}
137139

@@ -151,10 +153,11 @@ struct ray_intersector_impl<line2D<algebra_t>, algebra_t, false> {
151153
const mask_t &mask, const transform3_type &trf,
152154
const std::array<scalar_type, 2u> &mask_tolerance =
153155
{0.f, 1.f * unit<scalar_type>::mm},
156+
const scalar_type mask_tol_scalor = 0.f,
154157
const scalar_type overstep_tol = 0.f) const {
155158

156159
sfi = this->operator()(ray, sfi.sf_desc, mask, trf, mask_tolerance,
157-
overstep_tol);
160+
mask_tol_scalor, overstep_tol);
158161
}
159162
};
160163

core/include/detray/navigation/intersection/ray_plane_intersector.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ struct ray_intersector_impl<cartesian2D<algebra_t>, algebra_t, false> {
5858
const transform3_type &trf,
5959
const std::array<scalar_type, 2u> mask_tolerance =
6060
{0.f, 1.f * unit<scalar_type>::mm},
61+
const scalar_type mask_tol_scalor = 0.f,
6162
const scalar_type overstep_tol = 0.f) const {
6263

6364
assert((mask_tolerance[0] <= mask_tolerance[1]) &&
@@ -86,10 +87,10 @@ struct ray_intersector_impl<cartesian2D<algebra_t>, algebra_t, false> {
8687
is.local = mask.to_local_frame(trf, p3, ray.dir());
8788
// Tolerance: per mille of the distance
8889
is.status = mask.is_inside(
89-
is.local,
90-
math::max(mask_tolerance[0],
91-
math::min(mask_tolerance[1],
92-
1e-3f * math::fabs(is.path))));
90+
is.local, math::max(mask_tolerance[0],
91+
math::min(mask_tolerance[1],
92+
mask_tol_scalor *
93+
math::fabs(is.path))));
9394

9495
// prepare some additional information in case the intersection
9596
// is valid
@@ -115,7 +116,7 @@ struct ray_intersector_impl<cartesian2D<algebra_t>, algebra_t, false> {
115116
const ray_type &ray, const surface_descr_t &sf, const mask_t &mask,
116117
const transform3_type &trf, const scalar_type mask_tolerance,
117118
const scalar_type overstep_tol = 0.f) const {
118-
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f},
119+
return this->operator()(ray, sf, mask, trf, {mask_tolerance, 0.f}, 0.f,
119120
overstep_tol);
120121
}
121122

@@ -136,9 +137,10 @@ struct ray_intersector_impl<cartesian2D<algebra_t>, algebra_t, false> {
136137
const mask_t &mask, const transform3_type &trf,
137138
const std::array<scalar_type, 2u> &mask_tolerance =
138139
{0.f, 1.f * unit<scalar_type>::mm},
140+
const scalar_type mask_tol_scalor = 0.f,
139141
const scalar_type overstep_tol = 0.f) const {
140142
sfi = this->operator()(ray, sfi.sf_desc, mask, trf, mask_tolerance,
141-
overstep_tol);
143+
mask_tol_scalor, overstep_tol);
142144
}
143145
};
144146

0 commit comments

Comments
 (0)