Import Geant4 8.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-09 14:44:26 +02:00
parent 8a51e0bc40
commit 216a75eeb1
8717 changed files with 360418 additions and 141343 deletions
@@ -1,28 +1,31 @@
//
// ********************************************************************
// * DISCLAIMER *
// * License and Disclaimer *
// * *
// * The following disclaimer summarizes all the specific disclaimers *
// * of contributors to this software. The specific disclaimers,which *
// * govern, are listed with their locations in: *
// * http://cern.ch/geant4/license *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the intellectual property of the *
// * GEANT4 collaboration. *
// * By copying, distributing or modifying the Program (or any work *
// * based on the Program) you indicate your acceptance of this *
// * statement, and all its terms. *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
// $Id: G4PhysicalVolumeModel.cc,v 1.36 2005/11/24 11:15:21 allison Exp $
// GEANT4 tag $Name: geant4-08-00 $
// $Id: G4PhysicalVolumeModel.cc,v 1.47 2006/06/29 21:32:54 gunter Exp $
// GEANT4 tag $Name: geant4-08-01 $
//
//
// John Allison 31st December 1997.
@@ -41,11 +44,37 @@
#include "G4BoundingSphereScene.hh"
#include "G4PhysicalVolumeSearchScene.hh"
#include "G4TransportationManager.hh"
#include "G4VVisManager.hh"
#include "G4Polyhedron.hh"
#include <sstream>
G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator<
(const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID& right) const
{
if (fpPV < right.fpPV) return true;
if (fpPV == right.fpPV) return fCopyNo < right.fCopyNo;
return false;
}
G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator==
(const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID& right) const
{
return fpPV == right.fpPV && fCopyNo == right.fCopyNo;
}
std::ostream& operator<<
(std::ostream& os, const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID node)
{
G4VPhysicalVolume* pPV = node.GetPhysicalVolume();
if (pPV) {
os << pPV->GetName() << ':'
<< node.GetCopyNo();
} else {
os << "Null node";
}
return os;
}
G4PhysicalVolumeModel::G4PhysicalVolumeModel
(G4VPhysicalVolume* pVPV,
G4int requestedDepth,
@@ -61,12 +90,14 @@ G4PhysicalVolumeModel::G4PhysicalVolumeModel
fCurrentDepth (0),
fpCurrentPV (0),
fpCurrentLV (0),
fpCurrentMaterial (0),
fCurtailDescent (false),
fpClippingPolyhedron (0),
fpCurrentDepth (0),
fppCurrentPV (0),
fppCurrentLV (0),
fppCurrentMaterial (0)
fpCurrentDepth (0),
fppCurrentPV (0),
fppCurrentLV (0),
fppCurrentMaterial (0),
fpDrawnPVPath (0)
{
std::ostringstream o;
o << fpTopPV -> GetCopyNo ();
@@ -78,7 +109,8 @@ G4PhysicalVolumeModel::G4PhysicalVolumeModel
G4PhysicalVolumeModel::~G4PhysicalVolumeModel () {}
void G4PhysicalVolumeModel::CalculateExtent () {
void G4PhysicalVolumeModel::CalculateExtent ()
{
if (fUseFullExtent) {
fExtent = fpTopPV -> GetLogicalVolume () -> GetSolid () -> GetExtent ();
}
@@ -88,7 +120,7 @@ void G4PhysicalVolumeModel::CalculateExtent () {
fRequestedDepth = -1; // Always search to all depths to define extent.
const G4ModelingParameters* tempMP = fpMP;
G4ModelingParameters mParams
(0, // No default vis attributes.
(0, // No default vis attributes needed.
G4ModelingParameters::wireframe,
true, // Global culling.
true, // Cull invisible volumes.
@@ -120,43 +152,52 @@ void G4PhysicalVolumeModel::CalculateExtent () {
}
void G4PhysicalVolumeModel::DescribeYourselfTo
(G4VGraphicsScene& sceneHandler) {
(G4VGraphicsScene& sceneHandler)
{
if (!fpMP) G4Exception
("G4PhysicalVolumeModel::DescribeYourselfTo: No modeling parameters.");
if (fpMP && fpMP -> IsViewGeom ()) {
sceneHandler.EstablishSpecials (*this);
// See .hh file for explanation of this mechanism.
sceneHandler.EstablishSpecials (*this);
// See .hh file for explanation of this mechanism.
// For safety...
fCurrentDepth = 0;
// ...and in working space in scene handler, if required...
if (fpCurrentDepth) *fpCurrentDepth = 0;
fCurrentDepth = 0;
// Store in working space (via pointer to working space).
if (fpCurrentDepth) *fpCurrentDepth = fCurrentDepth;
G4Transform3D startingTransformation = fTransform;
G4Transform3D startingTransformation = fTransform;
VisitGeometryAndGetVisReps
(fpTopPV,
fRequestedDepth,
startingTransformation,
sceneHandler);
VisitGeometryAndGetVisReps (fpTopPV,
fRequestedDepth,
startingTransformation,
sceneHandler);
// Clear data...
fCurrentDepth = 0;
fpCurrentPV = 0;
fpCurrentLV = 0;
fpCurrentMaterial = 0;
fDrawnPVPath.clear();
// ...and in working space in scene handler, if required...
if (fpCurrentDepth) *fpCurrentDepth = 0;
if (fppCurrentPV) *fppCurrentPV = 0;
if (fppCurrentLV) *fppCurrentLV = 0;
if (fppCurrentMaterial) *fppCurrentMaterial = 0;
if (fpDrawnPVPath) fpDrawnPVPath->clear();
// Clear current data and working space (via pointers to working space).
fCurrentDepth = 0;
fpCurrentPV = 0;
fpCurrentLV = 0;
if (fpCurrentDepth) *fpCurrentDepth = fCurrentDepth;
if (fppCurrentPV) *fppCurrentPV = fpCurrentPV;
if (fppCurrentLV) *fppCurrentLV = fpCurrentLV;
if (fppCurrentMaterial) *fppCurrentMaterial = fpCurrentMaterial;
sceneHandler.DecommissionSpecials (*this);
sceneHandler.DecommissionSpecials (*this);
// Clear pointers to working space.
fpCurrentDepth = 0;
fppCurrentPV = 0;
fppCurrentLV = 0;
fppCurrentMaterial = 0;
}
// Clear pointers to working space.
fpCurrentDepth = 0;
fppCurrentPV = 0;
fppCurrentLV = 0;
fppCurrentMaterial = 0;
fpDrawnPVPath = 0;
}
G4String G4PhysicalVolumeModel::GetCurrentTag () const {
G4String G4PhysicalVolumeModel::GetCurrentTag () const
{
if (fpCurrentPV) {
std::ostringstream o;
o << fpCurrentPV -> GetCopyNo ();
@@ -167,7 +208,8 @@ G4String G4PhysicalVolumeModel::GetCurrentTag () const {
}
}
G4String G4PhysicalVolumeModel::GetCurrentDescription () const {
G4String G4PhysicalVolumeModel::GetCurrentDescription () const
{
return "G4PhysicalVolumeModel " + GetCurrentTag ();
}
@@ -175,19 +217,22 @@ void G4PhysicalVolumeModel::DefinePointersToWorkingSpace
(G4int* pCurrentDepth,
G4VPhysicalVolume** ppCurrentPV,
G4LogicalVolume** ppCurrentLV,
G4Material** ppCurrentMaterial) {
fpCurrentDepth = pCurrentDepth;
fppCurrentPV = ppCurrentPV;
fppCurrentLV = ppCurrentLV;
G4Material** ppCurrentMaterial,
std::vector<G4PhysicalVolumeNodeID>* pDrawnPVPath)
{
fpCurrentDepth = pCurrentDepth;
fppCurrentPV = ppCurrentPV;
fppCurrentLV = ppCurrentLV;
fppCurrentMaterial = ppCurrentMaterial;
fpDrawnPVPath = pDrawnPVPath;
}
void G4PhysicalVolumeModel::VisitGeometryAndGetVisReps
(G4VPhysicalVolume* pVPV,
G4int requestedDepth,
const G4Transform3D& theAT,
G4VGraphicsScene& sceneHandler) {
G4VGraphicsScene& sceneHandler)
{
// Visits geometry structure to a given depth (requestedDepth), starting
// at given physical volume with given starting transformation and
// describes volumes to the scene handler.
@@ -326,17 +371,17 @@ void G4PhysicalVolumeModel::DescribeAndDescend
G4VSolid* pSol,
G4Material* pMaterial,
const G4Transform3D& theAT,
G4VGraphicsScene& sceneHandler) {
// Maintain data members and store in working space (via pointers to
// working space).
if (fpCurrentDepth) *fpCurrentDepth = fCurrentDepth;
G4VGraphicsScene& sceneHandler)
{
// Maintain useful data members...
fpCurrentPV = pVPV;
fpCurrentLV = pLV;
fpCurrentMaterial = pMaterial;
if (fppCurrentPV) *fppCurrentPV = fpCurrentPV;
if (fppCurrentLV) *fppCurrentLV = fpCurrentLV;
if (fppCurrentMaterial) *fppCurrentMaterial = fpCurrentMaterial;
// ...and store in scene handler's working space, if required...
if (fpCurrentDepth) *fpCurrentDepth = fCurrentDepth;
if (fppCurrentPV) *fppCurrentPV = pVPV;
if (fppCurrentLV) *fppCurrentLV = pLV;
if (fppCurrentMaterial) *fppCurrentMaterial = pMaterial;
const G4RotationMatrix objectRotation = pVPV -> GetObjectRotationValue ();
const G4ThreeVector& translation = pVPV -> GetTranslation ();
@@ -378,50 +423,141 @@ void G4PhysicalVolumeModel::DescribeAndDescend
G4cout << G4endl;
**********************************************************/
// Make decision to Draw.
G4bool thisToBeDrawn = !IsThisCulled (pLV, pMaterial);
// Make decision to draw...
const G4VisAttributes* pVisAttribs = pLV->GetVisAttributes();
if (!pVisAttribs) pVisAttribs = fpMP->GetDefaultVisAttributes();
// Beware - pVisAttribs might still be zero - create a temporary default one...
G4bool visAttsCreated = false;
if (!pVisAttribs) {
pVisAttribs = new G4VisAttributes;
visAttsCreated = true;
}
G4bool thisToBeDrawn = true;
// There are various reasons why this volume
// might not be drawn...
G4bool culling = fpMP->IsCulling();
G4bool cullingInvisible = fpMP->IsCullingInvisible();
G4bool markedVisible = pVisAttribs? pVisAttribs->IsVisible(): true;
G4bool cullingLowDensity = fpMP->IsDensityCulling();
G4double density = pMaterial->GetDensity();
G4double densityCut = fpMP -> GetVisibleDensity ();
// 1) Global culling is on....
if (culling) {
// 2) Culling of invisible volumes is on...
if (cullingInvisible) {
// 3) ...and the volume is marked not visible...
if (!markedVisible) thisToBeDrawn = false;
}
// 4) Or culling of low density volumes is on...
if (cullingLowDensity) {
// 5) ...and density is less than cut value...
if (density < densityCut) thisToBeDrawn = false;
}
}
if (thisToBeDrawn) {
const G4VisAttributes* pVisAttribs = pLV -> GetVisAttributes ();
if (!pVisAttribs) pVisAttribs = fpMP -> GetDefaultVisAttributes ();
// Update path of physical volumes, if required...
G4int copyNo = fpCurrentPV->GetCopyNo();
fDrawnPVPath.push_back(G4PhysicalVolumeNodeID(fpCurrentPV,copyNo));
if (fpDrawnPVPath) {
fpDrawnPVPath->push_back(G4PhysicalVolumeNodeID(fpCurrentPV,copyNo));
}
DescribeSolid (theNewAT, pSol, pVisAttribs, sceneHandler);
}
if (fCurtailDescent) {
fCurtailDescent = false;
// Reset for normal descending of next volume at this level.
return;
}
// Make decision to draw daughters, if any. There are various
// reasons why daughters might not be drawn...
// First check if mother covers...
// First, reasons that do not depend on culling policy...
G4int nDaughters = pLV->GetNoDaughters();
G4bool daughtersToBeDrawn = true;
// 1) There are no daughters...
if (!nDaughters) daughtersToBeDrawn = false;
// 2) We are at the limit if requested depth...
else if (requestedDepth == 0) daughtersToBeDrawn = false;
// 3) The user has asked that the descent be curtailed...
else if (fCurtailDescent) daughtersToBeDrawn = false;
// This is only effective in surface drawing style, and then only if
// the volumes are visible and opaque, and then only if no sections
// or cutways are in operation.
G4bool cullDaughter = thisToBeDrawn && IsDaughterCulled (pLV);
if (!cullDaughter) {
// OK, now let's check for daughters...
if (requestedDepth != 0) {
int nDaughters = pLV -> GetNoDaughters ();
if (nDaughters) {
for (int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
G4VPhysicalVolume* pVPV = pLV -> GetDaughter (iDaughter);
// Descend the geometry structure recursively...
fCurrentDepth++;
VisitGeometryAndGetVisReps
(pVPV, requestedDepth - 1, theNewAT, sceneHandler);
fCurrentDepth--;
// Now, reasons that depend on culling policy...
else {
G4bool culling = fpMP->IsCulling();
G4bool cullingInvisible = fpMP->IsCullingInvisible();
G4bool daughtersInvisible =
pVisAttribs? pVisAttribs->IsDaughtersInvisible(): false;
// Culling of covered daughters request. This is computed in
// G4VSceneHandler::CreateModelingParameters() depending on view
// parameters...
G4bool cullingCovered = fpMP->IsCullingCovered();
G4bool surfaceDrawing =
fpMP->GetDrawingStyle() == G4ModelingParameters::hsr ||
fpMP->GetDrawingStyle() == G4ModelingParameters::hlhsr;
if (pVisAttribs && pVisAttribs->IsForceDrawingStyle()) {
switch (pVisAttribs->GetForcedDrawingStyle()) {
default:
case G4VisAttributes::wireframe: surfaceDrawing = false; break;
case G4VisAttributes::solid: surfaceDrawing = true; break;
}
}
G4bool opaque =
pVisAttribs? pVisAttribs->GetColour().GetAlpha() >= 1.: false;
// 4) Global culling is on....
if (culling) {
// 5) ..and culling of invisible volumes is on...
if (cullingInvisible) {
// 6) ...and the mother requests daughters invisible
if (daughtersInvisible) daughtersToBeDrawn = false;
}
// 7) Or culling of covered daughters is requested...
if (cullingCovered) {
// 8) ...and surface drawing is operating...
if (surfaceDrawing) {
// 9) ...but only if mother is visible...
if (thisToBeDrawn) {
// 10) ...and opaque...
if (opaque) daughtersToBeDrawn = false;
}
}
}
}
}
// Vis atts for this volume no longer needed if created...
if (visAttsCreated) delete pVisAttribs;
if (daughtersToBeDrawn) {
for (G4int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
G4VPhysicalVolume* pVPV = pLV -> GetDaughter (iDaughter);
// Descend the geometry structure recursively...
fCurrentDepth++;
VisitGeometryAndGetVisReps
(pVPV, requestedDepth - 1, theNewAT, sceneHandler);
fCurrentDepth--;
}
}
// Reset for normal descending of next volume at this level...
fCurtailDescent = false;
// Pop item from path of physical volumes...
if (thisToBeDrawn) {
fDrawnPVPath.pop_back();
if (fpDrawnPVPath) {
fpDrawnPVPath->pop_back();
}
}
}
void G4PhysicalVolumeModel::DescribeSolid
(const G4Transform3D& theAT,
G4VSolid* pSol,
const G4VisAttributes* pVisAttribs,
G4VGraphicsScene& sceneHandler) {
G4VGraphicsScene& sceneHandler)
{
sceneHandler.PreAddSolid (theAT, *pVisAttribs);
if (fpClippingPolyhedron) // Clip and force polyhedral representation...
{
@@ -445,7 +581,9 @@ void G4PhysicalVolumeModel::DescribeSolid
else
{
clipped.SetVisAttributes(pVisAttribs);
G4VVisManager::GetConcreteInstance()->Draw(clipped,theAT);
sceneHandler.BeginPrimitives(theAT);
sceneHandler.AddPrimitive(clipped);
sceneHandler.EndPrimitives();
}
}
}
@@ -457,66 +595,8 @@ void G4PhysicalVolumeModel::DescribeSolid
sceneHandler.PostAddSolid ();
}
G4bool G4PhysicalVolumeModel::IsThisCulled (const G4LogicalVolume* pLV,
const G4Material* pMaterial) {
// If true, cull, i.e., do not Draw.
G4double density = 0.;
if (pMaterial) density = pMaterial -> GetDensity ();
const G4VisAttributes* pVisAttribs = pLV -> GetVisAttributes ();
if (!pVisAttribs) pVisAttribs = fpMP -> GetDefaultVisAttributes ();
if (fpMP) {
return
fpMP -> IsCulling () && // Global culling flag.
(
// Invisible volumes...
(fpMP -> IsCullingInvisible () &&
!(pVisAttribs ? pVisAttribs -> IsVisible () : true)) ||
// Low density volumes...
(fpMP -> IsDensityCulling () &&
(density < fpMP -> GetVisibleDensity ()))
)
;
}
else {
return false;
}
}
G4bool G4PhysicalVolumeModel::IsDaughterCulled
(const G4LogicalVolume* pMotherLV) {
// If true, cull, i.e., do not Draw.
const G4VisAttributes* pVisAttribs = pMotherLV -> GetVisAttributes ();
if (!pVisAttribs) pVisAttribs = fpMP -> GetDefaultVisAttributes ();
if (fpMP) {
return
fpMP -> IsCulling () // Global culling flag.
&&
(
// Does mother request daughters not to be drawn?
(pVisAttribs ? pVisAttribs -> IsDaughtersInvisible () : false)
||
(
// Global covered daughter flag. This is affected by drawing
// style, etc. The enforcing of this is done in
// G4VScene::CreateModelingParameters ()
fpMP -> IsCullingCovered ()
&&
// Cull only if mother is visible...
(pVisAttribs ? pVisAttribs -> IsVisible () : true)
&&
// ...and opaque...
(pVisAttribs ? (pVisAttribs -> GetColour ().GetAlpha() >= 1.) : true)
)
)
;
}
else {
return false;
}
}
G4bool G4PhysicalVolumeModel::Validate (G4bool warn) {
G4bool G4PhysicalVolumeModel::Validate (G4bool warn)
{
G4VPhysicalVolume* world =
G4TransportationManager::GetTransportationManager ()
-> GetNavigatorForTracking () -> GetWorldVolume ();
@@ -525,9 +605,11 @@ G4bool G4PhysicalVolumeModel::Validate (G4bool warn) {
if (warn) {
G4cout << "G4PhysicalVolumeModel::Validate() called." << G4endl;
}
G4PhysicalVolumeSearchScene searchScene (fTopPVName, fTopPVCopyNo);
G4PhysicalVolumeModel searchModel (world);
G4PhysicalVolumeSearchScene searchScene
(&searchModel, fTopPVName, fTopPVCopyNo);
G4ModelingParameters mp; // Default modeling parameters for this search.
mp.SetDefaultVisAttributes(fpMP? fpMP->GetDefaultVisAttributes(): 0);
searchModel.SetModelingParameters (&mp);
searchModel.DescribeYourselfTo (searchScene);
G4VPhysicalVolume* foundVolume = searchScene.GetFoundVolume ();