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 // $Id: G4LogicalVolumeModel.cc,v 1.14 2006/11/01 10:28:42 allison Exp $ >> 28 // GEANT4 tag $Name: geant4-09-03-patch-02 $ 27 // 29 // 28 // 30 // 29 // John Allison 26th July 1999. 31 // John Allison 26th July 1999. 30 // Model for logical volumes. 32 // Model for logical volumes. 31 33 32 #include "G4LogicalVolumeModel.hh" 34 #include "G4LogicalVolumeModel.hh" 33 35 34 #include "G4VSolid.hh" 36 #include "G4VSolid.hh" 35 #include "G4LogicalVolume.hh" 37 #include "G4LogicalVolume.hh" 36 #include "G4PVPlacement.hh" 38 #include "G4PVPlacement.hh" 37 #include "G4PVParameterised.hh" << 38 #include "G4VPVParameterisation.hh" << 39 #include "G4ModelingParameters.hh" 39 #include "G4ModelingParameters.hh" 40 #include "G4VGraphicsScene.hh" 40 #include "G4VGraphicsScene.hh" 41 #include "G4DrawVoxels.hh" 41 #include "G4DrawVoxels.hh" 42 #include "G4VSensitiveDetector.hh" 42 #include "G4VSensitiveDetector.hh" 43 #include "G4VReadOutGeometry.hh" 43 #include "G4VReadOutGeometry.hh" 44 #include "G4Circle.hh" << 45 << 46 #include <vector> << 47 #include <utility> << 48 44 49 G4LogicalVolumeModel::G4LogicalVolumeModel 45 G4LogicalVolumeModel::G4LogicalVolumeModel 50 (G4LogicalVolume* pLV, 46 (G4LogicalVolume* pLV, 51 G4int soughtDepth, 47 G4int soughtDepth, 52 G4bool booleans, 48 G4bool booleans, 53 G4bool voxels, 49 G4bool voxels, 54 G4bool readout, 50 G4bool readout, 55 G4bool checkOverlaps, << 56 const G4Transform3D& modelTransformati 51 const G4Transform3D& modelTransformation, 57 const G4ModelingParameters* pMP): 52 const G4ModelingParameters* pMP): 58 // Instantiate a G4PhysicalVolumeModel with 53 // Instantiate a G4PhysicalVolumeModel with a G4PVPlacement to 59 // represent this logical volume. It has no 54 // represent this logical volume. It has no rotation and a null 60 // translation so that the logical volume wi 55 // translation so that the logical volume will be seen in its own 61 // reference system. It will be added to th 56 // reference system. It will be added to the physical volume store 62 // but it will not be part of the normal geo 57 // but it will not be part of the normal geometry heirarchy so it 63 // has no mother. 58 // has no mother. 64 G4PhysicalVolumeModel 59 G4PhysicalVolumeModel 65 (new G4PVPlacement (0, // No 60 (new G4PVPlacement (0, // No rotation. 66 G4ThreeVector(), // Null traslatio 61 G4ThreeVector(), // Null traslation. 67 "PhysVol representation of LogVol " + << 62 "PhysVol representaion of LogVol " + pLV -> GetName (), 68 pLV, 63 pLV, 69 0, // No mother. 64 0, // No mother. 70 false, // Not "MANY". 65 false, // Not "MANY". 71 0), // Copy number. 66 0), // Copy number. 72 soughtDepth, 67 soughtDepth, 73 modelTransformation, 68 modelTransformation, 74 pMP, 69 pMP, 75 true), // Us 70 true), // Use full extent. 76 fpLV (pLV), 71 fpLV (pLV), 77 fBooleans (booleans), 72 fBooleans (booleans), 78 fVoxels (voxels), 73 fVoxels (voxels), 79 fReadout (readout), << 74 fReadout (readout) 80 fCheckOverlaps(checkOverlaps), << 81 fOverlapsPrinted(false) << 82 { 75 { 83 fType = "G4LogicalVolumeModel"; << 84 fGlobalTag = fpLV -> GetName (); 76 fGlobalTag = fpLV -> GetName (); 85 fGlobalDescription = "G4LogicalVolumeModel " 77 fGlobalDescription = "G4LogicalVolumeModel " + fGlobalTag; 86 } 78 } 87 79 88 G4LogicalVolumeModel::~G4LogicalVolumeModel () 80 G4LogicalVolumeModel::~G4LogicalVolumeModel () {} 89 81 90 namespace { << 91 // Vis attributes << 92 const G4Colour highlightSolidColour(1.0,0.8, << 93 const G4double highlightSolidLineWidth(10./* << 94 const G4Colour highlightPointColour(0.5,0.5, << 95 const G4double highlightPointDiameter(20./*p << 96 // Keep a vector of solid-copy number pairs << 97 typedef std::pair<G4VSolid*,G4int> solidCopy << 98 std::vector<solidCopyNoPair> solidCopyNoVect << 99 void DrawSolid << 100 (G4VGraphicsScene& sceneHandler, << 101 G4VSolid* sol, G4int copyNo, const G4Transf << 102 // Avoid duplication. << 103 std::pair<G4VSolid*,G4int> pair(sol,copyNo << 104 auto iter = solidCopyNoVector.begin(); << 105 for ( ; iter != solidCopyNoVector.end(); + << 106 if (*iter == pair) break; << 107 } << 108 if (iter == solidCopyNoVector.end()) { << 109 solidCopyNoVector.push_back(pair); << 110 G4VisAttributes highlightSolidVisAtts(hi << 111 highlightSolidVisAtts.SetLineWidth(highl << 112 sceneHandler.PreAddSolid(t,highlightSoli << 113 sceneHandler.AddSolid(*sol); << 114 sceneHandler.PostAddSolid(); << 115 } << 116 } << 117 void DrawPoint << 118 (G4VGraphicsScene& sceneHandler, << 119 const G4ThreeVector& point) { << 120 G4VisAttributes highlightPointVisAtts(high << 121 G4Circle overlapPoint; << 122 overlapPoint.SetVisAttributes(highlightPoi << 123 overlapPoint.SetPosition(point); << 124 overlapPoint.SetDiameter(G4VMarker::SizeTy << 125 overlapPoint.SetFillStyle(G4VMarker::FillS << 126 sceneHandler.BeginPrimitives(); << 127 sceneHandler.AddPrimitive(overlapPoint); << 128 sceneHandler.EndPrimitives(); << 129 } << 130 } << 131 << 132 void G4LogicalVolumeModel::DescribeYourselfTo 82 void G4LogicalVolumeModel::DescribeYourselfTo 133 (G4VGraphicsScene& sceneHandler) { 83 (G4VGraphicsScene& sceneHandler) { 134 84 135 // Store current modeling parameters and ens 85 // Store current modeling parameters and ensure nothing is culled. 136 const G4ModelingParameters* tmpMP = fpMP; 86 const G4ModelingParameters* tmpMP = fpMP; 137 G4ModelingParameters nonCulledMP; 87 G4ModelingParameters nonCulledMP; 138 if (fpMP) nonCulledMP = *fpMP; 88 if (fpMP) nonCulledMP = *fpMP; 139 nonCulledMP.SetCulling (false); 89 nonCulledMP.SetCulling (false); 140 fpMP = &nonCulledMP; 90 fpMP = &nonCulledMP; 141 G4PhysicalVolumeModel::DescribeYourselfTo (s 91 G4PhysicalVolumeModel::DescribeYourselfTo (sceneHandler); 142 fpMP = tmpMP; 92 fpMP = tmpMP; 143 93 144 if (fVoxels) { 94 if (fVoxels) { 145 if (fpTopPV->GetLogicalVolume()->GetVoxelH 95 if (fpTopPV->GetLogicalVolume()->GetVoxelHeader()) { 146 // Add Voxels. 96 // Add Voxels. 147 G4DrawVoxels dv; 97 G4DrawVoxels dv; 148 G4PlacedPolyhedronList* pPPL = 98 G4PlacedPolyhedronList* pPPL = 149 dv.CreatePlacedPolyhedra (fpTopPV -> GetLogi 99 dv.CreatePlacedPolyhedra (fpTopPV -> GetLogicalVolume ()); 150 for (size_t i = 0; i < pPPL -> size (); 100 for (size_t i = 0; i < pPPL -> size (); i++) { 151 const G4Transform3D& transform = (*pPPL)[i]. 101 const G4Transform3D& transform = (*pPPL)[i].GetTransform (); 152 const G4Polyhedron& polyhedron = (*pPPL)[i]. 102 const G4Polyhedron& polyhedron = (*pPPL)[i].GetPolyhedron (); 153 sceneHandler.BeginPrimitives (transform); 103 sceneHandler.BeginPrimitives (transform); 154 sceneHandler.AddPrimitive (polyhedron); 104 sceneHandler.AddPrimitive (polyhedron); 155 sceneHandler.EndPrimitives (); 105 sceneHandler.EndPrimitives (); 156 } 106 } 157 delete pPPL; 107 delete pPPL; 158 } 108 } 159 } 109 } 160 110 161 if (fReadout) { 111 if (fReadout) { 162 // Draw readout geometry... 112 // Draw readout geometry... 163 G4VSensitiveDetector* sd = fpLV->GetSensit 113 G4VSensitiveDetector* sd = fpLV->GetSensitiveDetector(); 164 if (sd) { 114 if (sd) { 165 G4VReadOutGeometry* roGeom = sd->GetROge 115 G4VReadOutGeometry* roGeom = sd->GetROgeometry(); 166 if (roGeom) { 116 if (roGeom) { 167 G4VPhysicalVolume* roWorld = roGeom->GetROWo 117 G4VPhysicalVolume* roWorld = roGeom->GetROWorld(); 168 // G4cout << "Readout geometry \"" << roGeom- << 118 G4cout << "Readout geometry \"" << roGeom->GetName() 169 // << "\" with top physical volume \"" << 119 << "\" with top physical volume \"" 170 // << roWorld->GetName() << 120 << roWorld->GetName() 171 // << "\"" << G4endl; << 121 << "\"" << G4endl; 172 G4PhysicalVolumeModel pvModel(roWorld); 122 G4PhysicalVolumeModel pvModel(roWorld); 173 pvModel.SetModelingParameters(fpMP); 123 pvModel.SetModelingParameters(fpMP); 174 pvModel.DescribeYourselfTo(sceneHandler); 124 pvModel.DescribeYourselfTo(sceneHandler); 175 } 125 } 176 } 126 } 177 } 127 } 178 << 179 if (fCheckOverlaps) { << 180 G4LogicalVolume* motherLog = fpTopPV->GetL << 181 G4VSolid* motherSolid = motherLog->GetSoli << 182 G4int nDaughters = (G4int)motherLog->GetNo << 183 << 184 // Models are called repeatedly by the sce << 185 // Print overlaps - but only the first tim << 186 if (!fOverlapsPrinted) { << 187 for (G4int iDaughter = 0; iDaughter < nD << 188 G4VPhysicalVolume* daughterPhys = moth << 189 daughterPhys->CheckOverlaps(); << 190 } << 191 fOverlapsPrinted = true; << 192 } << 193 << 194 // Draw overlaps << 195 solidCopyNoVector.clear(); << 196 for (G4int iDaughter = 0; iDaughter < nDau << 197 G4VPhysicalVolume* daughterPhys = mother << 198 G4PVPlacement* daughterPVPlace = dynamic << 199 G4PVParameterised* daughterPVParam = dyn << 200 const G4int nPoints = 1000; << 201 << 202 if (daughterPVPlace) { << 203 << 204 // This algorithm is based on G4PVPlac << 205 G4AffineTransform tDaughter(daughterPh << 206 G4VSolid* daughterSolid = daughterPhys << 207 for (G4int i = 0; i < nPoints; ++i) { << 208 G4ThreeVector point = daughterSolid- << 209 // Transform to mother's coordinate << 210 G4ThreeVector motherPoint = tDaughte << 211 // Check overlaps with the mother vo << 212 if (motherSolid->Inside(motherPoint) << 213 // Draw mother and daughter and po << 214 DrawSolid(sceneHandler,motherSolid << 215 DrawSolid(sceneHandler,daughterSol << 216 DrawPoint(sceneHandler,motherPoint << 217 } << 218 // Check other daughters << 219 for (G4int iSister = 0; iSister < nD << 220 if (iSister == iDaughter) continue << 221 G4VPhysicalVolume* sisterPhys = mo << 222 G4AffineTransform tSister(sisterPh << 223 // Transform to sister's coordinat << 224 G4ThreeVector sisterPoint = tSiste << 225 G4LogicalVolume* sisterLog = siste << 226 G4VSolid* sisterSolid = sisterLog- << 227 if (sisterSolid->Inside(sisterPoin << 228 // Draw daughter and sister and << 229 DrawSolid(sceneHandler,daughterS << 230 DrawSolid(sceneHandler,sisterSol << 231 DrawPoint(sceneHandler,motherPoi << 232 } << 233 } << 234 } << 235 << 236 } else if (daughterPVParam) { << 237 << 238 // This algorithm is based on G4PVPara << 239 const G4int multiplicity = daughterPVP << 240 auto* param = daughterPVParam->GetPara << 241 // Cache points for later checking aga << 242 std::vector<G4ThreeVector> motherPoint << 243 for (G4int iP = 0; iP < multiplicity; << 244 G4VSolid* daughterSolid = param->Com << 245 daughterSolid->ComputeDimensions(par << 246 param->ComputeTransformation(iP, dau << 247 G4AffineTransform tDaughter(daughter << 248 for (G4int i = 0; i < nPoints; ++i) << 249 G4ThreeVector point = daughterSoli << 250 // Transform to mother's coordinat << 251 G4ThreeVector motherPoint = tDaugh << 252 // Check overlaps with the mother << 253 if (motherSolid->Inside(motherPoin << 254 // Draw mother and daughter and << 255 DrawSolid(sceneHandler,motherSol << 256 DrawSolid(sceneHandler,daughterS << 257 DrawPoint(sceneHandler,motherPoi << 258 } << 259 motherPoints.push_back(motherPoint << 260 } << 261 // Check sister parameterisations << 262 for (G4int iPP = iP + 1; iPP < multi << 263 G4VSolid* sisterSolid = param->Com << 264 sisterSolid->ComputeDimensions(par << 265 param->ComputeTransformation(iPP, << 266 G4AffineTransform tSister << 267 (daughterPVParam->GetRotation(),da << 268 for (const auto& motherPoint: moth << 269 // Transform each point into dau << 270 G4ThreeVector sisterPoint = tSis << 271 if (sisterSolid->Inside(sisterPo << 272 // Draw sister << 273 DrawSolid(sceneHandler,sisterS << 274 // Recompute daughter paramete << 275 daughterSolid->ComputeDimensio << 276 param->ComputeTransformation(i << 277 tDaughter = G4AffineTransform << 278 (daughterPVParam->GetRotation( << 279 DrawSolid(sceneHandler,daughte << 280 DrawPoint(sceneHandler,motherP << 281 } << 282 } << 283 } << 284 } << 285 } << 286 } << 287 } << 288 } 128 } 289 129 290 // This called from G4PhysicalVolumeModel::Des 130 // This called from G4PhysicalVolumeModel::DescribeAndDescend by the 291 // virtual function mechanism. 131 // virtual function mechanism. 292 void G4LogicalVolumeModel::DescribeSolid 132 void G4LogicalVolumeModel::DescribeSolid 293 (const G4Transform3D& theAT, 133 (const G4Transform3D& theAT, 294 G4VSolid* pSol, 134 G4VSolid* pSol, 295 const G4VisAttributes* pVisAttribs, 135 const G4VisAttributes* pVisAttribs, 296 G4VGraphicsScene& sceneHandler) { 136 G4VGraphicsScene& sceneHandler) { 297 137 298 if (fBooleans) { 138 if (fBooleans) { 299 // Look for "constituents". Could be a Bo 139 // Look for "constituents". Could be a Boolean solid. 300 G4VSolid* pSol0 = pSol -> GetConstituentSo 140 G4VSolid* pSol0 = pSol -> GetConstituentSolid (0); 301 if (pSol0) { // Composite solid... 141 if (pSol0) { // Composite solid... 302 G4VSolid* pSol1 = pSol -> GetConstituent 142 G4VSolid* pSol1 = pSol -> GetConstituentSolid (1); 303 if (!pSol1) { 143 if (!pSol1) { 304 G4Exception 144 G4Exception 305 ("G4PhysicalVolumeModel::DescribeSolid", << 145 ("G4PhysicalVolumeModel::DescribeSolid:" 306 "modeling0001", FatalException, << 146 " 2nd component solid is missing."); 307 "2nd component solid in Boolean is missin << 308 } 147 } 309 // Draw these constituents white and "fo 148 // Draw these constituents white and "forced wireframe"... 310 G4VisAttributes constituentAttributes; 149 G4VisAttributes constituentAttributes; 311 constituentAttributes.SetForceWireframe( 150 constituentAttributes.SetForceWireframe(true); 312 DescribeSolid (theAT, pSol0, &constituen 151 DescribeSolid (theAT, pSol0, &constituentAttributes, sceneHandler); 313 DescribeSolid (theAT, pSol1, &constituen 152 DescribeSolid (theAT, pSol1, &constituentAttributes, sceneHandler); 314 } 153 } 315 } 154 } 316 155 317 // In any case draw the original/resultant s 156 // In any case draw the original/resultant solid... 318 sceneHandler.PreAddSolid (theAT, *pVisAttrib 157 sceneHandler.PreAddSolid (theAT, *pVisAttribs); 319 pSol -> DescribeYourselfTo (sceneHandler); 158 pSol -> DescribeYourselfTo (sceneHandler); 320 sceneHandler.PostAddSolid (); 159 sceneHandler.PostAddSolid (); 321 } 160 } 322 161