Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:14

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 and of QinetiQ Ltd,   *
0020 // * subject to DEFCON 705 IPR conditions.                            *
0021 // * By using,  copying,  modifying or  distributing the software (or *
0022 // * any work based  on the software)  you  agree  to acknowledge its *
0023 // * use  in  resulting  scientific  publications,  and indicate your *
0024 // * acceptance of all terms of the Geant4 Software license.          *
0025 // ********************************************************************
0026 //
0027 // G4TriangularFacet
0028 //
0029 // Class description:
0030 //
0031 //   The G4TriangularFacet class is used for the contruction of
0032 //   G4TessellatedSolid.
0033 //   It is defined by three fVertices, which shall be supplied in anti-clockwise
0034 //   order looking from the outsider of the solid where it belongs.
0035 //   Its constructor:
0036 //   
0037 //      G4TriangularFacet (const G4ThreeVector Pt0, const G4ThreeVector vt1,
0038 //                         const G4ThreeVector vt2, G4FacetVertexType);
0039 //
0040 //   takes 4 parameters to define the three fVertices:
0041 //      1) G4FacetvertexType = "ABSOLUTE": in this case Pt0, vt1 and vt2 are 
0042 //         the 3 fVertices in anti-clockwise order looking from the outsider.
0043 //      2) G4FacetvertexType = "RELATIVE": in this case the first vertex is Pt0,
0044 //         the second vertex is Pt0+vt1 and the third vertex is Pt0+vt2, all  
0045 //         in anti-clockwise order when looking from the outsider.
0046 
0047 // 31 October 2004, P R Truscott, QinetiQ Ltd, UK - Created.
0048 // 12 October 2012, M Gayer, CERN, - Reviewed optimized implementation.
0049 // --------------------------------------------------------------------
0050 #ifndef G4TRIANGULARFACET_HH
0051 #define G4TRIANGULARFACET_HH 1
0052 
0053 #include "G4VFacet.hh"
0054 #include "G4Types.hh"
0055 #include "G4ThreeVector.hh"
0056 
0057 #include <vector>
0058 #include <array>
0059 
0060 class G4TriangularFacet : public G4VFacet
0061 {
0062   public:
0063 
0064     G4TriangularFacet ();
0065    ~G4TriangularFacet () override;
0066 
0067     G4TriangularFacet (const G4ThreeVector& vt0, const G4ThreeVector& vt1,
0068                        const G4ThreeVector& vt2, G4FacetVertexType);
0069     G4TriangularFacet (const G4TriangularFacet& right);
0070     G4TriangularFacet (      G4TriangularFacet&& right) noexcept ;
0071 
0072     G4TriangularFacet& operator=(const G4TriangularFacet& right);    
0073     G4TriangularFacet& operator=(      G4TriangularFacet&& right) noexcept ;    
0074 
0075     G4VFacet* GetClone () override;
0076     G4TriangularFacet* GetFlippedFacet ();
0077 
0078     G4ThreeVector Distance (const G4ThreeVector& p);
0079     G4double Distance (const G4ThreeVector& p, G4double minDist) override;
0080     G4double Distance (const G4ThreeVector& p, G4double minDist,
0081                        const G4bool outgoing) override;
0082     G4double Extent   (const G4ThreeVector axis) override;
0083     G4bool Intersect  (const G4ThreeVector& p, const G4ThreeVector& v,
0084                        const G4bool outgoing, G4double& distance,
0085                              G4double& distFromSurface,
0086                              G4ThreeVector& normal) override;
0087     G4double GetArea () const override;
0088     G4ThreeVector GetPointOnFace () const override;
0089 
0090     G4ThreeVector GetSurfaceNormal () const override;
0091     void SetSurfaceNormal (const G4ThreeVector& normal);
0092 
0093     G4GeometryType GetEntityType () const override;
0094 
0095     inline G4bool IsDefined () const override;
0096     inline G4int GetNumberOfVertices () const override;
0097     inline G4ThreeVector GetVertex (G4int i) const override;
0098     inline void SetVertex (G4int i, const G4ThreeVector& val) override;
0099 
0100     inline G4ThreeVector GetCircumcentre () const override;
0101     inline G4double GetRadius () const override;
0102 
0103     inline G4int AllocatedMemory() override;
0104 
0105     inline G4int GetVertexIndex (G4int i) const override;
0106     inline void SetVertexIndex (G4int i, G4int j) override;
0107     inline void SetVertices(std::vector<G4ThreeVector>* v) override;
0108 
0109   private:
0110 
0111     void CopyFrom(const G4TriangularFacet& rhs);
0112     void MoveFrom(G4TriangularFacet& rhs);
0113 
0114     G4ThreeVector fSurfaceNormal;
0115     G4double fArea = 0.0;
0116     G4ThreeVector fCircumcentre;
0117     G4double fRadius = 0.0;
0118     std::array<G4int, 3> fIndices;
0119     std::vector<G4ThreeVector>* fVertices = nullptr;
0120 
0121     G4double fA, fB, fC;
0122     G4double fDet;
0123     G4double fSqrDist = 0.0;
0124     G4ThreeVector fE1, fE2;
0125     G4bool fIsDefined = false;
0126 };
0127 
0128 // --------------------------------------------------------------------
0129 // Inlined Methods
0130 // --------------------------------------------------------------------
0131 
0132 inline G4bool G4TriangularFacet::IsDefined () const
0133 {
0134   return fIsDefined;
0135 }
0136 
0137 inline G4int G4TriangularFacet::GetNumberOfVertices () const
0138 {
0139   return 3;
0140 }
0141 
0142 inline G4ThreeVector G4TriangularFacet::GetVertex (G4int i) const
0143 {      
0144   G4int indice = fIndices[i];
0145   return indice < 0 ? (*fVertices)[i] : (*fVertices)[indice];
0146 }
0147 
0148 inline void G4TriangularFacet::SetVertex (G4int i, const G4ThreeVector& val)
0149 {
0150   (*fVertices)[i] = val;
0151 }
0152 
0153 inline G4ThreeVector G4TriangularFacet::GetCircumcentre () const
0154 {
0155   return fCircumcentre;
0156 }
0157 
0158 inline G4double G4TriangularFacet::GetRadius () const
0159 {
0160   return fRadius;
0161 }
0162 
0163 inline G4int G4TriangularFacet::AllocatedMemory()
0164 {
0165   G4int size = sizeof(*this);
0166   size += GetNumberOfVertices() * sizeof(G4ThreeVector);
0167   return size;
0168 }
0169 
0170 inline G4int G4TriangularFacet::GetVertexIndex (G4int i) const
0171 {
0172   if (i < 3) return fIndices[i];
0173   else       return 999999999;
0174 }
0175 
0176 inline void G4TriangularFacet::SetVertexIndex (G4int i, G4int j)
0177 {
0178   fIndices[i] = j;
0179 }
0180 
0181 inline void G4TriangularFacet::SetVertices(std::vector<G4ThreeVector>* v)
0182 {
0183   if (fIndices[0] < 0 && (fVertices != nullptr))
0184   {
0185     delete fVertices;
0186     fVertices = nullptr;
0187   }
0188   fVertices = v;
0189 }
0190 
0191 #endif