Geant4-11
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
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 G4int GetFacetIndex (const G4ThreeVector& p) 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 G4int CheckStructure() const;
181
182 inline void SetMaxVoxels(G4int max);
183
184 inline G4Voxelizer& GetVoxels();
185
186 virtual G4bool CalculateExtent(const EAxis pAxis,
187 const G4VoxelLimits& pVoxelLimit,
188 const G4AffineTransform& pTransform,
189 G4double& pMin, G4double& pMax) const;
190
192
193 G4double GetMinXExtent () const;
194 G4double GetMaxXExtent () const;
195 G4double GetMinYExtent () const;
196 G4double GetMaxYExtent () const;
197 G4double GetMinZExtent () const;
198 G4double GetMaxZExtent () const;
199
200 virtual G4Polyhedron* CreatePolyhedron () const;
201 virtual G4Polyhedron* GetPolyhedron () const;
202 virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const;
203 virtual G4VisExtent GetExtent () const;
204
208
209 private: // without description
210
211 void Initialize();
212
214 const G4ThreeVector& v,
215 G4ThreeVector& aNormalVector,
216 G4bool& aConvex,
217 G4double aPstep = kInfinity) const;
218 G4double DistanceToInCandidates(const std::vector<G4int>& candidates,
219 const G4ThreeVector& aPoint,
220 const G4ThreeVector& aDirection) const;
221 void DistanceToOutCandidates(const std::vector<G4int>& candidates,
222 const G4ThreeVector& aPoint,
223 const G4ThreeVector& direction,
224 G4double& minDist,
225 G4ThreeVector& minNormal,
226 G4int& minCandidate) const;
228 const G4ThreeVector& v,
229 G4double aPstep = kInfinity) const;
230 void SetExtremeFacets();
231
232 EInside InsideNoVoxels (const G4ThreeVector& p) const;
233 EInside InsideVoxels(const G4ThreeVector& aPoint) const;
234
235 void Voxelize();
236
237 void CreateVertexList();
238
239 void PrecalculateInsides();
240
241 void SetRandomVectors();
242
244 G4double aPstep = kInfinity) const;
246 G4ThreeVector& aNormalVector,
247 G4bool& aConvex,
248 G4double aPstep = kInfinity) const;
249
250 G4int SetAllUsingStack(const std::vector<G4int>& voxel,
251 const std::vector<G4int>& max,
252 G4bool status, G4SurfBits& checked);
253
254 void DeleteObjects ();
255 void CopyObjects (const G4TessellatedSolid& s);
256
257 static G4bool CompareSortedVoxel(const std::pair<G4int, G4double>& l,
258 const std::pair<G4int, G4double>& r);
259
261 G4VFacet* &facet) const;
262
263 inline G4bool OutsideOfExtent(const G4ThreeVector& p,
264 G4double tolerance = 0.0) const;
265
266 protected:
267
269
270 private:
271
272 mutable G4bool fRebuildPolyhedron = false;
273 mutable G4Polyhedron* fpPolyhedron = nullptr;
274
275 std::vector<G4VFacet*> fFacets;
276 std::set<G4VFacet*> fExtremeFacets; // Does all other facets lie on
277 // or behind this surface?
278
282
283 std::vector<G4ThreeVector> fVertexList;
284
285 std::set<G4VertexInfo,G4VertexComparator> fFacetList;
286
288
290
291 std::vector<G4ThreeVector> fRandir;
292
294
295 G4Voxelizer fVoxels; // Pointer to the voxelized solid
296
298};
299
301// Inlined Methods
303
305{
306 return fFacets[i];
307}
308
310{
312}
313
315{
316 return fVoxels;
317}
318
320 G4double tolerance) const
321{
322 return ( p.x() < fMinExtent.x() - tolerance
323 || p.x() > fMaxExtent.x() + tolerance
324 || p.y() < fMinExtent.y() - tolerance
325 || p.y() > fMaxExtent.y() + tolerance
326 || p.z() < fMinExtent.z() - tolerance
327 || p.z() > fMaxExtent.z() + tolerance);
328}
329
330#endif
331
332#endif
static const G4double pMax
static const G4double pMin
static constexpr double s
Definition: G4SIunits.hh:154
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
std::vector< G4ThreeVector > fRandir
virtual G4bool Normal(const G4ThreeVector &p, G4ThreeVector &n) const
G4double GetMinYExtent() const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
void CopyObjects(const G4TessellatedSolid &s)
G4int CheckStructure() const
virtual G4Polyhedron * GetPolyhedron() const
virtual G4double GetSurfaceArea()
G4double GetMinZExtent() const
virtual std::ostream & StreamInfo(std::ostream &os) const
EInside InsideVoxels(const G4ThreeVector &aPoint) const
G4double MinDistanceFacet(const G4ThreeVector &p, G4bool simple, G4VFacet *&facet) const
G4double DistanceToOutCore(const G4ThreeVector &p, const G4ThreeVector &v, G4ThreeVector &aNormalVector, G4bool &aConvex, G4double aPstep=kInfinity) const
G4Polyhedron * fpPolyhedron
G4TessellatedSolid & operator=(const G4TessellatedSolid &right)
G4bool OutsideOfExtent(const G4ThreeVector &p, G4double tolerance=0.0) const
G4TessellatedSolid & operator+=(const G4TessellatedSolid &right)
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
G4bool AddFacet(G4VFacet *aFacet)
std::set< G4VFacet * > fExtremeFacets
static G4bool CompareSortedVoxel(const std::pair< G4int, G4double > &l, const std::pair< G4int, G4double > &r)
G4int GetNumberOfFacets() const
G4double GetMaxYExtent() const
EInside InsideNoVoxels(const G4ThreeVector &p) 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 DistanceToOutNoVoxels(const G4ThreeVector &p, const G4ThreeVector &v, G4ThreeVector &aNormalVector, G4bool &aConvex, G4double aPstep=kInfinity) const
G4double GetMinXExtent() const
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const
void SetSolidClosed(const G4bool t)
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4int SetAllUsingStack(const std::vector< G4int > &voxel, const std::vector< G4int > &max, G4bool status, G4SurfBits &checked)
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
G4double DistanceToInCore(const G4ThreeVector &p, const G4ThreeVector &v, G4double aPstep=kInfinity) const
G4Voxelizer & GetVoxels()
G4double DistanceToInNoVoxels(const G4ThreeVector &p, const G4ThreeVector &v, G4double aPstep=kInfinity) const
std::set< G4VertexInfo, G4VertexComparator > fFacetList
virtual G4GeometryType GetEntityType() const
G4double DistanceToInCandidates(const std::vector< G4int > &candidates, const G4ThreeVector &aPoint, const G4ThreeVector &aDirection) const
virtual EInside Inside(const G4ThreeVector &p) const
G4int GetFacetIndex(const G4ThreeVector &p) const
virtual G4double SafetyFromOutside(const G4ThreeVector &p, G4bool aAccurate=false) const
void DistanceToOutCandidates(const std::vector< G4int > &candidates, const G4ThreeVector &aPoint, const G4ThreeVector &direction, G4double &minDist, G4ThreeVector &minNormal, G4int &minCandidate) const
std::vector< G4ThreeVector > fVertexList
void SetMaxVoxels(G4int max)
virtual G4double GetCubicVolume()
virtual G4VSolid * Clone() const
G4GeometryType fGeometryType
virtual G4ThreeVector GetPointOnSurface() const
std::vector< G4VFacet * > fFacets
G4bool operator()(const G4VertexInfo &l, const G4VertexInfo &r) const
void SetMaxVoxels(G4int max)
EAxis
Definition: geomdefs.hh:54
EInside
Definition: geomdefs.hh:67
static const G4double kInfinity
Definition: geomdefs.hh:41
T max(const T t1, const T t2)
brief Return the largest of the two arguments
const char * name(G4int ptype)