Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // 27 // 28 // 28 // 29 // John Allison 31st December 1997. 29 // John Allison 31st December 1997. 30 // Model for physical volumes. 30 // Model for physical volumes. 31 31 32 #include "G4PhysicalVolumeModel.hh" 32 #include "G4PhysicalVolumeModel.hh" 33 33 34 #include "G4VGraphicsScene.hh" 34 #include "G4VGraphicsScene.hh" 35 #include "G4VPhysicalVolume.hh" 35 #include "G4VPhysicalVolume.hh" 36 #include "G4PhysicalVolumeStore.hh" 36 #include "G4PhysicalVolumeStore.hh" 37 #include "G4VPVParameterisation.hh" 37 #include "G4VPVParameterisation.hh" 38 #include "G4LogicalVolume.hh" 38 #include "G4LogicalVolume.hh" 39 #include "G4VSolid.hh" 39 #include "G4VSolid.hh" 40 #include "G4SubtractionSolid.hh" 40 #include "G4SubtractionSolid.hh" 41 #include "G4IntersectionSolid.hh" 41 #include "G4IntersectionSolid.hh" 42 #include "G4Material.hh" 42 #include "G4Material.hh" 43 #include "G4VisAttributes.hh" 43 #include "G4VisAttributes.hh" 44 #include "G4BoundingExtentScene.hh" 44 #include "G4BoundingExtentScene.hh" >> 45 #include "G4PhysicalVolumeSearchScene.hh" 45 #include "G4TransportationManager.hh" 46 #include "G4TransportationManager.hh" 46 #include "G4Polyhedron.hh" 47 #include "G4Polyhedron.hh" 47 #include "HepPolyhedronProcessor.h" 48 #include "HepPolyhedronProcessor.h" 48 #include "G4AttDefStore.hh" 49 #include "G4AttDefStore.hh" 49 #include "G4AttDef.hh" 50 #include "G4AttDef.hh" 50 #include "G4AttValue.hh" 51 #include "G4AttValue.hh" 51 #include "G4UnitsTable.hh" 52 #include "G4UnitsTable.hh" 52 #include "G4Vector3D.hh" 53 #include "G4Vector3D.hh" 53 #include "G4Mesh.hh" 54 #include "G4Mesh.hh" 54 55 55 #include <sstream> 56 #include <sstream> 56 #include <iomanip> 57 #include <iomanip> 57 58 58 #define G4warn G4cout << 59 namespace { >> 60 G4int volumeCount = 0; >> 61 } 59 62 60 G4PhysicalVolumeModel::G4PhysicalVolumeModel 63 G4PhysicalVolumeModel::G4PhysicalVolumeModel 61 (G4VPhysicalVolume* pVPV 64 (G4VPhysicalVolume* pVPV 62 , G4int requestedDepth 65 , G4int requestedDepth 63 , const G4Transform3D& modelTransform 66 , const G4Transform3D& modelTransform 64 , const G4ModelingParameters* pMP 67 , const G4ModelingParameters* pMP 65 , G4bool useFullExtent 68 , G4bool useFullExtent 66 , const std::vector<G4PhysicalVolumeNodeID>& 69 , const std::vector<G4PhysicalVolumeNodeID>& baseFullPVPath) 67 : G4VModel (pMP) 70 : G4VModel (pMP) 68 , fpTopPV (pVPV) 71 , fpTopPV (pVPV) 69 , fTopPVCopyNo (pVPV? pVPV->GetCopyNo(): 72 , fTopPVCopyNo (pVPV? pVPV->GetCopyNo(): 0) 70 , fRequestedDepth (requestedDepth) 73 , fRequestedDepth (requestedDepth) 71 , fUseFullExtent (useFullExtent) 74 , fUseFullExtent (useFullExtent) 72 , fTransform (modelTransform) 75 , fTransform (modelTransform) 73 , fCurrentDepth (0) 76 , fCurrentDepth (0) 74 , fpCurrentPV (fpTopPV) 77 , fpCurrentPV (fpTopPV) 75 , fCurrentPVCopyNo (fpTopPV? fpTopPV->GetCop 78 , fCurrentPVCopyNo (fpTopPV? fpTopPV->GetCopyNo(): 0) 76 , fpCurrentLV (fpTopPV? fpTopPV->GetLog 79 , fpCurrentLV (fpTopPV? fpTopPV->GetLogicalVolume(): 0) 77 , fpCurrentMaterial (fpCurrentLV? fpCurrentLV 80 , fpCurrentMaterial (fpCurrentLV? fpCurrentLV->GetMaterial(): 0) 78 , fCurrentTransform (modelTransform) 81 , fCurrentTransform (modelTransform) 79 , fBaseFullPVPath (baseFullPVPath) 82 , fBaseFullPVPath (baseFullPVPath) 80 , fFullPVPath (fBaseFullPVPath) << 81 , fAbort (false) 83 , fAbort (false) 82 , fCurtailDescent (false) 84 , fCurtailDescent (false) 83 , fpClippingSolid (0) 85 , fpClippingSolid (0) 84 , fClippingMode (subtraction) 86 , fClippingMode (subtraction) 85 , fNClippers (0) << 86 , fTotalTouchables (0) << 87 { 87 { 88 fType = "G4PhysicalVolumeModel"; 88 fType = "G4PhysicalVolumeModel"; 89 89 90 if (!fpTopPV) { 90 if (!fpTopPV) { 91 91 92 // In some circumstances creating an "empt 92 // In some circumstances creating an "empty" G4PhysicalVolumeModel is 93 // allowed, so I have supressed the G4Exce 93 // allowed, so I have supressed the G4Exception below. If it proves to 94 // be a problem we might have to re-instat 94 // be a problem we might have to re-instate it, but it is unlikley to 95 // be used except by visualisation experts 95 // be used except by visualisation experts. See, for example, /vis/list, 96 // where it is used simply to get a list o 96 // where it is used simply to get a list of G4AttDefs. 97 // G4Exception 97 // G4Exception 98 // ("G4PhysicalVolumeModel::G4PhysicalV 98 // ("G4PhysicalVolumeModel::G4PhysicalVolumeModel", 99 // "modeling0010", FatalException, "Nu 99 // "modeling0010", FatalException, "Null G4PhysicalVolumeModel pointer."); 100 100 101 fTopPVName = "NULL"; 101 fTopPVName = "NULL"; 102 fGlobalTag = "Empty"; 102 fGlobalTag = "Empty"; 103 fGlobalDescription = "G4PhysicalVolumeMode 103 fGlobalDescription = "G4PhysicalVolumeModel " + fGlobalTag; 104 104 105 } else { 105 } else { 106 106 107 fTopPVName = fpTopPV -> GetName (); 107 fTopPVName = fpTopPV -> GetName (); 108 std::ostringstream oss; 108 std::ostringstream oss; 109 oss << fpTopPV->GetName() << ':' << fpTopP 109 oss << fpTopPV->GetName() << ':' << fpTopPV->GetCopyNo() 110 << " BasePath:" << fBaseFullPVPath; 110 << " BasePath:" << fBaseFullPVPath; 111 fGlobalTag = oss.str(); 111 fGlobalTag = oss.str(); 112 fGlobalDescription = "G4PhysicalVolumeMode 112 fGlobalDescription = "G4PhysicalVolumeModel " + fGlobalTag; 113 CalculateExtent (); 113 CalculateExtent (); 114 } 114 } 115 } 115 } 116 116 117 G4PhysicalVolumeModel::~G4PhysicalVolumeModel 117 G4PhysicalVolumeModel::~G4PhysicalVolumeModel () 118 { 118 { 119 delete fpClippingSolid; 119 delete fpClippingSolid; 120 } 120 } 121 121 122 G4ModelingParameters::PVNameCopyNoPath G4Physi 122 G4ModelingParameters::PVNameCopyNoPath G4PhysicalVolumeModel::GetPVNameCopyNoPath 123 (const std::vector<G4PhysicalVolumeNodeID>& pa 123 (const std::vector<G4PhysicalVolumeNodeID>& path) 124 { 124 { 125 G4ModelingParameters::PVNameCopyNoPath PVNam 125 G4ModelingParameters::PVNameCopyNoPath PVNameCopyNoPath; 126 for (const auto& node: path) { 126 for (const auto& node: path) { 127 PVNameCopyNoPath.push_back 127 PVNameCopyNoPath.push_back 128 (G4ModelingParameters::PVNameCopyNo 128 (G4ModelingParameters::PVNameCopyNo 129 (node.GetPhysicalVolume()->GetName(),node 129 (node.GetPhysicalVolume()->GetName(),node.GetCopyNo())); 130 } 130 } 131 return PVNameCopyNoPath; 131 return PVNameCopyNoPath; 132 } 132 } 133 133 134 G4String G4PhysicalVolumeModel::GetPVNamePathS << 135 (const std::vector<G4PhysicalVolumeNodeID>& pa << 136 // Converts to path string, e.g., " World 0 En << 137 // Note leading space character. << 138 { << 139 std::ostringstream oss; << 140 oss << path; << 141 return oss.str(); << 142 } << 143 << 144 void G4PhysicalVolumeModel::CalculateExtent () 134 void G4PhysicalVolumeModel::CalculateExtent () 145 { 135 { 146 // To handle paramaterisations, set copy num 136 // To handle paramaterisations, set copy number and compute dimensions 147 // to get extent right 137 // to get extent right 148 G4VPVParameterisation* pP = fpTopPV -> GetPa 138 G4VPVParameterisation* pP = fpTopPV -> GetParameterisation (); 149 if (pP) { 139 if (pP) { 150 fpTopPV -> SetCopyNo (fTopPVCopyNo); 140 fpTopPV -> SetCopyNo (fTopPVCopyNo); 151 G4VSolid* solid = pP -> ComputeSolid (fTop 141 G4VSolid* solid = pP -> ComputeSolid (fTopPVCopyNo, fpTopPV); 152 solid -> ComputeDimensions (pP, fTopPVCopy 142 solid -> ComputeDimensions (pP, fTopPVCopyNo, fpTopPV); 153 } 143 } 154 if (fUseFullExtent) { 144 if (fUseFullExtent) { 155 fExtent = fpTopPV -> GetLogicalVolume () - 145 fExtent = fpTopPV -> GetLogicalVolume () -> GetSolid () -> GetExtent (); 156 } else { 146 } else { 157 // Calculate extent of *drawn* volumes, i. 147 // Calculate extent of *drawn* volumes, i.e., ignoring culled, e.g., 158 // invisible volumes, by traversing the wh 148 // invisible volumes, by traversing the whole geometry hierarchy below 159 // this physical volume. 149 // this physical volume. 160 G4BoundingExtentScene beScene(this); 150 G4BoundingExtentScene beScene(this); 161 const G4int tempRequestedDepth = fRequeste 151 const G4int tempRequestedDepth = fRequestedDepth; 162 const G4Transform3D tempTransform = fTrans 152 const G4Transform3D tempTransform = fTransform; 163 const G4ModelingParameters* tempMP = fpMP; 153 const G4ModelingParameters* tempMP = fpMP; 164 fRequestedDepth = -1; // Always search to 154 fRequestedDepth = -1; // Always search to all depths to define extent. 165 fTransform = G4Transform3D(); // Extent i 155 fTransform = G4Transform3D(); // Extent is in local cooridinates 166 G4ModelingParameters mParams 156 G4ModelingParameters mParams 167 (0, // No default vis attributes ne 157 (0, // No default vis attributes needed. 168 G4ModelingParameters::wf, // wireframe 158 G4ModelingParameters::wf, // wireframe (not relevant for this). 169 true, // Global culling. 159 true, // Global culling. 170 true, // Cull invisible volumes. 160 true, // Cull invisible volumes. 171 false, // Density culling. 161 false, // Density culling. 172 0., // Density (not relevant if den 162 0., // Density (not relevant if density culling false). 173 true, // Cull daughters of opaque mot 163 true, // Cull daughters of opaque mothers. 174 24); // No of sides (not relevant fo 164 24); // No of sides (not relevant for this operation). 175 mParams.SetSpecialMeshRendering(true); // << 176 fpMP = &mParams; 165 fpMP = &mParams; 177 DescribeYourselfTo (beScene); 166 DescribeYourselfTo (beScene); 178 fExtent = beScene.GetBoundingExtent(); 167 fExtent = beScene.GetBoundingExtent(); 179 fpMP = tempMP; 168 fpMP = tempMP; 180 fTransform = tempTransform; 169 fTransform = tempTransform; 181 fRequestedDepth = tempRequestedDepth; 170 fRequestedDepth = tempRequestedDepth; 182 } 171 } 183 G4double radius = fExtent.GetExtentRadius(); 172 G4double radius = fExtent.GetExtentRadius(); 184 if (radius < 0.) { // Nothing in the scene 173 if (radius < 0.) { // Nothing in the scene - revert to top extent 185 fExtent = fpTopPV -> GetLogicalVolume () - 174 fExtent = fpTopPV -> GetLogicalVolume () -> GetSolid () -> GetExtent (); 186 } 175 } 187 fExtent.Transform(fTransform); 176 fExtent.Transform(fTransform); 188 } 177 } 189 178 190 void G4PhysicalVolumeModel::DescribeYourselfTo 179 void G4PhysicalVolumeModel::DescribeYourselfTo 191 (G4VGraphicsScene& sceneHandler) 180 (G4VGraphicsScene& sceneHandler) 192 { 181 { 193 if (!fpTopPV) { << 182 if (!fpTopPV) G4Exception 194 G4Exception << 195 ("G4PhysicalVolumeModel::DescribeYourselfT 183 ("G4PhysicalVolumeModel::DescribeYourselfTo", 196 "modeling0012", FatalException, "No model 184 "modeling0012", FatalException, "No model."); 197 return; // Should never reach here, but k << 198 } << 199 185 200 if (!fpMP) { << 186 if (!fpMP) G4Exception 201 G4Exception << 202 ("G4PhysicalVolumeModel::DescribeYourselfT 187 ("G4PhysicalVolumeModel::DescribeYourselfTo", 203 "modeling0013", FatalException, "No model << 188 "modeling0003", FatalException, "No modeling parameters."); 204 return; // Should never reach here, but k << 205 } << 206 << 207 fNClippers = 0; << 208 G4DisplacedSolid* pSectionSolid = fpMP->GetS << 209 G4DisplacedSolid* pCutawaySolid = fpMP->GetC << 210 if (fpClippingSolid) fNClippers++; << 211 if (pSectionSolid) fNClippers++; << 212 if (pCutawaySolid) fNClippers++; << 213 if (fNClippers > 1) { << 214 G4ExceptionDescription ed; << 215 ed << "More than one solid cutter/clipper: << 216 if (fpClippingSolid) ed << "\nclipper in f << 217 if (pSectionSolid) ed << "\nsectioner in << 218 if (pCutawaySolid) ed << "\ncutaway in f << 219 G4Exception("G4PhysicalVolumeModel::Descri << 220 } << 221 189 222 G4Transform3D startingTransformation = fTran 190 G4Transform3D startingTransformation = fTransform; 223 191 224 fNTouchables.clear(); // Keeps count of tou << 192 volumeCount = 0; 225 193 226 VisitGeometryAndGetVisReps 194 VisitGeometryAndGetVisReps 227 (fpTopPV, 195 (fpTopPV, 228 fRequestedDepth, 196 fRequestedDepth, 229 startingTransformation, 197 startingTransformation, 230 sceneHandler); 198 sceneHandler); 231 199 232 fTotalTouchables = 0; << 200 // G4cout 233 for (const auto& entry : fNTouchables) { << 201 // << "G4PhysicalVolumeModel::DescribeYourselfTo: volume count: " 234 fTotalTouchables += entry.second; << 202 // << volumeCount 235 } << 203 // << G4endl; 236 204 237 // Reset or clear data... 205 // Reset or clear data... 238 fCurrentDepth = 0; 206 fCurrentDepth = 0; 239 fpCurrentPV = fpTopPV; 207 fpCurrentPV = fpTopPV; 240 fCurrentPVCopyNo = fpTopPV->GetCopyNo(); 208 fCurrentPVCopyNo = fpTopPV->GetCopyNo(); 241 fpCurrentLV = fpTopPV->GetLogicalVolum 209 fpCurrentLV = fpTopPV->GetLogicalVolume(); 242 fpCurrentMaterial = fpCurrentLV? fpCurrentLV 210 fpCurrentMaterial = fpCurrentLV? fpCurrentLV->GetMaterial(): 0; 243 fFullPVPath = fBaseFullPVPath; 211 fFullPVPath = fBaseFullPVPath; 244 fDrawnPVPath.clear(); 212 fDrawnPVPath.clear(); 245 fAbort = false; 213 fAbort = false; 246 fCurtailDescent = false; 214 fCurtailDescent = false; 247 } 215 } 248 216 249 G4String G4PhysicalVolumeModel::GetCurrentTag 217 G4String G4PhysicalVolumeModel::GetCurrentTag () const 250 { 218 { 251 if (fpCurrentPV) { 219 if (fpCurrentPV) { 252 std::ostringstream o; 220 std::ostringstream o; 253 o << fpCurrentPV -> GetCopyNo (); 221 o << fpCurrentPV -> GetCopyNo (); 254 return fpCurrentPV -> GetName () + ":" + o 222 return fpCurrentPV -> GetName () + ":" + o.str(); 255 } 223 } 256 else { 224 else { 257 return "WARNING: NO CURRENT VOLUME - globa 225 return "WARNING: NO CURRENT VOLUME - global tag is " + fGlobalTag; 258 } 226 } 259 } 227 } 260 228 261 G4String G4PhysicalVolumeModel::GetCurrentDesc 229 G4String G4PhysicalVolumeModel::GetCurrentDescription () const 262 { 230 { 263 return "G4PhysicalVolumeModel " + GetCurrent 231 return "G4PhysicalVolumeModel " + GetCurrentTag (); 264 } 232 } 265 233 266 void G4PhysicalVolumeModel::VisitGeometryAndGe 234 void G4PhysicalVolumeModel::VisitGeometryAndGetVisReps 267 (G4VPhysicalVolume* pVPV, 235 (G4VPhysicalVolume* pVPV, 268 G4int requestedDepth, 236 G4int requestedDepth, 269 const G4Transform3D& theAT, 237 const G4Transform3D& theAT, 270 G4VGraphicsScene& sceneHandler) 238 G4VGraphicsScene& sceneHandler) 271 { 239 { 272 // Visits geometry structure to a given dept 240 // Visits geometry structure to a given depth (requestedDepth), starting 273 // at given physical volume with given sta 241 // at given physical volume with given starting transformation and 274 // describes volumes to the scene handler. 242 // describes volumes to the scene handler. 275 // requestedDepth < 0 (default) implies full 243 // requestedDepth < 0 (default) implies full visit. 276 // theAT is the Accumulated Transformation. 244 // theAT is the Accumulated Transformation. 277 245 278 // Find corresponding logical volume and (la 246 // Find corresponding logical volume and (later) solid, storing in 279 // local variables to preserve re-entrancy. 247 // local variables to preserve re-entrancy. 280 G4LogicalVolume* pLV = pVPV -> GetLogicalVo 248 G4LogicalVolume* pLV = pVPV -> GetLogicalVolume (); 281 G4VSolid* pSol = nullptr; 249 G4VSolid* pSol = nullptr; 282 G4Material* pMaterial = nullptr; 250 G4Material* pMaterial = nullptr; 283 251 284 if (!(pVPV -> IsReplicated ())) { 252 if (!(pVPV -> IsReplicated ())) { 285 // Non-replicated physical volume. 253 // Non-replicated physical volume. 286 pSol = pLV -> GetSolid (); 254 pSol = pLV -> GetSolid (); 287 pMaterial = pLV -> GetMaterial (); 255 pMaterial = pLV -> GetMaterial (); 288 DescribeAndDescend (pVPV, requestedDepth, 256 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial, 289 theAT, sceneHandler); 257 theAT, sceneHandler); 290 } 258 } 291 else { 259 else { 292 // Replicated or parametrised physical vol 260 // Replicated or parametrised physical volume. 293 EAxis axis; 261 EAxis axis; 294 G4int nReplicas; 262 G4int nReplicas; 295 G4double width; 263 G4double width; 296 G4double offset; 264 G4double offset; 297 G4bool consuming; 265 G4bool consuming; 298 pVPV -> GetReplicationData (axis, nReplica 266 pVPV -> GetReplicationData (axis, nReplicas, width, offset, consuming); 299 G4int nBegin = 0; 267 G4int nBegin = 0; 300 G4int nEnd = nReplicas; 268 G4int nEnd = nReplicas; 301 if (fCurrentDepth == 0) { // i.e., top vol 269 if (fCurrentDepth == 0) { // i.e., top volume 302 nBegin = fTopPVCopyNo; // Describe only 270 nBegin = fTopPVCopyNo; // Describe only one volume, namely the one 303 nEnd = nBegin + 1; // specified by 271 nEnd = nBegin + 1; // specified by the given copy number. 304 } 272 } 305 G4VPVParameterisation* pP = pVPV -> GetPar 273 G4VPVParameterisation* pP = pVPV -> GetParameterisation (); 306 if (pP) { // Parametrised volume. 274 if (pP) { // Parametrised volume. 307 for (int n = nBegin; n < nEnd; n++) { 275 for (int n = nBegin; n < nEnd; n++) { 308 pSol = pP -> ComputeSolid (n, pVPV); << 276 pSol = pP -> ComputeSolid (n, pVPV); 309 pP -> ComputeTransformation (n, pVPV); << 277 pP -> ComputeTransformation (n, pVPV); 310 pSol -> ComputeDimensions (pP, n, pVPV << 278 pSol -> ComputeDimensions (pP, n, pVPV); 311 pVPV -> SetCopyNo (n); << 279 pVPV -> SetCopyNo (n); 312 fCurrentPVCopyNo = n; 280 fCurrentPVCopyNo = n; 313 // Create a touchable of current paren << 281 // Create a touchable of current parent for ComputeMaterial. 314 // fFullPVPath has not been updated ye << 282 // fFullPVPath has not been updated yet so at this point it 315 // corresponds to the parent. << 283 // corresponds to the parent. 316 G4PhysicalVolumeModelTouchable parentT << 284 G4PhysicalVolumeModelTouchable parentTouchable(fFullPVPath); 317 pMaterial = pP -> ComputeMaterial (n, << 285 pMaterial = pP -> ComputeMaterial (n, pVPV, &parentTouchable); 318 DescribeAndDescend (pVPV, requestedDep << 286 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial, 319 theAT, sceneHandle << 287 theAT, sceneHandler); 320 } 288 } 321 } 289 } 322 else { // Plain replicated volume. From 290 else { // Plain replicated volume. From geometry_guide.txt... 323 // The replica's positions are claculate 291 // The replica's positions are claculated by means of a linear formula. 324 // Replication may occur along: 292 // Replication may occur along: 325 // 293 // 326 // o Cartesian axes (kXAxis,kYAxis,kZAxi 294 // o Cartesian axes (kXAxis,kYAxis,kZAxis) 327 // 295 // 328 // The replications, of specified widt 296 // The replications, of specified width have coordinates of 329 // form (-width*(nReplicas-1)*0.5+n*wi 297 // form (-width*(nReplicas-1)*0.5+n*width,0,0) where n=0.. nReplicas-1 330 // for the case of kXAxis, and are unr 298 // for the case of kXAxis, and are unrotated. 331 // 299 // 332 // o Radial axis (cylindrical polar) (kR 300 // o Radial axis (cylindrical polar) (kRho) 333 // 301 // 334 // The replications are cons/tubs sect 302 // The replications are cons/tubs sections, centred on the origin 335 // and are unrotated. 303 // and are unrotated. 336 // They have radii of width*n+offset t 304 // They have radii of width*n+offset to width*(n+1)+offset 337 // where n=0..nRepl 305 // where n=0..nReplicas-1 338 // 306 // 339 // o Phi axis (cylindrical polar) (kPhi) 307 // o Phi axis (cylindrical polar) (kPhi) 340 // The replications are `phi sections' 308 // The replications are `phi sections' or wedges, and of cons/tubs form 341 // They have phi of offset+n*width to 309 // They have phi of offset+n*width to offset+(n+1)*width where 342 // n=0..nReplicas-1 310 // n=0..nReplicas-1 343 // 311 // 344 pSol = pLV -> GetSolid (); 312 pSol = pLV -> GetSolid (); 345 pMaterial = pLV -> GetMaterial (); 313 pMaterial = pLV -> GetMaterial (); 346 G4ThreeVector originalTranslation = pVPV 314 G4ThreeVector originalTranslation = pVPV -> GetTranslation (); 347 G4RotationMatrix* pOriginalRotation = pV 315 G4RotationMatrix* pOriginalRotation = pVPV -> GetRotation (); 348 G4double originalRMin = 0., originalRMax 316 G4double originalRMin = 0., originalRMax = 0.; 349 if (axis == kRho && pSol->GetEntityType( 317 if (axis == kRho && pSol->GetEntityType() == "G4Tubs") { 350 originalRMin = ((G4Tubs*)pSol)->GetInn << 318 originalRMin = ((G4Tubs*)pSol)->GetInnerRadius(); 351 originalRMax = ((G4Tubs*)pSol)->GetOut << 319 originalRMax = ((G4Tubs*)pSol)->GetOuterRadius(); 352 } 320 } 353 G4bool visualisable = true; 321 G4bool visualisable = true; 354 for (int n = nBegin; n < nEnd; n++) { 322 for (int n = nBegin; n < nEnd; n++) { 355 G4ThreeVector translation; // Identit << 323 G4ThreeVector translation; // Identity. 356 G4RotationMatrix rotation; // Identit << 324 G4RotationMatrix rotation; // Identity - life enough for visualizing. 357 G4RotationMatrix* pRotation = 0; << 325 G4RotationMatrix* pRotation = 0; 358 switch (axis) { << 326 switch (axis) { 359 default: << 327 default: 360 case kXAxis: << 328 case kXAxis: 361 translation = G4ThreeVector (-widt << 329 translation = G4ThreeVector (-width*(nReplicas-1)*0.5+n*width,0,0); 362 break; << 330 break; 363 case kYAxis: << 331 case kYAxis: 364 translation = G4ThreeVector (0,-wi << 332 translation = G4ThreeVector (0,-width*(nReplicas-1)*0.5+n*width,0); 365 break; << 333 break; 366 case kZAxis: << 334 case kZAxis: 367 translation = G4ThreeVector (0,0,- << 335 translation = G4ThreeVector (0,0,-width*(nReplicas-1)*0.5+n*width); 368 break; << 336 break; 369 case kRho: << 337 case kRho: 370 if (pSol->GetEntityType() == "G4Tu << 338 if (pSol->GetEntityType() == "G4Tubs") { 371 ((G4Tubs*)pSol)->SetInnerRadius( << 339 ((G4Tubs*)pSol)->SetInnerRadius(width*n+offset); 372 ((G4Tubs*)pSol)->SetOuterRadius( << 340 ((G4Tubs*)pSol)->SetOuterRadius(width*(n+1)+offset); 373 } else { << 341 } else { 374 if (fpMP->IsWarning()) << 342 if (fpMP->IsWarning()) 375 G4warn << << 343 G4cout << 376 "G4PhysicalVolumeModel::VisitG << 344 "G4PhysicalVolumeModel::VisitGeometryAndGetVisReps: WARNING:" 377 "\n built-in replicated volum << 345 "\n built-in replicated volumes replicated in radius for " 378 << pSol->GetEntityType() << << 346 << pSol->GetEntityType() << 379 "-type\n solids (your solid \ << 347 "-type\n solids (your solid \"" 380 << pSol->GetName() << << 348 << pSol->GetName() << 381 "\") are not visualisable." << 349 "\") are not visualisable." 382 << G4endl; << 350 << G4endl; 383 visualisable = false; << 351 visualisable = false; 384 } << 352 } 385 break; << 353 break; 386 case kPhi: << 354 case kPhi: 387 rotation.rotateZ (-(offset+(n+0.5) << 355 rotation.rotateZ (-(offset+(n+0.5)*width)); 388 // Minus Sign because for the phys << 356 // Minus Sign because for the physical volume we need the 389 // coordinate system rotation. << 357 // coordinate system rotation. 390 pRotation = &rotation; << 358 pRotation = &rotation; 391 break; << 359 break; 392 } << 360 } 393 pVPV -> SetTranslation (translation); << 361 pVPV -> SetTranslation (translation); 394 pVPV -> SetRotation (pRotation); << 362 pVPV -> SetRotation (pRotation); 395 pVPV -> SetCopyNo (n); << 363 pVPV -> SetCopyNo (n); 396 fCurrentPVCopyNo = n; 364 fCurrentPVCopyNo = n; 397 if (visualisable) { << 365 if (visualisable) { 398 DescribeAndDescend (pVPV, requestedD << 366 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial, 399 theAT, sceneHand << 367 theAT, sceneHandler); 400 } << 368 } 401 } 369 } 402 // Restore originals... 370 // Restore originals... 403 pVPV -> SetTranslation (originalTranslat 371 pVPV -> SetTranslation (originalTranslation); 404 pVPV -> SetRotation (pOriginalRotatio 372 pVPV -> SetRotation (pOriginalRotation); 405 if (axis == kRho && pSol->GetEntityType( 373 if (axis == kRho && pSol->GetEntityType() == "G4Tubs") { 406 ((G4Tubs*)pSol)->SetInnerRadius(origin << 374 ((G4Tubs*)pSol)->SetInnerRadius(originalRMin); 407 ((G4Tubs*)pSol)->SetOuterRadius(origin << 375 ((G4Tubs*)pSol)->SetOuterRadius(originalRMax); 408 } 376 } 409 } 377 } 410 } 378 } 411 } 379 } 412 380 413 void G4PhysicalVolumeModel::DescribeAndDescend 381 void G4PhysicalVolumeModel::DescribeAndDescend 414 (G4VPhysicalVolume* pVPV, 382 (G4VPhysicalVolume* pVPV, 415 G4int requestedDepth, 383 G4int requestedDepth, 416 G4LogicalVolume* pLV, 384 G4LogicalVolume* pLV, 417 G4VSolid* pSol, 385 G4VSolid* pSol, 418 G4Material* pMaterial, 386 G4Material* pMaterial, 419 const G4Transform3D& theAT, 387 const G4Transform3D& theAT, 420 G4VGraphicsScene& sceneHandler) 388 G4VGraphicsScene& sceneHandler) 421 { 389 { 422 // Maintain useful data members... 390 // Maintain useful data members... 423 fpCurrentPV = pVPV; 391 fpCurrentPV = pVPV; 424 fCurrentPVCopyNo = pVPV->GetCopyNo(); 392 fCurrentPVCopyNo = pVPV->GetCopyNo(); 425 fpCurrentLV = pLV; 393 fpCurrentLV = pLV; 426 fpCurrentMaterial = pMaterial; 394 fpCurrentMaterial = pMaterial; 427 395 428 // Create a nodeID for use below - note the 396 // Create a nodeID for use below - note the "drawn" flag is true 429 G4int copyNo = fpCurrentPV->GetCopyNo(); 397 G4int copyNo = fpCurrentPV->GetCopyNo(); 430 auto nodeID = G4PhysicalVolumeNodeID 398 auto nodeID = G4PhysicalVolumeNodeID 431 (fpCurrentPV,copyNo,fCurrentDepth,fCurrentTr 399 (fpCurrentPV,copyNo,fCurrentDepth,fCurrentTransform); 432 400 433 // Update full path of physical volumes... 401 // Update full path of physical volumes... 434 fFullPVPath.push_back(nodeID); 402 fFullPVPath.push_back(nodeID); 435 403 436 const G4RotationMatrix objectRotation = pVPV 404 const G4RotationMatrix objectRotation = pVPV -> GetObjectRotationValue (); 437 const G4ThreeVector& translation = pVPV 405 const G4ThreeVector& translation = pVPV -> GetTranslation (); 438 G4Transform3D theLT (G4Transform3D (objectRo 406 G4Transform3D theLT (G4Transform3D (objectRotation, translation)); 439 407 440 // Compute the accumulated transformation... 408 // Compute the accumulated transformation... 441 // Note that top volume's transformation rel 409 // Note that top volume's transformation relative to the world 442 // coordinate system is specified in theAT = 410 // coordinate system is specified in theAT == startingTransformation 443 // = fTransform (see DescribeYourselfTo), so 411 // = fTransform (see DescribeYourselfTo), so first time through the 444 // volume's own transformation, which is onl 412 // volume's own transformation, which is only relative to its 445 // mother, i.e., not relative to the world c 413 // mother, i.e., not relative to the world coordinate system, should 446 // not be accumulated. 414 // not be accumulated. 447 G4Transform3D theNewAT (theAT); 415 G4Transform3D theNewAT (theAT); 448 if (fCurrentDepth != 0) theNewAT = theAT * t 416 if (fCurrentDepth != 0) theNewAT = theAT * theLT; 449 fCurrentTransform = theNewAT; 417 fCurrentTransform = theNewAT; 450 418 451 const G4VisAttributes* pVisAttribs = pLV->Ge 419 const G4VisAttributes* pVisAttribs = pLV->GetVisAttributes(); 452 // If the volume does not have any vis attr 420 // If the volume does not have any vis attributes, create it. 453 G4VisAttributes* tempVisAtts = nullptr; 421 G4VisAttributes* tempVisAtts = nullptr; 454 if (!pVisAttribs) { 422 if (!pVisAttribs) { 455 if (fpMP->GetDefaultVisAttributes()) { 423 if (fpMP->GetDefaultVisAttributes()) { 456 tempVisAtts = new G4VisAttributes(*fpMP- 424 tempVisAtts = new G4VisAttributes(*fpMP->GetDefaultVisAttributes()); 457 } else { 425 } else { 458 tempVisAtts = new G4VisAttributes; 426 tempVisAtts = new G4VisAttributes; 459 } 427 } 460 // The user may request /vis/viewer/set/co 428 // The user may request /vis/viewer/set/colourByDensity. 461 if (fpMP->GetCBDAlgorithmNumber() == 1) { 429 if (fpMP->GetCBDAlgorithmNumber() == 1) { 462 // Algorithm 1: 3 parameters: Simple rai 430 // Algorithm 1: 3 parameters: Simple rainbow mapping. 463 if (fpMP->GetCBDParameters().size() != 3 431 if (fpMP->GetCBDParameters().size() != 3) { 464 G4Exception("G4PhysicalVolumeModelTouc 432 G4Exception("G4PhysicalVolumeModelTouchable::DescribeAndDescend", 465 "modeling0014", 433 "modeling0014", 466 FatalErrorInArgument, 434 FatalErrorInArgument, 467 "Algorithm-parameter misma 435 "Algorithm-parameter mismatch for Colour By Density"); 468 } else { 436 } else { 469 const G4double d = pMaterial? pMateria 437 const G4double d = pMaterial? pMaterial->GetDensity(): 0.; 470 const G4double d0 = fpMP->GetCBDParame 438 const G4double d0 = fpMP->GetCBDParameters()[0]; // Invisible d < d0. 471 const G4double d1 = fpMP->GetCBDParame 439 const G4double d1 = fpMP->GetCBDParameters()[1]; // Rainbow d0->d1->d2. 472 const G4double d2 = fpMP->GetCBDParame 440 const G4double d2 = fpMP->GetCBDParameters()[2]; // Blue d > d2. 473 if (d < d0) { // Density < d0 is invis 441 if (d < d0) { // Density < d0 is invisible. 474 tempVisAtts->SetVisibility(false); 442 tempVisAtts->SetVisibility(false); 475 } else { // Intermediate densities are 443 } else { // Intermediate densities are on a spectrum. 476 G4double red, green, blue; 444 G4double red, green, blue; 477 if (d < d1) { 445 if (d < d1) { 478 red = (d1-d)/(d1-d0); green = (d-d 446 red = (d1-d)/(d1-d0); green = (d-d0)/(d1-d0); blue = 0.; 479 } else if (d < d2) { 447 } else if (d < d2) { 480 red = 0.; green = (d2-d)/(d2-d1); 448 red = 0.; green = (d2-d)/(d2-d1); blue = (d-d1)/(d2-d1); 481 } else { // Density >= d2 is blue. 449 } else { // Density >= d2 is blue. 482 red = 0.; green = 0.; blue = 1.; 450 red = 0.; green = 0.; blue = 1.; 483 } 451 } 484 tempVisAtts->SetColour(G4Colour(red, 452 tempVisAtts->SetColour(G4Colour(red,green,blue)); 485 } 453 } 486 } 454 } 487 } else if (fpMP->GetCBDAlgorithmNumber() = 455 } else if (fpMP->GetCBDAlgorithmNumber() == 2) { 488 // Algorithm 2 456 // Algorithm 2 489 // ...etc. 457 // ...etc. 490 } 458 } 491 pVisAttribs = tempVisAtts; 459 pVisAttribs = tempVisAtts; 492 } 460 } 493 // From here, can assume pVisAttribs is a va 461 // From here, can assume pVisAttribs is a valid pointer. This is necessary 494 // because PreAddSolid needs a vis attribute 462 // because PreAddSolid needs a vis attributes object. 495 463 496 // Check if vis attributes are to be modifie 464 // Check if vis attributes are to be modified by a /vis/touchable/set/ command. 497 const auto& vams = fpMP->GetVisAttributesMod 465 const auto& vams = fpMP->GetVisAttributesModifiers(); 498 if (vams.size()) { 466 if (vams.size()) { 499 // OK, we have some VAMs (Vis Attributes M 467 // OK, we have some VAMs (Vis Attributes Modifiers). 500 for (const auto& vam: vams) { 468 for (const auto& vam: vams) { 501 const auto& vamPath = vam.GetPVNameCopyN 469 const auto& vamPath = vam.GetPVNameCopyNoPath(); 502 if (vamPath.size() == fFullPVPath.size() 470 if (vamPath.size() == fFullPVPath.size()) { 503 // OK, we have a size match. 471 // OK, we have a size match. 504 // Check the volume name/copy number p 472 // Check the volume name/copy number path. 505 auto iVAMNameCopyNo = vamPath.begin(); 473 auto iVAMNameCopyNo = vamPath.begin(); 506 auto iPVNodeId = fFullPVPath.begin(); 474 auto iPVNodeId = fFullPVPath.begin(); 507 for (; iVAMNameCopyNo != vamPath.end() 475 for (; iVAMNameCopyNo != vamPath.end(); ++iVAMNameCopyNo, ++iPVNodeId) { 508 if (!( 476 if (!( 509 iVAMNameCopyNo->GetName() == 477 iVAMNameCopyNo->GetName() == 510 iPVNodeId->GetPhysicalVolume() 478 iPVNodeId->GetPhysicalVolume()->GetName() && 511 iVAMNameCopyNo->GetCopyNo() == 479 iVAMNameCopyNo->GetCopyNo() == 512 iPVNodeId->GetPhysicalVolume() 480 iPVNodeId->GetPhysicalVolume()->GetCopyNo() 513 )) { 481 )) { 514 // This path element does NOT matc 482 // This path element does NOT match. 515 break; 483 break; 516 } 484 } 517 } 485 } 518 if (iVAMNameCopyNo == vamPath.end()) { 486 if (iVAMNameCopyNo == vamPath.end()) { 519 // OK, the paths match (the above lo 487 // OK, the paths match (the above loop terminated normally). 520 // Create a vis atts object for the 488 // Create a vis atts object for the modified vis atts. 521 // It is static so that we may retur 489 // It is static so that we may return a reliable pointer to it. 522 static G4VisAttributes modifiedVisAt 490 static G4VisAttributes modifiedVisAtts; 523 // Initialise it with the current vi 491 // Initialise it with the current vis atts and reset the pointer. 524 modifiedVisAtts = *pVisAttribs; 492 modifiedVisAtts = *pVisAttribs; 525 pVisAttribs = &modifiedVisAtts; 493 pVisAttribs = &modifiedVisAtts; 526 const G4VisAttributes& transVisAtts 494 const G4VisAttributes& transVisAtts = vam.GetVisAttributes(); 527 switch (vam.GetVisAttributesSignifie 495 switch (vam.GetVisAttributesSignifier()) { 528 case G4ModelingParameters::VASVisi 496 case G4ModelingParameters::VASVisibility: 529 modifiedVisAtts.SetVisibility(tr 497 modifiedVisAtts.SetVisibility(transVisAtts.IsVisible()); 530 break; 498 break; 531 case G4ModelingParameters::VASDaug 499 case G4ModelingParameters::VASDaughtersInvisible: 532 modifiedVisAtts.SetDaughtersInvi 500 modifiedVisAtts.SetDaughtersInvisible 533 (transVisAtts.IsDaughtersInvisib 501 (transVisAtts.IsDaughtersInvisible()); 534 break; 502 break; 535 case G4ModelingParameters::VASColo 503 case G4ModelingParameters::VASColour: 536 modifiedVisAtts.SetColour(transV 504 modifiedVisAtts.SetColour(transVisAtts.GetColour()); 537 break; 505 break; 538 case G4ModelingParameters::VASLine 506 case G4ModelingParameters::VASLineStyle: 539 modifiedVisAtts.SetLineStyle(tra 507 modifiedVisAtts.SetLineStyle(transVisAtts.GetLineStyle()); 540 break; 508 break; 541 case G4ModelingParameters::VASLine 509 case G4ModelingParameters::VASLineWidth: 542 modifiedVisAtts.SetLineWidth(tra 510 modifiedVisAtts.SetLineWidth(transVisAtts.GetLineWidth()); 543 break; 511 break; 544 case G4ModelingParameters::VASForc 512 case G4ModelingParameters::VASForceWireframe: 545 if (transVisAtts.IsForceDrawingS 513 if (transVisAtts.IsForceDrawingStyle()) { 546 if (transVisAtts.GetForcedDraw 514 if (transVisAtts.GetForcedDrawingStyle() == 547 G4VisAttributes::wireframe 515 G4VisAttributes::wireframe) { 548 modifiedVisAtts.SetForceWire 516 modifiedVisAtts.SetForceWireframe(true); 549 } 517 } 550 } 518 } 551 break; 519 break; 552 case G4ModelingParameters::VASForc 520 case G4ModelingParameters::VASForceSolid: 553 if (transVisAtts.IsForceDrawingS 521 if (transVisAtts.IsForceDrawingStyle()) { 554 if (transVisAtts.GetForcedDraw 522 if (transVisAtts.GetForcedDrawingStyle() == 555 G4VisAttributes::solid) { 523 G4VisAttributes::solid) { 556 modifiedVisAtts.SetForceSoli 524 modifiedVisAtts.SetForceSolid(true); 557 } 525 } 558 } 526 } 559 break; 527 break; 560 case G4ModelingParameters::VASForc 528 case G4ModelingParameters::VASForceCloud: 561 if (transVisAtts.IsForceDrawingS 529 if (transVisAtts.IsForceDrawingStyle()) { 562 if (transVisAtts.GetForcedDraw 530 if (transVisAtts.GetForcedDrawingStyle() == 563 G4VisAttributes::cloud) { 531 G4VisAttributes::cloud) { 564 modifiedVisAtts.SetForceClou 532 modifiedVisAtts.SetForceCloud(true); 565 } 533 } 566 } 534 } 567 break; 535 break; 568 case G4ModelingParameters::VASForc 536 case G4ModelingParameters::VASForceNumberOfCloudPoints: 569 modifiedVisAtts.SetForceNumberOf 537 modifiedVisAtts.SetForceNumberOfCloudPoints 570 (transVisAtts.GetForcedNumberOfC 538 (transVisAtts.GetForcedNumberOfCloudPoints()); 571 break; 539 break; 572 case G4ModelingParameters::VASForc 540 case G4ModelingParameters::VASForceAuxEdgeVisible: 573 if (transVisAtts.IsForceAuxEdgeV 541 if (transVisAtts.IsForceAuxEdgeVisible()) { 574 modifiedVisAtts.SetForceAuxEdg 542 modifiedVisAtts.SetForceAuxEdgeVisible 575 (transVisAtts.IsForcedAuxEdgeV 543 (transVisAtts.IsForcedAuxEdgeVisible()); 576 } 544 } 577 break; 545 break; 578 case G4ModelingParameters::VASForc 546 case G4ModelingParameters::VASForceLineSegmentsPerCircle: 579 modifiedVisAtts.SetForceLineSegm 547 modifiedVisAtts.SetForceLineSegmentsPerCircle 580 (transVisAtts.GetForcedLineSegme 548 (transVisAtts.GetForcedLineSegmentsPerCircle()); 581 break; 549 break; 582 } 550 } 583 } 551 } 584 } 552 } 585 } 553 } 586 } 554 } 587 555 588 // Check for special mesh rendering 556 // Check for special mesh rendering 589 if (fpMP->IsSpecialMeshRendering()) { 557 if (fpMP->IsSpecialMeshRendering()) { 590 G4bool potentialG4Mesh = false; << 591 if (fpMP->GetSpecialMeshVolumes().empty()) 558 if (fpMP->GetSpecialMeshVolumes().empty()) { 592 // No volumes specified - all are potent 559 // No volumes specified - all are potentially possible 593 potentialG4Mesh = true; << 560 goto create_mesh; 594 } else { 561 } else { 595 // Name and (optionally) copy number of << 596 for (const auto& pvNameCopyNo: fpMP->Get 562 for (const auto& pvNameCopyNo: fpMP->GetSpecialMeshVolumes()) { 597 if (pVPV->GetName() == pvNameCopyNo.Ge << 563 if (pVPV->GetName() == pvNameCopyNo.GetName()) { 598 // We have a name match << 564 // We have a name match 599 if (pvNameCopyNo.GetCopyNo() < 0) { << 565 if (pvNameCopyNo.GetCopyNo() < 0) { 600 // Any copy number is OK << 566 // Any copy number is OK 601 potentialG4Mesh = true; << 567 goto create_mesh; 602 } else { << 568 } else { 603 if (pVPV->GetCopyNo() == pvNameCop << 569 if (pVPV->GetCopyNo() == pvNameCopyNo.GetCopyNo()) { 604 // We have a name and copy numbe << 570 // We have a name and copy number match 605 potentialG4Mesh = true; << 571 goto create_mesh; 606 } << 572 } 607 } << 573 } 608 } << 574 } 609 } 575 } >> 576 // We have fallen out of this loop without finding a match >> 577 goto continue_processing; 610 } 578 } 611 if (potentialG4Mesh) { << 579 create_mesh: 612 // Create - or at least attempt to creat << 580 // Create - or at least attempt to create - a mesh. If it cannot be created 613 // out of this pVPV the type will be "in << 581 // out of this pVPV the type will be "invalid". 614 G4Mesh mesh(pVPV,theNewAT); << 582 G4Mesh mesh(pVPV,theNewAT); 615 if (mesh.GetMeshType() != G4Mesh::invali << 583 if (mesh.GetMeshType() != G4Mesh::invalid) { 616 // Create "artificial" nodeID to repre << 584 fFullPVPath.push_back(nodeID); 617 G4int artCopyNo = 0; << 585 fDrawnPVPath.push_back(nodeID); 618 auto artPV = mesh.GetParameterisedVolu << 586 sceneHandler.AddCompound(mesh); 619 auto artDepth = fCurrentDepth + 1; << 587 fFullPVPath.pop_back(); 620 auto artNodeID = G4PhysicalVolumeNodeI << 588 fDrawnPVPath.pop_back(); 621 fFullPVPath.push_back(artNodeID); << 589 delete tempVisAtts; // Needs cleaning up (Coverity warning!!) 622 fDrawnPVPath.push_back(artNodeID); << 590 return; 623 sceneHandler.AddCompound(mesh); << 591 } // else continue processing 624 fFullPVPath.pop_back(); << 625 fDrawnPVPath.pop_back(); << 626 delete tempVisAtts; // Needs cleaning << 627 return; // Mesh found and processed - << 628 } // else continue processing << 629 } << 630 } 592 } >> 593 continue_processing: 631 594 632 // Make decision to draw... 595 // Make decision to draw... 633 G4bool thisToBeDrawn = true; 596 G4bool thisToBeDrawn = true; 634 597 635 // There are various reasons why this volume 598 // There are various reasons why this volume 636 // might not be drawn... 599 // might not be drawn... 637 G4bool culling = fpMP->IsCulling(); 600 G4bool culling = fpMP->IsCulling(); 638 G4bool cullingInvisible = fpMP->IsCullingInv 601 G4bool cullingInvisible = fpMP->IsCullingInvisible(); 639 G4bool markedVisible 602 G4bool markedVisible 640 = pVisAttribs->IsVisible() && pVisAttribs->G 603 = pVisAttribs->IsVisible() && pVisAttribs->GetColour().GetAlpha() > 0; 641 G4bool cullingLowDensity = fpMP->IsDensityCu 604 G4bool cullingLowDensity = fpMP->IsDensityCulling(); 642 G4double density = pMaterial? pMaterial->Get 605 G4double density = pMaterial? pMaterial->GetDensity(): 0; 643 G4double densityCut = fpMP -> GetVisibleDens 606 G4double densityCut = fpMP -> GetVisibleDensity (); 644 607 645 // 1) Global culling is on.... 608 // 1) Global culling is on.... 646 if (culling) { 609 if (culling) { 647 // 2) Culling of invisible volumes is on.. 610 // 2) Culling of invisible volumes is on... 648 if (cullingInvisible) { 611 if (cullingInvisible) { 649 // 3) ...and the volume is marked not vi 612 // 3) ...and the volume is marked not visible... 650 if (!markedVisible) thisToBeDrawn = fals 613 if (!markedVisible) thisToBeDrawn = false; 651 } 614 } 652 // 4) Or culling of low density volumes is 615 // 4) Or culling of low density volumes is on... 653 if (cullingLowDensity) { 616 if (cullingLowDensity) { 654 // 5) ...and density is less than cut va 617 // 5) ...and density is less than cut value... 655 if (density < densityCut) thisToBeDrawn 618 if (density < densityCut) thisToBeDrawn = false; 656 } 619 } 657 } 620 } 658 // 6) The user has asked for all further tra 621 // 6) The user has asked for all further traversing to be aborted... 659 if (fAbort) thisToBeDrawn = false; 622 if (fAbort) thisToBeDrawn = false; 660 623 661 // Set "drawn" flag (it was true by default) 624 // Set "drawn" flag (it was true by default) - thisToBeDrawn may be false 662 nodeID.SetDrawn(thisToBeDrawn); 625 nodeID.SetDrawn(thisToBeDrawn); 663 626 664 if (thisToBeDrawn) { 627 if (thisToBeDrawn) { 665 628 666 // Update path of drawn physical volumes.. 629 // Update path of drawn physical volumes... 667 fDrawnPVPath.push_back(nodeID); 630 fDrawnPVPath.push_back(nodeID); 668 631 669 if (fpMP->IsExplode() && fDrawnPVPath.size 632 if (fpMP->IsExplode() && fDrawnPVPath.size() == 1) { 670 // For top-level drawn volumes, explode 633 // For top-level drawn volumes, explode along radius... 671 G4Transform3D centering = G4Translate3D( 634 G4Transform3D centering = G4Translate3D(fpMP->GetExplodeCentre()); 672 G4Transform3D centred = centering.invers 635 G4Transform3D centred = centering.inverse() * theNewAT; 673 G4Scale3D oldScale; 636 G4Scale3D oldScale; 674 G4Rotate3D oldRotation; 637 G4Rotate3D oldRotation; 675 G4Translate3D oldTranslation; 638 G4Translate3D oldTranslation; 676 centred.getDecomposition(oldScale, oldRo 639 centred.getDecomposition(oldScale, oldRotation, oldTranslation); 677 G4double explodeFactor = fpMP->GetExplod 640 G4double explodeFactor = fpMP->GetExplodeFactor(); 678 G4Translate3D newTranslation = 641 G4Translate3D newTranslation = 679 G4Translate3D(explodeFactor * oldTranslation 642 G4Translate3D(explodeFactor * oldTranslation.dx(), 680 explodeFactor * oldTranslation.dy(), 643 explodeFactor * oldTranslation.dy(), 681 explodeFactor * oldTranslation.dz()) 644 explodeFactor * oldTranslation.dz()); 682 theNewAT = centering * newTranslation * 645 theNewAT = centering * newTranslation * oldRotation * oldScale; 683 } 646 } 684 647 685 auto fullDepth = fCurrentDepth + (G4int)fB << 648 volumeCount++; 686 fNTouchables[fullDepth]++; // Increment f << 687 << 688 DescribeSolid (theNewAT, pSol, pVisAttribs 649 DescribeSolid (theNewAT, pSol, pVisAttribs, sceneHandler); 689 650 690 } 651 } 691 652 692 // Make decision to draw daughters, if any. 653 // Make decision to draw daughters, if any. There are various 693 // reasons why daughters might not be drawn. 654 // reasons why daughters might not be drawn... 694 655 695 // First, reasons that do not depend on cull 656 // First, reasons that do not depend on culling policy... 696 G4int nDaughters = (G4int)pLV->GetNoDaughter << 657 G4int nDaughters = pLV->GetNoDaughters(); 697 G4bool daughtersToBeDrawn = true; 658 G4bool daughtersToBeDrawn = true; 698 // 1) There are no daughters... 659 // 1) There are no daughters... 699 if (!nDaughters) daughtersToBeDrawn = false; 660 if (!nDaughters) daughtersToBeDrawn = false; 700 // 2) We are at the limit if requested depth 661 // 2) We are at the limit if requested depth... 701 else if (requestedDepth == 0) daughtersToBeD 662 else if (requestedDepth == 0) daughtersToBeDrawn = false; 702 // 3) The user has asked for all further tra 663 // 3) The user has asked for all further traversing to be aborted... 703 else if (fAbort) daughtersToBeDrawn = false; 664 else if (fAbort) daughtersToBeDrawn = false; 704 // 4) The user has asked that the descent be 665 // 4) The user has asked that the descent be curtailed... 705 else if (fCurtailDescent) daughtersToBeDrawn 666 else if (fCurtailDescent) daughtersToBeDrawn = false; 706 667 707 // Now, reasons that depend on culling polic 668 // Now, reasons that depend on culling policy... 708 else { 669 else { 709 G4bool daughtersInvisible = pVisAttribs->I 670 G4bool daughtersInvisible = pVisAttribs->IsDaughtersInvisible(); 710 // Culling of covered daughters request. 671 // Culling of covered daughters request. This is computed in 711 // G4VSceneHandler::CreateModelingParamete 672 // G4VSceneHandler::CreateModelingParameters() depending on view 712 // parameters... 673 // parameters... 713 G4bool cullingCovered = fpMP->IsCullingCov 674 G4bool cullingCovered = fpMP->IsCullingCovered(); 714 G4bool surfaceDrawing = 675 G4bool surfaceDrawing = 715 fpMP->GetDrawingStyle() == G4ModelingPar 676 fpMP->GetDrawingStyle() == G4ModelingParameters::hsr || 716 fpMP->GetDrawingStyle() == G4ModelingPar 677 fpMP->GetDrawingStyle() == G4ModelingParameters::hlhsr; 717 if (pVisAttribs->IsForceDrawingStyle()) { 678 if (pVisAttribs->IsForceDrawingStyle()) { 718 switch (pVisAttribs->GetForcedDrawingSty 679 switch (pVisAttribs->GetForcedDrawingStyle()) { 719 default: 680 default: 720 case G4VisAttributes::wireframe: surface 681 case G4VisAttributes::wireframe: surfaceDrawing = false; break; 721 case G4VisAttributes::solid: surfaceDraw 682 case G4VisAttributes::solid: surfaceDrawing = true; break; 722 } 683 } 723 } 684 } 724 G4bool opaque = pVisAttribs->GetColour().G 685 G4bool opaque = pVisAttribs->GetColour().GetAlpha() >= 1.; 725 // 5) Global culling is on.... 686 // 5) Global culling is on.... 726 if (culling) { 687 if (culling) { 727 // 6) ..and culling of invisible volumes 688 // 6) ..and culling of invisible volumes is on... 728 if (cullingInvisible) { 689 if (cullingInvisible) { 729 // 7) ...and the mother requests daughters i 690 // 7) ...and the mother requests daughters invisible 730 if (daughtersInvisible) daughtersToBeDrawn = 691 if (daughtersInvisible) daughtersToBeDrawn = false; 731 } 692 } 732 // 8) Or culling of covered daughters is 693 // 8) Or culling of covered daughters is requested... 733 if (cullingCovered) { 694 if (cullingCovered) { 734 // 9) ...and surface drawing is operating... 695 // 9) ...and surface drawing is operating... 735 if (surfaceDrawing) { 696 if (surfaceDrawing) { 736 // 10) ...but only if mother is visible... 697 // 10) ...but only if mother is visible... 737 if (thisToBeDrawn) { 698 if (thisToBeDrawn) { 738 // 11) ...and opaque... 699 // 11) ...and opaque... 739 if (opaque) daughtersToBeDrawn = false 700 if (opaque) daughtersToBeDrawn = false; 740 } 701 } 741 } 702 } 742 } 703 } 743 } 704 } 744 } 705 } 745 706 746 if (daughtersToBeDrawn) { 707 if (daughtersToBeDrawn) { 747 for (G4int iDaughter = 0; iDaughter < nDau 708 for (G4int iDaughter = 0; iDaughter < nDaughters; iDaughter++) { 748 // Store daughter pVPV in local variable 709 // Store daughter pVPV in local variable ready for recursion... 749 G4VPhysicalVolume* pDaughterVPV = pLV -> 710 G4VPhysicalVolume* pDaughterVPV = pLV -> GetDaughter (iDaughter); 750 // Descend the geometry structure recurs 711 // Descend the geometry structure recursively... 751 fCurrentDepth++; 712 fCurrentDepth++; 752 VisitGeometryAndGetVisReps 713 VisitGeometryAndGetVisReps 753 (pDaughterVPV, requestedDepth - 1, theNewAT, 714 (pDaughterVPV, requestedDepth - 1, theNewAT, sceneHandler); 754 fCurrentDepth--; 715 fCurrentDepth--; 755 } 716 } 756 } 717 } 757 718 758 // Clean up 719 // Clean up 759 delete tempVisAtts; 720 delete tempVisAtts; 760 721 761 // Reset for normal descending of next volum 722 // Reset for normal descending of next volume at this level... 762 fCurtailDescent = false; 723 fCurtailDescent = false; 763 724 764 // Pop item from paths physical volumes... 725 // Pop item from paths physical volumes... 765 fFullPVPath.pop_back(); 726 fFullPVPath.pop_back(); 766 if (thisToBeDrawn) { 727 if (thisToBeDrawn) { 767 fDrawnPVPath.pop_back(); 728 fDrawnPVPath.pop_back(); 768 } 729 } 769 } 730 } 770 731 771 namespace << 772 { << 773 G4bool SubtractionBoundingLimits(const G4VSo << 774 { << 775 // Algorithm from G4SubtractionSolid::Boun << 776 // Since it is unclear how the shape of th << 777 // after subtraction, just return its orig << 778 G4ThreeVector pMin, pMax; << 779 const auto& pSolA = target; << 780 pSolA->BoundingLimits(pMin,pMax); << 781 // Check correctness of the bounding box << 782 if (pMin.x() >= pMax.x() || pMin.y() >= pM << 783 // Bad bounding box (min >= max) << 784 // This signifies a subtraction of non-i << 785 return false; << 786 } << 787 return true; << 788 } << 789 << 790 G4bool IntersectionBoundingLimits(const G4VS << 791 { << 792 // Algorithm from G4IntersectionSolid::Bou << 793 G4ThreeVector pMin, pMax; << 794 G4ThreeVector minA,maxA, minB,maxB; << 795 const auto& pSolA = target; << 796 const auto& pSolB = intersector; << 797 pSolA->BoundingLimits(minA,maxA); << 798 pSolB->BoundingLimits(minB,maxB); << 799 pMin.set(std::max(minA.x(),minB.x()), << 800 std::max(minA.y(),minB.y()), << 801 std::max(minA.z(),minB.z())); << 802 pMax.set(std::min(maxA.x(),maxB.x()), << 803 std::min(maxA.y(),maxB.y()), << 804 std::min(maxA.z(),maxB.z())); << 805 if (pMin.x() >= pMax.x() || pMin.y() >= pM << 806 // Bad bounding box (min >= max) << 807 // This signifies a subtraction of non-i << 808 return false; << 809 } << 810 return true; << 811 } << 812 } << 813 << 814 void G4PhysicalVolumeModel::DescribeSolid 732 void G4PhysicalVolumeModel::DescribeSolid 815 (const G4Transform3D& theAT, 733 (const G4Transform3D& theAT, 816 G4VSolid* pSol, 734 G4VSolid* pSol, 817 const G4VisAttributes* pVisAttribs, 735 const G4VisAttributes* pVisAttribs, 818 G4VGraphicsScene& sceneHandler) 736 G4VGraphicsScene& sceneHandler) 819 { 737 { 820 G4DisplacedSolid* pSectionSolid = fpMP->GetS 738 G4DisplacedSolid* pSectionSolid = fpMP->GetSectionSolid(); 821 G4DisplacedSolid* pCutawaySolid = fpMP->GetC 739 G4DisplacedSolid* pCutawaySolid = fpMP->GetCutawaySolid(); 822 740 823 if (fNClippers <= 0 || fNClippers > 1) { << 741 if (!fpClippingSolid && !pSectionSolid && !pCutawaySolid) { 824 742 825 // Normal case - no clipping, etc. - or, i << 826 sceneHandler.PreAddSolid (theAT, *pVisAttr 743 sceneHandler.PreAddSolid (theAT, *pVisAttribs); 827 pSol -> DescribeYourselfTo (sceneHandler); 744 pSol -> DescribeYourselfTo (sceneHandler); // Standard treatment. 828 sceneHandler.PostAddSolid (); 745 sceneHandler.PostAddSolid (); 829 746 830 } else { // fNClippers == 1 << 747 } else { 831 748 832 G4VSolid* pResultantSolid = nullpt << 749 // Clipping, etc., performed by Boolean operations. 833 G4DisplacedSolid* pDisplacedSolid = nullpt << 834 750 835 if (fpClippingSolid) { << 751 // First, get polyhedron for current solid... 836 pDisplacedSolid = new G4DisplacedSolid(" << 752 if (pVisAttribs->IsForceLineSegmentsPerCircle()) 837 switch (fClippingMode) { << 753 G4Polyhedron::SetNumberOfRotationSteps 838 case subtraction: << 754 (pVisAttribs->GetForcedLineSegmentsPerCircle()); 839 if (SubtractionBoundingLimits(pSol)) << 755 else 840 pResultantSolid = new G4Subtractio << 756 G4Polyhedron::SetNumberOfRotationSteps(fpMP->GetNoOfSides()); 841 ("subtracted_clipped_solid", pSol, << 757 const G4Polyhedron* pOriginalPolyhedron = pSol->GetPolyhedron(); 842 } << 758 G4Polyhedron::ResetNumberOfRotationSteps(); 843 break; << 759 844 case intersection: << 760 if (!pOriginalPolyhedron) { 845 if (IntersectionBoundingLimits(pSol, << 761 846 pResultantSolid = new G4Intersecti << 762 if (fpMP->IsWarning()) 847 ("intersected_clipped_solid", pSol << 763 G4cout << 848 } << 764 "WARNING: G4PhysicalVolumeModel::DescribeSolid: solid\n \"" 849 break; << 765 << pSol->GetName() << >> 766 "\" has no polyhedron. Cannot by clipped." >> 767 << G4endl; >> 768 pSol -> DescribeYourselfTo (sceneHandler); // Standard treatment. >> 769 >> 770 } else { >> 771 >> 772 G4VSolid* pResultantSolid = 0; >> 773 >> 774 if (fpClippingSolid) { >> 775 switch (fClippingMode) { >> 776 default: >> 777 case subtraction: >> 778 pResultantSolid = new G4SubtractionSolid >> 779 ("subtracted_clipped_solid", pSol, fpClippingSolid, theAT.inverse()); >> 780 break; >> 781 case intersection: >> 782 pResultantSolid = new G4IntersectionSolid >> 783 ("intersected_clipped_solid", pSol, fpClippingSolid, theAT.inverse()); >> 784 break; >> 785 } 850 } 786 } 851 787 852 } else if (pSectionSolid) { << 788 if (pSectionSolid) { 853 pDisplacedSolid = new G4DisplacedSolid(" << 789 pResultantSolid = new G4IntersectionSolid 854 if (IntersectionBoundingLimits(pSol, pDi << 790 ("sectioned_solid", pSol, pSectionSolid, theAT.inverse()); 855 pResultantSolid = new G4IntersectionSo << 791 } >> 792 >> 793 if (pCutawaySolid) { >> 794 // Follow above... >> 795 pResultantSolid = new G4SubtractionSolid >> 796 ("cutaway_solid", pSol, pCutawaySolid, theAT.inverse()); >> 797 } >> 798 >> 799 G4Polyhedron* pResultantPolyhedron = pResultantSolid->GetPolyhedron(); >> 800 if (!pResultantPolyhedron) { >> 801 if (fpMP->IsWarning()) >> 802 G4cout << >> 803 "WARNING: G4PhysicalVolumeModel::DescribeSolid: resultant polyhedron for" >> 804 "\n solid \"" << pSol->GetName() << >> 805 "\" not defined due to error during Boolean processing." >> 806 << G4endl; >> 807 } else { >> 808 // It seems that if the sectioning solid does not intersect the >> 809 // original solid the Boolean Processor returns the original >> 810 // polyhedron, or a copy thereof. We do not want it. >> 811 // Check the number of facets, etc. If same, ignore. >> 812 // What we need from the Boolean Processor is a null pointer or a >> 813 // null polyhedron. It seems to return the original or a copy of it. >> 814 if (pResultantPolyhedron->GetNoFacets() == pOriginalPolyhedron->GetNoFacets()) >> 815 // This works in most cases but I still get a box in test202 with >> 816 // /vis/viewer/set/sectionPlane on 0 0 0 m 0.1 0.1 1 >> 817 { >> 818 pResultantPolyhedron = nullptr; >> 819 } 856 } 820 } 857 821 858 } else if (pCutawaySolid) { << 822 if (pResultantPolyhedron) { 859 pDisplacedSolid = new G4DisplacedSolid(" << 823 // Finally, draw polyhedron... 860 switch (fpMP->GetCutawayMode()) { << 824 sceneHandler.BeginPrimitives(theAT); 861 case G4ModelingParameters::cutawayUnio << 825 pResultantPolyhedron->SetVisAttributes(pVisAttribs); 862 if (SubtractionBoundingLimits(pSol)) << 826 sceneHandler.AddPrimitive(*pResultantPolyhedron); 863 pResultantSolid = new G4Subtractio << 827 sceneHandler.EndPrimitives(); 864 } << 865 break; << 866 case G4ModelingParameters::cutawayInte << 867 if (IntersectionBoundingLimits(pSol, << 868 pResultantSolid = new G4Intersecti << 869 } << 870 break; << 871 } 828 } 872 } << 873 829 874 if (pResultantSolid) { << 830 delete pResultantSolid; 875 sceneHandler.PreAddSolid (theAT, *pVisAt << 876 pResultantSolid -> DescribeYourselfTo (s << 877 sceneHandler.PostAddSolid (); << 878 } 831 } 879 << 880 delete pResultantSolid; << 881 delete pDisplacedSolid; << 882 } 832 } 883 } 833 } 884 834 885 G4bool G4PhysicalVolumeModel::Validate (G4bool 835 G4bool G4PhysicalVolumeModel::Validate (G4bool warn) 886 { 836 { 887 // Not easy to see how to validate this sort o 837 // Not easy to see how to validate this sort of model. Previously there was 888 // a check that a volume of the same name (fTo 838 // a check that a volume of the same name (fTopPVName) existed somewhere in 889 // the geometry tree but under some circumstan 839 // the geometry tree but under some circumstances this consumed lots of CPU 890 // time. Instead, let us simply check that the 840 // time. Instead, let us simply check that the volume (fpTopPV) exists in the 891 // physical volume store. 841 // physical volume store. >> 842 892 const auto& pvStore = G4PhysicalVolumeStore: 843 const auto& pvStore = G4PhysicalVolumeStore::GetInstance(); 893 auto iterator = find(pvStore->begin(),pvStor 844 auto iterator = find(pvStore->begin(),pvStore->end(),fpTopPV); 894 if (iterator == pvStore->end()) { 845 if (iterator == pvStore->end()) { 895 if (warn) { 846 if (warn) { 896 G4ExceptionDescription ed; 847 G4ExceptionDescription ed; 897 ed << "Attempt to validate a volume that 848 ed << "Attempt to validate a volume that is no longer in the physical volume store."; 898 G4Exception("G4PhysicalVolumeModel::Vali 849 G4Exception("G4PhysicalVolumeModel::Validate", "modeling0015", JustWarning, ed); 899 } 850 } 900 return false; 851 return false; 901 } else { 852 } else { 902 return true; 853 return true; 903 } 854 } >> 855 >> 856 // Previous algorithm >> 857 // G4TransportationManager* transportationManager = >> 858 // G4TransportationManager::GetTransportationManager (); >> 859 // size_t nWorlds = transportationManager->GetNoWorlds(); >> 860 // G4bool found = false; >> 861 // std::vector<G4VPhysicalVolume*>::iterator iterWorld = >> 862 // transportationManager->GetWorldsIterator(); >> 863 // for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) { >> 864 // G4VPhysicalVolume* world = (*iterWorld); >> 865 // if (!world) break; // This can happen if geometry has been cleared/destroyed. >> 866 // // The idea now is to seek a PV with the same name and copy no >> 867 // // in the hope it's the same one!! >> 868 // G4PhysicalVolumeModel searchModel (world); >> 869 // G4int verbosity = 0; // Suppress messages from G4PhysicalVolumeSearchScene. >> 870 // G4PhysicalVolumeSearchScene searchScene >> 871 // (&searchModel, fTopPVName, fTopPVCopyNo, verbosity); >> 872 // G4ModelingParameters mp; // Default modeling parameters for this search. >> 873 // mp.SetDefaultVisAttributes(fpMP? fpMP->GetDefaultVisAttributes(): 0); >> 874 // searchModel.SetModelingParameters (&mp); >> 875 // searchModel.DescribeYourselfTo (searchScene); >> 876 // G4VPhysicalVolume* foundVolume = searchScene.GetFoundVolume (); >> 877 // if (foundVolume) { >> 878 // if (foundVolume != fpTopPV && warn) { >> 879 // G4cout << >> 880 // "G4PhysicalVolumeModel::Validate(): A volume of the same name and" >> 881 // "\n copy number (\"" >> 882 // << fTopPVName << "\", copy " << fTopPVCopyNo >> 883 // << ") still exists and is being used." >> 884 // "\n But it is not the same volume you originally specified" >> 885 // "\n in /vis/scene/add/." >> 886 // << G4endl; >> 887 // } >> 888 // fpTopPV = foundVolume; >> 889 // CalculateExtent (); >> 890 // found = true; >> 891 // } >> 892 // } >> 893 // if (found) return true; >> 894 // else { >> 895 // if (warn) { >> 896 // G4cout << >> 897 // "G4PhysicalVolumeModel::Validate(): No volume of name and" >> 898 // "\n copy number (\"" >> 899 // << fTopPVName << "\", copy " << fTopPVCopyNo >> 900 // << ") exists." >> 901 // << G4endl; >> 902 // } >> 903 // return false; >> 904 // } 904 } 905 } 905 906 906 const std::map<G4String,G4AttDef>* G4PhysicalV 907 const std::map<G4String,G4AttDef>* G4PhysicalVolumeModel::GetAttDefs() const 907 { 908 { 908 G4bool isNew; 909 G4bool isNew; 909 std::map<G4String,G4AttDef>* store 910 std::map<G4String,G4AttDef>* store 910 = G4AttDefStore::GetInstance("G4Physical 911 = G4AttDefStore::GetInstance("G4PhysicalVolumeModel", isNew); 911 if (isNew) { 912 if (isNew) { 912 (*store)["PVPath"] = 913 (*store)["PVPath"] = 913 G4AttDef("PVPath","Physical Volume Path" 914 G4AttDef("PVPath","Physical Volume Path","Physics","","G4String"); 914 (*store)["BasePVPath"] = 915 (*store)["BasePVPath"] = 915 G4AttDef("BasePVPath","Base Physical Vol 916 G4AttDef("BasePVPath","Base Physical Volume Path","Physics","","G4String"); 916 (*store)["LVol"] = 917 (*store)["LVol"] = 917 G4AttDef("LVol","Logical Volume","Physic << 918 G4AttDef("LVol","Logical Volume","Physics","","G4String"); 918 (*store)["Solid"] = 919 (*store)["Solid"] = 919 G4AttDef("Solid","Solid Name","Physics", << 920 G4AttDef("Solid","Solid Name","Physics","","G4String"); 920 (*store)["EType"] = 921 (*store)["EType"] = 921 G4AttDef("EType","Entity Type","Physics" << 922 G4AttDef("EType","Entity Type","Physics","","G4String"); 922 (*store)["DmpSol"] = 923 (*store)["DmpSol"] = 923 G4AttDef("DmpSol","Dump of Solid propert << 924 G4AttDef("DmpSol","Dump of Solid properties","Physics","","G4String"); 924 (*store)["LocalTrans"] = 925 (*store)["LocalTrans"] = 925 G4AttDef("LocalTrans","Local transformat << 926 G4AttDef("LocalTrans","Local transformation of volume","Physics","","G4String"); 926 (*store)["LocalExtent"] = << 927 G4AttDef("LocalExtent","Local extent of << 928 (*store)["GlobalTrans"] = 927 (*store)["GlobalTrans"] = 929 G4AttDef("GlobalTrans","Global transform << 928 G4AttDef("GlobalTrans","Global transformation of volume","Physics","","G4String"); 930 (*store)["GlobalExtent"] = << 931 G4AttDef("GlobalExtent","Global extent o << 932 (*store)["Material"] = 929 (*store)["Material"] = 933 G4AttDef("Material","Material Name","Phy << 930 G4AttDef("Material","Material Name","Physics","","G4String"); 934 (*store)["Density"] = 931 (*store)["Density"] = 935 G4AttDef("Density","Material Density","P << 932 G4AttDef("Density","Material Density","Physics","G4BestUnit","G4double"); 936 (*store)["State"] = 933 (*store)["State"] = 937 G4AttDef("State","Material State (enum u << 934 G4AttDef("State","Material State (enum undefined,solid,liquid,gas)","Physics","","G4String"); 938 (*store)["Radlen"] = 935 (*store)["Radlen"] = 939 G4AttDef("Radlen","Material Radiation Le << 936 G4AttDef("Radlen","Material Radiation Length","Physics","G4BestUnit","G4double"); 940 (*store)["Region"] = 937 (*store)["Region"] = 941 G4AttDef("Region","Cuts Region","Physics << 938 G4AttDef("Region","Cuts Region","Physics","","G4String"); 942 (*store)["RootRegion"] = 939 (*store)["RootRegion"] = 943 G4AttDef("RootRegion","Root Region (0/1 << 940 G4AttDef("RootRegion","Root Region (0/1 = false/true)","Physics","","G4bool"); 944 } 941 } 945 return store; 942 return store; 946 } 943 } 947 944 948 static std::ostream& operator<< (std::ostream& 945 static std::ostream& operator<< (std::ostream& o, const G4Transform3D t) 949 { 946 { 950 using namespace std; 947 using namespace std; 951 948 952 G4Scale3D sc; 949 G4Scale3D sc; 953 G4Rotate3D r; 950 G4Rotate3D r; 954 G4Translate3D tl; 951 G4Translate3D tl; 955 t.getDecomposition(sc, r, tl); 952 t.getDecomposition(sc, r, tl); 956 953 957 const int w = 10; 954 const int w = 10; 958 955 959 // Transformation itself 956 // Transformation itself 960 o << setw(w) << t.xx() << setw(w) << t.xy() 957 o << setw(w) << t.xx() << setw(w) << t.xy() << setw(w) << t.xz() << setw(w) << t.dx() << endl; 961 o << setw(w) << t.yx() << setw(w) << t.yy() 958 o << setw(w) << t.yx() << setw(w) << t.yy() << setw(w) << t.yz() << setw(w) << t.dy() << endl; 962 o << setw(w) << t.zx() << setw(w) << t.zy() 959 o << setw(w) << t.zx() << setw(w) << t.zy() << setw(w) << t.zz() << setw(w) << t.dz() << endl; 963 960 964 // Translation 961 // Translation 965 o << "= translation:" << endl; 962 o << "= translation:" << endl; 966 o << setw(w) << tl.dx() << setw(w) << tl.dy( 963 o << setw(w) << tl.dx() << setw(w) << tl.dy() << setw(w) << tl.dz() << endl; 967 964 968 // Rotation 965 // Rotation 969 o << "* rotation:" << endl; 966 o << "* rotation:" << endl; 970 o << setw(w) << r.xx() << setw(w) << r.xy() 967 o << setw(w) << r.xx() << setw(w) << r.xy() << setw(w) << r.xz() << endl; 971 o << setw(w) << r.yx() << setw(w) << r.yy() 968 o << setw(w) << r.yx() << setw(w) << r.yy() << setw(w) << r.yz() << endl; 972 o << setw(w) << r.zx() << setw(w) << r.zy() 969 o << setw(w) << r.zx() << setw(w) << r.zy() << setw(w) << r.zz() << endl; 973 970 974 // Scale 971 // Scale 975 o << "* scale:" << endl; 972 o << "* scale:" << endl; 976 o << setw(w) << sc.xx() << setw(w) << sc.yy( 973 o << setw(w) << sc.xx() << setw(w) << sc.yy() << setw(w) << sc.zz() << endl; 977 974 978 // Transformed axes 975 // Transformed axes 979 o << "Transformed axes:" << endl; 976 o << "Transformed axes:" << endl; 980 o << "x': " << r * G4Vector3D(1., 0., 0.) << 977 o << "x': " << r * G4Vector3D(1., 0., 0.) << endl; 981 o << "y': " << r * G4Vector3D(0., 1., 0.) << 978 o << "y': " << r * G4Vector3D(0., 1., 0.) << endl; 982 o << "z': " << r * G4Vector3D(0., 0., 1.) << 979 o << "z': " << r * G4Vector3D(0., 0., 1.) << endl; 983 980 984 return o; 981 return o; 985 } 982 } 986 983 987 std::vector<G4AttValue>* G4PhysicalVolumeModel 984 std::vector<G4AttValue>* G4PhysicalVolumeModel::CreateCurrentAttValues() const 988 { 985 { 989 std::vector<G4AttValue>* values = new std::v 986 std::vector<G4AttValue>* values = new std::vector<G4AttValue>; 990 987 991 if (!fpCurrentLV) { 988 if (!fpCurrentLV) { 992 G4Exception 989 G4Exception 993 ("G4PhysicalVolumeModel::CreateCurrent 990 ("G4PhysicalVolumeModel::CreateCurrentAttValues", 994 "modeling0004", 991 "modeling0004", 995 JustWarning, 992 JustWarning, 996 "Current logical volume not defined." 993 "Current logical volume not defined."); 997 return values; 994 return values; 998 } 995 } 999 996 1000 std::ostringstream oss; oss << fFullPVPath; 997 std::ostringstream oss; oss << fFullPVPath; 1001 values->push_back(G4AttValue("PVPath", oss. 998 values->push_back(G4AttValue("PVPath", oss.str(),"")); 1002 << 1003 oss.str(""); oss << fBaseFullPVPath; 999 oss.str(""); oss << fBaseFullPVPath; 1004 values->push_back(G4AttValue("BasePVPath", 1000 values->push_back(G4AttValue("BasePVPath", oss.str(),"")); 1005 << 1006 values->push_back(G4AttValue("LVol", fpCurr 1001 values->push_back(G4AttValue("LVol", fpCurrentLV->GetName(),"")); 1007 G4VSolid* pSol = fpCurrentLV->GetSolid(); 1002 G4VSolid* pSol = fpCurrentLV->GetSolid(); 1008 << 1009 values->push_back(G4AttValue("Solid", pSol- 1003 values->push_back(G4AttValue("Solid", pSol->GetName(),"")); 1010 << 1011 values->push_back(G4AttValue("EType", pSol- 1004 values->push_back(G4AttValue("EType", pSol->GetEntityType(),"")); 1012 << 1013 oss.str(""); oss << '\n' << *pSol; 1005 oss.str(""); oss << '\n' << *pSol; 1014 values->push_back(G4AttValue("DmpSol", oss. 1006 values->push_back(G4AttValue("DmpSol", oss.str(),"")); 1015 << 1016 const G4RotationMatrix localRotation = fpCu 1007 const G4RotationMatrix localRotation = fpCurrentPV->GetObjectRotationValue(); 1017 const G4ThreeVector& localTranslation = fpC 1008 const G4ThreeVector& localTranslation = fpCurrentPV->GetTranslation(); 1018 oss.str(""); oss << '\n' << G4Transform3D(l 1009 oss.str(""); oss << '\n' << G4Transform3D(localRotation,localTranslation); 1019 values->push_back(G4AttValue("LocalTrans", 1010 values->push_back(G4AttValue("LocalTrans", oss.str(),"")); 1020 << 1021 oss.str(""); oss << '\n' << pSol->GetExtent << 1022 values->push_back(G4AttValue("LocalExtent", << 1023 << 1024 oss.str(""); oss << '\n' << fCurrentTransfo 1011 oss.str(""); oss << '\n' << fCurrentTransform; 1025 values->push_back(G4AttValue("GlobalTrans", 1012 values->push_back(G4AttValue("GlobalTrans", oss.str(),"")); 1026 << 1027 oss.str(""); oss << '\n' << (pSol->GetExten << 1028 values->push_back(G4AttValue("GlobalExtent" << 1029 << 1030 G4String matName = fpCurrentMaterial? fpCur 1013 G4String matName = fpCurrentMaterial? fpCurrentMaterial->GetName(): G4String("No material"); 1031 values->push_back(G4AttValue("Material", ma 1014 values->push_back(G4AttValue("Material", matName,"")); 1032 << 1033 G4double matDensity = fpCurrentMaterial? fp 1015 G4double matDensity = fpCurrentMaterial? fpCurrentMaterial->GetDensity(): 0.; 1034 values->push_back(G4AttValue("Density", G4B 1016 values->push_back(G4AttValue("Density", G4BestUnit(matDensity,"Volumic Mass"),"")); 1035 << 1036 G4State matState = fpCurrentMaterial? fpCur 1017 G4State matState = fpCurrentMaterial? fpCurrentMaterial->GetState(): kStateUndefined; 1037 oss.str(""); oss << matState; 1018 oss.str(""); oss << matState; 1038 values->push_back(G4AttValue("State", oss.s 1019 values->push_back(G4AttValue("State", oss.str(),"")); 1039 << 1040 G4double matRadlen = fpCurrentMaterial? fpC 1020 G4double matRadlen = fpCurrentMaterial? fpCurrentMaterial->GetRadlen(): 0.; 1041 values->push_back(G4AttValue("Radlen", G4Be 1021 values->push_back(G4AttValue("Radlen", G4BestUnit(matRadlen,"Length"),"")); 1042 << 1043 G4Region* region = fpCurrentLV->GetRegion() 1022 G4Region* region = fpCurrentLV->GetRegion(); 1044 G4String regionName = region? region->GetNa 1023 G4String regionName = region? region->GetName(): G4String("No region"); 1045 values->push_back(G4AttValue("Region", regi 1024 values->push_back(G4AttValue("Region", regionName,"")); 1046 << 1047 oss.str(""); oss << fpCurrentLV->IsRootRegi 1025 oss.str(""); oss << fpCurrentLV->IsRootRegion(); 1048 values->push_back(G4AttValue("RootRegion", 1026 values->push_back(G4AttValue("RootRegion", oss.str(),"")); 1049 << 1050 return values; 1027 return values; 1051 } 1028 } 1052 1029 1053 G4bool G4PhysicalVolumeModel::G4PhysicalVolum 1030 G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator< 1054 (const G4PhysicalVolumeModel::G4PhysicalVol 1031 (const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID& right) const 1055 { 1032 { 1056 if (fpPV < right.fpPV) return true; 1033 if (fpPV < right.fpPV) return true; 1057 if (fpPV == right.fpPV) { 1034 if (fpPV == right.fpPV) { 1058 if (fCopyNo < right.fCopyNo) return true; 1035 if (fCopyNo < right.fCopyNo) return true; 1059 if (fCopyNo == right.fCopyNo) 1036 if (fCopyNo == right.fCopyNo) 1060 return fNonCulledDepth < right.fNonCull 1037 return fNonCulledDepth < right.fNonCulledDepth; 1061 } 1038 } 1062 return false; 1039 return false; 1063 } 1040 } 1064 1041 1065 G4bool G4PhysicalVolumeModel::G4PhysicalVolum 1042 G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator!= 1066 (const G4PhysicalVolumeModel::G4PhysicalVol 1043 (const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID& right) const 1067 { 1044 { 1068 if (fpPV != right.fpPV || 1045 if (fpPV != right.fpPV || 1069 fCopyNo != right.fCopyNo || 1046 fCopyNo != right.fCopyNo || 1070 fNonCulledDepth != right.fNonCulledDept 1047 fNonCulledDepth != right.fNonCulledDepth || 1071 fTransform != right.fTransform || 1048 fTransform != right.fTransform || 1072 fDrawn != right.fDrawn) return 1049 fDrawn != right.fDrawn) return true; 1073 return false; 1050 return false; 1074 } 1051 } 1075 1052 1076 std::ostream& operator<< 1053 std::ostream& operator<< 1077 (std::ostream& os, const G4PhysicalVolumeMo 1054 (std::ostream& os, const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID& node) 1078 { 1055 { 1079 G4VPhysicalVolume* pPV = node.GetPhysicalVo 1056 G4VPhysicalVolume* pPV = node.GetPhysicalVolume(); 1080 if (pPV) { 1057 if (pPV) { 1081 os << pPV->GetName() 1058 os << pPV->GetName() 1082 << ' ' << node.GetCopyNo() 1059 << ' ' << node.GetCopyNo() 1083 // << '[' << node.GetNonCulledDepth() < 1060 // << '[' << node.GetNonCulledDepth() << ']' 1084 // << ':' << node.GetTransform() 1061 // << ':' << node.GetTransform() 1085 ; 1062 ; 1086 // os << " ("; 1063 // os << " ("; 1087 // if (!node.GetDrawn()) os << "not "; 1064 // if (!node.GetDrawn()) os << "not "; 1088 // os << "drawn)"; 1065 // os << "drawn)"; 1089 } else { 1066 } else { 1090 os << " (Null PV node)"; 1067 os << " (Null PV node)"; 1091 } 1068 } 1092 return os; 1069 return os; 1093 } 1070 } 1094 1071 1095 std::ostream& operator<< 1072 std::ostream& operator<< 1096 (std::ostream& os, const std::vector<G4Physic 1073 (std::ostream& os, const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& path) 1097 { 1074 { 1098 if (path.empty()) { 1075 if (path.empty()) { 1099 os << " TOP"; 1076 os << " TOP"; 1100 } else { 1077 } else { 1101 for (const auto& nodeID: path) { 1078 for (const auto& nodeID: path) { 1102 os << ' ' << nodeID; 1079 os << ' ' << nodeID; 1103 } 1080 } 1104 } 1081 } 1105 return os; 1082 return os; 1106 } 1083 } 1107 1084 1108 G4PhysicalVolumeModel::G4PhysicalVolumeModelT 1085 G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::G4PhysicalVolumeModelTouchable 1109 (const std::vector<G4PhysicalVolumeNodeID>& f 1086 (const std::vector<G4PhysicalVolumeNodeID>& fullPVPath): 1110 fFullPVPath(fullPVPath) {} 1087 fFullPVPath(fullPVPath) {} 1111 1088 1112 const G4ThreeVector& G4PhysicalVolumeModel::G 1089 const G4ThreeVector& G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetTranslation(G4int depth) const 1113 { 1090 { 1114 size_t i = fFullPVPath.size() - depth - 1; 1091 size_t i = fFullPVPath.size() - depth - 1; 1115 if (i >= fFullPVPath.size()) { 1092 if (i >= fFullPVPath.size()) { 1116 G4Exception("G4PhysicalVolumeModelTouchab 1093 G4Exception("G4PhysicalVolumeModelTouchable::GetTranslation", 1117 "modeling0005", 1094 "modeling0005", 1118 FatalErrorInArgument, 1095 FatalErrorInArgument, 1119 "Index out of range. Asking for non-exist 1096 "Index out of range. Asking for non-existent depth"); 1120 } 1097 } 1121 static G4ThreeVector tempTranslation; 1098 static G4ThreeVector tempTranslation; 1122 tempTranslation = fFullPVPath[i].GetTransfo 1099 tempTranslation = fFullPVPath[i].GetTransform().getTranslation(); 1123 return tempTranslation; 1100 return tempTranslation; 1124 } 1101 } 1125 1102 1126 const G4RotationMatrix* G4PhysicalVolumeModel 1103 const G4RotationMatrix* G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetRotation(G4int depth) const 1127 { 1104 { 1128 size_t i = fFullPVPath.size() - depth - 1; 1105 size_t i = fFullPVPath.size() - depth - 1; 1129 if (i >= fFullPVPath.size()) { 1106 if (i >= fFullPVPath.size()) { 1130 G4Exception("G4PhysicalVolumeModelTouchab 1107 G4Exception("G4PhysicalVolumeModelTouchable::GetRotation", 1131 "modeling0006", 1108 "modeling0006", 1132 FatalErrorInArgument, 1109 FatalErrorInArgument, 1133 "Index out of range. Asking for non-exist 1110 "Index out of range. Asking for non-existent depth"); 1134 } 1111 } 1135 static G4RotationMatrix tempRotation; 1112 static G4RotationMatrix tempRotation; 1136 tempRotation = fFullPVPath[i].GetTransform( 1113 tempRotation = fFullPVPath[i].GetTransform().getRotation(); 1137 return &tempRotation; 1114 return &tempRotation; 1138 } 1115 } 1139 1116 1140 G4VPhysicalVolume* G4PhysicalVolumeModel::G4P 1117 G4VPhysicalVolume* G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetVolume(G4int depth) const 1141 { 1118 { 1142 size_t i = fFullPVPath.size() - depth - 1; 1119 size_t i = fFullPVPath.size() - depth - 1; 1143 if (i >= fFullPVPath.size()) { 1120 if (i >= fFullPVPath.size()) { 1144 G4Exception("G4PhysicalVolumeModelTouchab 1121 G4Exception("G4PhysicalVolumeModelTouchable::GetVolume", 1145 "modeling0007", 1122 "modeling0007", 1146 FatalErrorInArgument, 1123 FatalErrorInArgument, 1147 "Index out of range. Asking for non-exist 1124 "Index out of range. Asking for non-existent depth"); 1148 } 1125 } 1149 return fFullPVPath[i].GetPhysicalVolume(); 1126 return fFullPVPath[i].GetPhysicalVolume(); 1150 } 1127 } 1151 1128 1152 G4VSolid* G4PhysicalVolumeModel::G4PhysicalVo 1129 G4VSolid* G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetSolid(G4int depth) const 1153 { 1130 { 1154 size_t i = fFullPVPath.size() - depth - 1; 1131 size_t i = fFullPVPath.size() - depth - 1; 1155 if (i >= fFullPVPath.size()) { 1132 if (i >= fFullPVPath.size()) { 1156 G4Exception("G4PhysicalVolumeModelTouchab 1133 G4Exception("G4PhysicalVolumeModelTouchable::GetSolid", 1157 "modeling0008", 1134 "modeling0008", 1158 FatalErrorInArgument, 1135 FatalErrorInArgument, 1159 "Index out of range. Asking for non-exist 1136 "Index out of range. Asking for non-existent depth"); 1160 } 1137 } 1161 return fFullPVPath[i].GetPhysicalVolume()-> 1138 return fFullPVPath[i].GetPhysicalVolume()->GetLogicalVolume()->GetSolid(); 1162 } 1139 } 1163 1140 1164 G4int G4PhysicalVolumeModel::G4PhysicalVolume 1141 G4int G4PhysicalVolumeModel::G4PhysicalVolumeModelTouchable::GetReplicaNumber(G4int depth) const 1165 { 1142 { 1166 size_t i = fFullPVPath.size() - depth - 1; 1143 size_t i = fFullPVPath.size() - depth - 1; 1167 if (i >= fFullPVPath.size()) { 1144 if (i >= fFullPVPath.size()) { 1168 G4Exception("G4PhysicalVolumeModelTouchab 1145 G4Exception("G4PhysicalVolumeModelTouchable::GetReplicaNumber", 1169 "modeling0009", 1146 "modeling0009", 1170 FatalErrorInArgument, 1147 FatalErrorInArgument, 1171 "Index out of range. Asking for non-exist 1148 "Index out of range. Asking for non-existent depth"); 1172 } 1149 } 1173 return fFullPVPath[i].GetCopyNo(); 1150 return fFullPVPath[i].GetCopyNo(); 1174 } 1151 } 1175 1152