Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UAdapter.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4UAdapter
27//
28// Class description:
29//
30// Utility class for adapting VecGeom solids API to Geant4 solids.
31// NOTE: Using protected inheritance since the Adapter is supposed to
32// be a G4VSolid "implemented-in-terms-of" the VecGeom UnplacedVolume_t.
33// The choice of protected vs private is due to the fact that we want
34// to propagate functions further down in the inheritance hierarchy.
35
36// Author: Gabriele Cosmo (CERN), 17.05.2017
37// Adapted for G4VSolid from original G4USolids bridge
38// class and the USolidsAdapter class in VecGeom.
39// ------------------------------------------------------------------------
40#ifndef G4UADAPTER_HH
41#define G4UADAPTER_HH
42
43#include "G4ThreeVector.hh"
44#include "G4VSolid.hh"
45
46// Required for inline visualization adapter functions
47//
48#include "G4AffineTransform.hh"
49#include "G4VoxelLimits.hh"
50#include "G4VGraphicsScene.hh"
51#include "G4Polyhedron.hh"
52#include "G4VisExtent.hh"
53#include "G4BoundingEnvelope.hh"
54#include "G4AutoLock.hh"
55
56#include "G4GeomTypes.hh"
57
58#if ( defined(G4GEOM_USE_USOLIDS) || defined(G4GEOM_USE_PARTIAL_USOLIDS) )
59
60#include <VecGeom/base/Global.h>
61#include <VecGeom/base/Vector3D.h>
62
64
65/**
66 * @brief G4UAdapter is a utility class for adapting VecGeom solids API to
67 * Geant4 solids. The Adapter is supposed to be a G4VSolid
68 * "implemented-in-terms-of" the VecGeom UnplacedVolume_t.
69 */
70
71template <class UnplacedVolume_t>
72class G4UAdapter : public G4VSolid, protected UnplacedVolume_t
73{
74 public:
75
76 using U3Vector = vecgeom::Vector3D<G4double>;
77
78 /** VecGeom volumes have special delete/new ("AlignedBase")
79 and we need to make these functions public again. */
80 using UnplacedVolume_t::operator delete;
81 using UnplacedVolume_t::operator new;
82
83 /**
84 * Constructor taking a name.
85 * @param[in] name The name of the volume.
86 */
87 G4UAdapter(const G4String& name);
88
89 /**
90 * Constructor templated on arguments for UnplacedVolume_t.
91 * @param[in] name The name of the volume.
92 * @param[in] params Templated arguments for UnplacedVolume_t.
93 */
94 template <typename... T>
95 G4UAdapter(const G4String& name, const T &... params);
96
97 /**
98 * Virtual destructor.
99 */
100 virtual ~G4UAdapter();
101
102 /**
103 * Copy constructor and assignment operator.
104 */
105 G4UAdapter(const G4UAdapter& rhs);
106 G4UAdapter& operator=(const G4UAdapter& rhs);
107
108 /**
109 * Equality operator. Returns true only if addresses are the same.
110 */
111 G4bool operator==(const G4UAdapter& s) const;
112
113 /**
114 * Calculates the minimum and maximum extent of the solid, when under the
115 * specified transform, and within the specified limits.
116 * @param[in] pAxis The axis along which compute the extent.
117 * @param[in] pVoxelLimit The limiting space dictated by voxels.
118 * @param[in] pTransform The internal transformation applied to the solid.
119 * @param[out] pMin The minimum extent value.
120 * @param[out] pMax The maximum extent value.
121 * @returns True if the solid is intersected by the extent region.
122 */
123 virtual G4bool CalculateExtent(const EAxis pAxis,
124 const G4VoxelLimits& pVoxelLimit,
125 const G4AffineTransform& pTransform,
126 G4double& pMin, G4double& pMax) const override;
127
128 /**
129 * Returns the characterisation of a point at offset 'p' respect
130 * to the shape.
131 * @param[in] p The point at offset p.
132 * @returns kOutside if the point is outside the shapes boundaries
133 * plus Tolerance/2; kSurface if the point is less than
134 * Tolerance/2 from a surface; kInside otherwise.
135 */
136 virtual EInside Inside(const G4ThreeVector& p) const override;
137
138 /**
139 * Returns the outwards pointing unit normal of the shape for the
140 * surface closest to the point at offset 'p'.
141 * @param[in] p The point at offset p.
142 * @returns The outwards pointing unit normal.
143 */
144 virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
145
146 /**
147 * Returns the distance along the normalised vector 'v' to the shape,
148 * from the point at offset 'p'. If there is no intersection, returns
149 * kInfinity. The first intersection resulting from 'leaving' a
150 * surface/volume is discarded. Hence, it is tolerant of points on
151 * the surface of the shape.
152 * @param[in] p The point at offset p.
153 * @param[in] v The normalised direction vector.
154 * @returns The distance to enter the shape.
155 */
156 virtual G4double DistanceToIn(const G4ThreeVector& p,
157 const G4ThreeVector& v) const override;
158
159 /**
160 * Calculates the distance to the nearest surface of a shape from an
161 * outside point. The distance can be an underestimate.
162 * @param[in] p The point at offset p.
163 * @returns The safety distance to enter the shape.
164 */
165 virtual G4double DistanceToIn(const G4ThreeVector& p) const override;
166
167 /**
168 * Returns the distance along the normalised vector 'v' to the shape,
169 * from a point at an offset 'p' inside or on the surface of the shape.
170 * Intersections with surfaces, when the point is less than Tolerance/2
171 * from a surface must be ignored.
172 * @param[in] p The point at offset p.
173 * @param[in] v The normalised direction vector.
174 * @param[in] calcNorm Flag to indicate if to calculate the normal or not.
175 * @param[out] validNorm Flag set to true if the solid lies entirely
176 * behind or on the exiting surface. It is set false if the
177 * solid does not lie entirely behind or on the exiting surface.
178 * 'calcNorm' must be true, otherwise it is unused.
179 * @param[out] n The exiting outwards normal vector (undefined Magnitude).
180 * 'calcNorm' must be true, otherwise it is unused.
181 * @returns The distance to exit the shape.
182 */
183 virtual G4double DistanceToOut(const G4ThreeVector& p,
184 const G4ThreeVector& v,
185 const G4bool calcNorm = false,
186 G4bool* validNorm = 0,
187 G4ThreeVector* n = 0) const override;
188
189 /**
190 * Calculates the distance to the nearest surface of a shape from an
191 * inside point 'p'. The distance can be an underestimate.
192 * @param[in] p The point at offset p.
193 * @returns The safety distance to exit the shape.
194 */
195 virtual G4double DistanceToOut(const G4ThreeVector& p) const override;
196
197 /**
198 * Dispatch method for parameterisation replication mechanism and
199 * dimension computation. Throws exception if ComputeDimensions() is
200 * called from an illegal derived class.
201 */
202 virtual void ComputeDimensions(G4VPVParameterisation* p,
203 const G4int n,
204 const G4VPhysicalVolume* pRep) override;
205
206 /**
207 * Returns an estimation of the solid volume in internal units.
208 * This method may be overloaded by derived classes to compute the
209 * exact geometrical quantity for solids where this is possible,
210 * or anyway to cache the computed value.
211 * Note: the computed value is NOT cached.
212 */
213 virtual G4double GetCubicVolume() override;
214
215 /**
216 * Returns an estimation of the solid surface area in internal units.
217 * This method may be overloaded by derived classes to compute the
218 * exact geometrical quantity for solids where this is possible,
219 * or anyway to cache the computed value.
220 * Note: the computed value is NOT cached.
221 */
222 virtual G4double GetSurfaceArea() override;
223
224 /**
225 * Returns a random point located on the surface of the solid.
226 */
227 virtual G4ThreeVector GetPointOnSurface() const override;
228
229 /**
230 * Returns the number of constituents used for construction of the solid.
231 * For non-Boolean solids the return value is one.
232 */
233 virtual G4int GetNumOfConstituents() const override;
234
235 /**
236 * Returns true if the solid has only planar faces, false otherwise.
237 */
238 virtual G4bool IsFaceted() const override;
239
240 /**
241 * Provides identification of the class of an object
242 * (required for persistency).
243 */
244 virtual G4GeometryType GetEntityType() const override;
245
246 /**
247 * Returns a pointer of a dynamically allocated copy of the solid.
248 * Returns a null pointer with warning in case the concrete solid does not
249 * implement this method. The caller has responsibility for ownership.
250 */
251 virtual G4VSolid* Clone() const override;
252
253 /**
254 * Dumps contents of the solid to a stream.
255 */
256 virtual std::ostream& StreamInfo(std::ostream& os) const override;
257
258 /**
259 * A "double dispatch" function which identifies the solid
260 * to the graphics scene for visualization.
261 */
262 virtual void DescribeYourselfTo(G4VGraphicsScene& scene) const override;
263
264 /**
265 * Provides extent (bounding box) as possible hint to the graphics view.
266 */
267 virtual G4VisExtent GetExtent() const override;
268
269 /**
270 * Creates a Polyhedron used for Visualisation.
271 */
272 virtual G4Polyhedron* CreatePolyhedron() const override;
273
274 /**
275 * Smart access function - creates on request and stores for future
276 * access. A null pointer means "not available".
277 */
278 virtual G4Polyhedron* GetPolyhedron() const override;
279
280
281 // VecGeom overridden methods ---------------------------------------------
282
283 vecgeom::Precision
284 DistanceToOut(U3Vector const& position, U3Vector const& direction,
285 vecgeom::Precision stepMax = kInfinity) const override
286 {
287 return UnplacedVolume_t::DistanceToOut(position, direction, stepMax);
288 }
289
290 vecgeom::EnumInside
291 Inside(U3Vector const& aPoint) const override
292 {
293 return UnplacedVolume_t::Inside(aPoint);
294 }
295
296 vecgeom::Precision
297 DistanceToIn(U3Vector const& position, U3Vector const& direction,
298 const vecgeom::Precision step_max = kInfinity) const override
299 {
300 return UnplacedVolume_t::DistanceToIn(position, direction, step_max);
301 }
302
303 G4bool Normal(U3Vector const& aPoint, U3Vector& aNormal) const override
304 {
305 return UnplacedVolume_t::Normal(aPoint, aNormal);
306 }
307
308 void Extent(U3Vector& aMin, U3Vector& aMax) const override
309 {
310 return UnplacedVolume_t::Extent(aMin, aMax);
311 }
312
313 U3Vector SamplePointOnSurface() const override
314 {
315 return UnplacedVolume_t::SamplePointOnSurface();
316 }
317
318 protected: // data
319
320 mutable G4bool fRebuildPolyhedron = false;
321 mutable G4Polyhedron* fPolyhedron = nullptr;
322
323 /** Cached geometrical tolerance. */
324 G4double kHalfTolerance;
325
326 using UnplacedVolume_t::DistanceToOut;
327 using UnplacedVolume_t::DistanceToIn;
328};
329
330// Inline implementations
331
332#include "G4UAdapter.icc"
333
334#endif // G4GEOM_USE_USOLIDS
335
336#endif // G4UADAPTER_HH
G4bool operator==(const G4GeometryCell &k1, const G4GeometryCell &k2)
G4PVDivision & operator=(const G4PVDivision &)=delete
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4String G4GeometryType
Definition G4VSolid.hh:70
G4VPVParameterisation ia an abstract base class for Parameterisation, able to compute the transformat...
G4VSolid is an abstract base class for solids, physical shapes that can be tracked through....
Definition G4VSolid.hh:80
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67