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