File: CutPlanes.h

package info (click to toggle)
vecgeom 1.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,928 kB
  • sloc: cpp: 88,717; ansic: 6,894; python: 1,035; sh: 582; sql: 538; makefile: 29
file content (179 lines) | stat: -rw-r--r-- 5,348 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/// \file CutPlanes.h
/// \author mgheata

#ifndef VECGEOM_VOLUMES_CUTPLANES_H_
#define VECGEOM_VOLUMES_CUTPLANES_H_

#include "VecGeom/volumes/Plane.h"

namespace vecgeom {

VECGEOM_DEVICE_FORWARD_DECLARE(class CutPlanes;);
VECGEOM_DEVICE_DECLARE_CONV(class, CutPlanes);

inline namespace VECGEOM_IMPL_NAMESPACE {

class CutPlanes : public AlignedBase {

private:
  Plane fCutPlanes[2]; ///< Two cut planes

public:
  VECCORE_ATT_HOST_DEVICE
  CutPlanes() {}

  VECCORE_ATT_HOST_DEVICE
  ~CutPlanes() {}

  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  Plane const &GetCutPlane(int i) const;

  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  Vector3D<Precision> GetNormal(int i) const;

  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  Precision GetDistance(int i) const;

  VECCORE_ATT_HOST_DEVICE
  void Set(int index, Vector3D<Precision> const &normal, Vector3D<Precision> const &origin);

  VECCORE_ATT_HOST_DEVICE
  void Set(int index, Vector3D<Precision> const &normal, Precision distance);

  template <typename Real_v, typename Bool_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  void Contains(Vector3D<Real_v> const &point, Bool_v &inside) const;

  template <typename Real_v, typename Inside_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  void Inside(Vector3D<Real_v> const &point, Inside_v &inside) const;

  template <typename Real_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  void DistanceToIn(Vector3D<Real_v> const &point, Vector3D<Real_v> const &direction, Real_v &distance) const;

  template <typename Real_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  void DistanceToOut(Vector3D<Real_v> const &point, Vector3D<Real_v> const &direction, Real_v &distance) const;

  template <typename Real_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  void SafetyToIn(Vector3D<Real_v> const &point, Real_v &distance) const;

  template <typename Real_v>
  VECGEOM_FORCE_INLINE
  VECCORE_ATT_HOST_DEVICE
  void SafetyToOut(Vector3D<Real_v> const &point, Real_v &distance) const;
}; // class CutPlanes

std::ostream &operator<<(std::ostream &os, CutPlanes const &planes);

VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
Plane const &CutPlanes::GetCutPlane(int i) const
{
  return fCutPlanes[i];
}

VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
Vector3D<Precision> CutPlanes::GetNormal(int i) const
{
  return fCutPlanes[i].GetNormal();
}

VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
Precision CutPlanes::GetDistance(int i) const
{
  return fCutPlanes[i].GetDistance();
}

template <typename Real_v, typename Bool_v>
VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
void CutPlanes::Contains(Vector3D<Real_v> const &point, Bool_v &inside) const
{
  inside = fCutPlanes[0].DistPlane(point) < Real_v(0.) && fCutPlanes[1].DistPlane(point) < Real_v(0.);
}

template <typename Real_v, typename Inside_v>
VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
void CutPlanes::Inside(Vector3D<Real_v> const &point, Inside_v &inside) const
{
  Real_v d0 = fCutPlanes[0].DistPlane(point);
  Real_v d1 = fCutPlanes[1].DistPlane(point);

  inside =
      vecCore::Blend(d0 < Real_v(0.0) && d1 < Real_v(0.0), Inside_v(EInside::kInside), Inside_v(EInside::kOutside));
  vecCore::MaskedAssign(inside,
                        vecCore::math::Abs(d0) < Real_v(kTolerance) || vecCore::math::Abs(d1) < Real_v(kTolerance),
                        Inside_v(EInside::kSurface));
}

template <typename Real_v>
VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
void CutPlanes::DistanceToIn(Vector3D<Real_v> const &point, Vector3D<Real_v> const &direction, Real_v &distance) const
{
  // The function returns a negative distance for points coming from the
  // region in between the two planes, or from points outside going outwards
  // If a particle has valid crossings withe the 2 planes, the maximum distance
  // has to be taken
  Real_v d0, d1;
  fCutPlanes[0].DistanceToIn(point, direction, d0);
  vecCore::MaskedAssign(d0, direction.Dot(Vector3D<Real_v>(fCutPlanes[0].GetNormal())) > Real_v(0.),
                        Real_v(-kInfLength));
  fCutPlanes[1].DistanceToIn(point, direction, d1);
  vecCore::MaskedAssign(d1, direction.Dot(Vector3D<Real_v>(fCutPlanes[1].GetNormal())) > Real_v(0.),
                        Real_v(-kInfLength));
  distance = vecCore::math::Max(d0, d1);
}

template <typename Real_v>
VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
void CutPlanes::DistanceToOut(Vector3D<Real_v> const &point, Vector3D<Real_v> const &direction, Real_v &distance) const
{
  Real_v d0, d1;
  fCutPlanes[0].DistanceToOut(point, direction, d0);
  fCutPlanes[1].DistanceToOut(point, direction, d1);
  distance = vecCore::math::Min(d0, d1);
}

template <typename Real_v>
VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
void CutPlanes::SafetyToIn(Vector3D<Real_v> const &point, Real_v &distance) const
{
  Real_v d0, d1;
  fCutPlanes[0].SafetyToIn(point, d0);
  fCutPlanes[1].SafetyToIn(point, d1);
  distance = vecCore::math::Max(d0, d1);
}

template <typename Real_v>
VECGEOM_FORCE_INLINE
VECCORE_ATT_HOST_DEVICE
void CutPlanes::SafetyToOut(Vector3D<Real_v> const &point, Real_v &distance) const
{
  Real_v d0, d1;
  fCutPlanes[0].SafetyToOut(point, d0);
  fCutPlanes[1].SafetyToOut(point, d1);
  distance = vecCore::math::Min(d0, d1);
}

} // namespace VECGEOM_IMPL_NAMESPACE

} // namespace vecgeom

#endif // VECGEOM_VOLUMES_CUTPLANES_H_