File indexing completed on 2025-01-18 10:14:04
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef TBOOLEANMINUSIMPLEMENTATION_H_
0009 #define TBOOLEANMINUSIMPLEMENTATION_H_
0010
0011 #include "VecGeom/base/Vector3D.h"
0012 #include "VecGeom/volumes/TUnplacedBooleanMinusVolume.h"
0013
0014 namespace VECGEOM_NAMESPACE {
0015
0016 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0017 struct TBooleanMinusImplementation {
0018
0019 static const int transC = transCodeT;
0020 static const int rotC = rotCodeT;
0021
0022
0023 template <typename Backend>
0024 VECGEOM_FORCE_INLINE
0025 VECCORE_ATT_HOST_DEVICE
0026 static void UnplacedContains(TUnplacedBooleanMinusVolume const &unplaced,
0027 Vector3D<typename Backend::precision_v> const &localPoint,
0028 typename Backend::bool_v &inside);
0029
0030 template <typename Backend>
0031 VECGEOM_FORCE_INLINE
0032 VECCORE_ATT_HOST_DEVICE
0033 static void Contains(TUnplacedBooleanMinusVolume const &unplaced, Transformation3D const &transformation,
0034 Vector3D<typename Backend::precision_v> const &point,
0035 Vector3D<typename Backend::precision_v> &localPoint, typename Backend::bool_v &inside);
0036
0037 template <typename Backend>
0038 VECGEOM_FORCE_INLINE
0039 VECCORE_ATT_HOST_DEVICE
0040 static void Inside(TUnplacedBooleanMinusVolume const &unplaced, Transformation3D const &transformation,
0041 Vector3D<typename Backend::precision_v> const &point, typename Backend::inside_v &inside);
0042
0043 template <typename Backend>
0044 VECGEOM_FORCE_INLINE
0045 VECCORE_ATT_HOST_DEVICE
0046 static void DistanceToIn(TUnplacedBooleanMinusVolume const &unplaced, Transformation3D const &transformation,
0047 Vector3D<typename Backend::precision_v> const &point,
0048 Vector3D<typename Backend::precision_v> const &direction,
0049 typename Backend::precision_v const &stepMax, typename Backend::precision_v &distance);
0050
0051 template <typename Backend>
0052 VECGEOM_FORCE_INLINE
0053 VECCORE_ATT_HOST_DEVICE
0054 static void DistanceToOut(TUnplacedBooleanMinusVolume const &unplaced,
0055 Vector3D<typename Backend::precision_v> const &point,
0056 Vector3D<typename Backend::precision_v> const &direction,
0057 typename Backend::precision_v const &stepMax, typename Backend::precision_v &distance);
0058
0059 template <typename Backend>
0060 VECGEOM_FORCE_INLINE
0061 VECCORE_ATT_HOST_DEVICE
0062 static void SafetyToIn(TUnplacedBooleanMinusVolume const &unplaced, Transformation3D const &transformation,
0063 Vector3D<typename Backend::precision_v> const &point, typename Backend::precision_v &safety);
0064
0065 template <typename Backend>
0066 VECGEOM_FORCE_INLINE
0067 VECCORE_ATT_HOST_DEVICE
0068 static void SafetyToOut(TUnplacedBooleanMinusVolume const &unplaced,
0069 Vector3D<typename Backend::precision_v> const &point, typename Backend::precision_v &safety);
0070
0071 template <typename Backend>
0072 VECGEOM_FORCE_INLINE
0073 VECCORE_ATT_HOST_DEVICE
0074 static void ContainsKernel(TUnplacedBooleanMinusVolume const &unplaced,
0075 Vector3D<typename Backend::precision_v> const &point, typename Backend::bool_v &inside);
0076
0077 template <typename Backend>
0078 VECGEOM_FORCE_INLINE
0079 VECCORE_ATT_HOST_DEVICE
0080 static void InsideKernel(TUnplacedBooleanMinusVolume const &unplaced,
0081 Vector3D<typename Backend::precision_v> const &point, typename Backend::inside_v &inside);
0082
0083 template <typename Backend>
0084 VECGEOM_FORCE_INLINE
0085 VECCORE_ATT_HOST_DEVICE
0086 static void DistanceToInKernel(TUnplacedBooleanMinusVolume const &unplaced,
0087 Vector3D<typename Backend::precision_v> const &point,
0088 Vector3D<typename Backend::precision_v> const &direction,
0089 typename Backend::precision_v const &stepMax, typename Backend::precision_v &distance);
0090
0091 template <typename Backend>
0092 VECGEOM_FORCE_INLINE
0093 VECCORE_ATT_HOST_DEVICE
0094 static void DistanceToOutKernel(TUnplacedBooleanMinusVolume const &unplaced,
0095 Vector3D<typename Backend::precision_v> const &point,
0096 Vector3D<typename Backend::precision_v> const &direction,
0097 typename Backend::precision_v const &stepMax,
0098 typename Backend::precision_v &distance);
0099
0100 template <typename Backend>
0101 VECGEOM_FORCE_INLINE
0102 VECCORE_ATT_HOST_DEVICE
0103 static void SafetyToInKernel(TUnplacedBooleanMinusVolume const &unplaced,
0104 Vector3D<typename Backend::precision_v> const &point,
0105 typename Backend::precision_v &safety);
0106
0107 template <typename Backend>
0108 VECGEOM_FORCE_INLINE
0109 VECCORE_ATT_HOST_DEVICE
0110 static void SafetyToOutKernel(TUnplacedBooleanMinusVolume const &unplaced,
0111 Vector3D<typename Backend::precision_v> const &point,
0112 typename Backend::precision_v &safety);
0113
0114 template <typename Backend>
0115 VECGEOM_FORCE_INLINE
0116 VECCORE_ATT_HOST_DEVICE
0117 static void NormalKernel(TUnplacedBooleanMinusVolume const &unplaced,
0118 Vector3D<typename Backend::precision_v> const &point,
0119 Vector3D<typename Backend::precision_v> &normal, typename Backend::bool_v &valid);
0120
0121 };
0122
0123 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0124 template <typename Backend>
0125 VECCORE_ATT_HOST_DEVICE
0126 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::UnplacedContains(
0127 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &localPoint,
0128 typename Backend::bool_v &inside)
0129 {
0130
0131 ContainsKernel<Backend>(unplaced, localPoint, inside);
0132 }
0133
0134 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0135 template <typename Backend>
0136 VECCORE_ATT_HOST_DEVICE
0137 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::Contains(
0138 TUnplacedBooleanMinusVolume const &unplaced, Transformation3D const &transformation,
0139 Vector3D<typename Backend::precision_v> const &point, Vector3D<typename Backend::precision_v> &localPoint,
0140 typename Backend::bool_v &inside)
0141 {
0142
0143 localPoint = transformation.Transform<transCodeT, rotCodeT>(point);
0144 UnplacedContains<Backend>(unplaced, localPoint, inside);
0145 }
0146
0147 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0148 template <typename Backend>
0149 VECCORE_ATT_HOST_DEVICE
0150 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::Inside(
0151 TUnplacedBooleanMinusVolume const &unplaced, Transformation3D const &transformation,
0152 Vector3D<typename Backend::precision_v> const &point, typename Backend::inside_v &inside)
0153 {
0154
0155 InsideKernel<Backend>(unplaced, transformation.Transform<transCodeT, rotCodeT>(point), inside);
0156 }
0157
0158 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0159 template <typename Backend>
0160 VECCORE_ATT_HOST_DEVICE
0161 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::DistanceToIn(
0162 TUnplacedBooleanMinusVolume const &unplaced, Transformation3D const &transformation,
0163 Vector3D<typename Backend::precision_v> const &point, Vector3D<typename Backend::precision_v> const &direction,
0164 typename Backend::precision_v const &stepMax, typename Backend::precision_v &distance)
0165 {
0166
0167 DistanceToInKernel<Backend>(unplaced, transformation.Transform<transCodeT, rotCodeT>(point),
0168 transformation.TransformDirection<rotCodeT>(direction), stepMax, distance);
0169 }
0170
0171 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0172 template <typename Backend>
0173 VECCORE_ATT_HOST_DEVICE
0174 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::DistanceToOut(
0175 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &point,
0176 Vector3D<typename Backend::precision_v> const &direction, typename Backend::precision_v const &stepMax,
0177 typename Backend::precision_v &distance)
0178 {
0179
0180 DistanceToOutKernel<Backend>(unplaced, point, direction, stepMax, distance);
0181 }
0182
0183 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0184 template <typename Backend>
0185 VECGEOM_FORCE_INLINE
0186 VECCORE_ATT_HOST_DEVICE
0187 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::SafetyToIn(
0188 TUnplacedBooleanMinusVolume const &unplaced, Transformation3D const &transformation,
0189 Vector3D<typename Backend::precision_v> const &point, typename Backend::precision_v &safety)
0190 {
0191
0192 SafetyToInKernel<Backend>(unplaced, transformation.Transform<transCodeT, rotCodeT>(point), safety);
0193 }
0194
0195 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0196 template <class Backend>
0197 VECGEOM_FORCE_INLINE
0198 VECCORE_ATT_HOST_DEVICE
0199 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::SafetyToOut(
0200 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &point,
0201 typename Backend::precision_v &safety)
0202 {
0203
0204 SafetyToOutKernel<Backend>(unplaced, point, safety);
0205 }
0206
0207 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0208 template <typename Backend>
0209 VECCORE_ATT_HOST_DEVICE
0210 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::ContainsKernel(
0211 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &localPoint,
0212 typename Backend::bool_v &inside)
0213 {
0214
0215
0216
0217
0218
0219
0220 Vector3D<typename Backend::precision_v> tmp;
0221 LeftPlacedType_t::Implementation::template Contains<Backend>(
0222 *((LeftPlacedType_t *)unplaced.fLeftVolume)->GetUnplacedVolume(), *unplaced.fLeftVolume->transformation(),
0223 localPoint, tmp, inside);
0224
0225
0226
0227
0228
0229
0230
0231
0232 if (vecCore::MaskEmpty(inside)) return;
0233
0234 typename Backend::bool_v rightInside;
0235 RightPlacedType_t::Implementation::template Contains<Backend>(
0236 *((RightPlacedType_t *)unplaced.fRightVolume)->GetUnplacedVolume(), *unplaced.fRightVolume->transformation(),
0237 localPoint, tmp, rightInside);
0238
0239 inside &= !rightInside;
0240 }
0241
0242 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0243 template <typename Backend>
0244 VECCORE_ATT_HOST_DEVICE
0245 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::InsideKernel(
0246 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &point,
0247 typename Backend::inside_v &inside)
0248 {
0249
0250
0251
0252
0253 }
0254
0255 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0256 template <typename Backend>
0257 VECCORE_ATT_HOST_DEVICE
0258 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::DistanceToInKernel(
0259 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &point,
0260 Vector3D<typename Backend::precision_v> const &direction, typename Backend::precision_v const &stepMax,
0261 typename Backend::precision_v &distance)
0262 {
0263
0264 typedef typename Backend::precision_v Float_t;
0265 typedef typename Backend::bool_v Bool_t;
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316 }
0317 #include <iostream>
0318 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0319 template <typename Backend>
0320 VECCORE_ATT_HOST_DEVICE
0321 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::DistanceToOutKernel(
0322 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &point,
0323 Vector3D<typename Backend::precision_v> const &direction, typename Backend::precision_v const &stepMax,
0324 typename Backend::precision_v &distance)
0325 {
0326
0327 typedef typename Backend::precision_v Float_t;
0328 typedef typename Backend::bool_v Bool_t;
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341 LeftPlacedType_t::Implementation::template DistanceToOut<Backend>(
0342 *((LeftPlacedType_t *)unplaced.fLeftVolume)->GetUnplacedVolume(), point, direction, stepMax, distance);
0343 Float_t dinright(kInfLength);
0344 RightPlacedType_t::Implementation::template DistanceToIn<Backend>(
0345 *((RightPlacedType_t *)unplaced.fRightVolume)->GetUnplacedVolume(), *unplaced.fRightVolume->transformation(),
0346 point, direction, stepMax, dinright);
0347 distance = Min(distance, dinright);
0348 return;
0349 }
0350
0351 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0352 template <typename Backend>
0353 VECCORE_ATT_HOST_DEVICE
0354 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::SafetyToInKernel(
0355 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &point,
0356 typename Backend::precision_v &safety)
0357 {
0358
0359 typedef typename Backend::precision_v Float_t;
0360 typedef typename Backend::bool_v Bool_t;
0361
0362
0363
0364
0365
0366
0367
0368
0369
0370
0371
0372
0373
0374 }
0375
0376 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0377 template <typename Backend>
0378 VECCORE_ATT_HOST_DEVICE
0379 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::SafetyToOutKernel(
0380 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &point,
0381 typename Backend::precision_v &safety)
0382 {
0383
0384 typedef typename Backend::bool_v Bool_t;
0385 typedef typename Backend::precision_v Float_t;
0386
0387 LeftPlacedType_t::Implementation::template SafetyToOut<Backend>(
0388 *((LeftPlacedType_t *)unplaced.fLeftVolume)->GetUnplacedVolume(), point, safety);
0389 Float_t safetyright(kInfLength);
0390 RightPlacedType_t::Implementation::template SafetyToIn<Backend>(
0391 *((RightPlacedType_t *)unplaced.fRightVolume)->GetUnplacedVolume(), *unplaced.fRightVolume->transformation(),
0392 point, safetyright);
0393 safety = Min(safety, safetyright);
0394 return;
0395 }
0396
0397 template <typename LeftPlacedType_t, typename RightPlacedType_t, TranslationCode transCodeT, RotationCode rotCodeT>
0398 template <typename Backend>
0399 VECCORE_ATT_HOST_DEVICE
0400 void TBooleanMinusImplementation<LeftPlacedType_t, RightPlacedType_t, transCodeT, rotCodeT>::NormalKernel(
0401 TUnplacedBooleanMinusVolume const &unplaced, Vector3D<typename Backend::precision_v> const &point,
0402 Vector3D<typename Backend::precision_v> &normal, typename Backend::bool_v &valid)
0403 {
0404
0405 }
0406
0407 }
0408
0409 #endif