Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 // 28 // 29 // John Allison May 2021 30 // 31 // G4Mesh captures and validates a parameteris 32 // call a "mesh". This is typically intended f 33 // a large number of parameterisations, such a 34 // 35 // G4Mesh is used by G4PhysicalVolumeModel if 36 // G4ModelingParameters::fSpecialMeshRendering 37 // name matches one in G4ModelingParameters::f 38 // if any. Then, if a valid mesh is found it c 39 // implementation of G4VGraphicsScene::AddComp 40 // 41 // To set the above parameters use the followi 42 // standard Geant4 Visualisation System: 43 // /vis/viewer/set/specialMeshRendering 44 // /vis/viewer/set/specialMeshRenderingOpti 45 // /vis/viewer/set/specialMeshVolumes 46 // See guidance on the above commmands for mor 47 // 48 // Note that if no special mesh volumes are sp 49 // G4PhysicalVolumeModel will test all volumes 50 // it will capture *all* parameterisations. Th 51 // a problem, since there is usually only one, 52 // selective you have to /vis/viewer/set/speci 53 // 54 // The specified G4VPhysicalVolume is searched 55 // parameterisation. If none is found it will 56 // and it should simply be destroyed (as in G4 57 // The overhead of an invalid attempt is small 58 59 #include "G4Mesh.hh" 60 61 #include "G4VPhysicalVolume.hh" 62 #include "G4LogicalVolume.hh" 63 #include "G4PVParameterised.hh" 64 #include "G4VNestedParameterisation.hh" 65 #include "G4Box.hh" 66 #include "G4Tubs.hh" 67 #include "G4Sphere.hh" 68 #include "G4Tet.hh" 69 70 std::map<G4int,G4String> G4Mesh::fEnumMap = { 71 {invalid,"invalid"}, 72 {rectangle,"rectangle"}, 73 {nested3DRectangular,"nested3Drectangular"}, 74 {cylinder,"cylinder"}, 75 {sphere,"sphere"}, 76 {tetrahedron,"tetrahedron"} 77 }; 78 79 G4Mesh::G4Mesh (G4VPhysicalVolume* containerVo 80 : fpContainerVolume(containerVolume) 81 , fpParameterisedVolume(nullptr) 82 , fMeshType(invalid) 83 , fMeshDepth(0) 84 , fTransform(transform) 85 { 86 if (fpContainerVolume == nullptr) return; 87 88 G4VPhysicalVolume* pv0 = fpContainerVolume; 89 G4VPhysicalVolume* pv1 = nullptr; 90 G4VPhysicalVolume* pv2 = nullptr; 91 G4VPhysicalVolume* pv3 = nullptr; 92 G4LogicalVolume* lv0 = pv0->GetLogicalVolu 93 G4LogicalVolume* lv1 = nullptr; 94 G4LogicalVolume* lv2 = nullptr; 95 96 // Check if this is a container for a parame 97 // A simple parameterisation may only be one 98 // Nested parameterisations may be 2- or 3-l 99 G4bool isContainer = false; 100 if (lv0->GetNoDaughters()) { 101 fMeshDepth++; 102 pv1 = lv0->GetDaughter(0); 103 lv1 = pv1->GetLogicalVolume(); 104 if (dynamic_cast<G4PVParameterised*>(pv1)) 105 isContainer = true; 106 fpParameterisedVolume = pv1; 107 } else if (lv1->GetNoDaughters()) { 108 fMeshDepth++; 109 pv2 = lv1->GetDaughter(0); 110 lv2 = pv2->GetLogicalVolume(); 111 if (dynamic_cast<G4PVParameterised*>(pv2 112 dynamic_cast<G4VNestedParameterisati 113 isContainer = true; 114 fpParameterisedVolume = pv2; 115 } else if (lv2->GetNoDaughters()) { 116 fMeshDepth++; 117 pv3 = lv2->GetDaughter(0); 118 if (dynamic_cast<G4PVParameterised*>(p 119 dynamic_cast<G4VNestedParameterisa 120 isContainer = true; 121 fpParameterisedVolume = pv3; 122 } 123 } 124 } 125 } 126 127 if (isContainer) { 128 129 // Get type 130 G4VSolid* pEndSol = fpParameterisedVolume- 131 if (dynamic_cast<G4Box*>(pEndSol)) { 132 fMeshType = rectangle; 133 auto pBox = static_cast<G4Box*>(pEndSol) 134 f3DRPs.fHalfX = pBox->GetXHalfLength(); 135 f3DRPs.fHalfY = pBox->GetYHalfLength(); 136 f3DRPs.fHalfZ = pBox->GetZHalfLength(); 137 } else if (dynamic_cast<G4Tet*>(pEndSol)) 138 fMeshType = tetrahedron; 139 } else if (dynamic_cast<G4Tubs*>(pEndSol)) 140 fMeshType = cylinder; 141 } else if (dynamic_cast<G4Sphere*>(pEndSol 142 fMeshType = sphere; 143 } 144 145 // Special case for rectangular nested par 146 if (fMeshDepth == 3 && fMeshType == rectan 147 auto nestedParam3 = dynamic_cast<G4VNest 148 if (nestedParam3) { 149 fMeshType = nested3DRectangular; 150 pv1->GetReplicationData 151 (f3DRPs.fAxis1,f3DRPs.fNreplica1,f3DRP 152 pv2->GetReplicationData 153 (f3DRPs.fAxis2,f3DRPs.fNreplica2,f3DRP 154 pv3->GetReplicationData 155 (f3DRPs.fAxis3,f3DRPs.fNreplica3,f3DRP 156 } 157 } 158 } 159 } 160 161 G4Mesh::~G4Mesh () {} 162 163 std::ostream& operator << (std::ostream& os, c 164 os << "G4Mesh: "; 165 os << "\nContainer: " << mesh.GetContainerVo 166 const auto& map = mesh.GetEnumMap(); 167 const auto& typeEntry = map.find(mesh.GetMes 168 G4String type; 169 if (typeEntry != map.end()) { 170 type = typeEntry->second; 171 } else { 172 type = "unrecognised"; 173 } 174 os << "\nType: " << type; 175 os << "\nDepth: " << mesh.GetMeshDepth(); 176 os << "\nTranslation: " << mesh.GetTransform 177 os << "\nRotation: " << mesh.GetTransform(). 178 if (mesh.GetMeshType() == G4Mesh::rectangle 179 mesh.GetMeshDepth() == 3) { 180 // Print ThreeDRectangleParameters 181 } 182 return os; 183 } 184