[834] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: G4LogicalVolumeModel.cc,v 1.14 2006/11/01 10:28:42 allison Exp $ |
---|
[850] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[834] | 29 | // |
---|
| 30 | // |
---|
| 31 | // John Allison 26th July 1999. |
---|
| 32 | // Model for logical volumes. |
---|
| 33 | |
---|
| 34 | #include "G4LogicalVolumeModel.hh" |
---|
| 35 | |
---|
| 36 | #include "G4VSolid.hh" |
---|
| 37 | #include "G4LogicalVolume.hh" |
---|
| 38 | #include "G4PVPlacement.hh" |
---|
| 39 | #include "G4ModelingParameters.hh" |
---|
| 40 | #include "G4VGraphicsScene.hh" |
---|
| 41 | #include "G4DrawVoxels.hh" |
---|
| 42 | #include "G4VSensitiveDetector.hh" |
---|
| 43 | #include "G4VReadOutGeometry.hh" |
---|
| 44 | |
---|
| 45 | G4LogicalVolumeModel::G4LogicalVolumeModel |
---|
| 46 | (G4LogicalVolume* pLV, |
---|
| 47 | G4int soughtDepth, |
---|
| 48 | G4bool booleans, |
---|
| 49 | G4bool voxels, |
---|
| 50 | G4bool readout, |
---|
| 51 | const G4Transform3D& modelTransformation, |
---|
| 52 | const G4ModelingParameters* pMP): |
---|
| 53 | // Instantiate a G4PhysicalVolumeModel with a G4PVPlacement to |
---|
| 54 | // represent this logical volume. It has no rotation and a null |
---|
| 55 | // translation so that the logical volume will be seen in its own |
---|
| 56 | // reference system. It will be added to the physical volume store |
---|
| 57 | // but it will not be part of the normal geometry heirarchy so it |
---|
| 58 | // has no mother. |
---|
| 59 | G4PhysicalVolumeModel |
---|
| 60 | (new G4PVPlacement (0, // No rotation. |
---|
| 61 | G4ThreeVector(), // Null traslation. |
---|
| 62 | "PhysVol representaion of LogVol " + pLV -> GetName (), |
---|
| 63 | pLV, |
---|
| 64 | 0, // No mother. |
---|
| 65 | false, // Not "MANY". |
---|
| 66 | 0), // Copy number. |
---|
| 67 | soughtDepth, |
---|
| 68 | modelTransformation, |
---|
| 69 | pMP, |
---|
| 70 | true), // Use full extent. |
---|
| 71 | fpLV (pLV), |
---|
| 72 | fBooleans (booleans), |
---|
| 73 | fVoxels (voxels), |
---|
| 74 | fReadout (readout) |
---|
| 75 | { |
---|
| 76 | fGlobalTag = fpLV -> GetName (); |
---|
| 77 | fGlobalDescription = "G4LogicalVolumeModel " + fGlobalTag; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | G4LogicalVolumeModel::~G4LogicalVolumeModel () {} |
---|
| 81 | |
---|
| 82 | void G4LogicalVolumeModel::DescribeYourselfTo |
---|
| 83 | (G4VGraphicsScene& sceneHandler) { |
---|
| 84 | |
---|
| 85 | // Store current modeling parameters and ensure nothing is culled. |
---|
| 86 | const G4ModelingParameters* tmpMP = fpMP; |
---|
| 87 | G4ModelingParameters nonCulledMP; |
---|
| 88 | if (fpMP) nonCulledMP = *fpMP; |
---|
| 89 | nonCulledMP.SetCulling (false); |
---|
| 90 | fpMP = &nonCulledMP; |
---|
| 91 | G4PhysicalVolumeModel::DescribeYourselfTo (sceneHandler); |
---|
| 92 | fpMP = tmpMP; |
---|
| 93 | |
---|
| 94 | if (fVoxels) { |
---|
| 95 | if (fpTopPV->GetLogicalVolume()->GetVoxelHeader()) { |
---|
| 96 | // Add Voxels. |
---|
| 97 | G4DrawVoxels dv; |
---|
| 98 | G4PlacedPolyhedronList* pPPL = |
---|
| 99 | dv.CreatePlacedPolyhedra (fpTopPV -> GetLogicalVolume ()); |
---|
| 100 | for (size_t i = 0; i < pPPL -> size (); i++) { |
---|
| 101 | const G4Transform3D& transform = (*pPPL)[i].GetTransform (); |
---|
| 102 | const G4Polyhedron& polyhedron = (*pPPL)[i].GetPolyhedron (); |
---|
| 103 | sceneHandler.BeginPrimitives (transform); |
---|
| 104 | sceneHandler.AddPrimitive (polyhedron); |
---|
| 105 | sceneHandler.EndPrimitives (); |
---|
| 106 | } |
---|
| 107 | delete pPPL; |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | if (fReadout) { |
---|
| 112 | // Draw readout geometry... |
---|
| 113 | G4VSensitiveDetector* sd = fpLV->GetSensitiveDetector(); |
---|
| 114 | if (sd) { |
---|
| 115 | G4VReadOutGeometry* roGeom = sd->GetROgeometry(); |
---|
| 116 | if (roGeom) { |
---|
| 117 | G4VPhysicalVolume* roWorld = roGeom->GetROWorld(); |
---|
| 118 | G4cout << "Readout geometry \"" << roGeom->GetName() |
---|
| 119 | << "\" with top physical volume \"" |
---|
| 120 | << roWorld->GetName() |
---|
| 121 | << "\"" << G4endl; |
---|
| 122 | G4PhysicalVolumeModel pvModel(roWorld); |
---|
| 123 | pvModel.SetModelingParameters(fpMP); |
---|
| 124 | pvModel.DescribeYourselfTo(sceneHandler); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | // This called from G4PhysicalVolumeModel::DescribeAndDescend by the |
---|
| 131 | // virtual function mechanism. |
---|
| 132 | void G4LogicalVolumeModel::DescribeSolid |
---|
| 133 | (const G4Transform3D& theAT, |
---|
| 134 | G4VSolid* pSol, |
---|
| 135 | const G4VisAttributes* pVisAttribs, |
---|
| 136 | G4VGraphicsScene& sceneHandler) { |
---|
| 137 | |
---|
| 138 | if (fBooleans) { |
---|
| 139 | // Look for "constituents". Could be a Boolean solid. |
---|
| 140 | G4VSolid* pSol0 = pSol -> GetConstituentSolid (0); |
---|
| 141 | if (pSol0) { // Composite solid... |
---|
| 142 | G4VSolid* pSol1 = pSol -> GetConstituentSolid (1); |
---|
| 143 | if (!pSol1) { |
---|
| 144 | G4Exception |
---|
| 145 | ("G4PhysicalVolumeModel::DescribeSolid:" |
---|
| 146 | " 2nd component solid is missing."); |
---|
| 147 | } |
---|
| 148 | // Draw these constituents white and "forced wireframe"... |
---|
| 149 | G4VisAttributes constituentAttributes; |
---|
| 150 | constituentAttributes.SetForceWireframe(true); |
---|
| 151 | DescribeSolid (theAT, pSol0, &constituentAttributes, sceneHandler); |
---|
| 152 | DescribeSolid (theAT, pSol1, &constituentAttributes, sceneHandler); |
---|
| 153 | } |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | // In any case draw the original/resultant solid... |
---|
| 157 | sceneHandler.PreAddSolid (theAT, *pVisAttribs); |
---|
| 158 | pSol -> DescribeYourselfTo (sceneHandler); |
---|
| 159 | sceneHandler.PostAddSolid (); |
---|
| 160 | } |
---|