File indexing completed on 2026-08-19 09:10:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #ifndef G4VTWISTSURFACE_HH
0037 #define G4VTWISTSURFACE_HH
0038
0039 #include <CLHEP/Units/SystemOfUnits.h>
0040
0041 #include "G4VSolid.hh"
0042 #include "geomdefs.hh"
0043
0044 #include "G4RotationMatrix.hh"
0045
0046 #define G4VSURFACENXX 10
0047
0048
0049
0050
0051
0052 class G4VTwistSurface
0053 {
0054 public:
0055
0056 enum EValidate { kDontValidate = 0, kValidateWithTol = 1,
0057 kValidateWithoutTol = 2, kUninitialized = 3 };
0058
0059
0060
0061
0062
0063 G4VTwistSurface (const G4String& name);
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 G4VTwistSurface (const G4String& name,
0079 const G4RotationMatrix& rot,
0080 const G4ThreeVector& tlate,
0081 G4int handedness,
0082 const EAxis axis0,
0083 const EAxis axis1,
0084 G4double axis0min = -kInfinity,
0085 G4double axis1min = -kInfinity,
0086 G4double axis0max = kInfinity,
0087 G4double axis1max = kInfinity);
0088
0089
0090
0091
0092 virtual ~G4VTwistSurface() = default;
0093
0094
0095
0096
0097
0098
0099
0100
0101 virtual G4int AmIOnLeftSide(const G4ThreeVector& me,
0102 const G4ThreeVector& vec,
0103 G4bool withTol = true);
0104
0105
0106
0107
0108
0109
0110
0111
0112 virtual G4double DistanceToBoundary(G4int areacode,
0113 G4ThreeVector& xx,
0114 const G4ThreeVector& p) ;
0115
0116
0117
0118
0119
0120
0121
0122
0123 virtual G4double DistanceToIn(const G4ThreeVector& gp,
0124 const G4ThreeVector& gv,
0125 G4ThreeVector& gxxbest);
0126
0127
0128
0129
0130
0131
0132
0133
0134 virtual G4double DistanceToOut(const G4ThreeVector& gp,
0135 const G4ThreeVector& gv,
0136 G4ThreeVector& gxxbest);
0137
0138
0139
0140
0141
0142
0143 virtual G4double DistanceTo(const G4ThreeVector& gp,
0144 G4ThreeVector& gxx);
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 virtual G4int DistanceToSurface(const G4ThreeVector& gp,
0158 const G4ThreeVector& gv,
0159 G4ThreeVector gxx[],
0160 G4double distance[],
0161 G4int areacode[],
0162 G4bool isvalid[],
0163 EValidate validate = kValidateWithTol) = 0;
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173 virtual G4int DistanceToSurface(const G4ThreeVector& gp,
0174 G4ThreeVector gxx[],
0175 G4double distance[],
0176 G4int areacode[]) = 0;
0177
0178
0179
0180
0181
0182
0183
0184
0185 virtual G4ThreeVector GetNormal(const G4ThreeVector& p,
0186 G4bool isGlobal) = 0;
0187
0188
0189
0190
0191
0192
0193
0194
0195 virtual void GetBoundaryParameters(const G4int& areacode,
0196 G4ThreeVector& d,
0197 G4ThreeVector& x0,
0198 G4int& boundarytype) const;
0199
0200
0201
0202
0203
0204
0205
0206 virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode,
0207 const G4ThreeVector& p) const;
0208
0209
0210
0211
0212 inline G4double DistanceToPlaneWithV(const G4ThreeVector& p,
0213 const G4ThreeVector& v,
0214 const G4ThreeVector& x0,
0215 const G4ThreeVector& n0,
0216 G4ThreeVector& xx);
0217 inline G4double DistanceToPlane(const G4ThreeVector& p,
0218 const G4ThreeVector& x0,
0219 const G4ThreeVector& n0,
0220 G4ThreeVector& xx);
0221 inline G4double DistanceToPlane(const G4ThreeVector& p,
0222 const G4ThreeVector& x0,
0223 const G4ThreeVector& t1,
0224 const G4ThreeVector& t2,
0225 G4ThreeVector& xx,
0226 G4ThreeVector& n);
0227 inline G4double DistanceToLine (const G4ThreeVector& p,
0228 const G4ThreeVector& x0,
0229 const G4ThreeVector& d,
0230 G4ThreeVector& xx);
0231
0232
0233
0234
0235 inline G4bool IsAxis0 (G4int areacode) const;
0236 inline G4bool IsAxis1 (G4int areacode) const;
0237 inline G4bool IsOutside (G4int areacode) const;
0238 inline G4bool IsInside (G4int areacode, G4bool testbitmode = false) const;
0239 inline G4bool IsBoundary (G4int areacode, G4bool testbitmode = false) const;
0240 inline G4bool IsCorner (G4int areacode, G4bool testbitmode = false) const;
0241 inline G4bool IsValidNorm() const { return fIsValidNorm; }
0242 G4bool IsSameBoundary (G4VTwistSurface* surface1, G4int areacode1,
0243 G4VTwistSurface* surface2, G4int areacode2 ) const;
0244 inline G4int GetAxisType(G4int areacode, G4int whichaxis) const;
0245
0246
0247
0248
0249 inline G4ThreeVector ComputeGlobalPoint (const G4ThreeVector& lp) const;
0250 inline G4ThreeVector ComputeLocalPoint (const G4ThreeVector& gp) const;
0251 inline G4ThreeVector ComputeGlobalDirection (const G4ThreeVector& lp) const;
0252 inline G4ThreeVector ComputeLocalDirection (const G4ThreeVector& gp) const;
0253
0254
0255
0256
0257 inline void SetAxis(G4int i, const EAxis axis) { fAxis[i] = axis; }
0258 inline void SetNeighbours(G4VTwistSurface* ax0min, G4VTwistSurface* ax1min,
0259 G4VTwistSurface* ax0max, G4VTwistSurface* ax1max);
0260
0261
0262
0263
0264 virtual G4ThreeVector SurfacePoint(G4double, G4double,
0265 G4bool isGlobal = false ) = 0 ;
0266
0267
0268
0269
0270 virtual G4double GetBoundaryMin(G4double) = 0 ;
0271 virtual G4double GetBoundaryMax(G4double) = 0 ;
0272 virtual G4double GetSurfaceArea() = 0 ;
0273 virtual void GetFacets(G4int m, G4int n, G4double xyz[][3],
0274 G4int faces[][4], G4int iside) = 0 ;
0275
0276
0277
0278
0279 G4int GetNode( G4int i, G4int j, G4int m, G4int n, G4int iside ) ;
0280 G4int GetFace( G4int i, G4int j, G4int m, G4int n, G4int iside ) ;
0281
0282
0283
0284
0285
0286 G4int GetEdgeVisibility( G4int i, G4int j, G4int m, G4int n,
0287 G4int number, G4int orientation) ;
0288
0289
0290
0291
0292 inline const G4String& GetName() const { return fName; }
0293
0294
0295
0296
0297 void DebugPrint() const;
0298
0299
0300
0301
0302
0303
0304 G4VTwistSurface(__void__&);
0305
0306 protected:
0307
0308
0309
0310
0311 inline G4VTwistSurface** GetNeighbours() { return fNeighbours; }
0312 inline G4int GetNeighbours(G4int areacode, G4VTwistSurface* surfaces[]);
0313 inline G4ThreeVector GetCorner(G4int areacode) const;
0314 void GetBoundaryAxis(G4int areacode, EAxis axis[]) const;
0315 void GetBoundaryLimit(G4int areacode, G4double limit[]) const;
0316 virtual G4int GetAreaCode(const G4ThreeVector& xx, G4bool withtol=true) = 0;
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329 virtual void SetBoundary(const G4int& axiscode,
0330 const G4ThreeVector& direction,
0331 const G4ThreeVector& x0,
0332 const G4int& boundarytype);
0333
0334
0335
0336
0337 void SetCorner(G4int areacode, G4double x, G4double y, G4double z);
0338
0339 private:
0340
0341
0342
0343
0344 virtual void SetBoundaries() = 0;
0345 virtual void SetCorners() = 0;
0346
0347
0348
0349 public:
0350
0351
0352 static const G4int sOutside ;
0353 static const G4int sInside ;
0354 static const G4int sBoundary;
0355 static const G4int sCorner;
0356 static const G4int sC0Min1Min;
0357 static const G4int sC0Max1Min;
0358 static const G4int sC0Max1Max;
0359 static const G4int sC0Min1Max;
0360 static const G4int sAxisMin;
0361 static const G4int sAxisMax;
0362 static const G4int sAxisX;
0363 static const G4int sAxisY;
0364 static const G4int sAxisZ;
0365 static const G4int sAxisRho;
0366 static const G4int sAxisPhi;
0367 static const G4int sAxis0;
0368 static const G4int sAxis1;
0369 static const G4int sSizeMask;
0370 static const G4int sAxisMask;
0371 static const G4int sAreaMask;
0372
0373 protected:
0374
0375 class CurrentStatus
0376 {
0377
0378
0379
0380 public:
0381
0382 CurrentStatus();
0383 virtual ~CurrentStatus();
0384
0385 inline G4ThreeVector GetXX(G4int i) const { return fXX[i]; }
0386 inline G4double GetDistance(G4int i) const { return fDistance[i]; }
0387 inline G4int GetAreacode(G4int i) const { return fAreacode[i]; }
0388 inline G4int GetNXX() const { return fNXX; }
0389 inline G4bool IsDone() const { return fDone; }
0390 inline G4bool IsValid(G4int i) const { return fIsValid[i]; }
0391
0392 void SetCurrentStatus(G4int i,
0393 G4ThreeVector& xx,
0394 G4double& dist,
0395 G4int& areacode,
0396 G4bool& isvalid,
0397 G4int nxx,
0398 EValidate validate,
0399 const G4ThreeVector* p,
0400 const G4ThreeVector* v = nullptr);
0401
0402 void ResetfDone(EValidate validate,
0403 const G4ThreeVector* p,
0404 const G4ThreeVector* v = nullptr);
0405
0406
0407 void DebugPrint() const;
0408
0409 private:
0410
0411 G4double fDistance[G4VSURFACENXX];
0412 G4ThreeVector fXX[G4VSURFACENXX];
0413 G4int fAreacode[G4VSURFACENXX];
0414 G4bool fIsValid[G4VSURFACENXX];
0415 G4int fNXX;
0416 G4ThreeVector fLastp;
0417 G4ThreeVector fLastv;
0418 EValidate fLastValidate;
0419 G4bool fDone;
0420 };
0421
0422 class Boundary
0423 {
0424
0425
0426
0427 public:
0428
0429 Boundary() = default;
0430 virtual ~Boundary() = default;
0431
0432 void SetFields(const G4int& areacode,
0433 const G4ThreeVector& d,
0434 const G4ThreeVector& x0,
0435 const G4int& boundarytype);
0436
0437 G4bool IsEmpty() const;
0438
0439 G4bool GetBoundaryParameters(const G4int& areacode,
0440 G4ThreeVector& d,
0441 G4ThreeVector& x0,
0442 G4int& boundarytype) const;
0443
0444 private:
0445
0446 G4int fBoundaryAcode{-1};
0447 G4ThreeVector fBoundaryDirection;
0448 G4ThreeVector fBoundaryX0;
0449 G4int fBoundaryType{0};
0450 };
0451
0452 EAxis fAxis[2];
0453 G4double fAxisMin[2];
0454 G4double fAxisMax[2];
0455 CurrentStatus fCurStatWithV;
0456 CurrentStatus fCurStat;
0457 G4RotationMatrix fRot;
0458 G4ThreeVector fTrans;
0459 G4int fHandedness;
0460
0461 class G4SurfCurNormal
0462 {
0463 public:
0464
0465 G4ThreeVector p;
0466 G4ThreeVector normal;
0467 };
0468
0469 G4SurfCurNormal fCurrentNormal;
0470 G4bool fIsValidNorm;
0471 G4double kCarTolerance;
0472
0473 private:
0474
0475 G4VTwistSurface* fNeighbours[4];
0476
0477 G4ThreeVector fCorners[4];
0478 Boundary fBoundaries[4];
0479 G4String fName;
0480
0481 class G4SurfSideQuery
0482 {
0483 public:
0484
0485 G4ThreeVector me;
0486 G4ThreeVector vec;
0487 G4bool withTol;
0488 G4int amIOnLeftSide;
0489 };
0490 G4SurfSideQuery fAmIOnLeftSide;
0491 };
0492
0493
0494
0495
0496
0497 #include "G4VTwistSurface.icc"
0498
0499 #endif