G4VTwistSurface.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4VTwistSurface.hh 67011 2013-01-29 16:17:41Z gcosmo $
00028 //
00029 // 
00030 // --------------------------------------------------------------------
00031 // GEANT 4 class header file
00032 //
00033 //
00034 // G4VTwistSurface
00035 //
00036 // Class description:
00037 //
00038 //  Abstract base class for boundary surface of G4VSolid.
00039 
00040 // Author: 
00041 //   01-Aug-2002 - Kotoyo Hoshina (hoshina@hepburn.s.chiba-u.ac.jp)
00042 //
00043 // History:
00044 //   13-Nov-2003 - O.Link (Oliver.Link@cern.ch), Integration in Geant4
00045 //                 from original version in Jupiter-2.5.02 application.
00046 // --------------------------------------------------------------------
00047 #ifndef __G4VTWISTSURFACE__
00048 #define __G4VTWISTSURFACE__
00049 
00050 #include <CLHEP/Units/SystemOfUnits.h>
00051 
00052 #include "G4VSolid.hh"
00053 #include "geomdefs.hh"
00054 
00055 #include "G4RotationMatrix.hh"
00056 
00057 #define G4VSURFACENXX 10
00058 
00059 class G4VTwistSurface
00060 {
00061  public:  // without description
00062 
00063    enum EValidate      {kDontValidate = 0, kValidateWithTol = 1, 
00064                         kValidateWithoutTol = 2, kUninitialized = 3};
00065 
00066  public:  // with description
00067 
00068    G4VTwistSurface (const G4String &name);
00069    G4VTwistSurface (const G4String &name,
00070                const G4RotationMatrix &rot,
00071                const G4ThreeVector    &tlate,
00072                      G4int             handedness,
00073                const EAxis             axis1,
00074                const EAxis             axis2,
00075                      G4double          axis0min = -kInfinity,
00076                      G4double          axis1min = -kInfinity,
00077                      G4double          axis0max = kInfinity,
00078                      G4double          axis1max = kInfinity);
00079 
00080    virtual ~G4VTwistSurface();
00081 
00082    virtual G4int     AmIOnLeftSide(const G4ThreeVector &me, 
00083                                    const G4ThreeVector &vec, 
00084                                          G4bool withTol = true);
00085 
00086    virtual G4double  DistanceToBoundary(      G4int areacode,
00087                                               G4ThreeVector &xx,
00088                                         const G4ThreeVector &p) ;
00089 
00090 
00091    virtual G4double  DistanceToIn(const G4ThreeVector &gp,
00092                                   const G4ThreeVector &gv,
00093                                         G4ThreeVector &gxxbest);
00094    virtual G4double  DistanceToOut(const G4ThreeVector &gp,
00095                                    const G4ThreeVector &gv,
00096                                          G4ThreeVector &gxxbest);
00097    virtual G4double  DistanceTo(const G4ThreeVector &gp,
00098                                       G4ThreeVector &gxx);
00099       
00100    virtual G4int     DistanceToSurface(const G4ThreeVector &gp,
00101                                        const G4ThreeVector &gv,
00102                                              G4ThreeVector gxx[],
00103                                              G4double      distance[],
00104                                              G4int         areacode[],
00105                                              G4bool        isvalid[],
00106                                        EValidate validate=kValidateWithTol) = 0;
00107 
00108    virtual G4int     DistanceToSurface(const G4ThreeVector &gp,
00109                                              G4ThreeVector gxx[],
00110                                              G4double      distance[],
00111                                              G4int         areacode[]) = 0;
00112                                              
00113    void              DebugPrint() const;
00114 
00115    // get methods
00116 
00117    virtual G4ThreeVector GetNormal(const G4ThreeVector &xx,G4bool isGlobal) = 0;
00118    
00119    virtual G4String      GetName() const { return fName; }
00120    virtual void          GetBoundaryParameters(const G4int   &areacode,
00121                                                G4ThreeVector &d,
00122                                                G4ThreeVector &x0,
00123                                                G4int &boundarytype) const;
00124    virtual G4ThreeVector GetBoundaryAtPZ(G4int areacode,
00125                                          const G4ThreeVector &p) const;
00126 
00127    inline  G4double      DistanceToPlaneWithV(const G4ThreeVector &p,
00128                                               const G4ThreeVector &v,
00129                                               const G4ThreeVector &x0,
00130                                               const G4ThreeVector &n0,
00131                                                     G4ThreeVector &xx);
00132 
00133    inline  G4double      DistanceToPlane(const G4ThreeVector &p,
00134                                          const G4ThreeVector &x0,
00135                                          const G4ThreeVector &n0,
00136                                                G4ThreeVector &xx);
00137    
00138    inline  G4double      DistanceToPlane(const G4ThreeVector &p,
00139                                          const G4ThreeVector &x0,
00140                                          const G4ThreeVector &t1,
00141                                          const G4ThreeVector &t2,
00142                                                G4ThreeVector &xx,
00143                                                G4ThreeVector &n);
00144 
00145    inline  G4double      DistanceToLine (const G4ThreeVector &p,
00146                                          const G4ThreeVector &x0,
00147                                          const G4ThreeVector &d,
00148                                                G4ThreeVector &xx);
00149                                                
00150    inline  G4bool IsAxis0    (G4int areacode) const;
00151    inline  G4bool IsAxis1    (G4int areacode) const;
00152    inline  G4bool IsOutside  (G4int areacode) const;
00153    inline  G4bool IsInside   (G4int areacode, G4bool testbitmode = false) const;
00154    inline  G4bool IsBoundary (G4int areacode, G4bool testbitmode = false) const;
00155    inline  G4bool IsCorner   (G4int areacode, G4bool testbitmode = false) const;
00156    inline  G4bool IsValidNorm() const { return fIsValidNorm; }
00157            G4bool IsSameBoundary (G4VTwistSurface *surface1, G4int areacode1,
00158                                   G4VTwistSurface *surface2, G4int areacode2 ) const;
00159    inline  G4int  GetAxisType(G4int areacode, G4int whichaxis) const;
00160 
00161    inline  G4ThreeVector ComputeGlobalPoint     (const G4ThreeVector &lp) const;
00162    inline  G4ThreeVector ComputeLocalPoint      (const G4ThreeVector &gp) const;
00163    inline  G4ThreeVector ComputeGlobalDirection (const G4ThreeVector &lp) const;
00164    inline  G4ThreeVector ComputeLocalDirection  (const G4ThreeVector &gp) const;
00165   
00166    // set methods
00167 
00168    inline void SetAxis(G4int i, const EAxis axis)  { fAxis[i] = axis; }
00169    inline void SetNeighbours(G4VTwistSurface* axis0min, G4VTwistSurface* axis1min, 
00170                              G4VTwistSurface* axis0max, G4VTwistSurface* axis1max);
00171 
00172    virtual G4ThreeVector SurfacePoint(G4double , G4double,
00173                                       G4bool isGlobal = false ) = 0 ;
00174    virtual G4double GetBoundaryMin(G4double) = 0 ;
00175    virtual G4double GetBoundaryMax(G4double) = 0 ;
00176    virtual G4double GetSurfaceArea() = 0 ;
00177    virtual void GetFacets(G4int m, G4int n, G4double xyz[][3],
00178                           G4int faces[][4], G4int iside) = 0 ;
00179    G4int GetNode( G4int i, G4int j, G4int m, G4int n, G4int iside )  ;
00180    G4int GetFace( G4int i, G4int j, G4int m, G4int n, G4int iside )  ;
00181    G4int GetEdgeVisibility( G4int i, G4int j, G4int m, G4int n, G4int number, G4int orientation) ;
00182 
00183 
00184  public:  // without description
00185 
00186    G4VTwistSurface(__void__&);
00187      // Fake default constructor for usage restricted to direct object
00188      // persistency for clients requiring preallocation of memory for
00189      // persistifiable objects.
00190 
00191  protected:  // with description
00192  
00193    // get methods
00194 
00195    inline  G4VTwistSurface**  GetNeighbours() { return fNeighbours; } 
00196    inline  G4int GetNeighbours(G4int areacode, G4VTwistSurface* surfaces[]);
00197    inline  G4ThreeVector GetCorner(G4int areacode) const;
00198            void GetBoundaryAxis(G4int areacode, EAxis axis[]) const;
00199            void GetBoundaryLimit(G4int areacode, G4double limit[]) const;
00200    virtual G4int GetAreaCode(const G4ThreeVector &xx, G4bool withtol=true) = 0;
00201       
00202    // set methods
00203 
00204    virtual void SetBoundary(const G4int         &axiscode, 
00205                             const G4ThreeVector &direction,
00206                             const G4ThreeVector &x0, 
00207                             const G4int         &boundarytype);
00208      // areacode must be one of them:
00209      // sAxis0 & sAxisMin, sAxis0 & sAxisMax,
00210      // sAxis1 & sAxisMin, sAxis1 & sAxisMax.
00211      // boundarytype represents the shape of locus
00212      // from the start point to end point of boundary.
00213      // ex.
00214      // sAxisRho = linear line which start point is fixed at origin.
00215      // sAxisPhi = part of circle which center placed at the origin.
00216                             
00217    void SetCorner(G4int areacode, G4double x, G4double y, G4double z);
00218 
00219  private:
00220 
00221    virtual void SetBoundaries() = 0;
00222    virtual void SetCorners()    = 0;
00223    
00224  // data members ---------------------------------------------------------
00225 
00226  public:
00227 
00228    static const G4int sOutside ;
00229    static const G4int sInside  ;
00230    static const G4int sBoundary;
00231    static const G4int sCorner;
00232    static const G4int sC0Min1Min;
00233    static const G4int sC0Max1Min;
00234    static const G4int sC0Max1Max;
00235    static const G4int sC0Min1Max;
00236    static const G4int sAxisMin;
00237    static const G4int sAxisMax;
00238    static const G4int sAxisX;
00239    static const G4int sAxisY;
00240    static const G4int sAxisZ;
00241    static const G4int sAxisRho;
00242    static const G4int sAxisPhi;
00243    static const G4int sAxis0;
00244    static const G4int sAxis1;
00245    static const G4int sSizeMask;
00246    static const G4int sAxisMask;
00247    static const G4int sAreaMask;
00248 
00249  protected:
00250  
00251    class CurrentStatus 
00252    {
00253     public:
00254 
00255       CurrentStatus();
00256       virtual ~CurrentStatus();
00257       
00258       inline G4ThreeVector GetXX(G4int i)       const { return fXX[i];       }
00259       inline G4double      GetDistance(G4int i) const { return fDistance[i]; }
00260       inline G4int         GetAreacode(G4int i) const { return fAreacode[i]; }
00261       inline G4int         GetNXX()             const { return fNXX;         }
00262       inline G4bool        IsDone()             const { return fDone;        }
00263       inline G4bool        IsValid(G4int i)     const { return fIsValid[i];  }
00264 
00265       void SetCurrentStatus(G4int                i, 
00266                             G4ThreeVector       &xx, 
00267                             G4double            &dist, 
00268                             G4int               &areacode, 
00269                             G4bool              &isvalid,
00270                             G4int                nxx,
00271                             EValidate            validate,
00272                       const G4ThreeVector *p, 
00273                       const G4ThreeVector *v = 0);
00274 
00275       void ResetfDone(EValidate            validate,
00276                 const G4ThreeVector *p, 
00277                 const G4ThreeVector *v = 0);
00278 
00279 
00280       void DebugPrint() const;
00281 
00282     private:
00283 
00284       G4double             fDistance[G4VSURFACENXX];
00285       G4ThreeVector        fXX[G4VSURFACENXX];
00286       G4int                fAreacode[G4VSURFACENXX];
00287       G4bool               fIsValid[G4VSURFACENXX];
00288       G4int                fNXX;
00289       G4ThreeVector        fLastp;
00290       G4ThreeVector        fLastv;
00291       EValidate            fLastValidate;
00292       G4bool               fDone;
00293    };
00294       
00295    class Boundary 
00296    {
00297     public:
00298       Boundary();
00299       virtual ~Boundary();
00300       
00301       void SetFields(const G4int         &areacode, 
00302                      const G4ThreeVector &d, 
00303                      const G4ThreeVector &x0, 
00304                      const G4int         &boundarytype);
00305       
00306       G4bool IsEmpty() const;
00307       
00308       G4bool GetBoundaryParameters(const G4int         &areacode, 
00309                                          G4ThreeVector &d,
00310                                          G4ThreeVector &x0, 
00311                                          G4int         &boundarytype) const;
00312 
00313     private:
00314       G4int          fBoundaryAcode;
00315       G4ThreeVector  fBoundaryDirection;
00316       G4ThreeVector  fBoundaryX0;
00317       G4int          fBoundaryType;
00318    };
00319 
00320    EAxis               fAxis[2];
00321    G4double            fAxisMin[2];
00322    G4double            fAxisMax[2];
00323    CurrentStatus       fCurStatWithV;
00324    CurrentStatus       fCurStat;
00325    G4RotationMatrix    fRot;
00326    G4ThreeVector       fTrans;
00327    G4int               fHandedness;
00328    class G4SurfCurNormal
00329    {
00330      public:
00331        G4ThreeVector p;
00332        G4ThreeVector normal;
00333    };
00334    G4SurfCurNormal     fCurrentNormal;
00335    G4bool              fIsValidNorm;
00336    G4double            kCarTolerance;
00337                         
00338  private:
00339                      
00340    G4VTwistSurface    *fNeighbours[4]; // {0,1,2,3} = sAxis0min, sAxis1min, 
00341                                   //             sAxis0max, sAxis1max
00342    G4ThreeVector fCorners[4];     // corners of the surface in local coordinate
00343    Boundary      fBoundaries[4];  // boundaries of the surface.
00344    G4String      fName;
00345    
00346    class G4SurfSideQuery
00347    {
00348      public:
00349        G4ThreeVector me;
00350        G4ThreeVector vec;
00351        G4bool        withTol;
00352        G4int         amIOnLeftSide;
00353    };
00354    G4SurfSideQuery fAmIOnLeftSide;
00355 };
00356 
00357 //========================================================
00358 // inline functions
00359 //========================================================
00360 
00361 struct Intersection
00362 {    
00363   G4double phi ;  // parameter phi
00364   G4double u ;    // parameter u
00365   G4ThreeVector xx ;   // intersection point in cartesian
00366   G4double distance ;  // distance to intersection
00367   G4int areacode;      // the areacode of the intersection
00368   G4bool isvalid ;     // valid intersection ??
00369 
00370 };
00371 
00372 inline
00373 G4bool DistanceSort( const Intersection &a, const Intersection &b) 
00374 {
00375   return a.distance < b.distance ;
00376 }
00377 
00378 inline
00379 G4bool EqualIntersection( const Intersection &a, const Intersection &b)
00380 {
00381   return ( ( a.xx - b.xx ).mag() < 1E-9*CLHEP::mm ) ;
00382 }
00383 
00384 #include "G4VTwistSurface.icc"
00385 
00386 #endif

Generated on Mon May 27 17:50:23 2013 for Geant4 by  doxygen 1.4.7