Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TessellatedSolid.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 and of QinetiQ Ltd, *
20// * subject to DEFCON 705 IPR conditions. *
21// * By using, copying, modifying or distributing the software (or *
22// * any work based on the software) you agree to acknowledge its *
23// * use in resulting scientific publications, and indicate your *
24// * acceptance of all terms of the Geant4 Software license. *
25// ********************************************************************
26//
27// G4TessellatedSolid
28//
29// Class description:
30//
31// G4TessellatedSolid is a special Geant4 solid defined by a number of
32// facets (UVFacet). It is important that the supplied facets shall form a
33// fully enclose space which is the solid.
34// At the moment only two types of facet can be used for the construction of
35// a G4TessellatedSolid, i.e. the G4TriangularFacet and G4QuadrangularFacet.
36//
37// How to contruct a G4TessellatedSolid:
38//
39// First declare a tessellated solid:
40//
41// G4TessellatedSolid* solidTarget = new G4TessellatedSolid("Solid_name");
42//
43// Define the facets which form the solid
44//
45// G4double targetSiz = 10*cm ;
46// G4TriangularFacet *facet1 = new
47// G4TriangularFacet (G4ThreeVector(-targetSize,-targetSize, 0.0),
48// G4ThreeVector(+targetSize,-targetSize, 0.0),
49// G4ThreeVector( 0.0, 0.0,+targetSize),
50// ABSOLUTE);
51// G4TriangularFacet *facet2 = new
52// G4TriangularFacet (G4ThreeVector(+targetSize,-targetSize, 0.0),
53// G4ThreeVector(+targetSize,+targetSize, 0.0),
54// G4ThreeVector( 0.0, 0.0,+targetSize),
55// ABSOLUTE);
56// G4TriangularFacet *facet3 = new
57// G4TriangularFacet (G4ThreeVector(+targetSize,+targetSize, 0.0),
58// G4ThreeVector(-targetSize,+targetSize, 0.0),
59// G4ThreeVector( 0.0, 0.0,+targetSize),
60// ABSOLUTE);
61// G4TriangularFacet *facet4 = new
62// G4TriangularFacet (G4ThreeVector(-targetSize,+targetSize, 0.0),
63// G4ThreeVector(-targetSize,-targetSize, 0.0),
64// G4ThreeVector( 0.0, 0.0,+targetSize),
65// ABSOLUTE);
66// G4QuadrangularFacet *facet5 = new
67// G4QuadrangularFacet (G4ThreeVector(-targetSize,-targetSize, 0.0),
68// G4ThreeVector(-targetSize,+targetSize, 0.0),
69// G4ThreeVector(+targetSize,+targetSize, 0.0),
70// G4ThreeVector(+targetSize,-targetSize, 0.0),
71// ABSOLUTE);
72//
73// Then add the facets to the solid:
74//
75// solidTarget->AddFacet((UVFacet*) facet1);
76// solidTarget->AddFacet((UVFacet*) facet2);
77// solidTarget->AddFacet((UVFacet*) facet3);
78// solidTarget->AddFacet((UVFacet*) facet4);
79// solidTarget->AddFacet((UVFacet*) facet5);
80//
81// Finally declare the solid is complete:
82//
83// solidTarget->SetSolidClosed(true);
84
85// 31.10.2004, P R Truscott, QinetiQ Ltd, UK - Created.
86// 12.10.2012, M Gayer, CERN - New implementation with voxelization of surfaces.
87// --------------------------------------------------------------------
88#ifndef G4TESSELLATEDSOLID_HH
89#define G4TESSELLATEDSOLID_HH 1
90
91#include "G4GeomTypes.hh"
92
93#if defined(G4GEOM_USE_USOLIDS)
94#define G4GEOM_USE_UTESSELLATEDSOLID 1
95#endif
96
97#if defined(G4GEOM_USE_UTESSELLATEDSOLID)
98 #define G4UTessellatedSolid G4TessellatedSolid
99 #include "G4UTessellatedSolid.hh"
100#else
101
102#include <iostream>
103#include <vector>
104#include <set>
105#include <map>
106
107#include "G4Types.hh"
108#include "G4VSolid.hh"
109#include "G4Voxelizer.hh"
110#include "G4VFacet.hh"
111
113{
116};
117
119{
120public:
121 G4bool operator() (const G4VertexInfo& l, const G4VertexInfo& r) const
122 {
123 return l.mag2 == r.mag2 ? l.id < r.id : l.mag2 < r.mag2;
124 }
125};
126
128{
129 public: // with description
130
132 virtual ~G4TessellatedSolid ();
133
134 G4TessellatedSolid (const G4String& name);
135
136 G4TessellatedSolid(__void__&);
137 // Fake default constructor for usage restricted to direct object
138 // persistency for clients requiring preallocation of memory for
139 // persistifiable objects.
140
144
145 G4bool AddFacet (G4VFacet* aFacet);
146 inline G4VFacet* GetFacet (G4int i) const;
147
148 G4int GetNumberOfFacets () const;
149
150 virtual EInside Inside (const G4ThreeVector& p) const;
151 virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const;
152 virtual G4double DistanceToIn(const G4ThreeVector& p,
153 const G4ThreeVector& v)const;
154 virtual G4double DistanceToIn(const G4ThreeVector& p) const;
155 virtual G4double DistanceToOut(const G4ThreeVector& p) const;
156 virtual G4double DistanceToOut(const G4ThreeVector& p,
157 const G4ThreeVector& v,
158 const G4bool calcNorm,
159 G4bool* validNorm,
160 G4ThreeVector* norm) const;
161
162 virtual G4bool Normal (const G4ThreeVector& p, G4ThreeVector& n) const;
164 G4bool aAccurate = false) const;
165 virtual G4double SafetyFromInside (const G4ThreeVector& p,
166 G4bool aAccurate = false) const;
167
168 virtual G4GeometryType GetEntityType () const;
169 virtual std::ostream& StreamInfo(std::ostream& os) const;
170
171 virtual G4VSolid* Clone() const;
172
173 virtual G4ThreeVector GetPointOnSurface() const;
174 virtual G4double GetSurfaceArea();
175 virtual G4double GetCubicVolume();
176
177 void SetSolidClosed (const G4bool t);
178 G4bool GetSolidClosed () const;
179
180 inline void SetMaxVoxels(G4int max);
181
182 inline G4Voxelizer& GetVoxels();
183
184 virtual G4bool CalculateExtent(const EAxis pAxis,
185 const G4VoxelLimits& pVoxelLimit,
186 const G4AffineTransform& pTransform,
187 G4double& pMin, G4double& pMax) const;
188
189 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const;
190
191 G4double GetMinXExtent () const;
192 G4double GetMaxXExtent () const;
193 G4double GetMinYExtent () const;
194 G4double GetMaxYExtent () const;
195 G4double GetMinZExtent () const;
196 G4double GetMaxZExtent () const;
197
198 virtual G4Polyhedron* CreatePolyhedron () const;
199 virtual G4Polyhedron* GetPolyhedron () const;
200 virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const;
201 virtual G4VisExtent GetExtent () const;
202
206
207 private: // without description
208
209 void Initialize();
210
211 G4double DistanceToOutNoVoxels(const G4ThreeVector& p,
212 const G4ThreeVector& v,
213 G4ThreeVector& aNormalVector,
214 G4bool& aConvex,
215 G4double aPstep = kInfinity) const;
216 G4double DistanceToInCandidates(const std::vector<G4int>& candidates,
217 const G4ThreeVector& aPoint,
218 const G4ThreeVector& aDirection) const;
219 void DistanceToOutCandidates(const std::vector<G4int>& candidates,
220 const G4ThreeVector& aPoint,
221 const G4ThreeVector& direction,
222 G4double& minDist,
223 G4ThreeVector& minNormal,
224 G4int& minCandidate) const;
225 G4double DistanceToInNoVoxels(const G4ThreeVector& p,
226 const G4ThreeVector& v,
227 G4double aPstep = kInfinity) const;
228 void SetExtremeFacets();
229
230 EInside InsideNoVoxels (const G4ThreeVector& p) const;
231 EInside InsideVoxels(const G4ThreeVector& aPoint) const;
232
233 void Voxelize();
234
235 void CreateVertexList();
236
237 void PrecalculateInsides();
238
239 void SetRandomVectors();
240
241 G4double DistanceToInCore(const G4ThreeVector &p, const G4ThreeVector& v,
242 G4double aPstep = kInfinity) const;
243 G4double DistanceToOutCore(const G4ThreeVector& p, const G4ThreeVector& v,
244 G4ThreeVector& aNormalVector,
245 G4bool& aConvex,
246 G4double aPstep = kInfinity) const;
247
248 G4int SetAllUsingStack(const std::vector<G4int>& voxel,
249 const std::vector<G4int>& max,
250 G4bool status, G4SurfBits& checked);
251
252 void DeleteObjects ();
253 void CopyObjects (const G4TessellatedSolid& s);
254
255 static G4bool CompareSortedVoxel(const std::pair<G4int, G4double>& l,
256 const std::pair<G4int, G4double>& r);
257
258 G4double MinDistanceFacet(const G4ThreeVector& p, G4bool simple,
259 G4VFacet* &facet) const;
260
261 inline G4bool OutsideOfExtent(const G4ThreeVector& p,
262 G4double tolerance = 0.0) const;
263
264 protected:
265
267
268 private:
269
270 mutable G4bool fRebuildPolyhedron = false;
271 mutable G4Polyhedron* fpPolyhedron = nullptr;
272
273 std::vector<G4VFacet*> fFacets;
274 std::set<G4VFacet*> fExtremeFacets; // Does all other facets lie on
275 // or behind this surface?
276
277 G4GeometryType fGeometryType;
278 G4double fCubicVolume = 0.0;
279 G4double fSurfaceArea = 0.0;
280
281 std::vector<G4ThreeVector> fVertexList;
282
283 std::set<G4VertexInfo,G4VertexComparator> fFacetList;
284
285 G4ThreeVector fMinExtent, fMaxExtent;
286
287 G4bool fSolidClosed = false;
288
289 std::vector<G4ThreeVector> fRandir;
290
291 G4int fMaxTries;
292
293 G4Voxelizer fVoxels; // Pointer to the voxelized solid
294
295 G4SurfBits fInsides;
296};
297
298///////////////////////////////////////////////////////////////////////////////
299// Inlined Methods
300///////////////////////////////////////////////////////////////////////////////
301
303{
304 return fFacets[i];
305}
306
308{
309 fVoxels.SetMaxVoxels(max);
310}
311
313{
314 return fVoxels;
315}
316
317inline G4bool G4TessellatedSolid::OutsideOfExtent(const G4ThreeVector& p,
318 G4double tolerance) const
319{
320 return ( p.x() < fMinExtent.x() - tolerance
321 || p.x() > fMaxExtent.x() + tolerance
322 || p.y() < fMinExtent.y() - tolerance
323 || p.y() > fMaxExtent.y() + tolerance
324 || p.z() < fMinExtent.z() - tolerance
325 || p.z() > fMaxExtent.z() + tolerance);
326}
327
328#endif
329
330#endif
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
double z() const
double x() const
double y() const
virtual G4bool Normal(const G4ThreeVector &p, G4ThreeVector &n) const
G4double GetMinYExtent() const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
virtual G4Polyhedron * GetPolyhedron() const
virtual G4double GetSurfaceArea()
G4double GetMinZExtent() const
virtual std::ostream & StreamInfo(std::ostream &os) const
G4TessellatedSolid & operator=(const G4TessellatedSolid &right)
G4TessellatedSolid & operator+=(const G4TessellatedSolid &right)
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4bool AddFacet(G4VFacet *aFacet)
G4int GetNumberOfFacets() const
G4double GetMaxYExtent() const
G4double GetMaxZExtent() const
G4double GetMaxXExtent() const
G4bool GetSolidClosed() const
virtual G4double DistanceToOut(const G4ThreeVector &p) const
G4VFacet * GetFacet(G4int i) const
virtual G4double SafetyFromInside(const G4ThreeVector &p, G4bool aAccurate=false) const
G4double GetMinXExtent() const
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const
void SetSolidClosed(const G4bool t)
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
virtual G4VisExtent GetExtent() const
virtual G4Polyhedron * CreatePolyhedron() const
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
G4Voxelizer & GetVoxels()
virtual G4GeometryType GetEntityType() const
virtual EInside Inside(const G4ThreeVector &p) const
virtual G4double SafetyFromOutside(const G4ThreeVector &p, G4bool aAccurate=false) const
void SetMaxVoxels(G4int max)
virtual G4double GetCubicVolume()
virtual G4VSolid * Clone() const
virtual G4ThreeVector GetPointOnSurface() const
G4bool operator()(const G4VertexInfo &l, const G4VertexInfo &r) const
void SetMaxVoxels(G4int max)
EAxis
Definition: geomdefs.hh:54
EInside
Definition: geomdefs.hh:67