Geant4  10.00.p02
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 66373 2012-12-18 09:41:34Z 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  fpObjectTransformation (0)
43 {}
44 
46 
48 (const G4Transform3D& objectTransformation,
49  const G4VisAttributes&) {
50  fpObjectTransformation = &objectTransformation;
51 }
52 
54  return G4VisExtent (fCentre, fRadius);
55 }
56 
58 
59  const G4VisExtent& newExtent = solid.GetExtent ();
60  G4Point3D newCentre = newExtent.GetExtentCentre ();
62  newCentre.transform (*fpObjectTransformation);
63  }
64  const G4double newRadius = newExtent.GetExtentRadius ();
65  AccrueBoundingSphere (newCentre, newRadius);
66 
67  // Curtail descent - can assume daughters are contained within mother...
68  G4PhysicalVolumeModel* pPVM = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
69  if (pPVM) pPVM->CurtailDescent();
70 }
71 
73  fCentre = G4Point3D ();
74  fRadius = -1.;
76 }
77 
79 (const G4Point3D& newCentre,
80  G4double newRadius) {
81 
82  if (fRadius < 0 ) { // First time.
83  fCentre = newCentre;
84  fRadius = newRadius;
85  }
86  else {
87  G4Vector3D join = newCentre - fCentre;
88  if (join == G4Vector3D (0., 0., 0.)) { // Centres coincide.
89  if (fRadius < newRadius) fRadius = newRadius;
90  }
91  else if (join.mag () + newRadius <= fRadius) { // Inside accrued sphere.
92  // Do nothing.
93  }
94  else {
95  G4Vector3D unitJoin = join.unit ();
96  G4Point3D oldExtremity1 = fCentre - fRadius * unitJoin;
97  G4Point3D newExtremity1 = newCentre - newRadius * unitJoin;
98  G4Point3D oldExtremity2 = fCentre + fRadius * unitJoin;
99  G4Point3D newExtremity2 = newCentre + newRadius * unitJoin;
100  G4Point3D extremity1;
101  if (oldExtremity1 * unitJoin < newExtremity1 * unitJoin) {
102  extremity1 = oldExtremity1;
103  }
104  else {
105  extremity1 = newExtremity1;
106  }
107  G4Point3D extremity2;
108  if (oldExtremity2 * unitJoin > newExtremity2 * unitJoin) {
109  extremity2 = oldExtremity2;
110  }
111  else {
112  extremity2 = newExtremity2;
113  }
114  fCentre = 0.5 * (extremity2 + extremity1);
115  fRadius = 0.5 * (extremity2 - extremity1).mag ();
116  }
117  }
118 }
G4BoundingSphereScene(G4VModel *pModel=0)
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()
void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
HepGeom::Transform3D G4Transform3D
virtual G4VisExtent GetExtent() const
Definition: G4VSolid.cc:621
void Accrue(const G4VSolid &solid)
void AccrueBoundingSphere(const G4Point3D &centre, G4double radius)
double G4double
Definition: G4Types.hh:76
const G4Transform3D * fpObjectTransformation