Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VTwistSurface.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// G4VTwistSurface
27//
28// Class description:
29//
30// Abstract base class for boundary surface of G4VSolid.
31
32// Author: Kotoyo Hoshina (Chiba University), 01.08.2002 - Created.
33// Oliver Link (CERN), 13.11.2003 - Integration in Geant4
34// from original version in Jupiter-2.5.02 application.
35// --------------------------------------------------------------------
36#ifndef G4VTWISTSURFACE_HH
37#define G4VTWISTSURFACE_HH
38
40
41#include "G4VSolid.hh"
42#include "geomdefs.hh"
43
44#include "G4RotationMatrix.hh"
45
46#define G4VSURFACENXX 10
47
48/**
49 * @brief G4VTwistSurface is a base class for boundary surface of a G4VSolid.
50 */
51
53{
54 public:
55
58
59 /**
60 * Base constructor, given a name.
61 * @param[in] name The surface name.
62 */
63 G4VTwistSurface (const G4String& name);
64
65 /**
66 * Constructs a surface, given its parameters.
67 * @param[in] name The surface name.
68 * @param[in] rot Rotation: 0.5*(phi-width segment).
69 * @param[in] tlate Translation.
70 * @param[in] handedness Orientation: R-hand = 1, L-hand = -1.
71 * @param[in] axis0 First axis.
72 * @param[in] axis1 Second axis.
73 * @param[in] axis0min Minimum in first axis.
74 * @param[in] axis1min Minimum in second axis.
75 * @param[in] axis0max Maximum in first axis.
76 * @param[in] axis1max Maximum in second axis.
77 */
78 G4VTwistSurface (const G4String& name,
79 const G4RotationMatrix& rot,
80 const G4ThreeVector& tlate,
81 G4int handedness,
82 const EAxis axis0,
83 const EAxis axis1,
84 G4double axis0min = -kInfinity,
85 G4double axis1min = -kInfinity,
86 G4double axis0max = kInfinity,
87 G4double axis1max = kInfinity);
88
89 /**
90 * Default destructor.
91 */
92 virtual ~G4VTwistSurface() = default;
93
94 /**
95 * Returns the phi-location of point 'me' (phi relation between 'me' and
96 * 'vec' projected on z=0 plane). If 'me' is on -ve-phi-side of 'vec', it
97 * returns 1; on the other hand, if 'me' is on +ve-phi-side of 'vec',
98 * it returns -1. If 'me' is on boundary of 'vec', it returns 0.
99 * @returns The z-coordinate of normal vector of me.cross(vec).
100 */
101 virtual G4int AmIOnLeftSide(const G4ThreeVector& me,
102 const G4ThreeVector& vec,
103 G4bool withTol = true);
104
105 /**
106 * Returns the distance to the nearest boundary from an arbitrary point 'p'
107 * in local coodinate.
108 * @param[in] areacode Point location code according to axes.
109 * @param[out] xx The returned reference point on boundary.
110 * @param[in] p The arbitrary point in input.
111 */
112 virtual G4double DistanceToBoundary(G4int areacode,
113 G4ThreeVector& xx,
114 const G4ThreeVector& p) ;
115
116 /**
117 * Returns the distance from outside to a boundary from an arbitrary
118 * point 'gp' and direction 'gv'.
119 * @param[in] gp The arbitrary point.
120 * @param[in] gv The direction vector.
121 * @param[out] gxxbest The returned reference point on boundary.
122 */
123 virtual G4double DistanceToIn(const G4ThreeVector& gp,
124 const G4ThreeVector& gv,
125 G4ThreeVector& gxxbest);
126
127 /**
128 * Returns the distance from inside to a boundary from an arbitrary
129 * point 'gp' and direction 'gv'.
130 * @param[in] gp The arbitrary point.
131 * @param[in] gv The direction vector.
132 * @param[out] gxxbest The returned reference point on boundary.
133 */
134 virtual G4double DistanceToOut(const G4ThreeVector& gp,
135 const G4ThreeVector& gv,
136 G4ThreeVector& gxxbest);
137
138 /**
139 * Returns the safety distance to a boundary from an arbitrary point 'gp'.
140 * @param[in] gp The arbitrary point.
141 * @param[out] gxxbest The returned reference point on boundary.
142 */
143 virtual G4double DistanceTo(const G4ThreeVector& gp,
144 G4ThreeVector& gxx);
145
146 /**
147 * Returns the distance to surface, given point 'gp' and direction 'gv'.
148 * @param[in] gp The point from where computing the distance.
149 * @param[in] gv The direction along which computing the distance.
150 * @param[out] gxx Vector of global points based on number of solutions.
151 * @param[out] distance The distance vector based on number of solutions.
152 * @param[out] areacode The location vector based on number of solutions.
153 * @param[out] isvalid Validity vector based on number of solutions.
154 * @param[in] validate Adopted validation criteria.
155 * @returns The number of solutions.
156 */
158 const G4ThreeVector& gv,
159 G4ThreeVector gxx[],
160 G4double distance[],
161 G4int areacode[],
162 G4bool isvalid[],
163 EValidate validate = kValidateWithTol) = 0;
164
165 /**
166 * Returns the safety distance to surface, given point 'gp'.
167 * @param[in] gp The point from where computing the safety distance.
168 * @param[out] gxx Vector of global points based on number of solutions.
169 * @param[out] distance The distance vector based on number of solutions.
170 * @param[out] areacode The location vector based on number of solutions.
171 * @returns The number of solutions.
172 */
174 G4ThreeVector gxx[],
175 G4double distance[],
176 G4int areacode[]) = 0;
177
178 /**
179 * Returns a normal vector at a surface (or very close to the surface)
180 * point at 'p'.
181 * @param[in] p The point where computing the normal.
182 * @param[in] isGlobal If true, it returns the normal in global coordinates.
183 * @returns The normal vector.
184 */
186 G4bool isGlobal) = 0;
187
188 /**
189 * Returns parameters of boundaries.
190 * @param[in] areacode The location code.
191 * @param[out] d Boundary direction.
192 * @param[out] x0 The point on boundary.
193 * @param[out] boundarytype The boundary code.
194 */
195 virtual void GetBoundaryParameters(const G4int& areacode,
196 G4ThreeVector& d,
197 G4ThreeVector& x0,
198 G4int& boundarytype) const;
199
200 /**
201 * Returns Z projection of point 'p' on boundary.
202 * @param[in] areacode The location code.
203 * @param[out] p The arbitrary point.
204 * @returns The Z projection on boundary.
205 */
206 virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode,
207 const G4ThreeVector& p) const;
208
209 /**
210 * Utility methods to compute the distance from a plane/line.
211 */
213 const G4ThreeVector& v,
214 const G4ThreeVector& x0,
215 const G4ThreeVector& n0,
216 G4ThreeVector& xx);
218 const G4ThreeVector& x0,
219 const G4ThreeVector& n0,
220 G4ThreeVector& xx);
222 const G4ThreeVector& x0,
223 const G4ThreeVector& t1,
224 const G4ThreeVector& t2,
225 G4ThreeVector& xx,
226 G4ThreeVector& n);
228 const G4ThreeVector& x0,
229 const G4ThreeVector& d,
230 G4ThreeVector& xx);
231
232 /**
233 * Test functions/accessors, based on 'areacode' location.
234 */
235 inline G4bool IsAxis0 (G4int areacode) const;
236 inline G4bool IsAxis1 (G4int areacode) const;
237 inline G4bool IsOutside (G4int areacode) const;
238 inline G4bool IsInside (G4int areacode, G4bool testbitmode = false) const;
239 inline G4bool IsBoundary (G4int areacode, G4bool testbitmode = false) const;
240 inline G4bool IsCorner (G4int areacode, G4bool testbitmode = false) const;
241 inline G4bool IsValidNorm() const { return fIsValidNorm; }
242 G4bool IsSameBoundary (G4VTwistSurface* surface1, G4int areacode1,
243 G4VTwistSurface* surface2, G4int areacode2 ) const;
244 inline G4int GetAxisType(G4int areacode, G4int whichaxis) const;
245
246 /**
247 * Utility functions computing global/local point/direction.
248 */
253
254 /**
255 * Modifiers for axes.
256 */
257 inline void SetAxis(G4int i, const EAxis axis) { fAxis[i] = axis; }
258 inline void SetNeighbours(G4VTwistSurface* ax0min, G4VTwistSurface* ax1min,
259 G4VTwistSurface* ax0max, G4VTwistSurface* ax1max);
260
261 /**
262 * Returns point on surface given the axes.
263 */
265 G4bool isGlobal = false ) = 0 ;
266
267 /**
268 * Internal accessors to be implemented in concrete derived classes.
269 */
272 virtual G4double GetSurfaceArea() = 0 ;
273 virtual void GetFacets(G4int m, G4int n, G4double xyz[][3],
274 G4int faces[][4], G4int iside) = 0 ;
275
276 /**
277 * Node/face mapping functions.
278 */
279 G4int GetNode( G4int i, G4int j, G4int m, G4int n, G4int iside ) ;
280 G4int GetFace( G4int i, G4int j, G4int m, G4int n, G4int iside ) ;
281
282 /**
283 * Checks face visibility, based on verteces and orientation.
284 * @returns -1 if invisible; 1 if visible.
285 */
287 G4int number, G4int orientation) ;
288
289 /**
290 * Returns the surface name.
291 */
292 inline const G4String& GetName() const { return fName; }
293
294 /**
295 * Prints on standard output surface data.
296 */
297 void DebugPrint() const;
298
299 /**
300 * Fake default constructor for usage restricted to direct object
301 * persistency for clients requiring preallocation of memory for
302 * persistifiable objects.
303 */
304 G4VTwistSurface(__void__&);
305
306 protected:
307
308 /**
309 * Internal accessors.
310 */
311 inline G4VTwistSurface** GetNeighbours() { return fNeighbours; }
312 inline G4int GetNeighbours(G4int areacode, G4VTwistSurface* surfaces[]);
313 inline G4ThreeVector GetCorner(G4int areacode) const;
314 void GetBoundaryAxis(G4int areacode, EAxis axis[]) const;
315 void GetBoundaryLimit(G4int areacode, G4double limit[]) const;
316 virtual G4int GetAreaCode(const G4ThreeVector& xx, G4bool withtol=true) = 0;
317
318 /**
319 * Modifier for boundaries.
320 * @param[in] axiscode The location code, either: sAxis0 & sAxisMin,
321 * sAxis0 & sAxisMax, sAxis1 & sAxisMin, sAxis1 & sAxisMax.
322 * @param[in] direction Direction.
323 * @param[in] x0 Point on boundary.
324 * @param[in] boundarytype The shape of locus from the start point to
325 * end point of boundary (ex. sAxisRho = linear line which
326 * start point is fixed at origin; sAxisPhi = part of circle
327 * which center placed at the origin.
328 */
329 virtual void SetBoundary(const G4int& axiscode,
330 const G4ThreeVector& direction,
331 const G4ThreeVector& x0,
332 const G4int& boundarytype);
333
334 /**
335 * Modifier for corners.
336 */
337 void SetCorner(G4int areacode, G4double x, G4double y, G4double z);
338
339 private:
340
341 /**
342 * Internal setters to be implemented in concrete dereived classes.
343 */
344 virtual void SetBoundaries() = 0;
345 virtual void SetCorners() = 0;
346
347 // data members ---------------------------------------------------------
348
349 public:
350
351 /** Boundary types. */
352 static const G4int sOutside ;
353 static const G4int sInside ;
354 static const G4int sBoundary;
355 static const G4int sCorner;
356 static const G4int sC0Min1Min;
357 static const G4int sC0Max1Min;
358 static const G4int sC0Max1Max;
359 static const G4int sC0Min1Max;
360 static const G4int sAxisMin;
361 static const G4int sAxisMax;
362 static const G4int sAxisX;
363 static const G4int sAxisY;
364 static const G4int sAxisZ;
365 static const G4int sAxisRho;
366 static const G4int sAxisPhi;
367 static const G4int sAxis0;
368 static const G4int sAxis1;
369 static const G4int sSizeMask;
370 static const G4int sAxisMask;
371 static const G4int sAreaMask;
372
373 protected:
374
376 {
377 /**
378 * @brief Internal class defining the surface status.
379 */
380 public:
381
383 virtual ~CurrentStatus();
384
385 inline G4ThreeVector GetXX(G4int i) const { return fXX[i]; }
386 inline G4double GetDistance(G4int i) const { return fDistance[i]; }
387 inline G4int GetAreacode(G4int i) const { return fAreacode[i]; }
388 inline G4int GetNXX() const { return fNXX; }
389 inline G4bool IsDone() const { return fDone; }
390 inline G4bool IsValid(G4int i) const { return fIsValid[i]; }
391
392 void SetCurrentStatus(G4int i,
393 G4ThreeVector& xx,
394 G4double& dist,
395 G4int& areacode,
396 G4bool& isvalid,
397 G4int nxx,
398 EValidate validate,
399 const G4ThreeVector* p,
400 const G4ThreeVector* v = nullptr);
401
402 void ResetfDone(EValidate validate,
403 const G4ThreeVector* p,
404 const G4ThreeVector* v = nullptr);
405
406
407 void DebugPrint() const;
408
409 private:
410
411 G4double fDistance[G4VSURFACENXX];
413 G4int fAreacode[G4VSURFACENXX];
414 G4bool fIsValid[G4VSURFACENXX];
415 G4int fNXX;
416 G4ThreeVector fLastp;
417 G4ThreeVector fLastv;
418 EValidate fLastValidate;
419 G4bool fDone;
420 };
421
422 class Boundary
423 {
424 /**
425 * @brief Internal class defining a surface boundary type.
426 */
427 public:
428
429 Boundary() = default;
430 virtual ~Boundary() = default;
431
432 void SetFields(const G4int& areacode,
433 const G4ThreeVector& d,
434 const G4ThreeVector& x0,
435 const G4int& boundarytype);
436
437 G4bool IsEmpty() const;
438
439 G4bool GetBoundaryParameters(const G4int& areacode,
440 G4ThreeVector& d,
441 G4ThreeVector& x0,
442 G4int& boundarytype) const;
443
444 private:
445
446 G4int fBoundaryAcode{-1};
447 G4ThreeVector fBoundaryDirection;
448 G4ThreeVector fBoundaryX0;
449 G4int fBoundaryType{0};
450 };
451
460
462 {
463 public:
464
467 };
468
472
473 private:
474
475 G4VTwistSurface* fNeighbours[4]; // {0,1,2,3} = sAxis0min, sAxis1min,
476 // sAxis0max, sAxis1max
477 G4ThreeVector fCorners[4]; // corners of the surface in local coordinate
478 Boundary fBoundaries[4]; // boundaries of the surface.
479 G4String fName;
480
481 class G4SurfSideQuery
482 {
483 public:
484
485 G4ThreeVector me;
486 G4ThreeVector vec;
487 G4bool withTol;
488 G4int amIOnLeftSide;
489 };
490 G4SurfSideQuery fAmIOnLeftSide;
491};
492
493//========================================================
494// inline functions
495//========================================================
496
497#include "G4VTwistSurface.icc"
498
499#endif
CLHEP::HepRotation G4RotationMatrix
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4VSURFACENXX
virtual ~Boundary()=default
void SetFields(const G4int &areacode, const G4ThreeVector &d, const G4ThreeVector &x0, const G4int &boundarytype)
G4bool GetBoundaryParameters(const G4int &areacode, G4ThreeVector &d, G4ThreeVector &x0, G4int &boundarytype) const
Boundary()=default
Internal class defining a surface boundary type.
G4double GetDistance(G4int i) const
CurrentStatus()
Internal class defining the surface status.
void SetCurrentStatus(G4int i, G4ThreeVector &xx, G4double &dist, G4int &areacode, G4bool &isvalid, G4int nxx, EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=nullptr)
G4ThreeVector GetXX(G4int i) const
void ResetfDone(EValidate validate, const G4ThreeVector *p, const G4ThreeVector *v=nullptr)
G4VTwistSurface is a base class for boundary surface of a G4VSolid.
virtual G4ThreeVector GetNormal(const G4ThreeVector &p, G4bool isGlobal)=0
virtual G4int AmIOnLeftSide(const G4ThreeVector &me, const G4ThreeVector &vec, G4bool withTol=true)
static const G4int sAxisMask
static const G4int sC0Min1Min
static const G4int sC0Min1Max
G4VTwistSurface(const G4String &name)
virtual void GetFacets(G4int m, G4int n, G4double xyz[][3], G4int faces[][4], G4int iside)=0
G4bool IsAxis1(G4int areacode) const
G4double DistanceToPlane(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
G4int GetNode(G4int i, G4int j, G4int m, G4int n, G4int iside)
static const G4int sOutside
void SetAxis(G4int i, const EAxis axis)
void SetNeighbours(G4VTwistSurface *ax0min, G4VTwistSurface *ax1min, G4VTwistSurface *ax0max, G4VTwistSurface *ax1max)
virtual ~G4VTwistSurface()=default
G4ThreeVector ComputeGlobalDirection(const G4ThreeVector &lp) const
G4bool IsCorner(G4int areacode, G4bool testbitmode=false) const
static const G4int sAxisMax
static const G4int sAxis0
virtual G4double GetBoundaryMin(G4double)=0
G4int GetFace(G4int i, G4int j, G4int m, G4int n, G4int iside)
G4bool IsValidNorm() const
void GetBoundaryAxis(G4int areacode, EAxis axis[]) const
const G4String & GetName() const
virtual G4double DistanceTo(const G4ThreeVector &gp, G4ThreeVector &gxx)
G4bool IsAxis0(G4int areacode) const
G4RotationMatrix fRot
G4int GetEdgeVisibility(G4int i, G4int j, G4int m, G4int n, G4int number, G4int orientation)
virtual G4int DistanceToSurface(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector gxx[], G4double distance[], G4int areacode[], G4bool isvalid[], EValidate validate=kValidateWithTol)=0
G4VTwistSurface ** GetNeighbours()
G4double DistanceToLine(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &d, G4ThreeVector &xx)
G4ThreeVector ComputeLocalDirection(const G4ThreeVector &gp) const
void GetBoundaryLimit(G4int areacode, G4double limit[]) const
void DebugPrint() const
G4int GetAxisType(G4int areacode, G4int whichaxis) const
static const G4int sAxisPhi
static const G4int sAxisMin
static const G4int sC0Max1Max
virtual G4double DistanceToOut(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector &gxxbest)
virtual G4double DistanceToIn(const G4ThreeVector &gp, const G4ThreeVector &gv, G4ThreeVector &gxxbest)
static const G4int sAxis1
virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode, const G4ThreeVector &p) const
G4bool IsInside(G4int areacode, G4bool testbitmode=false) const
virtual G4ThreeVector SurfacePoint(G4double, G4double, G4bool isGlobal=false)=0
G4ThreeVector fTrans
virtual void SetBoundary(const G4int &axiscode, const G4ThreeVector &direction, const G4ThreeVector &x0, const G4int &boundarytype)
G4ThreeVector ComputeLocalPoint(const G4ThreeVector &gp) const
virtual G4double GetBoundaryMax(G4double)=0
static const G4int sAxisRho
void SetCorner(G4int areacode, G4double x, G4double y, G4double z)
G4ThreeVector GetCorner(G4int areacode) const
virtual G4int GetAreaCode(const G4ThreeVector &xx, G4bool withtol=true)=0
static const G4int sBoundary
static const G4int sAxisZ
G4bool IsOutside(G4int areacode) const
virtual G4double DistanceToBoundary(G4int areacode, G4ThreeVector &xx, const G4ThreeVector &p)
virtual G4int DistanceToSurface(const G4ThreeVector &gp, G4ThreeVector gxx[], G4double distance[], G4int areacode[])=0
static const G4int sCorner
static const G4int sC0Max1Min
static const G4int sInside
G4bool IsSameBoundary(G4VTwistSurface *surface1, G4int areacode1, G4VTwistSurface *surface2, G4int areacode2) const
CurrentStatus fCurStatWithV
G4int GetNeighbours(G4int areacode, G4VTwistSurface *surfaces[])
static const G4int sAxisY
static const G4int sSizeMask
static const G4int sAxisX
G4double DistanceToPlaneWithV(const G4ThreeVector &p, const G4ThreeVector &v, const G4ThreeVector &x0, const G4ThreeVector &n0, G4ThreeVector &xx)
static const G4int sAreaMask
G4bool IsBoundary(G4int areacode, G4bool testbitmode=false) const
G4ThreeVector ComputeGlobalPoint(const G4ThreeVector &lp) const
G4double DistanceToPlane(const G4ThreeVector &p, const G4ThreeVector &x0, const G4ThreeVector &t1, const G4ThreeVector &t2, G4ThreeVector &xx, G4ThreeVector &n)
G4SurfCurNormal fCurrentNormal
virtual G4double GetSurfaceArea()=0
virtual void GetBoundaryParameters(const G4int &areacode, G4ThreeVector &d, G4ThreeVector &x0, G4int &boundarytype) const
CurrentStatus fCurStat
EAxis
Definition geomdefs.hh:54
const axis_t axis_to_type< N >::axis
Definition pugixml.cc:9668