G4VTwistedFaceted.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: G4VTwistedFaceted.hh 67011 2013-01-29 16:17:41Z gcosmo $
00028 // 
00029 // --------------------------------------------------------------------
00030 // GEANT 4 class header file
00031 //
00032 //
00033 // G4VTwistedFaceted
00034 //
00035 // Class description:
00036 //
00037 //  G4VTwistedFaceted is an abstract base class for twisted boxoids:
00038 //  G4TwistedTrd, G4TwistedTrap and G4TwistedBox
00039 
00040 // Author:
00041 //
00042 //   27-Oct-2004 - O.Link (Oliver.Link@cern.ch)
00043 //
00044 // --------------------------------------------------------------------
00045 
00046 #ifndef __G4VTWISTEDFACETED__
00047 #define __G4VTWISTEDFACETED__
00048 
00049 #include "G4VSolid.hh"
00050 #include "G4TwistTrapAlphaSide.hh"
00051 #include "G4TwistTrapParallelSide.hh"
00052 #include "G4TwistBoxSide.hh"
00053 #include "G4TwistTrapFlatSide.hh" 
00054 
00055 class G4SolidExtentList;
00056 class G4ClippablePolygon;
00057 
00058 class G4VTwistedFaceted: public G4VSolid
00059 {
00060  public:  // with description
00061  
00062   G4VTwistedFaceted(const G4String &pname,    // Name of instance
00063                           G4double PhiTwist,  // twist angle
00064                           G4double pDz,       // half z lenght
00065                           G4double pTheta,  // direction between end planes
00066                           G4double pPhi,    // defined by polar & azim. angles
00067                           G4double pDy1,    // half y length at -pDz
00068                           G4double pDx1,    // half x length at -pDz,-pDy
00069                           G4double pDx2,    // half x length at -pDz,+pDy
00070                           G4double pDy2,    // half y length at +pDz
00071                           G4double pDx3,    // half x length at +pDz,-pDy
00072                           G4double pDx4,    // half x length at +pDz,+pDy
00073                           G4double pAlph    // tilt angle at +pDz
00074                    );
00075   
00076   virtual ~G4VTwistedFaceted();
00077              
00078   virtual void ComputeDimensions(G4VPVParameterisation*,
00079                                  const G4int,
00080                                  const G4VPhysicalVolume*  );
00081  
00082   virtual G4bool CalculateExtent(const EAxis               pAxis,
00083                                  const G4VoxelLimits      &pVoxelLimit,
00084                                  const G4AffineTransform  &pTransform,
00085                                        G4double           &pMin,
00086                                        G4double           &pMax ) const;
00087 
00088   virtual G4double DistanceToIn (const G4ThreeVector &p,
00089                                  const G4ThreeVector &v ) const;
00090 
00091   virtual G4double DistanceToIn (const G4ThreeVector &p ) const;
00092    
00093   virtual G4double DistanceToOut(const G4ThreeVector &p, 
00094                                  const G4ThreeVector &v,
00095                                  const G4bool         calcnorm  = false,
00096                                        G4bool        *validnorm = 0, 
00097                                        G4ThreeVector *n=0 ) const;
00098 
00099   virtual G4double DistanceToOut(const G4ThreeVector &p) const;
00100   
00101   virtual EInside Inside (const G4ThreeVector &p) const;
00102 
00103   virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const;
00104 
00105   G4ThreeVector GetPointOnSurface() const;
00106   G4ThreeVector GetPointInSolid(G4double z) const;
00107   
00108   virtual inline G4double GetCubicVolume() ;
00109   virtual inline G4double GetSurfaceArea() ;
00110 
00111   virtual void            DescribeYourselfTo (G4VGraphicsScene &scene) const;
00112   virtual G4Polyhedron   *CreatePolyhedron   () const ;
00113   virtual G4NURBS        *CreateNURBS        () const;
00114   virtual G4Polyhedron   *GetPolyhedron      () const;
00115 
00116   virtual std::ostream &StreamInfo(std::ostream& os) const;
00117 
00118   // accessors
00119   
00120   inline G4double GetTwistAngle    () const { return fPhiTwist; }
00121 
00122   inline G4double GetDx1   () const { return fDx1   ; } 
00123   inline G4double GetDx2   () const { return fDx2   ; } 
00124   inline G4double GetDx3   () const { return fDx3   ; } 
00125   inline G4double GetDx4   () const { return fDx4   ; } 
00126   inline G4double GetDy1   () const { return fDy1   ; } 
00127   inline G4double GetDy2   () const { return fDy2   ; } 
00128   inline G4double GetDz    () const { return fDz    ; }
00129   inline G4double GetPhi   () const { return fPhi   ; }
00130   inline G4double GetTheta () const { return fTheta ; }
00131   inline G4double GetAlpha () const { return fAlph  ; }
00132 
00133   inline G4double Xcoef(G4double u,G4double phi, G4double ftg) const ;
00134     // For calculating the w(u) function
00135 
00136   inline G4double GetValueA(G4double phi) const;
00137   inline G4double GetValueB(G4double phi) const;
00138   inline G4double GetValueD(G4double phi) const;
00139 
00140   virtual G4VisExtent     GetExtent    () const;
00141   virtual G4GeometryType  GetEntityType() const;
00142 
00143  public:  // without description
00144 
00145   G4VTwistedFaceted(__void__&);
00146     // Fake default constructor for usage restricted to direct object
00147     // persistency for clients requiring preallocation of memory for
00148     // persistifiable objects.
00149 
00150   G4VTwistedFaceted(const G4VTwistedFaceted& rhs);
00151   G4VTwistedFaceted& operator=(const G4VTwistedFaceted& rhs); 
00152     // Copy constructor and assignment operator.
00153 
00154  protected:  // with description
00155 
00156   G4ThreeVectorList*
00157     CreateRotatedVertices(const G4AffineTransform& pTransform) const;
00158       // Create the List of transformed vertices in the format required
00159       // for G4VSolid:: ClipCrossSection and ClipBetweenSections.
00160 
00161  private:
00162  
00163   void CreateSurfaces();
00164 
00165  private:
00166  
00167   G4double fTheta;   
00168   G4double fPhi ;
00169 
00170   G4double fDy1;   
00171   G4double fDx1;     
00172   G4double fDx2;     
00173   
00174   G4double fDy2;   
00175   G4double fDx3;     
00176   G4double fDx4;     
00177 
00178   G4double fDz;        // Half-length along the z axis
00179 
00180   G4double fDx ;       // maximum side in x 
00181   G4double fDy ;       // maximum side in y
00182 
00183   G4double fAlph ;
00184   G4double fTAlph ;    // std::tan(fAlph)
00185 
00186   G4double fdeltaX ;
00187   G4double fdeltaY ;
00188     
00189   G4double fPhiTwist;  // twist angle ( dphi in surface equation)
00190 
00191   G4VTwistSurface *fLowerEndcap ;  // surface of -ve z
00192   G4VTwistSurface *fUpperEndcap ;  // surface of +ve z
00193   
00194   G4VTwistSurface *fSide0 ;         // Twisted Side at phi = 0 deg
00195   G4VTwistSurface *fSide90 ;        // Twisted Side at phi = 90 deg
00196   G4VTwistSurface *fSide180 ;       // Twisted Side at phi = 180 deg
00197   G4VTwistSurface *fSide270 ;       // Twisted Side at phi = 270 deg
00198 
00199   G4double fCubicVolume ;      // volume of the solid
00200   G4double fSurfaceArea ;      // area of the solid
00201 
00202   mutable G4Polyhedron* fpPolyhedron;  // pointer to polyhedron for vis
00203 
00204   class LastState              // last Inside result
00205   {
00206     public:
00207       LastState()
00208       {
00209         p.set(kInfinity,kInfinity,kInfinity); inside = kOutside;
00210       }
00211       ~LastState(){}
00212       LastState(const LastState& r) : p(r.p), inside(r.inside){}
00213       LastState& operator=(const LastState& r)
00214       {
00215         if (this == &r)  { return *this; }
00216         p = r.p; inside = r.inside;
00217         return *this;
00218       }
00219     public:
00220       G4ThreeVector p;
00221       EInside       inside;
00222   };
00223               
00224   class LastVector             // last SurfaceNormal result
00225   {
00226     public:
00227       LastVector()
00228       {
00229         p.set(kInfinity,kInfinity,kInfinity);
00230         vec.set(kInfinity,kInfinity,kInfinity);
00231         surface = new G4VTwistSurface*[1];
00232       }
00233       ~LastVector()
00234       {
00235         delete [] surface;
00236       }
00237       LastVector(const LastVector& r) : p(r.p), vec(r.vec)
00238       {
00239         surface = new G4VTwistSurface*[1];
00240         surface[0] = r.surface[0];
00241       }
00242       LastVector& operator=(const LastVector& r)
00243       {
00244         if (&r == this)  { return *this; }
00245         p = r.p; vec = r.vec;
00246         delete [] surface; surface = new G4VTwistSurface*[1];
00247         surface[0] = r.surface[0];
00248         return *this;
00249       }
00250     public:
00251       G4ThreeVector   p;
00252       G4ThreeVector   vec;
00253       G4VTwistSurface **surface;
00254   };
00255 
00256   class LastValue              // last G4double value
00257   {
00258     public:
00259       LastValue()
00260       {
00261         p.set(kInfinity,kInfinity,kInfinity);
00262         value = DBL_MAX;
00263       }
00264       ~LastValue(){}
00265       LastValue(const LastValue& r) : p(r.p), value(r.value){}
00266       LastValue& operator=(const LastValue& r)
00267       {
00268         if (this == &r)  { return *this; }
00269         p = r.p; value = r.value;
00270         return *this;
00271       }
00272     public:
00273       G4ThreeVector p;
00274       G4double      value;
00275   };
00276               
00277   class LastValueWithDoubleVector   // last G4double value
00278   {
00279     public:
00280       LastValueWithDoubleVector()
00281       {
00282         p.set(kInfinity,kInfinity,kInfinity);
00283         vec.set(kInfinity,kInfinity,kInfinity);
00284         value = DBL_MAX;
00285       }
00286       ~LastValueWithDoubleVector(){}
00287       LastValueWithDoubleVector(const LastValueWithDoubleVector& r)
00288         : p(r.p), vec(r.vec), value(r.value){}
00289       LastValueWithDoubleVector& operator=(const LastValueWithDoubleVector& r)
00290       {
00291         if (this == &r)  { return *this; }
00292         p = r.p; vec = r.vec; value = r.value;
00293         return *this;
00294       }
00295     public:
00296       G4ThreeVector p;
00297       G4ThreeVector vec;
00298       G4double      value;
00299   };
00300               
00301   LastState    fLastInside;
00302   LastVector   fLastNormal;
00303   LastValue    fLastDistanceToIn;
00304   LastValue    fLastDistanceToOut;
00305   LastValueWithDoubleVector   fLastDistanceToInWithV;
00306   LastValueWithDoubleVector   fLastDistanceToOutWithV;
00307 
00308  };
00309 
00310 //=====================================================================
00311 
00312 inline
00313 G4double G4VTwistedFaceted::GetCubicVolume()
00314 {
00315   if(fCubicVolume != 0.) ;
00316   else   fCubicVolume = 2 * fDz
00317                       * ( ( fDx1 + fDx2 ) * fDy1 + ( fDx3 + fDx4 ) * fDy2  );
00318   return fCubicVolume;
00319 }
00320 
00321 inline
00322 G4double G4VTwistedFaceted::GetSurfaceArea()
00323 {
00324   if(fSurfaceArea != 0.) ;
00325   else   fSurfaceArea = G4VSolid::GetSurfaceArea();
00326   return fSurfaceArea;
00327 }
00328 
00329 inline
00330 G4double G4VTwistedFaceted::GetValueA(G4double phi) const
00331 {
00332   return ( fDx4 + fDx2  + ( fDx4 - fDx2 ) * ( 2 * phi ) / fPhiTwist  ) ;
00333 }
00334 
00335 inline
00336 G4double G4VTwistedFaceted::GetValueD(G4double phi) const
00337 {
00338   return ( fDx3 + fDx1  + ( fDx3 - fDx1 ) * ( 2 * phi ) / fPhiTwist  ) ;
00339 } 
00340 
00341 inline 
00342 G4double G4VTwistedFaceted::GetValueB(G4double phi) const
00343 {
00344   return ( fDy2 + fDy1  + ( fDy2 - fDy1 ) * ( 2 * phi ) / fPhiTwist ) ;
00345 }
00346 
00347 inline
00348 G4double G4VTwistedFaceted::Xcoef(G4double u, G4double phi, G4double ftg) const 
00349 {
00350   return GetValueA(phi)/2. + (GetValueD(phi)-GetValueA(phi))/4. 
00351     - u*( ( GetValueD(phi)-GetValueA(phi) ) / ( 2 * GetValueB(phi) ) - ftg );
00352 }
00353 
00354 #endif

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