Geant4  10.03
G4BoundingSphereScene.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: G4BoundingSphereScene.cc 81056 2014-05-20 09:02:16Z gcosmo $
28 //
29 //
30 // John Allison 7th June 1997
31 // An artificial scene to reuse G4VScene code to calculate a bounding sphere.
32 
33 #include "G4BoundingSphereScene.hh"
34 
35 #include "G4VSolid.hh"
36 #include "G4PhysicalVolumeModel.hh"
37 #include "G4Vector3D.hh"
38 
40 :fpModel(pModel)
41 ,fRadius(-1.)
42 {}
43 
45 
47  return G4VisExtent (fCentre, fRadius);
48 }
49 
51 {
52  const G4VisExtent& newExtent = solid.GetExtent ();
53  G4Point3D newCentre = newExtent.GetExtentCentre ();
55  newCentre.transform (*fpCurrentObjectTransformation);
56  }
57  const G4double newRadius = newExtent.GetExtentRadius ();
58  AccrueBoundingSphere (newCentre, newRadius);
59 
60  // Curtail descent - can assume daughters are contained within mother...
61  G4PhysicalVolumeModel* pPVM = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
62  if (pPVM) pPVM->CurtailDescent();
63 }
64 
66  fCentre = G4Point3D ();
67  fRadius = -1.;
69 }
70 
72 (const G4Point3D& newCentre,
73  G4double newRadius) {
74 
75  if (fRadius < 0 ) { // First time.
76  fCentre = newCentre;
77  fRadius = newRadius;
78  }
79  else {
80  G4Vector3D join = newCentre - fCentre;
81  if (join == G4Vector3D (0., 0., 0.)) { // Centres coincide.
82  if (fRadius < newRadius) fRadius = newRadius;
83  }
84  else if (join.mag () + newRadius <= fRadius) { // Inside accrued sphere.
85  // Do nothing.
86  }
87  else {
88  G4Vector3D unitJoin = join.unit ();
89  G4Point3D oldExtremity1 = fCentre - fRadius * unitJoin;
90  G4Point3D newExtremity1 = newCentre - newRadius * unitJoin;
91  G4Point3D oldExtremity2 = fCentre + fRadius * unitJoin;
92  G4Point3D newExtremity2 = newCentre + newRadius * unitJoin;
93  G4Point3D extremity1;
94  if (oldExtremity1 * unitJoin < newExtremity1 * unitJoin) {
95  extremity1 = oldExtremity1;
96  }
97  else {
98  extremity1 = newExtremity1;
99  }
100  G4Point3D extremity2;
101  if (oldExtremity2 * unitJoin > newExtremity2 * unitJoin) {
102  extremity2 = oldExtremity2;
103  }
104  else {
105  extremity2 = newExtremity2;
106  }
107  fCentre = 0.5 * (extremity2 + extremity1);
108  fRadius = 0.5 * (extremity2 - extremity1).mag ();
109  }
110  }
111 }
G4BoundingSphereScene(G4VModel *pModel=0)
void ProcessVolume(const G4VSolid &solid)
const G4Transform3D * fpCurrentObjectTransformation
const G4Point3D & GetExtentCentre() const
Definition: G4VisExtent.cc:63
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
G4VisExtent GetBoundingSphereExtent()
virtual G4VisExtent GetExtent() const
Definition: G4VSolid.cc:642
void AccrueBoundingSphere(const G4Point3D &centre, G4double radius)
double G4double
Definition: G4Types.hh:76