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,v 1.11 2006/06/29 21:32:40 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
29 | // |
---|
30 | // |
---|
31 | // John Allison 7th June 1997 |
---|
32 | // An artificial scene to reuse G4VScene code to calculate a bounding sphere. |
---|
33 | |
---|
34 | #include "G4BoundingSphereScene.hh" |
---|
35 | |
---|
36 | #include "G4VSolid.hh" |
---|
37 | #include "G4PhysicalVolumeModel.hh" |
---|
38 | #include "G4Vector3D.hh" |
---|
39 | |
---|
40 | G4BoundingSphereScene::G4BoundingSphereScene (G4VModel* pModel): |
---|
41 | fpModel (pModel), |
---|
42 | fRadius (-1.), |
---|
43 | fpObjectTransformation (0) |
---|
44 | {} |
---|
45 | |
---|
46 | G4BoundingSphereScene::~G4BoundingSphereScene () {} |
---|
47 | |
---|
48 | void G4BoundingSphereScene::PreAddSolid |
---|
49 | (const G4Transform3D& objectTransformation, |
---|
50 | const G4VisAttributes&) { |
---|
51 | fpObjectTransformation = &objectTransformation; |
---|
52 | } |
---|
53 | |
---|
54 | G4VisExtent G4BoundingSphereScene::GetBoundingSphereExtent () { |
---|
55 | return G4VisExtent (fCentre, fRadius); |
---|
56 | } |
---|
57 | |
---|
58 | void G4BoundingSphereScene::Accrue (const G4VSolid& solid) { |
---|
59 | |
---|
60 | const G4VisExtent& newExtent = solid.GetExtent (); |
---|
61 | G4Point3D newCentre = newExtent.GetExtentCentre (); |
---|
62 | if (fpObjectTransformation) { |
---|
63 | newCentre.transform (*fpObjectTransformation); |
---|
64 | } |
---|
65 | const G4double newRadius = newExtent.GetExtentRadius (); |
---|
66 | AccrueBoundingSphere (newCentre, newRadius); |
---|
67 | |
---|
68 | // Curtail descent - can assume daughters are contained within mother... |
---|
69 | G4PhysicalVolumeModel* pPVM = dynamic_cast<G4PhysicalVolumeModel*>(fpModel); |
---|
70 | if (pPVM) pPVM->CurtailDescent(); |
---|
71 | } |
---|
72 | |
---|
73 | void G4BoundingSphereScene::ResetBoundingSphere () { |
---|
74 | fCentre = G4Point3D (); |
---|
75 | fRadius = -1.; |
---|
76 | fpObjectTransformation = 0; |
---|
77 | } |
---|
78 | |
---|
79 | void G4BoundingSphereScene::AccrueBoundingSphere |
---|
80 | (const G4Point3D& newCentre, |
---|
81 | G4double newRadius) { |
---|
82 | |
---|
83 | if (fRadius < 0 ) { // First time. |
---|
84 | fCentre = newCentre; |
---|
85 | fRadius = newRadius; |
---|
86 | } |
---|
87 | else { |
---|
88 | G4Vector3D join = newCentre - fCentre; |
---|
89 | if (join == G4Vector3D (0., 0., 0.)) { // Centres coincide. |
---|
90 | if (fRadius < newRadius) fRadius = newRadius; |
---|
91 | } |
---|
92 | else if (join.mag () + newRadius <= fRadius) { // Inside accrued sphere. |
---|
93 | // Do nothing. |
---|
94 | } |
---|
95 | else { |
---|
96 | G4Vector3D unitJoin = join.unit (); |
---|
97 | G4Point3D oldExtremity1 = fCentre - fRadius * unitJoin; |
---|
98 | G4Point3D newExtremity1 = newCentre - newRadius * unitJoin; |
---|
99 | G4Point3D oldExtremity2 = fCentre + fRadius * unitJoin; |
---|
100 | G4Point3D newExtremity2 = newCentre + newRadius * unitJoin; |
---|
101 | G4Point3D extremity1; |
---|
102 | if (oldExtremity1 * unitJoin < newExtremity1 * unitJoin) { |
---|
103 | extremity1 = oldExtremity1; |
---|
104 | } |
---|
105 | else { |
---|
106 | extremity1 = newExtremity1; |
---|
107 | } |
---|
108 | G4Point3D extremity2; |
---|
109 | if (oldExtremity2 * unitJoin > newExtremity2 * unitJoin) { |
---|
110 | extremity2 = oldExtremity2; |
---|
111 | } |
---|
112 | else { |
---|
113 | extremity2 = newExtremity2; |
---|
114 | } |
---|
115 | fCentre = 0.5 * (extremity2 + extremity1); |
---|
116 | fRadius = 0.5 * (extremity2 - extremity1).mag (); |
---|
117 | } |
---|
118 | } |
---|
119 | } |
---|