Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4TessellatedSolid.hh
이 파일의 문서화 페이지로 가기
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: G4TessellatedSolid.hh 108151 2018-01-12 09:29:46Z gcosmo $
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 //
99 #ifndef G4TessellatedSolid_hh
100 #define G4TessellatedSolid_hh 1
101 
102 #if defined(G4GEOM_USE_USOLIDS)
103 #define G4GEOM_USE_UTESSELLATEDSOLID 1
104 #endif
105 
106 #if defined(G4GEOM_USE_UTESSELLATEDSOLID)
107  #define G4UTessellatedSolid G4TessellatedSolid
108  #include "G4UTessellatedSolid.hh"
109 #else
110 
111 #include <iostream>
112 #include <vector>
113 #include <set>
114 #include <map>
115 
116 #include "G4VSolid.hh"
117 #include "G4Types.hh"
118 #include "G4Voxelizer.hh"
119 
121 {
124 };
125 
126 class G4VFacet;
127 
129 {
130 public:
131  G4bool operator() (const G4VertexInfo &l, const G4VertexInfo &r) const
132  {
133  return l.mag2 == r.mag2 ? l.id < r.id : l.mag2 < r.mag2;
134  }
135 };
136 
138 {
139  public: // with description
140 
142  virtual ~G4TessellatedSolid ();
143 
145 
146  G4TessellatedSolid(__void__&);
147  // Fake default constructor for usage restricted to direct object
148  // persistency for clients requiring preallocation of memory for
149  // persistifiable objects.
150 
154 
155  G4bool AddFacet (G4VFacet *aFacet);
156  inline G4VFacet *GetFacet (G4int i) const;
157 
158  G4int GetNumberOfFacets () const;
159 
160  virtual EInside Inside (const G4ThreeVector &p) const;
161  virtual G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const;
162  virtual G4double DistanceToIn(const G4ThreeVector& p,
163  const G4ThreeVector& v)const;
164  virtual G4double DistanceToIn(const G4ThreeVector& p) const;
165  virtual G4double DistanceToOut(const G4ThreeVector& p) const;
166  virtual G4double DistanceToOut(const G4ThreeVector& p,
167  const G4ThreeVector& v,
168  const G4bool calcNorm,
169  G4bool *validNorm,
170  G4ThreeVector *norm) const;
171 
172  virtual G4bool Normal (const G4ThreeVector &p, G4ThreeVector &n) const;
173  virtual G4double SafetyFromOutside(const G4ThreeVector &p,
174  G4bool aAccurate=false) const;
175  virtual G4double SafetyFromInside (const G4ThreeVector &p,
176  G4bool aAccurate=false) const;
177 
178  virtual G4GeometryType GetEntityType () const;
179  virtual std::ostream &StreamInfo(std::ostream &os) const;
180 
181  virtual G4VSolid* Clone() const;
182 
183  virtual G4ThreeVector GetPointOnSurface() const;
184  virtual G4double GetSurfaceArea();
185  virtual G4double GetCubicVolume ();
186 
187  void SetSolidClosed (const G4bool t);
188  G4bool GetSolidClosed () const;
189 
190  inline void SetMaxVoxels(G4int max);
191 
192  inline G4Voxelizer &GetVoxels();
193 
194  virtual G4bool CalculateExtent(const EAxis pAxis,
195  const G4VoxelLimits& pVoxelLimit,
196  const G4AffineTransform& pTransform,
197  G4double& pMin, G4double& pMax) const;
198 
199  void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const;
200 
201  G4double GetMinXExtent () const;
202  G4double GetMaxXExtent () const;
203  G4double GetMinYExtent () const;
204  G4double GetMaxYExtent () const;
205  G4double GetMinZExtent () const;
206  G4double GetMaxZExtent () const;
207 
208  virtual G4Polyhedron* CreatePolyhedron () const;
209  virtual G4Polyhedron* GetPolyhedron () const;
210  virtual void DescribeYourselfTo (G4VGraphicsScene& scene) const;
211  virtual G4VisExtent GetExtent () const;
212 
215  void DisplayAllocatedMemory();
216 
217  private: // without description
218 
219  void Initialize();
220 
222  const G4ThreeVector &v,
223  G4ThreeVector &aNormalVector,
224  G4bool &aConvex,
225  G4double aPstep = kInfinity) const;
226  G4double DistanceToInCandidates(const std::vector<G4int> &candidates,
227  const G4ThreeVector &aPoint,
228  const G4ThreeVector &aDirection) const;
229  void DistanceToOutCandidates(const std::vector<G4int> &candidates,
230  const G4ThreeVector &aPoint,
231  const G4ThreeVector &direction,
232  G4double &minDist,
233  G4ThreeVector &minNormal,
234  G4int &minCandidate) const;
236  const G4ThreeVector &v,
237  G4double aPstep = kInfinity) const;
238  void SetExtremeFacets();
239 
240  EInside InsideNoVoxels (const G4ThreeVector &p) const;
241  EInside InsideVoxels(const G4ThreeVector &aPoint) const;
242 
243  void Voxelize();
244 
245  void CreateVertexList();
246 
247  void PrecalculateInsides();
248 
249  void SetRandomVectors();
250 
252  G4double aPstep = kInfinity) const;
254  G4ThreeVector &aNormalVector,
255  G4bool &aConvex,
256  G4double aPstep = kInfinity) const;
257 
258  G4int SetAllUsingStack(const std::vector<G4int> &voxel,
259  const std::vector<G4int> &max,
260  G4bool status, G4SurfBits &checked);
261 
262  void DeleteObjects ();
263  void CopyObjects (const G4TessellatedSolid &s);
264 
265  static G4bool CompareSortedVoxel(const std::pair<G4int, G4double> &l,
266  const std::pair<G4int, G4double> &r);
267 
269  G4VFacet * &facet) const;
270 
271  inline G4bool OutsideOfExtent(const G4ThreeVector &p,
272  G4double tolerance=0) const;
273 
274  protected:
275 
277 
278  private:
279 
282 
283  std::vector<G4VFacet *> fFacets;
284  std::set<G4VFacet *> fExtremeFacets; // Does all other facets lie on
285  // or behind this surface?
286 
290 
291  std::vector<G4ThreeVector> fVertexList;
292 
293  std::set<G4VertexInfo,G4VertexComparator> fFacetList;
294 
296 
298 
299  std::vector<G4ThreeVector> fRandir;
300 
302 
303  G4Voxelizer fVoxels; // Pointer to the voxelized solid
304 
306 };
307 
309 // Inlined Methods
311 
313 {
314  return fFacets[i];
315 }
316 
318 {
319  fVoxels.SetMaxVoxels(max);
320 }
321 
323 {
324  return fVoxels;
325 }
326 
328  G4double tolerance) const
329 {
330  return ( p.x() < fMinExtent.x() - tolerance
331  || p.x() > fMaxExtent.x() + tolerance
332  || p.y() < fMinExtent.y() - tolerance
333  || p.y() > fMaxExtent.y() + tolerance
334  || p.z() < fMinExtent.z() - tolerance
335  || p.z() > fMaxExtent.z() + tolerance);
336 }
337 
338 #endif
339 
340 #endif
void CopyObjects(const G4TessellatedSolid &s)
G4double GetMinZExtent() const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
const XML_Char * name
Definition: expat.h:151
G4bool GetSolidClosed() const
G4double GetMaxXExtent() const
static const G4double kInfinity
Definition: geomdefs.hh:42
virtual G4VisExtent GetExtent() const
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const
G4TessellatedSolid & operator=(const G4TessellatedSolid &right)
virtual G4VSolid * Clone() const
std::set< G4VFacet * > fExtremeFacets
const char * p
Definition: xmltok.h:285
G4Voxelizer & GetVoxels()
EInside InsideNoVoxels(const G4ThreeVector &p) const
double z() const
virtual G4Polyhedron * GetPolyhedron() const
virtual std::ostream & StreamInfo(std::ostream &os) const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const
virtual EInside Inside(const G4ThreeVector &p) const
void SetSolidClosed(const G4bool t)
G4bool AddFacet(G4VFacet *aFacet)
virtual G4double GetCubicVolume()
G4double GetMinXExtent() const
G4bool operator()(const G4VertexInfo &l, const G4VertexInfo &r) const
void SetMaxVoxels(G4int max)
virtual G4double SafetyFromOutside(const G4ThreeVector &p, G4bool aAccurate=false) const
const XML_Char * s
Definition: expat.h:262
G4double DistanceToInCandidates(const std::vector< G4int > &candidates, const G4ThreeVector &aPoint, const G4ThreeVector &aDirection) const
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4double GetMaxZExtent() const
void SetMaxVoxels(G4int max)
G4double DistanceToOutNoVoxels(const G4ThreeVector &p, const G4ThreeVector &v, G4ThreeVector &aNormalVector, G4bool &aConvex, G4double aPstep=kInfinity) const
static G4bool CompareSortedVoxel(const std::pair< G4int, G4double > &l, const std::pair< G4int, G4double > &r)
virtual G4double SafetyFromInside(const G4ThreeVector &p, G4bool aAccurate=false) const
virtual G4double GetSurfaceArea()
G4double DistanceToOutCore(const G4ThreeVector &p, const G4ThreeVector &v, G4ThreeVector &aNormalVector, G4bool &aConvex, G4double aPstep=kInfinity) const
virtual G4GeometryType GetEntityType() const
virtual G4double DistanceToOut(const G4ThreeVector &p) const
G4int GetNumberOfFacets() const
virtual G4Polyhedron * CreatePolyhedron() const
G4bool OutsideOfExtent(const G4ThreeVector &p, G4double tolerance=0) const
virtual G4ThreeVector GetPointOnSurface() const
G4double GetMaxYExtent() const
virtual G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const
std::vector< G4ThreeVector > fRandir
int G4int
Definition: G4Types.hh:78
EInside
Definition: geomdefs.hh:58
std::vector< G4VFacet * > fFacets
EAxis
Definition: geomdefs.hh:54
Float_t norm
double x() const
EInside InsideVoxels(const G4ThreeVector &aPoint) const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const
G4TessellatedSolid & operator+=(const G4TessellatedSolid &right)
Char_t n[5]
G4double GetMinYExtent() const
virtual G4bool CalculateExtent(const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
double y() const
G4double DistanceToInNoVoxels(const G4ThreeVector &p, const G4ThreeVector &v, G4double aPstep=kInfinity) const
virtual G4bool Normal(const G4ThreeVector &p, G4ThreeVector &n) const
std::vector< G4ThreeVector > fVertexList
G4double DistanceToInCore(const G4ThreeVector &p, const G4ThreeVector &v, G4double aPstep=kInfinity) const
void DistanceToOutCandidates(const std::vector< G4int > &candidates, const G4ThreeVector &aPoint, const G4ThreeVector &direction, G4double &minDist, G4ThreeVector &minNormal, G4int &minCandidate) const
G4double MinDistanceFacet(const G4ThreeVector &p, G4bool simple, G4VFacet *&facet) const
G4int SetAllUsingStack(const std::vector< G4int > &voxel, const std::vector< G4int > &max, G4bool status, G4SurfBits &checked)
G4GeometryType fGeometryType
G4Polyhedron * fpPolyhedron
std::set< G4VertexInfo, G4VertexComparator > fFacetList
G4VFacet * GetFacet(G4int i) const