Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4VTwistSurface.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4VTwistSurface
0027 //
0028 // Class description:
0029 //
0030 // Abstract base class for boundary surface of G4VSolid.
0031 
0032 // 01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp), created.
0033 // 13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
0034 //               from original version in Jupiter-2.5.02 application.
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 class G4VTwistSurface
0049 {
0050  public:
0051 
0052    enum EValidate { kDontValidate = 0, kValidateWithTol = 1, 
0053                     kValidateWithoutTol = 2, kUninitialized = 3 };
0054 
0055    G4VTwistSurface (const G4String& name);
0056    G4VTwistSurface (const G4String& name,
0057                     const G4RotationMatrix& rot,
0058                     const G4ThreeVector&    tlate,
0059                           G4int             handedness,
0060                     const EAxis             axis1,
0061                     const EAxis             axis2,
0062                           G4double          axis0min = -kInfinity,
0063                           G4double          axis1min = -kInfinity,
0064                           G4double          axis0max = kInfinity,
0065                           G4double          axis1max = kInfinity);
0066 
0067    virtual ~G4VTwistSurface();
0068 
0069    virtual G4int     AmIOnLeftSide(const G4ThreeVector& me, 
0070                                    const G4ThreeVector& vec, 
0071                                          G4bool withTol = true);
0072 
0073    virtual G4double  DistanceToBoundary(      G4int areacode,
0074                                               G4ThreeVector& xx,
0075                                         const G4ThreeVector& p) ;
0076 
0077    virtual G4double  DistanceToIn(const G4ThreeVector& gp,
0078                                   const G4ThreeVector& gv,
0079                                         G4ThreeVector& gxxbest);
0080    virtual G4double  DistanceToOut(const G4ThreeVector& gp,
0081                                    const G4ThreeVector& gv,
0082                                          G4ThreeVector& gxxbest);
0083    virtual G4double  DistanceTo(const G4ThreeVector& gp,
0084                                       G4ThreeVector& gxx);
0085       
0086    virtual G4int     DistanceToSurface(const G4ThreeVector& gp,
0087                                        const G4ThreeVector& gv,
0088                                              G4ThreeVector gxx[],
0089                                              G4double      distance[],
0090                                              G4int         areacode[],
0091                                              G4bool        isvalid[],
0092                                        EValidate validate=kValidateWithTol) = 0;
0093 
0094    virtual G4int     DistanceToSurface(const G4ThreeVector& gp,
0095                                              G4ThreeVector gxx[],
0096                                              G4double      distance[],
0097                                              G4int         areacode[]) = 0;
0098                                              
0099    void              DebugPrint() const;
0100 
0101    virtual G4ThreeVector GetNormal(const G4ThreeVector& xx,G4bool isGlobal) = 0;
0102    
0103    virtual G4String      GetName() const { return fName; }
0104    virtual void          GetBoundaryParameters(const G4int& areacode,
0105                                                G4ThreeVector& d,
0106                                                G4ThreeVector& x0,
0107                                                G4int& boundarytype) const;
0108    virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode,
0109                                          const G4ThreeVector& p) const;
0110 
0111    inline  G4double DistanceToPlaneWithV(const G4ThreeVector& p,
0112                                          const G4ThreeVector& v,
0113                                          const G4ThreeVector& x0,
0114                                          const G4ThreeVector& n0,
0115                                                G4ThreeVector& xx);
0116 
0117    inline  G4double DistanceToPlane(const G4ThreeVector& p,
0118                                     const G4ThreeVector& x0,
0119                                     const G4ThreeVector& n0,
0120                                           G4ThreeVector& xx);
0121    
0122    inline  G4double DistanceToPlane(const G4ThreeVector& p,
0123                                     const G4ThreeVector& x0,
0124                                     const G4ThreeVector& t1,
0125                                     const G4ThreeVector& t2,
0126                                           G4ThreeVector& xx,
0127                                           G4ThreeVector& n);
0128 
0129    inline  G4double DistanceToLine (const G4ThreeVector& p,
0130                                     const G4ThreeVector& x0,
0131                                     const G4ThreeVector& d,
0132                                           G4ThreeVector& xx);
0133 
0134    inline G4bool IsAxis0    (G4int areacode) const;
0135    inline G4bool IsAxis1    (G4int areacode) const;
0136    inline G4bool IsOutside  (G4int areacode) const;
0137    inline G4bool IsInside   (G4int areacode, G4bool testbitmode = false) const;
0138    inline G4bool IsBoundary (G4int areacode, G4bool testbitmode = false) const;
0139    inline G4bool IsCorner   (G4int areacode, G4bool testbitmode = false) const;
0140    inline G4bool IsValidNorm() const { return fIsValidNorm; }
0141    G4bool IsSameBoundary (G4VTwistSurface* surface1, G4int areacode1,
0142                           G4VTwistSurface* surface2, G4int areacode2 ) const;
0143    inline G4int  GetAxisType(G4int areacode, G4int whichaxis) const;
0144 
0145    inline G4ThreeVector ComputeGlobalPoint     (const G4ThreeVector& lp) const;
0146    inline G4ThreeVector ComputeLocalPoint      (const G4ThreeVector& gp) const;
0147    inline G4ThreeVector ComputeGlobalDirection (const G4ThreeVector& lp) const;
0148    inline G4ThreeVector ComputeLocalDirection  (const G4ThreeVector& gp) const;
0149   
0150    // set methods
0151 
0152    inline void SetAxis(G4int i, const EAxis axis)  { fAxis[i] = axis; }
0153    inline void SetNeighbours(G4VTwistSurface* ax0min, G4VTwistSurface* ax1min, 
0154                              G4VTwistSurface* ax0max, G4VTwistSurface* ax1max);
0155 
0156    virtual G4ThreeVector SurfacePoint(G4double, G4double,
0157                                       G4bool isGlobal = false ) = 0 ;
0158    virtual G4double GetBoundaryMin(G4double) = 0 ;
0159    virtual G4double GetBoundaryMax(G4double) = 0 ;
0160    virtual G4double GetSurfaceArea() = 0 ;
0161    virtual void GetFacets(G4int m, G4int n, G4double xyz[][3],
0162                           G4int faces[][4], G4int iside) = 0 ;
0163    G4int GetNode( G4int i, G4int j, G4int m, G4int n, G4int iside ) ;
0164    G4int GetFace( G4int i, G4int j, G4int m, G4int n, G4int iside ) ;
0165    G4int GetEdgeVisibility( G4int i, G4int j, G4int m, G4int n,
0166                             G4int number, G4int orientation) ;
0167 
0168    G4VTwistSurface(__void__&);
0169      // Fake default constructor for usage restricted to direct object
0170      // persistency for clients requiring preallocation of memory for
0171      // persistifiable objects.
0172 
0173  protected:
0174  
0175    inline G4VTwistSurface** GetNeighbours() { return fNeighbours; } 
0176    inline G4int GetNeighbours(G4int areacode, G4VTwistSurface* surfaces[]);
0177    inline G4ThreeVector GetCorner(G4int areacode) const;
0178    void GetBoundaryAxis(G4int areacode, EAxis axis[]) const;
0179    void GetBoundaryLimit(G4int areacode, G4double limit[]) const;
0180    virtual G4int GetAreaCode(const G4ThreeVector& xx, G4bool withtol=true) = 0;
0181 
0182    virtual void SetBoundary(const G4int&         axiscode, 
0183                             const G4ThreeVector& direction,
0184                             const G4ThreeVector& x0, 
0185                             const G4int&         boundarytype);
0186      // areacode must be one of them:
0187      // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
0188      // sAxis1 & sAxisMin, sAxis1 & sAxisMax.
0189      // boundarytype represents the shape of locus
0190      // from the start point to end point of boundary.
0191      // ex.
0192      // sAxisRho = linear line which start point is fixed at origin.
0193      // sAxisPhi = part of circle which center placed at the origin.
0194                             
0195    void SetCorner(G4int areacode, G4double x, G4double y, G4double z);
0196 
0197  private:
0198 
0199    virtual void SetBoundaries() = 0;
0200    virtual void SetCorners()    = 0;
0201    
0202  // data members ---------------------------------------------------------
0203 
0204  public:
0205 
0206    static const G4int sOutside ;
0207    static const G4int sInside  ;
0208    static const G4int sBoundary;
0209    static const G4int sCorner;
0210    static const G4int sC0Min1Min;
0211    static const G4int sC0Max1Min;
0212    static const G4int sC0Max1Max;
0213    static const G4int sC0Min1Max;
0214    static const G4int sAxisMin;
0215    static const G4int sAxisMax;
0216    static const G4int sAxisX;
0217    static const G4int sAxisY;
0218    static const G4int sAxisZ;
0219    static const G4int sAxisRho;
0220    static const G4int sAxisPhi;
0221    static const G4int sAxis0;
0222    static const G4int sAxis1;
0223    static const G4int sSizeMask;
0224    static const G4int sAxisMask;
0225    static const G4int sAreaMask;
0226 
0227  protected:
0228  
0229    class CurrentStatus 
0230    {
0231      public:
0232 
0233       CurrentStatus();
0234       virtual ~CurrentStatus();
0235       
0236       inline G4ThreeVector GetXX(G4int i)       const { return fXX[i];       }
0237       inline G4double      GetDistance(G4int i) const { return fDistance[i]; }
0238       inline G4int         GetAreacode(G4int i) const { return fAreacode[i]; }
0239       inline G4int         GetNXX()             const { return fNXX;         }
0240       inline G4bool        IsDone()             const { return fDone;        }
0241       inline G4bool        IsValid(G4int i)     const { return fIsValid[i];  }
0242 
0243       void SetCurrentStatus(G4int                i, 
0244                             G4ThreeVector&       xx, 
0245                             G4double&            dist, 
0246                             G4int&               areacode, 
0247                             G4bool&              isvalid,
0248                             G4int                nxx,
0249                             EValidate            validate,
0250                       const G4ThreeVector* p, 
0251                       const G4ThreeVector* v = nullptr);
0252 
0253       void ResetfDone(EValidate validate,
0254                 const G4ThreeVector* p, 
0255                 const G4ThreeVector* v = nullptr);
0256 
0257 
0258       void DebugPrint() const;
0259 
0260      private:
0261 
0262       G4double             fDistance[G4VSURFACENXX];
0263       G4ThreeVector        fXX[G4VSURFACENXX];
0264       G4int                fAreacode[G4VSURFACENXX];
0265       G4bool               fIsValid[G4VSURFACENXX];
0266       G4int                fNXX;
0267       G4ThreeVector        fLastp;
0268       G4ThreeVector        fLastv;
0269       EValidate            fLastValidate;
0270       G4bool               fDone;
0271    };
0272       
0273    class Boundary 
0274    {
0275      public:
0276 
0277       Boundary();
0278       virtual ~Boundary();
0279       
0280       void SetFields(const G4int&        areacode, 
0281                      const G4ThreeVector& d, 
0282                      const G4ThreeVector& x0, 
0283                      const G4int&         boundarytype);
0284       
0285       G4bool IsEmpty() const;
0286       
0287       G4bool GetBoundaryParameters(const G4int&         areacode, 
0288                                          G4ThreeVector& d,
0289                                          G4ThreeVector& x0, 
0290                                          G4int&         boundarytype) const;
0291 
0292      private:
0293 
0294       G4int          fBoundaryAcode{-1};
0295       G4ThreeVector  fBoundaryDirection;
0296       G4ThreeVector  fBoundaryX0;
0297       G4int          fBoundaryType{0};
0298    };
0299 
0300    EAxis               fAxis[2];
0301    G4double            fAxisMin[2];
0302    G4double            fAxisMax[2];
0303    CurrentStatus       fCurStatWithV;
0304    CurrentStatus       fCurStat;
0305    G4RotationMatrix    fRot;
0306    G4ThreeVector       fTrans;
0307    G4int               fHandedness;
0308    class G4SurfCurNormal
0309    {
0310      public:
0311 
0312        G4ThreeVector p;
0313        G4ThreeVector normal;
0314    };
0315    G4SurfCurNormal     fCurrentNormal;
0316    G4bool              fIsValidNorm;
0317    G4double            kCarTolerance;
0318                         
0319  private:
0320                      
0321    G4VTwistSurface* fNeighbours[4]; // {0,1,2,3} = sAxis0min, sAxis1min, 
0322                                     //             sAxis0max, sAxis1max
0323    G4ThreeVector fCorners[4];     // corners of the surface in local coordinate
0324    Boundary      fBoundaries[4];  // boundaries of the surface.
0325    G4String      fName;
0326    
0327    class G4SurfSideQuery
0328    {
0329      public:
0330 
0331        G4ThreeVector me;
0332        G4ThreeVector vec;
0333        G4bool        withTol;
0334        G4int         amIOnLeftSide;
0335    };
0336    G4SurfSideQuery fAmIOnLeftSide;
0337 };
0338 
0339 //========================================================
0340 // inline functions
0341 //========================================================
0342 
0343 struct Intersection
0344 {    
0345   G4double phi ;  // parameter phi
0346   G4double u ;    // parameter u
0347   G4ThreeVector xx ;   // intersection point in cartesian
0348   G4double distance ;  // distance to intersection
0349   G4int areacode ;     // the areacode of the intersection
0350   G4bool isvalid ;     // valid intersection ??
0351 
0352 };
0353 
0354 inline
0355 G4bool DistanceSort( const Intersection& a, const Intersection& b) 
0356 {
0357   return a.distance < b.distance ;
0358 }
0359 
0360 inline
0361 G4bool EqualIntersection( const Intersection& a, const Intersection& b)
0362 {
0363   return ( ( a.xx - b.xx ).mag() < 1E-9*CLHEP::mm ) ;  
0364 }
0365 
0366 #include "G4VTwistSurface.icc"
0367 
0368 #endif