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 $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
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 | |
---|
99 | // FIXME : LG 1 May 2009 : return a pointer...should be destroy by the compiler |
---|
100 | G4PlacedPolyhedronList* pPPL = |
---|
101 | dv.CreatePlacedPolyhedra (fpTopPV -> GetLogicalVolume ()); |
---|
102 | for (size_t i = 0; i < pPPL -> size (); i++) { |
---|
103 | const G4Transform3D& transform = (*pPPL)[i].GetTransform (); |
---|
104 | const G4Polyhedron& polyhedron = (*pPPL)[i].GetPolyhedron (); |
---|
105 | sceneHandler.BeginPrimitives (transform); |
---|
106 | printf("G4LogicalVolumeModel::DescribeYourselfTo BEFORE ADD %d\n",fpTopPV -> GetLogicalVolume ()); |
---|
107 | if (&polyhedron) { |
---|
108 | printf("G4LogicalVolumeModel::DescribeYourselfTo poly FAILED\n"); |
---|
109 | } else { |
---|
110 | printf("G4LogicalVolumeModel::DescribeYourselfTo poly OK\n"); |
---|
111 | } |
---|
112 | sceneHandler.AddPrimitive (polyhedron); |
---|
113 | printf("G4LogicalVolumeModel::DescribeYourselfTo AFTER ADD\n"); |
---|
114 | sceneHandler.EndPrimitives (); |
---|
115 | } |
---|
116 | delete pPPL; |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | if (fReadout) { |
---|
121 | // Draw readout geometry... |
---|
122 | G4VSensitiveDetector* sd = fpLV->GetSensitiveDetector(); |
---|
123 | if (sd) { |
---|
124 | G4VReadOutGeometry* roGeom = sd->GetROgeometry(); |
---|
125 | if (roGeom) { |
---|
126 | G4VPhysicalVolume* roWorld = roGeom->GetROWorld(); |
---|
127 | G4cout << "Readout geometry \"" << roGeom->GetName() |
---|
128 | << "\" with top physical volume \"" |
---|
129 | << roWorld->GetName() |
---|
130 | << "\"" << G4endl; |
---|
131 | G4PhysicalVolumeModel pvModel(roWorld); |
---|
132 | pvModel.SetModelingParameters(fpMP); |
---|
133 | pvModel.DescribeYourselfTo(sceneHandler); |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | } |
---|
138 | |
---|
139 | // This called from G4PhysicalVolumeModel::DescribeAndDescend by the |
---|
140 | // virtual function mechanism. |
---|
141 | void G4LogicalVolumeModel::DescribeSolid |
---|
142 | (const G4Transform3D& theAT, |
---|
143 | G4VSolid* pSol, |
---|
144 | const G4VisAttributes* pVisAttribs, |
---|
145 | G4VGraphicsScene& sceneHandler) { |
---|
146 | |
---|
147 | if (fBooleans) { |
---|
148 | // Look for "constituents". Could be a Boolean solid. |
---|
149 | G4VSolid* pSol0 = pSol -> GetConstituentSolid (0); |
---|
150 | if (pSol0) { // Composite solid... |
---|
151 | G4VSolid* pSol1 = pSol -> GetConstituentSolid (1); |
---|
152 | if (!pSol1) { |
---|
153 | G4Exception |
---|
154 | ("G4PhysicalVolumeModel::DescribeSolid:" |
---|
155 | " 2nd component solid is missing."); |
---|
156 | } |
---|
157 | // Draw these constituents white and "forced wireframe"... |
---|
158 | G4VisAttributes constituentAttributes; |
---|
159 | constituentAttributes.SetForceWireframe(true); |
---|
160 | DescribeSolid (theAT, pSol0, &constituentAttributes, sceneHandler); |
---|
161 | DescribeSolid (theAT, pSol1, &constituentAttributes, sceneHandler); |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | // In any case draw the original/resultant solid... |
---|
166 | sceneHandler.PreAddSolid (theAT, *pVisAttribs); |
---|
167 | pSol -> DescribeYourselfTo (sceneHandler); |
---|
168 | sceneHandler.PostAddSolid (); |
---|
169 | } |
---|