G4BoundingSphereScene.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // John Allison  7th June 1997
00031 // An artificial scene to reuse G4VScene code to calculate a bounding sphere.
00032 
00033 #include "G4BoundingSphereScene.hh"
00034 
00035 #include "G4VSolid.hh"
00036 #include "G4PhysicalVolumeModel.hh"
00037 #include "G4Vector3D.hh"
00038 
00039 G4BoundingSphereScene::G4BoundingSphereScene (G4VModel* pModel):
00040   fpModel (pModel),
00041   fRadius (-1.),
00042   fpObjectTransformation (0)
00043 {}
00044 
00045 G4BoundingSphereScene::~G4BoundingSphereScene () {}
00046 
00047 void G4BoundingSphereScene::PreAddSolid
00048 (const G4Transform3D& objectTransformation,
00049  const G4VisAttributes&) {
00050   fpObjectTransformation = &objectTransformation;
00051 }
00052 
00053 G4VisExtent G4BoundingSphereScene::GetBoundingSphereExtent () {
00054   return G4VisExtent (fCentre, fRadius);
00055 }
00056 
00057 void G4BoundingSphereScene::Accrue (const G4VSolid& solid) {
00058 
00059   const G4VisExtent& newExtent = solid.GetExtent ();
00060   G4Point3D newCentre = newExtent.GetExtentCentre ();
00061   if (fpObjectTransformation) {
00062     newCentre.transform (*fpObjectTransformation);
00063   }
00064   const G4double newRadius = newExtent.GetExtentRadius ();
00065   AccrueBoundingSphere (newCentre, newRadius);
00066 
00067   // Curtail descent - can assume daughters are contained within mother...
00068   G4PhysicalVolumeModel* pPVM = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
00069   if (pPVM) pPVM->CurtailDescent();
00070 }
00071 
00072 void G4BoundingSphereScene::ResetBoundingSphere () {
00073   fCentre = G4Point3D ();
00074   fRadius = -1.;
00075   fpObjectTransformation = 0;
00076 }
00077 
00078 void G4BoundingSphereScene::AccrueBoundingSphere
00079 (const G4Point3D& newCentre,
00080  G4double newRadius) {
00081 
00082   if (fRadius < 0 ) {  // First time.
00083     fCentre = newCentre;
00084     fRadius = newRadius;
00085   }
00086   else {
00087     G4Vector3D join = newCentre - fCentre;
00088     if (join == G4Vector3D (0., 0., 0.)) {             // Centres coincide.
00089       if (fRadius < newRadius) fRadius = newRadius;
00090     }
00091     else if (join.mag () + newRadius <= fRadius) {  // Inside accrued sphere.
00092       // Do nothing.
00093     }
00094     else {
00095       G4Vector3D unitJoin = join.unit ();
00096       G4Point3D oldExtremity1 = fCentre - fRadius * unitJoin;
00097       G4Point3D newExtremity1 = newCentre - newRadius * unitJoin;
00098       G4Point3D oldExtremity2 = fCentre + fRadius * unitJoin;
00099       G4Point3D newExtremity2 = newCentre + newRadius * unitJoin;
00100       G4Point3D extremity1;
00101       if (oldExtremity1 * unitJoin < newExtremity1 * unitJoin) {
00102         extremity1 = oldExtremity1;
00103       }
00104       else {
00105         extremity1 = newExtremity1;
00106       }
00107       G4Point3D extremity2;
00108       if (oldExtremity2 * unitJoin > newExtremity2 * unitJoin) {
00109         extremity2 = oldExtremity2;
00110       }
00111       else {
00112         extremity2 = newExtremity2;
00113       }
00114       fCentre = 0.5 * (extremity2 + extremity1);
00115       fRadius = 0.5 * (extremity2 - extremity1).mag ();
00116     }
00117   }
00118 }

Generated on Mon May 27 17:47:46 2013 for Geant4 by  doxygen 1.4.7