Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MultiUnion.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// G4MultiUnion
27//
28// Class description:
29//
30// An instance of "G4MultiUnion" constitutes a grouping of several solids.
31// The constituent solids are stored with their respective location in a node
32// instance. An instance of "G4MultiUnion" is subsequently composed of one
33// or several nodes.
34
35// Author: Marek Gayer (CERN), 19.10.2012 - Original implementation from USolids
36// Gabriele Cosmo (CERN) 06.04.2017 - Adapted implementation in Geant4
37// for VecGeom migration
38// --------------------------------------------------------------------
39#ifndef G4MULTIUNION_HH
40#define G4MULTIUNION_HH
41
42#include <vector>
43
44#include "G4VSolid.hh"
45#include "G4ThreeVector.hh"
46#include "G4Transform3D.hh"
47#include "G4Point3D.hh"
48#include "G4Vector3D.hh"
49#include "G4SurfBits.hh"
50#include "G4Voxelizer.hh"
51
52class G4Polyhedron;
53
54/**
55 * @brief An instance of G4MultiUnion constitutes a grouping of several solids.
56 * The constituent solids are stored with their respective location in a node
57 * instance. An instance of G4MultiUnion is subsequently composed of one or
58 * several nodes.
59 */
60
61class G4MultiUnion : public G4VSolid
62{
63 friend class G4Voxelizer;
64
65 public:
66
67 /**
68 * Empty default constructor.
69 */
71
72
73 /**
74 * Constructor assigning a name and initialising components.
75 */
76 G4MultiUnion(const G4String& name);
77
78 /**
79 * Default destructor.
80 */
81 ~G4MultiUnion() override = default;
82
83 /**
84 * Fake default constructor for usage restricted to direct object
85 * persistency for clients requiring preallocation of memory for
86 * persistifiable objects.
87 */
88 G4MultiUnion(__void__&);
89
90 /**
91 * Methods to build the multiple union by adding nodes (by pointer or ref).
92 * @param[in] solid The solid to be added to the structure.
93 * @param[in] trans The 3D transformation relative to the structure.
94 */
95 void AddNode(G4VSolid& solid, const G4Transform3D& trans);
96 void AddNode(G4VSolid* solid, const G4Transform3D& trans);
97
98 /**
99 * Copy constructor and assignment operator.
100 */
101 G4MultiUnion(const G4MultiUnion& rhs);
103
104 /**
105 * Accessors to retrieve a transformation or a solid, given an index
106 * and the total number of solids in the structure.
107 */
108 inline const G4Transform3D& GetTransformation(G4int index) const;
109 inline G4VSolid* GetSolid(G4int index) const;
111
112 /**
113 * Returns if the given point "aPoint" is inside or not the solid.
114 */
115 EInside Inside(const G4ThreeVector& aPoint) const override;
116
117 // Safety methods
118 G4double DistanceToIn(const G4ThreeVector& aPoint) const override;
119 G4double DistanceToOut(const G4ThreeVector& aPoint) const override;
120 inline void SetAccurateSafety(G4bool flag);
121
122 /**
123 * Returns the distance along the normalised vector "aDirection" to the
124 * shape, from the point at offset "aPoint". If there is no intersection,
125 * return kInfinity. The first intersection resulting from leaving a
126 * surface/volume is discarded. Hence, it is tolerant of points on
127 * the surface of the shape.
128 */
129 G4double DistanceToIn(const G4ThreeVector& aPoint,
130 const G4ThreeVector& aDirection) const override;
131
132 /**
133 * Computes distance from a point presumably inside the solid to the solid
134 * surface. Ignores first surface along each axis systematically (for points
135 * inside or outside. Early returns zero in case the second surface is
136 * behind the starting point.
137 * The normal vector to the crossed surface is always filled.
138 * In the case the considered point is located inside the G4MultiUnion
139 * structure, it acts as follows:
140 * - investigation of the candidates for the passed point
141 * - progressive moving of the point towards the surface, along the
142 * provided direction
143 * - processing of the normal.
144 * @param[in] aPoint The reference point in space.
145 * @param[in] aDirection The normalised direction.
146 * @param[in] calcNorm Flag unused.
147 * @param[out] validNorm Unused.
148 * @param[out] aNormalVector The exiting outwards normal vector (undefined
149 * Magnitude).
150 * @returns The distance value to exit a volume.
151 */
153 const G4ThreeVector& aDirection,
154 const G4bool calcNorm = false,
155 G4bool* validNorm = nullptr,
156 G4ThreeVector* aNormalVector = nullptr) const override;
157
158 /**
159 * Methods to compute the distance to enter/exit a volume, given point and
160 * direction, in presence of voxels-based optimisation structure or not.
161 */
163 const G4ThreeVector& aDirection) const;
165 const G4ThreeVector& aDirection,
166 G4ThreeVector* aNormalVector) const;
168 const G4ThreeVector& aDirection,
169 G4ThreeVector* aNormalVector) const;
170
171 /**
172 * Returns the outwards pointing unit normal of the shape for the
173 * surface closest to the point at offset "aPoint".
174 */
175 G4ThreeVector SurfaceNormal(const G4ThreeVector& aPoint) const override;
176
177 /**
178 * Determines the bounding box for the considered instance of G4MultiUnion.
179 * @param[in] aAxis The axis along which computing the extent.
180 * @param[out] aMin The minimum bounding limit point.
181 * @param[out] aMax The maximum bounding limit point.
182 */
183 void Extent(EAxis aAxis, G4double& aMin, G4double& aMax) const;
184
185 /**
186 * Computes the bounding limits of the solid.
187 * @param[out] aMin The minimum bounding limit point.
188 * @param[out] aMax The maximum bounding limit point.
189 */
190 void BoundingLimits(G4ThreeVector& aMin, G4ThreeVector& aMax) const override;
191
192 /**
193 * Calculates the minimum and maximum extent of a solid, when under the
194 * specified transform, and within the specified limits.
195 * @param[in] pAxis The axis along which compute the extent.
196 * @param[in] pVoxelLimit The limiting space dictated by voxels.
197 * @param[in] pTransform The internal transformation applied to the solid.
198 * @param[out] pMin The minimum extent value.
199 * @param[out] pMax The maximum extent value.
200 * @returns True if the solid is intersected by the extent region.
201 */
202 G4bool CalculateExtent(const EAxis pAxis,
203 const G4VoxelLimits& pVoxelLimit,
204 const G4AffineTransform& pTransform,
205 G4double& pMin, G4double& pMax) const override;
206
207 /**
208 * Returns an estimate of the structure capacity or surface area.
209 */
210 G4double GetCubicVolume() override;
211 G4double GetSurfaceArea() override;
212
213 /**
214 * Returns the number of solids part of the structure.
215 */
216 G4int GetNumOfConstituents() const override;
217
218 /**
219 * Returns false if any of the solids part of the structure is not faceted.
220 */
221 G4bool IsFaceted() const override;
222
223 /**
224 * Returns a new allocated clone of the multi-union structure.
225 */
226 G4VSolid* Clone() const override ;
227
228 /**
229 * Returns the type ID, "G4MultiUnion" of the solid.
230 */
231 G4GeometryType GetEntityType() const override { return "G4MultiUnion"; }
232
233 /**
234 * Finalises and prepares for use, creating the optimisation structure
235 * for all solids in the structure. It must be called once before
236 * navigation use.
237 */
238 void Voxelize();
239
240 /**
241 * Returns the xoxelised optimisation structure.
242 */
243 inline G4Voxelizer& GetVoxels() const;
244
245 /**
246 * Streams the object contents to an output stream.
247 */
248 std::ostream& StreamInfo(std::ostream& os) const override;
249
250 /**
251 * Returns a point (G4ThreeVector) randomly and uniformly generated
252 * on the surface of a solid.
253 */
254 G4ThreeVector GetPointOnSurface() const override;
255
256 /**
257 * Methods for creating graphical representations (i.e. for visualisation).
258 */
259 void DescribeYourselfTo ( G4VGraphicsScene& scene ) const override ;
260 G4Polyhedron* CreatePolyhedron () const override ;
261 G4Polyhedron* GetPolyhedron () const override;
262
263 private:
264
265 /**
266 * Utility methods for safety and distance computation.
267 */
268 EInside InsideNoVoxels(const G4ThreeVector& aPoint) const;
269 EInside InsideWithExclusion(const G4ThreeVector& aPoint,
270 G4SurfBits* bits = nullptr) const;
271 G4int SafetyFromOutsideNumberNode(const G4ThreeVector& aPoint,
272 G4double& safety) const;
273 G4double DistanceToInCandidates(const G4ThreeVector& aPoint,
274 const G4ThreeVector& aDirection,
275 std::vector<G4int>& candidates,
276 G4SurfBits& bits) const;
277
278 /**
279 * Conversion utilities.
280 */
281 inline G4ThreeVector GetLocalPoint(const G4Transform3D& trans,
282 const G4ThreeVector& gpoint) const;
283 inline G4ThreeVector GetLocalVector(const G4Transform3D& trans,
284 const G4ThreeVector& gvec) const;
285 inline G4ThreeVector GetGlobalPoint(const G4Transform3D& trans,
286 const G4ThreeVector& lpoint) const;
287 inline G4ThreeVector GetGlobalVector(const G4Transform3D& trans,
288 const G4ThreeVector& lvec) const;
289 void TransformLimits(G4ThreeVector& min, G4ThreeVector& max,
290 const G4Transform3D& transformation) const;
291
292 private:
293
294 struct G4MultiUnionSurface
295 {
296 G4ThreeVector point;
297 G4VSolid* solid;
298 };
299
300 std::vector<G4VSolid*> fSolids;
301 std::vector<G4Transform3D> fTransformObjs;
302 G4Voxelizer fVoxels; // Vozelizer for the solid
303 G4double fCubicVolume = 0.0; // Cubic Volume
304 G4double fSurfaceArea = 0.0; // Surface Area
305 G4double kRadTolerance; // Cached radial tolerance
306 mutable G4bool fAccurate = false; // Accurate safety (off by default)
307
308 mutable G4bool fRebuildPolyhedron = false;
309 mutable G4Polyhedron* fpPolyhedron = nullptr;
310};
311
312#include "G4MultiUnion.icc"
313
314#endif
CLHEP::Hep3Vector G4ThreeVector
HepGeom::Transform3D G4Transform3D
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4String G4GeometryType
Definition G4VSolid.hh:70
G4AffineTransform is a class for geometric affine transformations. It supports efficient arbitrary ro...
const G4Transform3D & GetTransformation(G4int index) const
G4int GetNumberOfSolids() const
friend class G4Voxelizer
G4ThreeVector SurfaceNormal(const G4ThreeVector &aPoint) const override
G4ThreeVector GetPointOnSurface() const override
G4double GetCubicVolume() override
void DescribeYourselfTo(G4VGraphicsScene &scene) const override
void BoundingLimits(G4ThreeVector &aMin, G4ThreeVector &aMax) const override
G4double DistanceToOutNoVoxels(const G4ThreeVector &aPoint, const G4ThreeVector &aDirection, G4ThreeVector *aNormalVector) const
G4VSolid * Clone() const override
G4double DistanceToInNoVoxels(const G4ThreeVector &aPoint, const G4ThreeVector &aDirection) const
G4double GetSurfaceArea() override
G4int GetNumOfConstituents() const override
G4Polyhedron * CreatePolyhedron() const override
G4double DistanceToOutVoxels(const G4ThreeVector &aPoint, const G4ThreeVector &aDirection, G4ThreeVector *aNormalVector) const
G4GeometryType GetEntityType() const override
G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const override
std::ostream & StreamInfo(std::ostream &os) const override
G4double DistanceToIn(const G4ThreeVector &aPoint) const override
void AddNode(G4VSolid &solid, const G4Transform3D &trans)
~G4MultiUnion() override=default
G4double DistanceToOut(const G4ThreeVector &aPoint) const override
G4bool IsFaceted() const override
void Extent(EAxis aAxis, G4double &aMin, G4double &aMax) const
G4VSolid * GetSolid(G4int index) const
void SetAccurateSafety(G4bool flag)
EInside Inside(const G4ThreeVector &aPoint) const override
G4Voxelizer & GetVoxels() const
G4Polyhedron * GetPolyhedron() const override
G4MultiUnion & operator=(const G4MultiUnion &rhs)
G4SurfBits provides a simple container of bits, to be used for optimization of tessellated surfaces....
Definition G4SurfBits.hh:57
G4VSolid(const G4String &name)
Definition G4VSolid.cc:59
G4VoxelLimits represents limitation/restrictions of space, where restrictions are only made perpendic...
G4Voxelizer is a tool for generating the optimisation structure of tessellated surfaces and solids po...
EAxis
Definition geomdefs.hh:54
EInside
Definition geomdefs.hh:67