File indexing completed on 2025-01-18 10:14:06
0001
0002
0003
0004 #ifndef VECGEOM_VOLUMES_CUTPLANES_H_
0005 #define VECGEOM_VOLUMES_CUTPLANES_H_
0006
0007 #include "VecGeom/volumes/Plane.h"
0008
0009 namespace vecgeom {
0010
0011 VECGEOM_DEVICE_FORWARD_DECLARE(class CutPlanes;);
0012 VECGEOM_DEVICE_DECLARE_CONV(class, CutPlanes);
0013
0014 inline namespace VECGEOM_IMPL_NAMESPACE {
0015
0016 class CutPlanes : public AlignedBase {
0017
0018 private:
0019 Plane fCutPlanes[2];
0020
0021 public:
0022 VECCORE_ATT_HOST_DEVICE
0023 CutPlanes() {}
0024
0025 VECCORE_ATT_HOST_DEVICE
0026 ~CutPlanes() {}
0027
0028 VECGEOM_FORCE_INLINE
0029 VECCORE_ATT_HOST_DEVICE
0030 Plane const &GetCutPlane(int i) const;
0031
0032 VECGEOM_FORCE_INLINE
0033 VECCORE_ATT_HOST_DEVICE
0034 Vector3D<Precision> GetNormal(int i) const;
0035
0036 VECGEOM_FORCE_INLINE
0037 VECCORE_ATT_HOST_DEVICE
0038 Precision GetDistance(int i) const;
0039
0040 VECCORE_ATT_HOST_DEVICE
0041 void Set(int index, Vector3D<Precision> const &normal, Vector3D<Precision> const &origin);
0042
0043 VECCORE_ATT_HOST_DEVICE
0044 void Set(int index, Vector3D<Precision> const &normal, Precision distance);
0045
0046 template <typename Real_v, typename Bool_v>
0047 VECGEOM_FORCE_INLINE
0048 VECCORE_ATT_HOST_DEVICE
0049 void Contains(Vector3D<Real_v> const &point, Bool_v &inside) const;
0050
0051 template <typename Real_v, typename Inside_v>
0052 VECGEOM_FORCE_INLINE
0053 VECCORE_ATT_HOST_DEVICE
0054 void Inside(Vector3D<Real_v> const &point, Inside_v &inside) const;
0055
0056 template <typename Real_v>
0057 VECGEOM_FORCE_INLINE
0058 VECCORE_ATT_HOST_DEVICE
0059 void DistanceToIn(Vector3D<Real_v> const &point, Vector3D<Real_v> const &direction, Real_v &distance) const;
0060
0061 template <typename Real_v>
0062 VECGEOM_FORCE_INLINE
0063 VECCORE_ATT_HOST_DEVICE
0064 void DistanceToOut(Vector3D<Real_v> const &point, Vector3D<Real_v> const &direction, Real_v &distance) const;
0065
0066 template <typename Real_v>
0067 VECGEOM_FORCE_INLINE
0068 VECCORE_ATT_HOST_DEVICE
0069 void SafetyToIn(Vector3D<Real_v> const &point, Real_v &distance) const;
0070
0071 template <typename Real_v>
0072 VECGEOM_FORCE_INLINE
0073 VECCORE_ATT_HOST_DEVICE
0074 void SafetyToOut(Vector3D<Real_v> const &point, Real_v &distance) const;
0075 };
0076
0077 std::ostream &operator<<(std::ostream &os, CutPlanes const &planes);
0078
0079 VECGEOM_FORCE_INLINE
0080 VECCORE_ATT_HOST_DEVICE
0081 Plane const &CutPlanes::GetCutPlane(int i) const
0082 {
0083 return fCutPlanes[i];
0084 }
0085
0086 VECGEOM_FORCE_INLINE
0087 VECCORE_ATT_HOST_DEVICE
0088 Vector3D<Precision> CutPlanes::GetNormal(int i) const
0089 {
0090 return fCutPlanes[i].GetNormal();
0091 }
0092
0093 VECGEOM_FORCE_INLINE
0094 VECCORE_ATT_HOST_DEVICE
0095 Precision CutPlanes::GetDistance(int i) const
0096 {
0097 return fCutPlanes[i].GetDistance();
0098 }
0099
0100 template <typename Real_v, typename Bool_v>
0101 VECGEOM_FORCE_INLINE
0102 VECCORE_ATT_HOST_DEVICE
0103 void CutPlanes::Contains(Vector3D<Real_v> const &point, Bool_v &inside) const
0104 {
0105 inside = fCutPlanes[0].DistPlane(point) < Real_v(0.) && fCutPlanes[1].DistPlane(point) < Real_v(0.);
0106 }
0107
0108 template <typename Real_v, typename Inside_v>
0109 VECGEOM_FORCE_INLINE
0110 VECCORE_ATT_HOST_DEVICE
0111 void CutPlanes::Inside(Vector3D<Real_v> const &point, Inside_v &inside) const
0112 {
0113 Real_v d0 = fCutPlanes[0].DistPlane(point);
0114 Real_v d1 = fCutPlanes[1].DistPlane(point);
0115
0116 inside =
0117 vecCore::Blend(d0 < Real_v(0.0) && d1 < Real_v(0.0), Inside_v(EInside::kInside), Inside_v(EInside::kOutside));
0118 vecCore::MaskedAssign(inside,
0119 vecCore::math::Abs(d0) < Real_v(kTolerance) || vecCore::math::Abs(d1) < Real_v(kTolerance),
0120 Inside_v(EInside::kSurface));
0121 }
0122
0123 template <typename Real_v>
0124 VECGEOM_FORCE_INLINE
0125 VECCORE_ATT_HOST_DEVICE
0126 void CutPlanes::DistanceToIn(Vector3D<Real_v> const &point, Vector3D<Real_v> const &direction, Real_v &distance) const
0127 {
0128
0129
0130
0131
0132 Real_v d0, d1;
0133 fCutPlanes[0].DistanceToIn(point, direction, d0);
0134 vecCore::MaskedAssign(d0, direction.Dot(Vector3D<Real_v>(fCutPlanes[0].GetNormal())) > Real_v(0.),
0135 Real_v(-kInfLength));
0136 fCutPlanes[1].DistanceToIn(point, direction, d1);
0137 vecCore::MaskedAssign(d1, direction.Dot(Vector3D<Real_v>(fCutPlanes[1].GetNormal())) > Real_v(0.),
0138 Real_v(-kInfLength));
0139 distance = vecCore::math::Max(d0, d1);
0140 }
0141
0142 template <typename Real_v>
0143 VECGEOM_FORCE_INLINE
0144 VECCORE_ATT_HOST_DEVICE
0145 void CutPlanes::DistanceToOut(Vector3D<Real_v> const &point, Vector3D<Real_v> const &direction, Real_v &distance) const
0146 {
0147 Real_v d0, d1;
0148 fCutPlanes[0].DistanceToOut(point, direction, d0);
0149 fCutPlanes[1].DistanceToOut(point, direction, d1);
0150 distance = vecCore::math::Min(d0, d1);
0151 }
0152
0153 template <typename Real_v>
0154 VECGEOM_FORCE_INLINE
0155 VECCORE_ATT_HOST_DEVICE
0156 void CutPlanes::SafetyToIn(Vector3D<Real_v> const &point, Real_v &distance) const
0157 {
0158 Real_v d0, d1;
0159 fCutPlanes[0].SafetyToIn(point, d0);
0160 fCutPlanes[1].SafetyToIn(point, d1);
0161 distance = vecCore::math::Max(d0, d1);
0162 }
0163
0164 template <typename Real_v>
0165 VECGEOM_FORCE_INLINE
0166 VECCORE_ATT_HOST_DEVICE
0167 void CutPlanes::SafetyToOut(Vector3D<Real_v> const &point, Real_v &distance) const
0168 {
0169 Real_v d0, d1;
0170 fCutPlanes[0].SafetyToOut(point, d0);
0171 fCutPlanes[1].SafetyToOut(point, d1);
0172 distance = vecCore::math::Min(d0, d1);
0173 }
0174
0175 }
0176
0177 }
0178
0179 #endif