Geant4  10.01.p01
G4PhysicalVolumeModel.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: G4PhysicalVolumeModel.cc 81056 2014-05-20 09:02:16Z gcosmo $
28 //
29 //
30 // John Allison 31st December 1997.
31 // Model for physical volumes.
32 
33 #include "G4PhysicalVolumeModel.hh"
34 
35 #include "G4ModelingParameters.hh"
36 #include "G4VGraphicsScene.hh"
37 #include "G4VPhysicalVolume.hh"
38 #include "G4VPVParameterisation.hh"
39 #include "G4LogicalVolume.hh"
40 #include "G4VSolid.hh"
41 #include "G4SubtractionSolid.hh"
42 #include "G4IntersectionSolid.hh"
43 #include "G4Material.hh"
44 #include "G4VisAttributes.hh"
45 #include "G4BoundingSphereScene.hh"
48 #include "G4Polyhedron.hh"
49 #include "HepPolyhedronProcessor.h"
50 #include "G4AttDefStore.hh"
51 #include "G4AttDef.hh"
52 #include "G4AttValue.hh"
53 #include "G4UnitsTable.hh"
54 #include "G4Vector3D.hh"
55 
56 #include <sstream>
57 
60  , G4int requestedDepth
61  , const G4Transform3D& modelTransformation
62  , const G4ModelingParameters* pMP
63  , G4bool useFullExtent)
64 : G4VModel (modelTransformation, pMP)
65 , fpTopPV (pVPV)
66 , fTopPVCopyNo (0)
67 , fRequestedDepth (requestedDepth)
68 , fUseFullExtent (useFullExtent)
69 , fCurrentDepth (0)
70 , fpCurrentPV (0)
71 , fpCurrentLV (0)
72 , fpCurrentMaterial (0)
73 , fpCurrentTransform (0)
74 , fAbort (false)
75 , fCurtailDescent (false)
76 , fpClippingSolid (0)
77 , fClippingMode (subtraction)
78 {
79  fType = "G4PhysicalVolumeModel";
80 
81  if (!fpTopPV) {
82 
83  // In some circumstances creating an "empty" G4PhysicalVolumeModel is
84  // allowed, so I have supressed the G4Exception below. If it proves to
85  // be a problem we might have to re-instate it, but it is unlikley to
86  // be used except by visualisation experts. See, for example, /vis/list,
87  // where it is used simply to get a list of G4AttDefs.
88  // G4Exception
89  // ("G4PhysicalVolumeModel::G4PhysicalVolumeModel",
90  // "modeling0010", FatalException, "Null G4PhysicalVolumeModel pointer.");
91 
92  fTopPVName = "NULL";
93  fGlobalTag = "Empty";
94  fGlobalDescription = "G4PhysicalVolumeModel " + fGlobalTag;
95 
96  } else {
97 
98  fTopPVName = fpTopPV -> GetName ();
99  fTopPVCopyNo = fpTopPV -> GetCopyNo ();
100  std::ostringstream o;
101  o << fpTopPV -> GetCopyNo ();
102  fGlobalTag = fpTopPV -> GetName () + "." + o.str();
103  fGlobalDescription = "G4PhysicalVolumeModel " + fGlobalTag;
104 
105  fpCurrentPV = fpTopPV;
106  if (fpCurrentPV) fpCurrentLV = fpCurrentPV->GetLogicalVolume();
107  if (fpCurrentLV) fpCurrentMaterial = fpCurrentLV->GetMaterial();
108  fpCurrentTransform = const_cast<G4Transform3D*>(&modelTransformation);
109 
110  CalculateExtent ();
111  }
112 }
113 
115 {
116  delete fpClippingSolid;
117 }
118 
120 {
121  if (fUseFullExtent) {
122  fExtent = fpTopPV -> GetLogicalVolume () -> GetSolid () -> GetExtent ();
123  }
124  else {
125  G4BoundingSphereScene bsScene(this);
126  const G4int tempRequestedDepth = fRequestedDepth;
127  fRequestedDepth = -1; // Always search to all depths to define extent.
128  const G4ModelingParameters* tempMP = fpMP;
129  G4ModelingParameters mParams
130  (0, // No default vis attributes needed.
131  G4ModelingParameters::wf, // wireframe (not relevant for this).
132  true, // Global culling.
133  true, // Cull invisible volumes.
134  false, // Density culling.
135  0., // Density (not relevant if density culling false).
136  true, // Cull daughters of opaque mothers.
137  24); // No of sides (not relevant for this operation).
138  fpMP = &mParams;
139  DescribeYourselfTo (bsScene);
140  G4double radius = bsScene.GetRadius();
141  if (radius < 0.) { // Nothing in the scene.
142  fExtent = fpTopPV -> GetLogicalVolume () -> GetSolid () -> GetExtent ();
143  } else {
144  // Transform back to coordinates relative to the top
145  // transformation, which is in G4VModel::fTransform. This makes
146  // it conform to all models, which are defined by a
147  // transformation and an extent relative to that
148  // transformation...
149  G4Point3D centre = bsScene.GetCentre();
150  centre.transform(fTransform.inverse());
151  fExtent = G4VisExtent(centre, radius);
152  }
153  fpMP = tempMP;
154  fRequestedDepth = tempRequestedDepth;
155  }
156 }
157 
159 (G4VGraphicsScene& sceneHandler)
160 {
161  if (!fpTopPV) G4Exception
162  ("G4PhysicalVolumeModel::DescribeYourselfTo",
163  "modeling0012", FatalException, "No model.");
164 
165  if (!fpMP) G4Exception
166  ("G4PhysicalVolumeModel::DescribeYourselfTo",
167  "modeling0003", FatalException, "No modeling parameters.");
168 
169  // For safety...
170  fCurrentDepth = 0;
171 
172  G4Transform3D startingTransformation = fTransform;
173 
174  VisitGeometryAndGetVisReps
175  (fpTopPV,
176  fRequestedDepth,
177  startingTransformation,
178  sceneHandler);
179 
180  // Clear data...
181  fCurrentDepth = 0;
182  fpCurrentPV = 0;
183  fpCurrentLV = 0;
184  fpCurrentMaterial = 0;
185  if (fFullPVPath.size() != fBaseFullPVPath.size()) {
186  // They should be equal if pushing and popping is happening properly.
188  ("G4PhysicalVolumeModel::DescribeYourselfTo",
189  "modeling0013",
191  "Path at start of modeling not equal to base path. Something badly"
192  "\nwrong. Please contact visualisation coordinator.");
193  }
194  fDrawnPVPath.clear();
195  fAbort = false;
196  fCurtailDescent = false;
197 }
198 
200 {
201  if (fpCurrentPV) {
202  std::ostringstream o;
203  o << fpCurrentPV -> GetCopyNo ();
204  return fpCurrentPV -> GetName () + "." + o.str();
205  }
206  else {
207  return "WARNING: NO CURRENT VOLUME - global tag is " + fGlobalTag;
208  }
209 }
210 
212 {
213  return "G4PhysicalVolumeModel " + GetCurrentTag ();
214 }
215 
218  G4int requestedDepth,
219  const G4Transform3D& theAT,
220  G4VGraphicsScene& sceneHandler)
221 {
222  // Visits geometry structure to a given depth (requestedDepth), starting
223  // at given physical volume with given starting transformation and
224  // describes volumes to the scene handler.
225  // requestedDepth < 0 (default) implies full visit.
226  // theAT is the Accumulated Transformation.
227 
228  // Find corresponding logical volume and (later) solid, storing in
229  // local variables to preserve re-entrancy.
230  G4LogicalVolume* pLV = pVPV -> GetLogicalVolume ();
231 
232  G4VSolid* pSol;
233  G4Material* pMaterial;
234 
235  if (!(pVPV -> IsReplicated ())) {
236  // Non-replicated physical volume.
237  pSol = pLV -> GetSolid ();
238  pMaterial = pLV -> GetMaterial ();
239  DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial,
240  theAT, sceneHandler);
241  }
242  else {
243  // Replicated or parametrised physical volume.
244  EAxis axis;
245  G4int nReplicas;
246  G4double width;
247  G4double offset;
248  G4bool consuming;
249  pVPV -> GetReplicationData (axis, nReplicas, width, offset, consuming);
250  if (fCurrentDepth == 0) nReplicas = 1; // Just draw first
251  G4VPVParameterisation* pP = pVPV -> GetParameterisation ();
252  if (pP) { // Parametrised volume.
253  for (int n = 0; n < nReplicas; n++) {
254  pSol = pP -> ComputeSolid (n, pVPV);
255  pP -> ComputeTransformation (n, pVPV);
256  pSol -> ComputeDimensions (pP, n, pVPV);
257  pVPV -> SetCopyNo (n);
258  // Create a touchable of current parent for ComputeMaterial.
259  // fFullPVPath has not been updated yet so at this point it
260  // corresponds to the parent.
261  G4PhysicalVolumeModelTouchable parentTouchable(fFullPVPath);
262  pMaterial = pP -> ComputeMaterial (n, pVPV, &parentTouchable);
263  DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial,
264  theAT, sceneHandler);
265  }
266  }
267  else { // Plain replicated volume. From geometry_guide.txt...
268  // The replica's positions are claculated by means of a linear formula.
269  // Replication may occur along:
270  //
271  // o Cartesian axes (kXAxis,kYAxis,kZAxis)
272  //
273  // The replications, of specified width have coordinates of
274  // form (-width*(nReplicas-1)*0.5+n*width,0,0) where n=0.. nReplicas-1
275  // for the case of kXAxis, and are unrotated.
276  //
277  // o Radial axis (cylindrical polar) (kRho)
278  //
279  // The replications are cons/tubs sections, centred on the origin
280  // and are unrotated.
281  // They have radii of width*n+offset to width*(n+1)+offset
282  // where n=0..nReplicas-1
283  //
284  // o Phi axis (cylindrical polar) (kPhi)
285  // The replications are `phi sections' or wedges, and of cons/tubs form
286  // They have phi of offset+n*width to offset+(n+1)*width where
287  // n=0..nReplicas-1
288  //
289  pSol = pLV -> GetSolid ();
290  pMaterial = pLV -> GetMaterial ();
291  G4ThreeVector originalTranslation = pVPV -> GetTranslation ();
292  G4RotationMatrix* pOriginalRotation = pVPV -> GetRotation ();
293  G4double originalRMin = 0., originalRMax = 0.;
294  if (axis == kRho && pSol->GetEntityType() == "G4Tubs") {
295  originalRMin = ((G4Tubs*)pSol)->GetInnerRadius();
296  originalRMax = ((G4Tubs*)pSol)->GetOuterRadius();
297  }
298  G4bool visualisable = true;
299  for (int n = 0; n < nReplicas; n++) {
300  G4ThreeVector translation; // Null.
301  G4RotationMatrix rotation; // Null - life long enough for visualizing.
302  G4RotationMatrix* pRotation = 0;
303  switch (axis) {
304  default:
305  case kXAxis:
306  translation = G4ThreeVector (-width*(nReplicas-1)*0.5+n*width,0,0);
307  break;
308  case kYAxis:
309  translation = G4ThreeVector (0,-width*(nReplicas-1)*0.5+n*width,0);
310  break;
311  case kZAxis:
312  translation = G4ThreeVector (0,0,-width*(nReplicas-1)*0.5+n*width);
313  break;
314  case kRho:
315  if (pSol->GetEntityType() == "G4Tubs") {
316  ((G4Tubs*)pSol)->SetInnerRadius(width*n+offset);
317  ((G4Tubs*)pSol)->SetOuterRadius(width*(n+1)+offset);
318  } else {
319  if (fpMP->IsWarning())
320  G4cout <<
321  "G4PhysicalVolumeModel::VisitGeometryAndGetVisReps: WARNING:"
322  "\n built-in replicated volumes replicated in radius for "
323  << pSol->GetEntityType() <<
324  "-type\n solids (your solid \""
325  << pSol->GetName() <<
326  "\") are not visualisable."
327  << G4endl;
328  visualisable = false;
329  }
330  break;
331  case kPhi:
332  rotation.rotateZ (-(offset+(n+0.5)*width));
333  // Minus Sign because for the physical volume we need the
334  // coordinate system rotation.
335  pRotation = &rotation;
336  break;
337  }
338  pVPV -> SetTranslation (translation);
339  pVPV -> SetRotation (pRotation);
340  pVPV -> SetCopyNo (n);
341  if (visualisable) {
342  DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial,
343  theAT, sceneHandler);
344  }
345  }
346  // Restore originals...
347  pVPV -> SetTranslation (originalTranslation);
348  pVPV -> SetRotation (pOriginalRotation);
349  if (axis == kRho && pSol->GetEntityType() == "G4Tubs") {
350  ((G4Tubs*)pSol)->SetInnerRadius(originalRMin);
351  ((G4Tubs*)pSol)->SetOuterRadius(originalRMax);
352  }
353  }
354  }
355 }
356 
359  G4int requestedDepth,
360  G4LogicalVolume* pLV,
361  G4VSolid* pSol,
362  G4Material* pMaterial,
363  const G4Transform3D& theAT,
364  G4VGraphicsScene& sceneHandler)
365 {
366  // Maintain useful data members...
367  fpCurrentPV = pVPV;
368  fpCurrentLV = pLV;
369  fpCurrentMaterial = pMaterial;
370 
371  const G4RotationMatrix objectRotation = pVPV -> GetObjectRotationValue ();
372  const G4ThreeVector& translation = pVPV -> GetTranslation ();
373  G4Transform3D theLT (G4Transform3D (objectRotation, translation));
374 
375  // Compute the accumulated transformation...
376  // Note that top volume's transformation relative to the world
377  // coordinate system is specified in theAT == startingTransformation
378  // = fTransform (see DescribeYourselfTo), so first time through the
379  // volume's own transformation, which is only relative to its
380  // mother, i.e., not relative to the world coordinate system, should
381  // not be accumulated.
382  G4Transform3D theNewAT (theAT);
383  if (fCurrentDepth != 0) theNewAT = theAT * theLT;
384  fpCurrentTransform = &theNewAT;
385 
386  const G4VisAttributes* pVisAttribs = pLV->GetVisAttributes();
387  if (!pVisAttribs) pVisAttribs = fpMP->GetDefaultVisAttributes();
388  // Beware - pVisAttribs might still be zero - create a temporary default one...
389  G4bool visAttsCreated = false;
390  if (!pVisAttribs) {
391  pVisAttribs = new G4VisAttributes;
392  visAttsCreated = true;
393  }
394  // From here, can assume pVisAttribs is a valid pointer.
395 
396  // Make decision to draw...
397  G4bool thisToBeDrawn = true;
398 
399  // Update full path of physical volumes...
400  G4int copyNo = fpCurrentPV->GetCopyNo();
401  fFullPVPath.push_back
403  (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform));
404 
405  // In case we need to copy the vis atts for modification...
406  G4bool copyForVAM = false;
407  const G4VisAttributes* pUnmodifiedVisAtts = pVisAttribs;
408  G4VisAttributes* pModifiedVisAtts = 0;
409 
410  // Check if vis attributes are to be modified by a /vis/touchable/set/ command.
411  const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
412  fpMP->GetVisAttributesModifiers();
413  std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator
414  iModifier;
415  for (iModifier = vams.begin();
416  iModifier != vams.end();
417  ++iModifier) {
419  iModifier->GetPVNameCopyNoPath();
420  if (vamPath.size() == fFullPVPath.size()) {
421  // OK - there's a size match. Check it out.
422 // G4cout << "Size match" << G4endl;
424  std::vector<G4PhysicalVolumeNodeID>::const_iterator iPVNodeId;
425  for (iVAMNameCopyNo = vamPath.begin(), iPVNodeId = fFullPVPath.begin();
426  iVAMNameCopyNo != vamPath.end();
427  ++iVAMNameCopyNo, ++iPVNodeId) {
428 // G4cout
429 // << iVAMNameCopyNo->fName
430 // << ',' << iVAMNameCopyNo->fCopyNo
431 // << "; " << iPVNodeId->GetPhysicalVolume()->GetName()
432 // << ',' << iPVNodeId->GetPhysicalVolume()->GetCopyNo()
433 // << G4endl;
434  if (!(
435  iVAMNameCopyNo->GetName() ==
436  iPVNodeId->GetPhysicalVolume()->GetName() &&
437  iVAMNameCopyNo->GetCopyNo() ==
438  iPVNodeId->GetPhysicalVolume()->GetCopyNo()
439  )) {
440  break;
441  }
442  }
443  if (iVAMNameCopyNo == vamPath.end()) {
444 // G4cout << "Match found" << G4endl;
445  if (!copyForVAM) {
446  pModifiedVisAtts = new G4VisAttributes(*pUnmodifiedVisAtts);
447  pVisAttribs = pModifiedVisAtts;
448  copyForVAM = true;
449  }
450  const G4VisAttributes& transVisAtts = iModifier->GetVisAttributes();
451  switch (iModifier->GetVisAttributesSignifier()) {
453  pModifiedVisAtts->SetVisibility(transVisAtts.IsVisible());
454  break;
456  pModifiedVisAtts->SetDaughtersInvisible
457  (transVisAtts.IsDaughtersInvisible());
458  break;
460  pModifiedVisAtts->SetColour(transVisAtts.GetColour());
461  break;
463  pModifiedVisAtts->SetLineStyle(transVisAtts.GetLineStyle());
464  break;
466  pModifiedVisAtts->SetLineWidth(transVisAtts.GetLineWidth());
467  break;
469  if (transVisAtts.GetForcedDrawingStyle() ==
471  pModifiedVisAtts->SetForceWireframe
472  (transVisAtts.IsForceDrawingStyle());
473  }
474  break;
476  if (transVisAtts.GetForcedDrawingStyle() ==
478  pModifiedVisAtts->SetForceSolid
479  (transVisAtts.IsForceDrawingStyle());
480  }
481  break;
483  pModifiedVisAtts->SetForceAuxEdgeVisible
484  (transVisAtts.IsForceAuxEdgeVisible());
485  break;
487  pModifiedVisAtts->SetForceLineSegmentsPerCircle
488  (transVisAtts.GetForcedLineSegmentsPerCircle());
489  break;
490  }
491  }
492  }
493  }
494 
495  // There are various reasons why this volume
496  // might not be drawn...
497  G4bool culling = fpMP->IsCulling();
498  G4bool cullingInvisible = fpMP->IsCullingInvisible();
499  G4bool markedVisible = pVisAttribs->IsVisible();
500  G4bool cullingLowDensity = fpMP->IsDensityCulling();
501  G4double density = pMaterial? pMaterial->GetDensity(): 0;
502  G4double densityCut = fpMP -> GetVisibleDensity ();
503 
504  // 1) Global culling is on....
505  if (culling) {
506  // 2) Culling of invisible volumes is on...
507  if (cullingInvisible) {
508  // 3) ...and the volume is marked not visible...
509  if (!markedVisible) thisToBeDrawn = false;
510  }
511  // 4) Or culling of low density volumes is on...
512  if (cullingLowDensity) {
513  // 5) ...and density is less than cut value...
514  if (density < densityCut) thisToBeDrawn = false;
515  }
516  }
517  // 6) The user has asked for all further traversing to be aborted...
518  if (fAbort) thisToBeDrawn = false;
519 
520  // Record thisToBeDrawn in path...
521  fFullPVPath.back().SetDrawn(thisToBeDrawn);
522 
523  if (thisToBeDrawn) {
524 
525  // Update path of drawn physical volumes...
526  fDrawnPVPath.push_back
528  (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform,thisToBeDrawn));
529 
530  if (fpMP->IsExplode() && fDrawnPVPath.size() == 1) {
531  // For top-level drawn volumes, explode along radius...
532  G4Transform3D centering = G4Translate3D(fpMP->GetExplodeCentre());
533  G4Transform3D centred = centering.inverse() * theNewAT;
534  G4Scale3D oldScale;
535  G4Rotate3D oldRotation;
536  G4Translate3D oldTranslation;
537  centred.getDecomposition(oldScale, oldRotation, oldTranslation);
538  G4double explodeFactor = fpMP->GetExplodeFactor();
539  G4Translate3D newTranslation =
540  G4Translate3D(explodeFactor * oldTranslation.dx(),
541  explodeFactor * oldTranslation.dy(),
542  explodeFactor * oldTranslation.dz());
543  theNewAT = centering * newTranslation * oldRotation * oldScale;
544  }
545 
546  DescribeSolid (theNewAT, pSol, pVisAttribs, sceneHandler);
547 
548  }
549 
550  // Make decision to draw daughters, if any. There are various
551  // reasons why daughters might not be drawn...
552 
553  // First, reasons that do not depend on culling policy...
554  G4int nDaughters = pLV->GetNoDaughters();
555  G4bool daughtersToBeDrawn = true;
556  // 1) There are no daughters...
557  if (!nDaughters) daughtersToBeDrawn = false;
558  // 2) We are at the limit if requested depth...
559  else if (requestedDepth == 0) daughtersToBeDrawn = false;
560  // 3) The user has asked for all further traversing to be aborted...
561  else if (fAbort) daughtersToBeDrawn = false;
562  // 4) The user has asked that the descent be curtailed...
563  else if (fCurtailDescent) daughtersToBeDrawn = false;
564 
565  // Now, reasons that depend on culling policy...
566  else {
567  G4bool daughtersInvisible = pVisAttribs->IsDaughtersInvisible();
568  // Culling of covered daughters request. This is computed in
569  // G4VSceneHandler::CreateModelingParameters() depending on view
570  // parameters...
571  G4bool cullingCovered = fpMP->IsCullingCovered();
572  G4bool surfaceDrawing =
573  fpMP->GetDrawingStyle() == G4ModelingParameters::hsr ||
574  fpMP->GetDrawingStyle() == G4ModelingParameters::hlhsr;
575  if (pVisAttribs->IsForceDrawingStyle()) {
576  switch (pVisAttribs->GetForcedDrawingStyle()) {
577  default:
578  case G4VisAttributes::wireframe: surfaceDrawing = false; break;
579  case G4VisAttributes::solid: surfaceDrawing = true; break;
580  }
581  }
582  G4bool opaque = pVisAttribs->GetColour().GetAlpha() >= 1.;
583  // 5) Global culling is on....
584  if (culling) {
585  // 6) ..and culling of invisible volumes is on...
586  if (cullingInvisible) {
587  // 7) ...and the mother requests daughters invisible
588  if (daughtersInvisible) daughtersToBeDrawn = false;
589  }
590  // 8) Or culling of covered daughters is requested...
591  if (cullingCovered) {
592  // 9) ...and surface drawing is operating...
593  if (surfaceDrawing) {
594  // 10) ...but only if mother is visible...
595  if (thisToBeDrawn) {
596  // 11) ...and opaque...
597  if (opaque) daughtersToBeDrawn = false;
598  }
599  }
600  }
601  }
602  }
603 
604  // Delete modified vis atts if created...
605  if (copyForVAM) {
606  delete pModifiedVisAtts;
607  pVisAttribs = pUnmodifiedVisAtts;
608  copyForVAM = false;
609  }
610 
611  // Vis atts for this volume no longer needed if created...
612  if (visAttsCreated) delete pVisAttribs;
613 
614  if (daughtersToBeDrawn) {
615  for (G4int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
616  // Store daughter pVPV in local variable ready for recursion...
617  G4VPhysicalVolume* pDaughterVPV = pLV -> GetDaughter (iDaughter);
618  // Descend the geometry structure recursively...
619  fCurrentDepth++;
620  VisitGeometryAndGetVisReps
621  (pDaughterVPV, requestedDepth - 1, theNewAT, sceneHandler);
622  fCurrentDepth--;
623  }
624  }
625 
626  // Reset for normal descending of next volume at this level...
627  fCurtailDescent = false;
628 
629  // Pop item from paths physical volumes...
630  fFullPVPath.pop_back();
631  if (thisToBeDrawn) {
632  fDrawnPVPath.pop_back();
633  }
634 }
635 
637 (const G4Transform3D& theAT,
638  G4VSolid* pSol,
639  const G4VisAttributes* pVisAttribs,
640  G4VGraphicsScene& sceneHandler)
641 {
642  sceneHandler.PreAddSolid (theAT, *pVisAttribs);
643 
644  G4VSolid* pSectionSolid = fpMP->GetSectionSolid();
645  G4VSolid* pCutawaySolid = fpMP->GetCutawaySolid();
646 
647  if (!fpClippingSolid && !pSectionSolid && !pCutawaySolid) {
648 
649  pSol -> DescribeYourselfTo (sceneHandler); // Standard treatment.
650 
651  } else {
652 
653  // Clipping, etc., performed by Boolean operations.
654 
655  // First, get polyhedron for current solid...
656  if (pVisAttribs->IsForceLineSegmentsPerCircle())
657  G4Polyhedron::SetNumberOfRotationSteps
658  (pVisAttribs->GetForcedLineSegmentsPerCircle());
659  else
660  G4Polyhedron::SetNumberOfRotationSteps(fpMP->GetNoOfSides());
661  const G4Polyhedron* pOriginal = pSol->GetPolyhedron();
662  G4Polyhedron::ResetNumberOfRotationSteps();
663 
664  if (!pOriginal) {
665 
666  if (fpMP->IsWarning())
667  G4cout <<
668  "WARNING: G4PhysicalVolumeModel::DescribeSolid: solid\n \""
669  << pSol->GetName() <<
670  "\" has no polyhedron. Cannot by clipped."
671  << G4endl;
672  pSol -> DescribeYourselfTo (sceneHandler); // Standard treatment.
673 
674  } else {
675 
676  G4Polyhedron resultant(*pOriginal);
677  G4VisAttributes resultantVisAttribs(*pVisAttribs);
678  G4VSolid* resultantSolid = 0;
679 
680  if (fpClippingSolid) {
681  switch (fClippingMode) {
682  default:
683  case subtraction:
684  resultantSolid = new G4SubtractionSolid
685  ("resultant_solid", pSol, fpClippingSolid, theAT.inverse());
686  break;
687  case intersection:
688  resultantSolid = new G4IntersectionSolid
689  ("resultant_solid", pSol, fpClippingSolid, theAT.inverse());
690  break;
691  }
692  }
693 
694  if (pSectionSolid) {
695  resultantSolid = new G4IntersectionSolid
696  ("sectioned_solid", pSol, pSectionSolid, theAT.inverse());
697  }
698 
699  if (pCutawaySolid) {
700  resultantSolid = new G4SubtractionSolid
701  ("cutaway_solid", pSol, pCutawaySolid, theAT.inverse());
702  }
703 
704  G4Polyhedron* tmpResultant = resultantSolid->GetPolyhedron();
705  if (tmpResultant) resultant = *tmpResultant;
706  else {
707  if (fpMP->IsWarning())
708  G4cout <<
709  "WARNING: G4PhysicalVolumeModel::DescribeSolid: resultant polyhedron for"
710  "\n solid \"" << pSol->GetName() <<
711  "\" not defined due to error during Boolean processing."
712  "\n Original will be drawn in red."
713  << G4endl;
714  resultantVisAttribs.SetColour(G4Colour::Red());
715  }
716 
717  delete resultantSolid;
718 
719  // Finally, force polyhedron drawing...
720  resultant.SetVisAttributes(resultantVisAttribs);
721  sceneHandler.BeginPrimitives(theAT);
722  sceneHandler.AddPrimitive(resultant);
723  sceneHandler.EndPrimitives();
724  }
725  }
726  sceneHandler.PostAddSolid ();
727 }
728 
730 {
731  G4TransportationManager* transportationManager =
733 
734  size_t nWorlds = transportationManager->GetNoWorlds();
735 
736  G4bool found = false;
737 
738  std::vector<G4VPhysicalVolume*>::iterator iterWorld =
739  transportationManager->GetWorldsIterator();
740  for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
741  G4VPhysicalVolume* world = (*iterWorld);
742  // The idea now is to seek a PV with the same name and copy no
743  // in the hope it's the same one!!
744  G4PhysicalVolumeModel searchModel (world);
745  G4int verbosity = 0; // Suppress messages from G4PhysicalVolumeSearchScene.
746  G4PhysicalVolumeSearchScene searchScene
747  (&searchModel, fTopPVName, fTopPVCopyNo, verbosity);
748  G4ModelingParameters mp; // Default modeling parameters for this search.
750  searchModel.SetModelingParameters (&mp);
751  searchModel.DescribeYourselfTo (searchScene);
752  G4VPhysicalVolume* foundVolume = searchScene.GetFoundVolume ();
753  if (foundVolume) {
754  if (foundVolume != fpTopPV && warn) {
755  G4cout <<
756  "G4PhysicalVolumeModel::Validate(): A volume of the same name and"
757  "\n copy number (\""
758  << fTopPVName << "\", copy " << fTopPVCopyNo
759  << ") still exists and is being used."
760  "\n But it is not the same volume you originally specified"
761  "\n in /vis/scene/add/."
762  << G4endl;
763  }
764  fpTopPV = foundVolume;
765  CalculateExtent ();
766  found = true;
767  }
768  }
769  if (found) return true;
770  else {
771  if (warn) {
772  G4cout <<
773  "G4PhysicalVolumeModel::Validate(): No volume of name and"
774  "\n copy number (\""
775  << fTopPVName << "\", copy " << fTopPVCopyNo
776  << ") exists."
777  << G4endl;
778  }
779  return false;
780  }
781 }
782 
783 const std::map<G4String,G4AttDef>* G4PhysicalVolumeModel::GetAttDefs() const
784 {
785  G4bool isNew;
786  std::map<G4String,G4AttDef>* store
787  = G4AttDefStore::GetInstance("G4PhysicalVolumeModel", isNew);
788  if (isNew) {
789  (*store)["PVPath"] =
790  G4AttDef("PVPath","Physical Volume Path","Physics","","G4String");
791  (*store)["LVol"] =
792  G4AttDef("LVol","Logical Volume","Physics","","G4String");
793  (*store)["Solid"] =
794  G4AttDef("Solid","Solid Name","Physics","","G4String");
795  (*store)["EType"] =
796  G4AttDef("EType","Entity Type","Physics","","G4String");
797  (*store)["DmpSol"] =
798  G4AttDef("DmpSol","Dump of Solid properties","Physics","","G4String");
799  (*store)["Trans"] =
800  G4AttDef("Trans","Transformation of volume","Physics","","G4String");
801  (*store)["Material"] =
802  G4AttDef("Material","Material Name","Physics","","G4String");
803  (*store)["Density"] =
804  G4AttDef("Density","Material Density","Physics","G4BestUnit","G4double");
805  (*store)["State"] =
806  G4AttDef("State","Material State (enum undefined,solid,liquid,gas)","Physics","","G4String");
807  (*store)["Radlen"] =
808  G4AttDef("Radlen","Material Radiation Length","Physics","G4BestUnit","G4double");
809  (*store)["Region"] =
810  G4AttDef("Region","Cuts Region","Physics","","G4String");
811  (*store)["RootRegion"] =
812  G4AttDef("RootRegion","Root Region (0/1 = false/true)","Physics","","G4bool");
813  }
814  return store;
815 }
816 
817 #include <iomanip>
818 
819 static std::ostream& operator<< (std::ostream& o, const G4Transform3D t)
820 {
821  using namespace std;
822 
823  G4Scale3D sc;
824  G4Rotate3D r;
825  G4Translate3D tl;
826  t.getDecomposition(sc, r, tl);
827 
828  const int w = 10;
829 
830  // Transformation itself
831  o << setw(w) << t.xx() << setw(w) << t.xy() << setw(w) << t.xz() << setw(w) << t.dx() << endl;
832  o << setw(w) << t.yx() << setw(w) << t.yy() << setw(w) << t.yz() << setw(w) << t.dy() << endl;
833  o << setw(w) << t.zx() << setw(w) << t.zy() << setw(w) << t.zz() << setw(w) << t.dz() << endl;
834 
835  // Translation
836  o << "= translation:" << endl;
837  o << setw(w) << tl.dx() << setw(w) << tl.dy() << setw(w) << tl.dz() << endl;
838 
839  // Rotation
840  o << "* rotation:" << endl;
841  o << setw(w) << r.xx() << setw(w) << r.xy() << setw(w) << r.xz() << endl;
842  o << setw(w) << r.yx() << setw(w) << r.yy() << setw(w) << r.yz() << endl;
843  o << setw(w) << r.zx() << setw(w) << r.zy() << setw(w) << r.zz() << endl;
844 
845  // Scale
846  o << "* scale:" << endl;
847  o << setw(w) << sc.xx() << setw(w) << sc.yy() << setw(w) << sc.zz() << endl;
848 
849  // Transformed axes
850  o << "Transformed axes:" << endl;
851  o << "x': " << r * G4Vector3D(1., 0., 0.) << endl;
852  o << "y': " << r * G4Vector3D(0., 1., 0.) << endl;
853  o << "z': " << r * G4Vector3D(0., 0., 1.) << endl;
854 
855  return o;
856 }
857 
858 std::vector<G4AttValue>* G4PhysicalVolumeModel::CreateCurrentAttValues() const
859 {
860  std::vector<G4AttValue>* values = new std::vector<G4AttValue>;
861  std::ostringstream oss;
862  for (size_t i = 0; i < fFullPVPath.size(); ++i) {
863  oss << fFullPVPath[i].GetPhysicalVolume()->GetName()
864  << ':' << fFullPVPath[i].GetCopyNo();
865  if (i != fFullPVPath.size() - 1) oss << '/';
866  }
867 
868  if (!fpCurrentLV) {
870  ("G4PhysicalVolumeModel::CreateCurrentAttValues",
871  "modeling0004",
872  JustWarning,
873  "Current logical volume not defined.");
874  return values;
875  }
876 
877  values->push_back(G4AttValue("PVPath", oss.str(),""));
878  values->push_back(G4AttValue("LVol", fpCurrentLV->GetName(),""));
879  G4VSolid* pSol = fpCurrentLV->GetSolid();
880  values->push_back(G4AttValue("Solid", pSol->GetName(),""));
881  values->push_back(G4AttValue("EType", pSol->GetEntityType(),""));
882  oss.str(""); oss << '\n' << *pSol;
883  values->push_back(G4AttValue("DmpSol", oss.str(),""));
884  oss.str(""); oss << '\n' << *fpCurrentTransform;
885  values->push_back(G4AttValue("Trans", oss.str(),""));
886  G4String matName = fpCurrentMaterial? fpCurrentMaterial->GetName(): G4String("No material");
887  values->push_back(G4AttValue("Material", matName,""));
889  values->push_back(G4AttValue("Density", G4BestUnit(matDensity,"Volumic Mass"),""));
891  oss.str(""); oss << matState;
892  values->push_back(G4AttValue("State", oss.str(),""));
894  values->push_back(G4AttValue("Radlen", G4BestUnit(matRadlen,"Length"),""));
895  G4Region* region = fpCurrentLV->GetRegion();
896  G4String regionName = region? region->GetName(): G4String("No region");
897  values->push_back(G4AttValue("Region", regionName,""));
898  oss.str(""); oss << fpCurrentLV->IsRootRegion();
899  values->push_back(G4AttValue("RootRegion", oss.str(),""));
900  return values;
901 }
902 
903 G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator<
905 {
906  if (fpPV < right.fpPV) return true;
907  if (fpPV == right.fpPV) {
908  if (fCopyNo < right.fCopyNo) return true;
909  if (fCopyNo == right.fCopyNo)
910  return fNonCulledDepth < right.fNonCulledDepth;
911  }
912  return false;
913 }
914 
915 std::ostream& operator<<
916  (std::ostream& os, const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID node)
917 {
918  G4VPhysicalVolume* pPV = node.GetPhysicalVolume();
919  if (pPV) {
920  os << pPV->GetName()
921  << ':' << node.GetCopyNo()
922  << '[' << node.GetNonCulledDepth() << ']'
923  << ':' << node.GetTransform();
924  if (!node.GetDrawn()) os << " Not "; os << "drawn";
925  } else {
926  os << "Null node";
927  }
928  return os;
929 }
930 
932 (const std::vector<G4PhysicalVolumeNodeID>& fullPVPath):
933  fFullPVPath(fullPVPath) {}
934 
936 {
937  size_t i = fFullPVPath.size() - depth - 1;
938  if (i >= fFullPVPath.size()) {
939  G4Exception("G4PhysicalVolumeModelTouchable::GetTranslation",
940  "modeling0005",
942  "Index out of range. Asking for non-existent depth");
943  }
944  static G4ThreeVector tempTranslation;
945  tempTranslation = fFullPVPath[i].GetTransform().getTranslation();
946  return tempTranslation;
947 }
948 
950 {
951  size_t i = fFullPVPath.size() - depth - 1;
952  if (i >= fFullPVPath.size()) {
953  G4Exception("G4PhysicalVolumeModelTouchable::GetRotation",
954  "modeling0006",
956  "Index out of range. Asking for non-existent depth");
957  }
958  static G4RotationMatrix tempRotation;
959  tempRotation = fFullPVPath[i].GetTransform().getRotation();
960  return &tempRotation;
961 }
962 
964 {
965  size_t i = fFullPVPath.size() - depth - 1;
966  if (i >= fFullPVPath.size()) {
967  G4Exception("G4PhysicalVolumeModelTouchable::GetVolume",
968  "modeling0007",
970  "Index out of range. Asking for non-existent depth");
971  }
972  return fFullPVPath[i].GetPhysicalVolume();
973 }
974 
976 {
977  size_t i = fFullPVPath.size() - depth - 1;
978  if (i >= fFullPVPath.size()) {
979  G4Exception("G4PhysicalVolumeModelTouchable::GetSolid",
980  "modeling0008",
982  "Index out of range. Asking for non-existent depth");
983  }
984  return fFullPVPath[i].GetPhysicalVolume()->GetLogicalVolume()->GetSolid();
985 }
986 
988 {
989  size_t i = fFullPVPath.size() - depth - 1;
990  if (i >= fFullPVPath.size()) {
991  G4Exception("G4PhysicalVolumeModelTouchable::GetReplicaNumber",
992  "modeling0009",
994  "Index out of range. Asking for non-existent depth");
995  }
996  return fFullPVPath[i].GetCopyNo();
997 }
virtual void PostAddSolid()=0
virtual G4Polyhedron * GetPolyhedron() const
Definition: G4VSolid.cc:644
Definition: geomdefs.hh:54
G4bool IsForceAuxEdgeVisible() const
G4String GetName() const
G4Transform3D fTransform
Definition: G4VModel.hh:112
void SetColour(const G4Colour &)
const G4String & GetName() const
G4double GetAlpha() const
Definition: G4Colour.hh:142
void SetForceWireframe(G4bool)
const std::map< G4String, G4AttDef > * GetAttDefs() const
G4String GetName() const
CLHEP::Hep3Vector G4ThreeVector
const std::vector< G4PhysicalVolumeNodeID > & fFullPVPath
const G4VisAttributes * GetDefaultVisAttributes() const
CLHEP::HepRotation G4RotationMatrix
G4double GetLineWidth() const
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
G4State
Definition: G4Material.hh:114
const G4String & GetName() const
Definition: G4Material.hh:178
void SetLineStyle(LineStyle)
void SetLineWidth(G4double)
void SetVisibility(G4bool)
Definition: G4Tubs.hh:85
const G4ThreeVector & GetTranslation(G4int depth) const
G4double GetDensity() const
Definition: G4Material.hh:180
G4bool IsVisible() const
const G4Colour & GetColour() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())=0
#define width
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
G4bool Validate(G4bool warn)
const G4Point3D & GetCentre() const
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4Region * GetRegion() const
G4Transform3D * fpCurrentTransform
void SetForceSolid(G4bool)
virtual G4GeometryType GetEntityType() const =0
const G4VisExtent & GetExtent() const
static std::ostream & operator<<(std::ostream &o, const G4Transform3D t)
int G4int
Definition: G4Types.hh:78
void SetModelingParameters(const G4ModelingParameters *)
G4VPhysicalVolume * fpCurrentPV
LineStyle GetLineStyle() const
G4String fGlobalTag
Definition: G4VModel.hh:109
virtual void AddPrimitive(const G4Polyline &)=0
std::vector< G4PhysicalVolumeNodeID > fFullPVPath
G4double density
Definition: TRTMaterials.hh:39
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
G4bool IsDaughtersInvisible() const
bool G4bool
Definition: G4Types.hh:79
G4bool IsRootRegion() const
const G4VisAttributes * GetVisAttributes() const
const G4ModelingParameters * fpMP
Definition: G4VModel.hh:113
G4String GetCurrentDescription() const
HepGeom::Transform3D G4Transform3D
HepGeom::Scale3D G4Scale3D
const G4int n
virtual void DescribeSolid(const G4Transform3D &theAT, G4VSolid *pSol, const G4VisAttributes *pVisAttribs, G4VGraphicsScene &sceneHandler)
G4double GetRadlen() const
Definition: G4Material.hh:220
G4int GetNoDaughters() const
void SetForceAuxEdgeVisible(G4bool)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
static G4TransportationManager * GetTransportationManager()
G4int GetForcedLineSegmentsPerCircle() const
G4VPhysicalVolume * fpTopPV
G4PhysicalVolumeModelTouchable(const std::vector< G4PhysicalVolumeNodeID > &fullPVPath)
std::vector< PVNameCopyNo > PVNameCopyNoPath
HepGeom::Rotate3D G4Rotate3D
std::vector< G4AttValue > * CreateCurrentAttValues() const
EAxis
Definition: geomdefs.hh:54
G4bool IsForceDrawingStyle() const
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &visAttribs)=0
G4VPhysicalVolume * GetFoundVolume() const
HepGeom::Translate3D G4Translate3D
G4String GetCurrentTag() const
size_t GetNoWorlds() const
#define G4endl
Definition: G4ios.hh:61
static G4Colour Red()
Definition: G4Colour.hh:148
G4PhysicalVolumeModel(G4VPhysicalVolume *=0, G4int requestedDepth=UNLIMITED, const G4Transform3D &modelTransformation=G4Transform3D(), const G4ModelingParameters *=0, G4bool useFullExtent=false)
virtual void EndPrimitives()=0
G4State GetState() const
Definition: G4Material.hh:181
std::map< G4String, G4AttDef > * GetInstance(const G4String &storeKey, G4bool &isNew)
G4VisExtent fExtent
Definition: G4VModel.hh:111
double G4double
Definition: G4Types.hh:76
void VisitGeometryAndGetVisReps(G4VPhysicalVolume *, G4int requestedDepth, const G4Transform3D &, G4VGraphicsScene &)
Definition: geomdefs.hh:54
void SetDefaultVisAttributes(const G4VisAttributes *pDefaultVisAttributes)
G4bool IsForceLineSegmentsPerCircle() const
void SetDaughtersInvisible(G4bool)
void DescribeAndDescend(G4VPhysicalVolume *, G4int requestedDepth, G4LogicalVolume *, G4VSolid *, G4Material *, const G4Transform3D &, G4VGraphicsScene &)
ForcedDrawingStyle GetForcedDrawingStyle() const
PVNameCopyNoPath::const_iterator PVNameCopyNoPathConstIterator
G4VSolid * GetSolid() const
const G4RotationMatrix * GetRotation(G4int depth) const
void SetForceLineSegmentsPerCircle(G4int nSegments)
void DescribeYourselfTo(G4VGraphicsScene &)