Geant4  10.01.p02
G4LogicalVolumeModel.cc
Go to the documentation of this file.
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 66373 2012-12-18 09:41:34Z gcosmo $
28 //
29 //
30 // John Allison 26th July 1999.
31 // Model for logical volumes.
32 
33 #include "G4LogicalVolumeModel.hh"
34 
35 #include "G4VSolid.hh"
36 #include "G4LogicalVolume.hh"
37 #include "G4PVPlacement.hh"
38 #include "G4ModelingParameters.hh"
39 #include "G4VGraphicsScene.hh"
40 #include "G4DrawVoxels.hh"
41 #include "G4VSensitiveDetector.hh"
42 #include "G4VReadOutGeometry.hh"
43 
46  G4int soughtDepth,
47  G4bool booleans,
48  G4bool voxels,
49  G4bool readout,
50  const G4Transform3D& modelTransformation,
51  const G4ModelingParameters* pMP):
52  // Instantiate a G4PhysicalVolumeModel with a G4PVPlacement to
53  // represent this logical volume. It has no rotation and a null
54  // translation so that the logical volume will be seen in its own
55  // reference system. It will be added to the physical volume store
56  // but it will not be part of the normal geometry heirarchy so it
57  // has no mother.
59 (new G4PVPlacement (0, // No rotation.
60  G4ThreeVector(), // Null traslation.
61  "PhysVol representation of LogVol " + pLV -> GetName (),
62  pLV,
63  0, // No mother.
64  false, // Not "MANY".
65  0), // Copy number.
66  soughtDepth,
67  modelTransformation,
68  pMP,
69  true), // Use full extent.
70  fpLV (pLV),
71  fBooleans (booleans),
72  fVoxels (voxels),
73  fReadout (readout)
74 {
75  fType = "G4LogicalVolumeModel";
76  fGlobalTag = fpLV -> GetName ();
77  fGlobalDescription = "G4LogicalVolumeModel " + fGlobalTag;
78 }
79 
81 
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;
92  fpMP = tmpMP;
93 
94  if (fVoxels) {
95  if (fpTopPV->GetLogicalVolume()->GetVoxelHeader()) {
96  // Add Voxels.
97  G4DrawVoxels dv;
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.
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) {
145  ("G4PhysicalVolumeModel::DescribeSolid",
146  "modeling0001", FatalException,
147  "2nd component solid in Boolean is missing.");
148  }
149  // Draw these constituents white and "forced wireframe"...
150  G4VisAttributes constituentAttributes;
151  constituentAttributes.SetForceWireframe(true);
152  DescribeSolid (theAT, pSol0, &constituentAttributes, sceneHandler);
153  DescribeSolid (theAT, pSol1, &constituentAttributes, sceneHandler);
154  }
155  }
156 
157  // In any case draw the original/resultant solid...
158  sceneHandler.PreAddSolid (theAT, *pVisAttribs);
159  pSol -> DescribeYourselfTo (sceneHandler);
160  sceneHandler.PostAddSolid ();
161 }
virtual void PostAddSolid()=0
void DescribeYourselfTo(G4VGraphicsScene &)
void SetForceWireframe(G4bool)
CLHEP::Hep3Vector G4ThreeVector
void DescribeSolid(const G4Transform3D &theAT, G4VSolid *pSol, const G4VisAttributes *pVisAttribs, G4VGraphicsScene &sceneHandler)
G4PlacedPolyhedronList * CreatePlacedPolyhedra(const G4LogicalVolume *) const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())=0
G4LogicalVolumeModel(G4LogicalVolume *, G4int soughtDepth=1, G4bool booleans=true, G4bool voxels=true, G4bool readout=true, const G4Transform3D &modelTransformation=G4Transform3D(), const G4ModelingParameters *=0)
int G4int
Definition: G4Types.hh:78
void SetModelingParameters(const G4ModelingParameters *)
virtual void AddPrimitive(const G4Polyline &)=0
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
bool G4bool
Definition: G4Types.hh:79
G4String GetName() const
void SetCulling(G4bool)
G4VReadOutGeometry * GetROgeometry() const
HepGeom::Transform3D G4Transform3D
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &visAttribs)=0
#define G4endl
Definition: G4ios.hh:61
virtual void EndPrimitives()=0
void DescribeYourselfTo(G4VGraphicsScene &)
std::vector< G4PlacedPolyhedron > G4PlacedPolyhedronList
G4VPhysicalVolume * GetROWorld() const