ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4BoundingSphereScene.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4BoundingSphereScene.cc
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 //
28 //
29 // John Allison 7th June 1997
30 // An artificial scene to reuse G4VScene code to calculate a bounding sphere.
31 
32 #include "G4BoundingSphereScene.hh"
33 
34 #include "G4VSolid.hh"
35 #include "G4PhysicalVolumeModel.hh"
36 #include "G4Vector3D.hh"
37 
39 :fpModel(pModel)
40 ,fRadius(-1.)
41 {}
42 
44 
46  return G4VisExtent (fCentre, fRadius);
47 }
48 
50 {
51  const G4VisExtent& newExtent = solid.GetExtent ();
52  G4Point3D newCentre = newExtent.GetExtentCentre ();
54  newCentre.transform (*fpCurrentObjectTransformation);
55  }
56  const G4double newRadius = newExtent.GetExtentRadius ();
57  AccrueBoundingSphere (newCentre, newRadius);
58 
59  // Curtail descent - can assume daughters are contained within mother...
60  G4PhysicalVolumeModel* pPVM = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
61  if (pPVM) pPVM->CurtailDescent();
62 }
63 
65  fCentre = G4Point3D ();
66  fRadius = -1.;
68 }
69 
71 (const G4Point3D& newCentre,
72  G4double newRadius) {
73 
74  if (fRadius < 0 ) { // First time.
75  fCentre = newCentre;
76  fRadius = newRadius;
77  }
78  else {
79  G4Vector3D join = newCentre - fCentre;
80  if (join == G4Vector3D (0., 0., 0.)) { // Centres coincide.
81  if (fRadius < newRadius) fRadius = newRadius;
82  }
83  else if (join.mag () + newRadius <= fRadius) { // Inside accrued sphere.
84  // Do nothing.
85  }
86  else {
87  G4Vector3D unitJoin = join.unit ();
88  G4Point3D oldExtremity1 = fCentre - fRadius * unitJoin;
89  G4Point3D newExtremity1 = newCentre - newRadius * unitJoin;
90  G4Point3D oldExtremity2 = fCentre + fRadius * unitJoin;
91  G4Point3D newExtremity2 = newCentre + newRadius * unitJoin;
92  G4Point3D extremity1;
93  if (oldExtremity1 * unitJoin < newExtremity1 * unitJoin) {
94  extremity1 = oldExtremity1;
95  }
96  else {
97  extremity1 = newExtremity1;
98  }
99  G4Point3D extremity2;
100  if (oldExtremity2 * unitJoin > newExtremity2 * unitJoin) {
101  extremity2 = oldExtremity2;
102  }
103  else {
104  extremity2 = newExtremity2;
105  }
106  fCentre = 0.5 * (extremity2 + extremity1);
107  fRadius = 0.5 * (extremity2 - extremity1).mag ();
108  }
109  }
110 }