Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:58

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 //
0027 #ifndef MOLECULAR_OCTREE_NODE_HH
0028 #define MOLECULAR_OCTREE_NODE_HH
0029 
0030 #include "G4ThreeVector.hh"
0031 #include "globals.hh"
0032 
0033 #include <array>
0034 #include <vector>
0035 
0036 class G4VPhysicalVolume;
0037 
0038 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0039 
0040 class OctreeNode
0041 {
0042   public:
0043     // Uniform divisions constructor along each axis
0044     OctreeNode(const G4ThreeVector&, const G4ThreeVector&, G4int, OctreeNode* parent = nullptr);
0045 
0046     ~OctreeNode();
0047 
0048     inline G4bool HasChildren() const { return (fChildren[0] != nullptr); }
0049 
0050     inline OctreeNode* GetParent() const { return fParent; };
0051 
0052     inline const auto& GetHalfLengths() const { return fHalfLengths; };
0053 
0054     inline G4double GetHalfLengthsMag() const { return fHalfLengthsMag; };
0055 
0056     inline const G4ThreeVector& GetPosition() const { return fPosition; };
0057 
0058     inline const auto& GetChildren() const { return fChildren; };
0059 
0060     const std::vector<G4VPhysicalVolume*> SearchOctree(const G4ThreeVector&,
0061                                                        G4double _rad = 0) const;
0062 
0063     void SearchOctree(const G4ThreeVector& pos, std::vector<G4VPhysicalVolume*>& out,
0064                       G4double _rad = 0) const;
0065 
0066     const std::vector<G4VPhysicalVolume*> SearchOctree(const G4ThreeVector&) const;
0067 
0068     G4int GetNumberOfTerminalNodes();
0069 
0070     void AddPhysicalVolume(G4VPhysicalVolume*);
0071 
0072     std::vector<G4VPhysicalVolume*> GetContents() const;
0073 
0074     inline G4int GetMaxContents() const { return fMaxContents; };
0075 
0076   protected:
0077     void Split();
0078 
0079     const OctreeNode* GetChildFromPosition(G4ThreeVector const&) const;
0080 
0081     OctreeNode* GetChildFromPosition(G4ThreeVector const& pos);
0082 
0083   private:
0084     G4ThreeVector fPosition, fHalfLengths;
0085     G4int fMaxContents;
0086 
0087     std::vector<G4VPhysicalVolume*> fContents;
0088 
0089     OctreeNode* fParent;
0090     // fChildren is arranged logically to save on queries
0091     // The scheme is defined by quadrant as follows:
0092     // X Y Z Index | X Y Z Index
0093     // + + +   0   | - + +   4
0094     // + + -   1   | - + -   5
0095     // + - +   2   | - - +   6
0096     // + - -   3   | - - -   7
0097     std::array<OctreeNode*, 8> fChildren;
0098     G4double fHalfLengthsMag;
0099 };
0100 
0101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0102 
0103 #endif  // MOLECULAR_OCTREE_NODE_HH