Import Geant4 4.1.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-08 16:39:52 +02:00
parent 921d3b1cda
commit 330b82b769
4524 changed files with 178689 additions and 43575 deletions
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4AssemblyVolume.cc,v 1.6 2001/07/11 09:59:20 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4AssemblyVolume.cc,v 1.10 2002/06/24 07:15:27 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
//
// Class G4AssemblyVolume - implementation
@@ -51,16 +51,25 @@ G4AssemblyVolume::G4AssemblyVolume()
//
G4AssemblyVolume::~G4AssemblyVolume()
{
unsigned int howmany = fTriplets.size();
if( howmany != 0 ) {
for( unsigned int i = 0; i < howmany; i++ ) {
G4RotationMatrix* pRotToClean = fTriplets[i].GetRotation();
if( pRotToClean != 0 ) {
delete pRotToClean;
}
}
}
fTriplets.clear();
unsigned int howmany = fPVStore.size();
if( howmany != 0 )
{
for( unsigned int i = 0; i < howmany; i++ )
{
G4RotationMatrix* pRotToClean = fPVStore[i]->GetRotation();
if( pRotToClean != 0 ) delete pRotToClean;
delete fPVStore[i];
howmany = fPVStore.size();
if( howmany != 0 ) {
for( unsigned int j = 0; j < howmany; j++ ) {
G4RotationMatrix* pRotToClean = fPVStore[j]->GetRotation();
if( pRotToClean != 0 ) {
delete pRotToClean;
}
delete fPVStore[j];
}
}
@@ -71,11 +80,25 @@ G4AssemblyVolume::~G4AssemblyVolume()
// Add and place the given volume according to the specified
// translation and rotation.
//
// The rotation matrix passed in can be 0 = identity or an address even of an object
// on the upper stack frame. During assembly imprint, it creates anyway a new matrix
// and keeps track of it so it can delete it later at destruction time.
// This new policy has been adopted since user has no control on the way the rotations
// are combined it's safer doing it this way.
//
// WARNING! This interface will likely change in the next major release of Geant4 from
// a pointer to a reference due to the reason above
void G4AssemblyVolume::AddPlacedVolume( G4LogicalVolume* pVolume,
G4ThreeVector& translation,
G4RotationMatrix* pRotation )
{
G4AssemblyTriplet toAdd( pVolume, translation, pRotation );
G4RotationMatrix* toStore = new G4RotationMatrix;
if( pRotation != 0 ) {
*toStore = *pRotation;
}
G4AssemblyTriplet toAdd( pVolume, translation, toStore );
fTriplets.push_back( toAdd );
}
@@ -84,48 +107,77 @@ void G4AssemblyVolume::AddPlacedVolume( G4LogicalVolume* pVolume,
void G4AssemblyVolume::AddPlacedVolume( G4LogicalVolume* pVolume,
G4Transform3D& transformation )
{
G4ThreeVector v = transformation.getTranslation();
G4RotationMatrix r = transformation.getRotation();
G4AssemblyTriplet toAdd( pVolume, v, &r );
G4ThreeVector v = transformation.getTranslation();
G4RotationMatrix* r = new G4RotationMatrix;
*r = transformation.getRotation();
G4AssemblyTriplet toAdd( pVolume, v, r );
fTriplets.push_back( toAdd );
}
/**
* Create an instance of an assembly volume inside of the specified
* mother volume. This works analogically to making stamp imprints.
* This method makes use of the Geant4 affine transformation class.
* The algorithm is defined as follows:
*
* Having rotation matrix Rm and translation vector Tm to be applied
* inside the mother and rotation matrix Ra and translation vector Ta
* to be applied inside the assembly itself for each of the participating
* volumes the resulting transformation is
*
* Tfinal = Ta * Tm
*
* where Ta and Tm are constructed as
*
* -1 -1
* Ta = Ra * Ta and Tm = Rm * Tm
*
* which in words means that we create first the affine transformations
* by inverse rotation matrices and translations for mother and assembly.
* The resulting final transformation to be applied to each of the
* participating volumes is their product.
* IMPORTANT NOTE!
* The order of multiplication is reversed when comparing to CLHEP 3D
* transformation matrix(G4Transform3D class).
*/
//
// Create an instance of an assembly volume inside of the specified
// mother volume. This works analogically to making stamp imprints.
// This method makes use of the Geant4 affine transformation class.
// The algorithm is defined as follows:
//
// Having rotation matrix Rm and translation vector Tm to be applied
// inside the mother and rotation matrix Ra and translation vector Ta
// to be applied inside the assembly itself for each of the participating
// volumes the resulting transformation is
//
// Tfinal = Ta * Tm
//
// where Ta and Tm are constructed as
//
// -1 -1
// Ta = Ra * Ta and Tm = Rm * Tm
//
// which in words means that we create first the affine transformations
// by inverse rotation matrices and translations for mother and assembly.
// The resulting final transformation to be applied to each of the
// participating volumes is their product.
//
// IMPORTANT NOTE!
// The order of multiplication is reversed when comparing to CLHEP 3D
// transformation matrix(G4Transform3D class).
//
// The rotation matrix passed in can be 0 = identity or an address even of an object
// on the upper stack frame. During assembly imprint, it creates anyway a new matrix
// and keeps track of it so it can delete it later at destruction time.
// This new policy has been adopted since user has no control on the way the rotations
// are combined it's safer doing it this way.
//
// WARNING! This interface will likely change in the next major release of Geant4 from
// a pointer to a reference due to the reason above
//
void G4AssemblyVolume::MakeImprint( G4LogicalVolume* pMotherLV,
G4ThreeVector& translationInMother,
G4RotationMatrix* pRotationInMother )
G4RotationMatrix* pRotationInMother,
G4int copyNumBase )
{
unsigned int numberOfDaughters = pMotherLV->GetNoDaughters();
// If needed user can specify explicitly the base count from which to start off for the generation
// of phys. vol. copy numbers
// The old behaviour is preserved when copyNumBase == 0, e.g. the generated copy numbers start
// from the count equal to current number of daughter volumes before a imprint is made
unsigned int numberOfDaughters;
if( copyNumBase != 0 ) {
numberOfDaughters = pMotherLV->GetNoDaughters();
} else {
numberOfDaughters = copyNumBase;
}
// We start from the first available index
numberOfDaughters++;
ImprintsCountPlus();
if( pRotationInMother == 0 ) {
// Make it by default an indentity matrix;
pRotationInMother = const_cast<G4RotationMatrix*>( &G4RotationMatrix::IDENTITY );
}
for( unsigned int i = 0; i < fTriplets.size(); i++ )
{
@@ -182,9 +234,21 @@ void G4AssemblyVolume::MakeImprint( G4LogicalVolume* pMotherLV,
}
void G4AssemblyVolume::MakeImprint( G4LogicalVolume* pMotherLV,
G4Transform3D& transformation )
G4Transform3D& transformation,
G4int copyNumBase )
{
unsigned int numberOfDaughters = pMotherLV->GetNoDaughters();
// If needed user can specify explicitly the base count from which to start off for the generation
// of phys. vol. copy numbers
// The old behaviour is preserved when copyNumBase == 0, e.g. the generated copy numbers start
// from the count equal to current number of daughter volumes before a imprint is made
unsigned int numberOfDaughters;
if( copyNumBase != 0 ) {
numberOfDaughters = pMotherLV->GetNoDaughters();
} else {
numberOfDaughters = copyNumBase;
}
// We start from the first available index
numberOfDaughters++;
+19 -10
View File
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4DrawVoxels.cc,v 1.14 2001/07/11 09:59:20 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4DrawVoxels.cc,v 1.15 2002/04/19 08:20:22 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
//
// class G4DrawVoxels
@@ -41,6 +41,22 @@
#include "G4VVisManager.hh"
/****************************/
//Private Constructor
G4DrawVoxels::G4DrawVoxels(){
fVoxelsVisAttributes[0].SetColour(G4Colour(1.,0.,0.));
fVoxelsVisAttributes[1].SetColour(G4Colour(0.,1.,0.));
fVoxelsVisAttributes[2].SetColour(G4Colour(0.,0.,1.));
fBoundingBoxVisAttributes.SetColour(G4Colour(.3,0.,.2));
}
// Destructor
G4DrawVoxels::~G4DrawVoxels()
{
}
//Methods that allow changing colors of the drawing
void G4DrawVoxels::SetVoxelsVisAttributes(G4VisAttributes& VA_voxelX,G4VisAttributes& VA_voxelY,G4VisAttributes& VA_voxelZ){
fVoxelsVisAttributes[0]=VA_voxelX; //operateur de copie ...
@@ -172,14 +188,6 @@ void G4DrawVoxels::ComputeVoxelPolyhedra(const G4LogicalVolume* lv,
}//end of ComputeVoxelPolyhedra...
//######################################################################################################################
//Private Constructor
G4DrawVoxels::G4DrawVoxels(){
fVoxelsVisAttributes[0].SetColour(G4Colour(1.,0.,0.));
fVoxelsVisAttributes[1].SetColour(G4Colour(0.,1.,0.));
fVoxelsVisAttributes[2].SetColour(G4Colour(0.,0.,1.));
fBoundingBoxVisAttributes.SetColour(G4Colour(.3,0.,.2));
}
G4AffineTransform G4DrawVoxels::GetAbsoluteTransformation(const G4VPhysicalVolume* pv) const{
//Initialisation of the transformation to be computed
G4AffineTransform transf; //default constructor ie Id
@@ -209,6 +217,7 @@ G4PlacedPolyhedronList* G4DrawVoxels::CreatePlacedPolyhedra(const G4LogicalVolum
}
void G4DrawVoxels::DrawVoxels(const G4LogicalVolume* lv) const{
G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4GeometryManager.cc,v 1.6 2001/10/26 12:56:02 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4GeometryManager.cc,v 1.11 2002/05/17 17:59:47 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
// class G4GeometryManager
//
@@ -30,24 +30,47 @@
//
// Author:
// 26.07.95 P.Kent Initial version, including optimisation Build
// ********************************************************************
#include "g4std/iomanip"
#include "G4Timer.hh"
#include "G4GeometryManager.hh"
#include "g4std/iomanip"
// Close geometry - perform sanity checks and optionally Build optimisation
// for placed volumes (always built for replicas & parameterised)
// NOTE: Currently no sanity checks
// ***************************************************************************
// Static class variable: ptr to single instance of class
// ***************************************************************************
//
G4GeometryManager* G4GeometryManager::fgInstance = 0;
// ***************************************************************************
// Constructor. Set the geometry to be open
// ***************************************************************************
//
G4GeometryManager::G4GeometryManager()
{
fIsClosed=false;
}
// ***************************************************************************
// Closes geometry - performs sanity checks and optionally builds optimisation
// for placed volumes (always built for replicas & parameterised).
// NOTE: Currently no sanity checks are performed.
// ***************************************************************************
//
G4bool G4GeometryManager::CloseGeometry(G4bool pOptimise, G4bool verbose)
{
if (!fIsClosed)
{
BuildOptimisations(pOptimise, verbose);
fIsClosed=true;
BuildOptimisations(pOptimise, verbose);
fIsClosed=true;
}
return true;
}
// ***************************************************************************
// Opens the geometry and removes all optimisations.
// ***************************************************************************
//
void G4GeometryManager::OpenGeometry()
{
if (fIsClosed)
@@ -57,29 +80,34 @@ void G4GeometryManager::OpenGeometry()
}
}
// Static class variable: ptr to single instance of class
G4GeometryManager* G4GeometryManager::fgInstance = 0;
// ***************************************************************************
// Returns status of geometry
// ***************************************************************************
//
G4bool G4GeometryManager::IsGeometryClosed()
{
return fIsClosed;
}
// ***************************************************************************
// Returns the instance of the singleton.
// Creates it in case it's called for the first time.
// ***************************************************************************
//
G4GeometryManager* G4GeometryManager::GetInstance()
{
static G4GeometryManager worldManager;
if (!fgInstance)
{
fgInstance = &worldManager;
}
return fgInstance;
static G4GeometryManager worldManager;
if (!fgInstance)
{
fgInstance = &worldManager;
}
return fgInstance;
}
// Constructor. Set the geometry to be open
G4GeometryManager::G4GeometryManager()
{
fIsClosed=false;
}
//
// Create optimisation info. Build all voxels if allOpts=true
// else only for replicated volumes
// ***************************************************************************
// Creates optimisation info. Builds all voxels if allOpts=true
// otherwise it builds voxels only for replicated volumes.
// ***************************************************************************
//
void G4GeometryManager::BuildOptimisations(G4bool allOpts, G4bool verbose)
{
@@ -91,53 +119,57 @@ void G4GeometryManager::BuildOptimisations(G4bool allOpts, G4bool verbose)
G4LogicalVolumeStore *Store;
G4LogicalVolume *volume;
G4SmartVoxelHeader *head;
G4int nVolumes,n;
G4int nVolumes, n;
Store=G4LogicalVolumeStore::GetInstance();
nVolumes=Store->size();
for (n=0;n<nVolumes;n++)
for (n=0; n<nVolumes; n++)
{
volume=(*Store)[n];
// For safety, check if there are any existing voxels and delete before
// replacement
head = volume->GetVoxelHeader();
if (head)
{
delete head;
volume->SetVoxelHeader(0);
}
if ((volume->GetNoDaughters()>=kMinVoxelVolumesLevel1&&allOpts) ||
(volume->GetNoDaughters()==1 &&
volume->GetDaughter(0)->IsReplicated()==true))
{
volume=(*Store)[n];
// For safety, check if there are any existing voxels and
// delete before replacement
//
head = volume->GetVoxelHeader();
if (head)
{
delete head;
volume->SetVoxelHeader(0);
}
if ( (volume->IsToOptimise())
&& (volume->GetNoDaughters()>=kMinVoxelVolumesLevel1&&allOpts)
|| ( (volume->GetNoDaughters()==1)
&& (volume->GetDaughter(0)->IsReplicated()==true) ) )
{
#ifdef G4GEOMETRY_VOXELDEBUG
G4cout << "**** G4GeometryManager::BuildOptimisations" << G4endl
<< " Examining logical volume name = "
<< volume->GetName() << G4endl;
G4cout << "**** G4GeometryManager::BuildOptimisations" << G4endl
<< " Examining logical volume name = "
<< volume->GetName() << G4endl;
#endif
head = new G4SmartVoxelHeader(volume);
if (head)
{
volume->SetVoxelHeader(head);
}
else
{
G4Exception("G4GeometryManager::BuildOptimisations voxelheader new failed");
}
if (verbose)
{
timer.Stop();
stats.push_back( G4SmartVoxelStat( volume, head,
timer.GetSystemElapsed(),
timer.GetUserElapsed() ) );
}
head = new G4SmartVoxelHeader(volume);
if (head)
{
volume->SetVoxelHeader(head);
}
else
{
G4cout << "ERROR - VoxelHeader new failed." << G4endl;
G4Exception("ERROR - G4GeometryManager::BuildOptimisations");
}
if (verbose)
{
timer.Stop();
stats.push_back( G4SmartVoxelStat( volume, head,
timer.GetSystemElapsed(),
timer.GetUserElapsed() ) );
}
}
else
{
// Don't create voxels for this node
// Don't create voxels for this node
#ifdef G4GEOMETRY_VOXELDEBUG
G4cout << "**** G4GeometryManager::BuildOptimisations" << G4endl
<< " Skipping logical volume name = " << volume->GetName()
<< G4endl;
G4cout << "**** G4GeometryManager::BuildOptimisations" << G4endl
<< " Skipping logical volume name = " << volume->GetName()
<< G4endl;
#endif
}
}
@@ -149,37 +181,37 @@ void G4GeometryManager::BuildOptimisations(G4bool allOpts, G4bool verbose)
}
}
// Remove all optimisation info
// ***************************************************************************
// Removes all optimisation info.
// Loops over all logical volumes, deleting non-null voxels pointers.
// ***************************************************************************
//
// Process:
//
// Loop over all logical volumes, deleting non-null voxels ptrs
void G4GeometryManager::DeleteOptimisations()
{
G4LogicalVolumeStore *Store=G4LogicalVolumeStore::GetInstance();
G4LogicalVolume *volume;
G4SmartVoxelHeader *head;
G4int nVolumes,n;
nVolumes=Store->size();
for (n=0;n<nVolumes;n++)
{
volume=(*Store)[n];
head=volume->GetVoxelHeader();
if (head)
{
delete head;
volume->SetVoxelHeader(0);
}
}
G4LogicalVolumeStore* Store=G4LogicalVolumeStore::GetInstance();
G4LogicalVolume* volume;
G4SmartVoxelHeader* head;
G4int nVolumes, n;
nVolumes = Store->size();
for (n=0; n<nVolumes; n++)
{
volume=(*Store)[n];
head=volume->GetVoxelHeader();
if (head)
{
delete head;
volume->SetVoxelHeader(0);
}
}
}
// ***************************************************************************
// Reports statistics on voxel optimisation when closing geometry.
// ***************************************************************************
//
// ReportVoxelStats
//
void
G4GeometryManager::ReportVoxelStats( G4std::vector<G4SmartVoxelStat> &stats,
G4GeometryManager::ReportVoxelStats( G4std::vector<G4SmartVoxelStat> & stats,
G4double totalCpuTime )
{
G4cout << "G4GeometryManager::ReportVoxelStats -- Voxel Statistics"
@@ -234,7 +266,8 @@ G4GeometryManager::ReportVoxelStats( G4std::vector<G4SmartVoxelStat> &stats,
<< G4std::setw(13) << (stats[i].GetMemoryUse()+512)/1024
<< "k " << G4std::setiosflags(G4std::ios::left)
<< stats[i].GetVolume()->GetName()
<< G4std::resetiosflags(G4std::ios::left)
<< G4std::resetiosflags(G4std::ios::floatfield|G4std::ios::adjustfield)
<< G4std::setprecision(6)
<< G4endl;
}
@@ -268,7 +301,8 @@ G4GeometryManager::ReportVoxelStats( G4std::vector<G4SmartVoxelStat> &stats,
<< G4std::setw(13) << totTime << " "
<< G4std::setiosflags(G4std::ios::left)
<< stats[i].GetVolume()->GetName()
<< G4std::resetiosflags(G4std::ios::left)
<< G4std::resetiosflags(G4std::ios::floatfield|G4std::ios::adjustfield)
<< G4std::setprecision(6)
<< G4endl;
}
}
+136 -97
View File
@@ -21,153 +21,192 @@
// ********************************************************************
//
//
// $Id: G4LogicalVolume.cc,v 1.8 2001/07/11 09:59:20 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4LogicalVolume.cc,v 1.10 2002/05/17 17:59:47 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
//
// class G4LogicalVolume Implementation
//
// History:
// 12.02.99 S.Giani: Deafult initialization of voxelization quality.
// 10.20.97 - P. MoraDeFreitas : "Fast" replaces "Parameterisation" in
// class/method names. (release B.00 for parameterisation).
// 04.08.97 P.MoraDeFreitas/J.A. Added methods for ParameterisedSimulation
// 19.08.96 P.Kent Modified for G4VSensitive Detector
// 11.07.95 P.Kent Initial version
// 17.05.02 G.Cosmo: Added flag for optional optimisation
// 12.02.99 S.Giani: Default initialization of voxelization quality
// 04.08.97 P.M.DeFreitas: Added methods for parameterised simulation
// 19.08.96 P.Kent: Modified for G4VSensitive Detector
// 11.07.95 P.Kent: Initial version
// ********************************************************************
#include "G4LogicalVolume.hh"
#include "G4LogicalVolumeStore.hh"
// Constructor - set member data and add to logical Store, zero voxel ptr
// Initialises daughter vector to 0 length
// ********************************************************************
// Constructor - sets member data and adds to logical Store,
// voxel pointer for optimisation set to 0 by default.
// Initialises daughter vector to 0 length.
// ********************************************************************
//
G4LogicalVolume::G4LogicalVolume( G4VSolid *pSolid, G4Material *pMaterial,
const G4String& name,
G4FieldManager *pFieldMgr,
G4VSensitiveDetector *pSDetector,
G4UserLimits *pULimits)
: fDaughters(0,(G4VPhysicalVolume*)0), fFieldManager(pFieldMgr), fVoxel(0),
fSmartless(2.), fVisAttributes (0), fFastSimulationManager (0), fIsEnvelope(FALSE)
G4LogicalVolume::G4LogicalVolume( G4VSolid* pSolid,
G4Material* pMaterial,
const G4String& name,
G4FieldManager* pFieldMgr,
G4VSensitiveDetector* pSDetector,
G4UserLimits* pULimits,
G4bool optimise )
: fDaughters(0,(G4VPhysicalVolume*)0), fFieldManager(pFieldMgr),
fVoxel(0), fOptimise(optimise), fSmartless(2.), fVisAttributes (0),
fFastSimulationManager (0), fIsEnvelope(false)
{
SetSolid(pSolid);
SetMaterial(pMaterial);
SetName(name);
SetSensitiveDetector(pSDetector);
SetUserLimits(pULimits);
// Add to solid Store
G4LogicalVolumeStore::Register(this);
SetSolid(pSolid);
SetMaterial(pMaterial);
SetName(name);
SetSensitiveDetector(pSDetector);
SetUserLimits(pULimits);
//
// Add to solid Store
//
G4LogicalVolumeStore::Register(this);
}
// Destructor - remove from solid Store
// ********************************************************************
// Destructor - Removes itself from solid Store
// NOTE: Not virtual
// ********************************************************************
//
G4LogicalVolume::~G4LogicalVolume()
{
G4LogicalVolumeStore::DeRegister(this);
G4LogicalVolumeStore::DeRegister(this);
}
// As this method is recursive, inlining it is harder (and asking for it
// is pointless if not counterproductive: it will increase code size)
// ********************************************************************
// SetFastSimulationManager
//
// NOTE: recursive method, not inlined.
// ********************************************************************
//
void
G4LogicalVolume::SetFastSimulationManager(
G4FastSimulationManager* pNewFastSimul,
G4bool IsEnvelope)
G4LogicalVolume::
SetFastSimulationManager( G4FastSimulationManager* pNewFastSimul,
G4bool IsEnvelope )
{
if(!fIsEnvelope || IsEnvelope) {
fIsEnvelope=IsEnvelope;
fFastSimulationManager = pNewFastSimul;
if( !fIsEnvelope || IsEnvelope )
{
fIsEnvelope = IsEnvelope;
fFastSimulationManager = pNewFastSimul;
G4int NoDaughters=GetNoDaughters();
while((NoDaughters--)>0){
G4LogicalVolume *DaughterLogVol;
DaughterLogVol= GetDaughter(NoDaughters)->GetLogicalVolume();
if(DaughterLogVol->GetFastSimulationManager() != pNewFastSimul) {
DaughterLogVol->SetFastSimulationManager(pNewFastSimul,FALSE);
}
}
G4int NoDaughters = GetNoDaughters();
while ( (NoDaughters--)>0 )
{
G4LogicalVolume* DaughterLogVol;
DaughterLogVol = GetDaughter(NoDaughters)->GetLogicalVolume();
if( DaughterLogVol->GetFastSimulationManager() != pNewFastSimul )
{
DaughterLogVol->SetFastSimulationManager(pNewFastSimul,false);
}
}
}
}
// ********************************************************************
// ClearEnvelopeForFastSimulation
// ********************************************************************
//
void
G4LogicalVolume::ClearEnvelopeForFastSimulation(G4LogicalVolume* motherLogVol)
G4LogicalVolume::ClearEnvelopeForFastSimulation( G4LogicalVolume* motherLogVol )
{
if( fIsEnvelope ) {
G4FastSimulationManager* NewFastSimulationVal=NULL;
if( fIsEnvelope )
{
G4FastSimulationManager* NewFastSimulationVal = 0;
// This is no longer an envelope !
fIsEnvelope=FALSE;
// This is no longer an envelope !
//
fIsEnvelope = false;
if( motherLogVol == NULL ) {
motherLogVol = this->FindMotherLogicalVolumeForEnvelope();
} else {
// Check that motherLogVol is this' mother.
// If not, raise exception and set it to NULL.
if ( FALSE ){
G4Exception(
"G4LogicalVolume::ClearEnvelope Gave wrong mother LogicalVolume" );
motherLogVol = NULL;
}
}
// Reset the ParameterisedSimulation values of self and all daughters
// (after ensuring the mother was given correctly or was found)
if( motherLogVol != NULL ) {
NewFastSimulationVal = motherLogVol->
GetFastSimulationManager();
this->SetFastSimulationManager (NewFastSimulationVal,
FALSE);
}
}else{
G4Exception("Called G4LogicalVolume::ClearEnvelope for a non-envelope Logical Volume" );
if( motherLogVol == 0 )
{
motherLogVol = this->FindMotherLogicalVolumeForEnvelope();
}
else
{
// Check that "motherLogVol" is this mother.
// If not, raise exception and set it to 0.
//
if ( false )
{
G4cerr << "ERROR - Wrong mother LogicalVolume !" << G4endl;
G4Exception("ERROR - G4LogicalVolume::ClearEnvelopeForFastSimulation");
motherLogVol = 0;
}
}
// Reset its ParameterisedSimulation values and those of all daughters
// (after ensuring the mother was given correctly or was found)
//
if( motherLogVol != 0 )
{
NewFastSimulationVal = motherLogVol->GetFastSimulationManager();
this->SetFastSimulationManager(NewFastSimulationVal, false);
}
}
else
{
G4cerr << "ERROR - Called ClearEnvelope() for non-envelope Logical Volume !"
<< G4endl;
G4Exception("ERROR - G4LogicalVolume::ClearEnvelope");
}
}
// ********************************************************************
// SetFieldManager
// ********************************************************************
//
void
G4LogicalVolume::SetFieldManager(G4FieldManager* pNewFieldMgr,
G4bool forceAllDaughters)
{
fFieldManager = pNewFieldMgr;
G4int NoDaughters=GetNoDaughters();
while((NoDaughters--)>0){
G4LogicalVolume *DaughterLogVol;
DaughterLogVol= GetDaughter(NoDaughters)->GetLogicalVolume();
if(forceAllDaughters || (DaughterLogVol->GetFieldManager() != 0)) {
G4int NoDaughters = GetNoDaughters();
while ( (NoDaughters--)>0 )
{
G4LogicalVolume* DaughterLogVol;
DaughterLogVol = GetDaughter(NoDaughters)->GetLogicalVolume();
if ( forceAllDaughters || (DaughterLogVol->GetFieldManager() != 0) )
{
DaughterLogVol->SetFieldManager(pNewFieldMgr, forceAllDaughters);
}
}
}
// The following method returns a meaningful result IF and only IF
// the current logical volume has exactly one physical volume that
// uses it.
// ********************************************************************
// FindMotherLogicalVolumeForEnvelope
//
// Returns a meaningful result IF and only IF the current logical
// volume has exactly one physical volume that uses it.
// ********************************************************************
//
G4LogicalVolume*
G4LogicalVolume::FindMotherLogicalVolumeForEnvelope()
{
G4LogicalVolume* motherLogVol= 0;
G4LogicalVolumeStore *Store = G4LogicalVolumeStore::GetInstance();
G4LogicalVolume* motherLogVol = 0;
G4LogicalVolumeStore* Store = G4LogicalVolumeStore::GetInstance();
// Look for the current volume's mother volume.
for (size_t LV=0;LV < Store->size(); LV++){
G4LogicalVolume *aLogVol;
aLogVol= (*Store)[LV];
if( (aLogVol!=this) && // Don't look for it inside itself...
(aLogVol->GetFastSimulationManager()!=NULL)){
for (G4int daughter=0; daughter < aLogVol->GetNoDaughters();
daughter++){
if( aLogVol->GetDaughter(daughter)->GetLogicalVolume()==this) {
// "- Oh Dear, aLogVol is my mother !!!"
motherLogVol = aLogVol;
break;
}
}
}
//
for ( size_t LV=0; LV < Store->size(); LV++ )
{
G4LogicalVolume* aLogVol = (*Store)[LV]; // Don't look for it inside itself!
if( (aLogVol!=this) && (aLogVol->GetFastSimulationManager()!=0) )
{
for ( G4int daughter=0; daughter<aLogVol->GetNoDaughters(); daughter++ )
{
if( aLogVol->GetDaughter(daughter)->GetLogicalVolume()==this )
{
// aLogVol is the mother !!!
//
motherLogVol = aLogVol;
break;
}
}
}
}
return motherLogVol;
}
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4LogicalVolumeStore.cc,v 1.6 2001/07/11 09:59:20 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4LogicalVolumeStore.cc,v 1.8 2002/04/26 16:24:36 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
// G4LogicalVolumeStore
//
@@ -30,51 +30,115 @@
//
// History:
// 10.07.95 P.Kent Initial version
// ********************************************************************
#include "G4LogicalVolumeStore.hh"
#include "globals.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4GeometryManager.hh"
// ***************************************************************************
// Static class variables
// ***************************************************************************
//
G4LogicalVolumeStore* G4LogicalVolumeStore::fgInstance = 0;
G4bool G4LogicalVolumeStore::locked = false;
// ***************************************************************************
// Protected constructor: Construct underlying container with
// initial size of 100 entries
// ***************************************************************************
//
G4LogicalVolumeStore::G4LogicalVolumeStore()
: G4std::vector<G4LogicalVolume*>()
{
reserve(100);
}
// ***************************************************************************
// Destructor
// ***************************************************************************
//
G4LogicalVolumeStore::~G4LogicalVolumeStore()
{
while (!empty())
{
// delete front();
erase(begin());
}
Clean();
}
// Static class variable
G4LogicalVolumeStore* G4LogicalVolumeStore::fgInstance = 0;
// ***************************************************************************
// Delete all elements from the store
// ***************************************************************************
//
void G4LogicalVolumeStore::Clean()
{
// Do nothing if geometry is closed
//
if (G4GeometryManager::GetInstance()->IsGeometryClosed())
{
G4cout << "WARNING - Attempt to delete the logical volume store"
<< " while geometry closed !" << G4endl;
return;
}
// Locks store for deletion of volumes. De-registration will be
// performed at this stage. G4LogicalVolumes will not de-register themselves.
//
locked = true;
size_t i=0;
G4LogicalVolumeStore* store = GetInstance();
G4std::vector<G4LogicalVolume*>::iterator pos;
#ifdef G4GEOMETRY_VOXELDEBUG
G4cout << "Deleting Logical Volumes ... ";
#endif
for(pos=store->begin(); pos!=store->end(); pos++)
{
if (*pos) delete *pos; i++;
}
#ifdef G4GEOMETRY_VOXELDEBUG
if (store->size() < i-1)
{ G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
else
{ G4cout << i-1 << " volumes deleted !" << G4endl; }
#endif
locked = false;
store->clear();
}
// ***************************************************************************
// Add volume to container
// ***************************************************************************
//
void G4LogicalVolumeStore::Register(G4LogicalVolume* pVolume)
{
GetInstance()->push_back(pVolume);
}
// ***************************************************************************
// Remove volume from container
// ***************************************************************************
//
void G4LogicalVolumeStore::DeRegister(G4LogicalVolume* pVolume)
{
for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
if (!locked) // Do not de-register if locked !
{
if (**i==*pVolume)
for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
{
GetInstance()->erase(i);
break;
if (**i==*pVolume)
{
GetInstance()->erase(i);
break;
}
}
}
}
// ***************************************************************************
// Return ptr to Store, setting if necessary
// ***************************************************************************
//
G4LogicalVolumeStore* G4LogicalVolumeStore::GetInstance()
{
static G4LogicalVolumeStore worldStore;
@@ -22,7 +22,7 @@
//
//
// $Id: G4PVParameterised.cc,v 1.4 2001/07/11 09:59:21 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// GEANT4 tag $Name: geant4-04-01 $
//
//
// class G4PVParameterised
@@ -22,7 +22,7 @@
//
//
// $Id: G4PVPlacement.cc,v 1.4 2001/07/11 09:59:21 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// GEANT4 tag $Name: geant4-04-01 $
//
//
// class G4PVPlacement Implementation
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4PVReplica.cc,v 1.3 2001/07/11 09:59:21 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4PVReplica.cc,v 1.4 2002/05/15 10:07:20 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
//
// class G4PVReplica Implementation
@@ -89,6 +89,7 @@ void G4PVReplica::CheckAndSetParameters (const EAxis pAxis,
case kXAxis:
case kYAxis:
case kZAxis:
case kUndefined:
break;
default:
G4Exception("G4PVReplica::G4PVReplica Unknown axis");
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4PhysicalVolumeStore.cc,v 1.7 2001/07/11 09:59:21 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4PhysicalVolumeStore.cc,v 1.9 2002/04/26 16:24:36 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
// G4PhysicalVolumeStore
//
@@ -30,51 +30,116 @@
//
// History:
// 25.07.95 P.Kent Initial version
// ********************************************************************
#include "G4PhysicalVolumeStore.hh"
#include "globals.hh"
#include "G4PhysicalVolumeStore.hh"
#include "G4GeometryManager.hh"
// ***************************************************************************
// Static class variables
// ***************************************************************************
//
G4PhysicalVolumeStore* G4PhysicalVolumeStore::fgInstance = 0;
G4bool G4PhysicalVolumeStore::locked = false;
// ***************************************************************************
// Protected constructor: Construct underlying container with
// initial size of 100 entries
// ***************************************************************************
//
G4PhysicalVolumeStore::G4PhysicalVolumeStore()
: G4std::vector<G4VPhysicalVolume*>()
{
reserve(100);
}
// ***************************************************************************
// Destructor
// ***************************************************************************
//
G4PhysicalVolumeStore::~G4PhysicalVolumeStore()
{
while (!empty())
{
// delete front();
erase(begin());
}
Clean();
}
// Static class variable
G4PhysicalVolumeStore* G4PhysicalVolumeStore::fgInstance = 0;
// ***************************************************************************
// Delete all elements from the store
// ***************************************************************************
//
void G4PhysicalVolumeStore::Clean()
{
// Do nothing if geometry is closed
//
if (G4GeometryManager::GetInstance()->IsGeometryClosed())
{
G4cout << "WARNING - Attempt to delete the physical volume store"
<< " while geometry closed !" << G4endl;
return;
}
// Locks store for deletion of volumes. De-registration will be
// performed at this stage. G4VPhysicalVolumes will not de-register
// themselves.
//
locked = true;
size_t i=0;
G4PhysicalVolumeStore* store = GetInstance();
G4std::vector<G4VPhysicalVolume*>::iterator pos;
#ifdef G4GEOMETRY_VOXELDEBUG
G4cout << "Deleting Physical Volumes ... ";
#endif
for(pos=store->begin(); pos!=store->end(); pos++)
{
if (*pos) delete *pos; i++;
}
#ifdef G4GEOMETRY_VOXELDEBUG
if (store->size() < i-1)
{ G4cout << "No volumes deleted. Already deleted by user ?" << G4endl; }
else
{ G4cout << i-1 << " volumes deleted !" << G4endl; }
#endif
locked = false;
store->clear();
}
// ***************************************************************************
// Add Solid to container
// ***************************************************************************
//
void G4PhysicalVolumeStore::Register(G4VPhysicalVolume* pVolume)
{
GetInstance()->push_back(pVolume);
}
// ***************************************************************************
// Remove Solid from container
// ***************************************************************************
//
void G4PhysicalVolumeStore::DeRegister(G4VPhysicalVolume* pVolume)
{
for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
if (!locked) // Do not de-register if locked !
{
if (**i==*pVolume)
for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
{
GetInstance()->erase(i);
break;
if (**i==*pVolume)
{
GetInstance()->erase(i);
break;
}
}
}
}
// ***************************************************************************
// Return ptr to Store, setting if necessary
// ***************************************************************************
//
G4PhysicalVolumeStore* G4PhysicalVolumeStore::GetInstance()
{
static G4PhysicalVolumeStore worldStore;
@@ -84,5 +149,3 @@ G4PhysicalVolumeStore* G4PhysicalVolumeStore::GetInstance()
}
return fgInstance;
}
File diff suppressed because it is too large Load Diff
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4SmartVoxelNode.cc,v 1.3 2001/07/11 09:59:21 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4SmartVoxelNode.cc,v 1.4 2002/04/19 08:20:22 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
// Class G4SmartVoxelNode
//
@@ -31,6 +31,12 @@
#include "G4SmartVoxelNode.hh"
// Empty destructor
//
G4SmartVoxelNode::~G4SmartVoxelNode()
{
}
// Return true if contents equal
//
// Preconditions:
@@ -52,14 +58,3 @@ G4bool G4SmartVoxelNode::operator == (const G4SmartVoxelNode& v) const
}
return false;
}
@@ -0,0 +1,38 @@
//
// ********************************************************************
// * 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 *
// * *
// * 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. *
// * *
// * 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. *
// ********************************************************************
//
//
// $Id: G4SmartVoxelProxy.cc,v 1.1 2002/04/19 08:20:22 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
// Class G4SmartVoxelProxy
//
// Implementation
//
#include "G4SmartVoxelProxy.hh"
// Empty destructor
//
G4SmartVoxelProxy::~G4SmartVoxelProxy()
{
}
@@ -22,7 +22,7 @@
//
//
// $Id: G4SmartVoxelStat.cc,v 1.1 2001/10/22 16:08:05 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-00 $
// GEANT4 tag $Name: geant4-04-01 $
//
// --------------------------------------------------------------------
// GEANT 4 class source file
+87 -21
View File
@@ -21,8 +21,8 @@
// ********************************************************************
//
//
// $Id: G4SolidStore.cc,v 1.7 2001/07/11 09:59:21 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4SolidStore.cc,v 1.9 2002/04/26 16:24:36 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
// G4SolidStore
//
@@ -30,57 +30,123 @@
//
// History:
// 10.07.95 P.Kent Initial version
// ********************************************************************
#include "G4SolidStore.hh"
#include "globals.hh"
#include "G4SolidStore.hh"
#include "G4GeometryManager.hh"
// ***************************************************************************
// Static class variables
// ***************************************************************************
//
G4SolidStore* G4SolidStore::fgInstance = 0;
G4bool G4SolidStore::locked = false;
// ***************************************************************************
// Protected constructor: Construct underlying container with
// initial size of 100 entries
// ***************************************************************************
//
G4SolidStore::G4SolidStore()
: G4std::vector<G4VSolid*>()
{
reserve(100);
}
// ***************************************************************************
// Destructor
// ***************************************************************************
//
G4SolidStore::~G4SolidStore()
{
while (!empty())
{
// delete front();
erase(begin());
}
// NOTE: destruction of solids is client responsibility !
// clear();
Clean();
}
// Static class variable
G4SolidStore* G4SolidStore::fgInstance = 0;
// ***************************************************************************
// Delete all elements from the store
// ***************************************************************************
//
void G4SolidStore::Clean()
{
// Do nothing if geometry is closed
//
if (G4GeometryManager::GetInstance()->IsGeometryClosed())
{
G4cout << "WARNING - Attempt to delete the solid store"
<< " while geometry closed !" << G4endl;
return;
}
// Locks store for deletion of solids. De-registration will be
// performed at this stage. G4VSolids will not de-register themselves.
//
locked = true;
size_t i=0;
G4SolidStore* store = GetInstance();
G4std::vector<G4VSolid*>::iterator pos;
#ifdef G4GEOMETRY_VOXELDEBUG
G4cout << "Deleting Solids ... ";
#endif
for(pos=store->begin(); pos!=store->end(); pos++)
{
if (*pos) delete *pos; i++;
}
#ifdef G4GEOMETRY_VOXELDEBUG
if (store->size() < i-1)
{ G4cout << "No solids deleted. Already deleted by user ?" << G4endl; }
else
{ G4cout << i-1 << " solids deleted !" << G4endl; }
#endif
locked = false;
store->clear();
}
// ***************************************************************************
// Add Solid to container
// ***************************************************************************
//
void G4SolidStore::Register(G4VSolid* pSolid)
{
GetInstance()->push_back(pSolid);
GetInstance()->push_back(pSolid);
}
// ***************************************************************************
// Remove Solid from container
// ***************************************************************************
//
void G4SolidStore::DeRegister(G4VSolid* pSolid)
{
for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
if (!locked) // Do not de-register if locked !
{
if (**i==*pSolid)
for (iterator i=GetInstance()->begin(); i!=GetInstance()->end(); i++)
{
GetInstance()->erase(i);
break;
if (**i==*pSolid)
{
GetInstance()->erase(i);
break;
}
}
}
}
// ***************************************************************************
// Return ptr to Store, setting if necessary
// ***************************************************************************
//
G4SolidStore* G4SolidStore::GetInstance()
{
static G4SolidStore worldStore;
if (!fgInstance)
{
fgInstance = &worldStore;
}
return fgInstance;
static G4SolidStore worldStore;
if (!fgInstance)
{
fgInstance = &worldStore;
}
return fgInstance;
}
@@ -22,7 +22,7 @@
//
//
// $Id: G4VPVParameterisation.cc,v 1.3 2001/07/11 09:59:21 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// GEANT4 tag $Name: geant4-04-01 $
//
// Default implementations for Parameterisations that do not
// parameterise solid and/or material
@@ -22,7 +22,7 @@
//
//
// $Id: G4VPhysicalVolume.cc,v 1.4 2001/07/11 09:59:21 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// GEANT4 tag $Name: geant4-04-01 $
//
//
// class G4VPhysicalVolume Implementation
+247 -208
View File
@@ -21,19 +21,24 @@
// ********************************************************************
//
//
// $Id: G4VSolid.cc,v 1.8 2001/07/11 09:59:21 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4VSolid.cc,v 1.13 2002/05/11 14:16:10 grichine Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
// class G4VSolid
//
// Implementation for solid base class
//
//
// History:
// 10.07.95 P.Kent Added == operator, solid Store entry
// 30.06.95 P.Kent
//
// 10.05.02 V.Grichine, bug fixed in ClipPoligon: clip only other axis and limited
// voxels
// 15.04.02 V.Grichine, bug fixed in ClipPoligon: clip only one axis
// 13.03.02 V.Grichine, cosmetics of voxel limit functions
// 15.11.00 D.Williams, V.Grichine change in CalculateClippedPolygonExtent:
// else if(component>pMax) ---> if
// 10.07.95 P.Kent Added == operator, solid Store entry
// 30.06.95 P.Kent
//
#include "G4VSolid.hh"
#include "G4SolidStore.hh"
@@ -42,34 +47,46 @@
#include "G4AffineTransform.hh"
#include "G4VisExtent.hh"
//////////////////////////////////////////////////////////////////////////
//
// Constructor
// - Copies name
// - Add ourselves to solid Store
G4VSolid::G4VSolid(const G4String& name) :
fshapeName(name)
G4VSolid::G4VSolid(const G4String& name)
: fshapeName(name)
{
G4SolidStore::GetInstance()->push_back(this);
G4SolidStore::GetInstance()->Register(this);
}
//////////////////////////////////////////////////////////////////////////
//
// Destructor (virtual)
// - Remove ourselves from solid Store
G4VSolid::~G4VSolid()
{
G4SolidStore::GetInstance()->DeRegister(this);
}
////////////////////////////////////////////////////////////////////////
//
// Returns name by value
G4String G4VSolid::GetName() const
{
return fshapeName;
}
/////////////////////////////////////////////////////////////////////////
void G4VSolid::SetName(const G4String& name)
{
fshapeName=name;
}
//////////////////////////////////////////////////////////////////////////
//
// Throw exception if ComputeDimensions called for illegal derived class
void G4VSolid::ComputeDimensions(G4VPVParameterisation* p,
const G4int n,
const G4VPhysicalVolume* pRep)
@@ -77,6 +94,90 @@ void G4VSolid::ComputeDimensions(G4VPVParameterisation* p,
G4Exception("G4VSolid::ComputeDimensions called illegally: not overloaded by derived class");
}
///////////////////////////////////////////////////////////////////////////
//
// Calculate the maximum and minimum extents of the polygon described
// by the vertices: pSectionIndex->pSectionIndex+1->
// pSectionIndex+2->pSectionIndex+3->pSectionIndex
// in the List pVertices
//
// If the minimum is <pMin pMin is set to the new minimum
// If the maximum is >pMax pMax is set to the new maximum
//
// No modifications are made to pVertices
//
void G4VSolid::ClipCrossSection( G4ThreeVectorList* pVertices,
const G4int pSectionIndex,
const G4VoxelLimits& pVoxelLimit,
const EAxis pAxis,
G4double& pMin, G4double& pMax) const
{
G4ThreeVectorList polygon;
polygon.push_back((*pVertices)[pSectionIndex]);
polygon.push_back((*pVertices)[pSectionIndex+1]);
polygon.push_back((*pVertices)[pSectionIndex+2]);
polygon.push_back((*pVertices)[pSectionIndex+3]);
// G4cout<<"ClipCrossSection: 0-1-2-3"<<G4endl;
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
return;
}
//////////////////////////////////////////////////////////////////////////////////
//
// Calculate the maximum and minimum extents of the polygons
// joining the CrossSections at pSectionIndex->pSectionIndex+3 and
// pSectionIndex+4->pSectionIndex7
//
// in the List pVertices, within the boundaries of the voxel limits pVoxelLimit
//
// If the minimum is <pMin pMin is set to the new minimum
// If the maximum is >pMax pMax is set to the new maximum
//
// No modifications are made to pVertices
void G4VSolid::ClipBetweenSections( G4ThreeVectorList* pVertices,
const G4int pSectionIndex,
const G4VoxelLimits& pVoxelLimit,
const EAxis pAxis,
G4double& pMin, G4double& pMax) const
{
G4ThreeVectorList polygon;
polygon.push_back((*pVertices)[pSectionIndex]);
polygon.push_back((*pVertices)[pSectionIndex+4]);
polygon.push_back((*pVertices)[pSectionIndex+5]);
polygon.push_back((*pVertices)[pSectionIndex+1]);
// G4cout<<"ClipBetweenSections: 0-4-5-1"<<G4endl;
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
polygon.clear();
polygon.push_back((*pVertices)[pSectionIndex+1]);
polygon.push_back((*pVertices)[pSectionIndex+5]);
polygon.push_back((*pVertices)[pSectionIndex+6]);
polygon.push_back((*pVertices)[pSectionIndex+2]);
// G4cout<<"ClipBetweenSections: 1-5-6-2"<<G4endl;
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
polygon.clear();
polygon.push_back((*pVertices)[pSectionIndex+2]);
polygon.push_back((*pVertices)[pSectionIndex+6]);
polygon.push_back((*pVertices)[pSectionIndex+7]);
polygon.push_back((*pVertices)[pSectionIndex+3]);
// G4cout<<"ClipBetweenSections: 2-6-7-3"<<G4endl;
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
polygon.clear();
polygon.push_back((*pVertices)[pSectionIndex+3]);
polygon.push_back((*pVertices)[pSectionIndex+7]);
polygon.push_back((*pVertices)[pSectionIndex+4]);
polygon.push_back((*pVertices)[pSectionIndex]);
// G4cout<<"ClipBetweenSections: 3-7-4-0"<<G4endl;
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
return;
}
///////////////////////////////////////////////////////////////////////////////
//
// Calculate the maximum and minimum extents of the convex polygon pPolygon
@@ -90,99 +191,46 @@ void G4VSolid::CalculateClippedPolygonExtent(G4ThreeVectorList& pPolygon,
{
G4int noLeft,i;
G4double component;
ClipPolygon(pPolygon,pVoxelLimit);
/*
G4cout<<G4endl;
for(i = 0 ; i < pPolygon.size() ; i++ )
{
G4cout<<i<<"\t"<<"p.x = "<<pPolygon[i].operator()(pAxis)<<"\t"
// <<"p.y = "<<pPolygon[i].y()<<"\t"
// <<"p.z = "<<pPolygon[i].z()<<"\t"
<<G4endl;
}
G4cout<<G4endl;
*/
ClipPolygon(pPolygon,pVoxelLimit,pAxis);
noLeft = pPolygon.size();
if (noLeft)
if ( noLeft )
{
// G4cout<<G4endl;
for (i=0;i<noLeft;i++)
{
component = pPolygon[i].operator()(pAxis);
if (component < pMin)
{
pMin = component;
// G4cout <<i<<"\t"<<component<<G4endl;
if (component < pMin)
{
// G4cout <<i<<"\t"<<"Pmin = "<<component<<G4endl;
pMin = component;
}
// else
if (component > pMax)
{
pMax = component;
}
{
// G4cout <<i<<"\t"<<"PMax = "<<component<<G4endl;
pMax = component;
}
}
// G4cout<<G4endl;
}
// G4cout<<"pMin = "<<pMin<<"\t"<<"pMax = "<<pMax<<G4endl;
}
///////////////////////////////////////////////////////////////////////////
//
// Calculate the maximum and minimum extents of the polygon described
// by the vertices: pSectionIndex->pSectionIndex+1->
// pSectionIndex+2->pSectionIndex+3->pSectionIndex
// in the List pVertices
/////////////////////////////////////////////////////////////////////////////
//
// If the minimum is <pMin pMin is set to the new minimum
// If the maximum is >pMax pMax is set to the new maximum
//
// No modifications are made to pVertices
void G4VSolid::ClipCrossSection(G4ThreeVectorList* pVertices,
const G4int pSectionIndex,
const G4VoxelLimits& pVoxelLimit,
const EAxis pAxis,
G4double& pMin, G4double& pMax) const
{
G4ThreeVectorList polygon;
polygon.push_back((*pVertices)[pSectionIndex]);
polygon.push_back((*pVertices)[pSectionIndex+1]);
polygon.push_back((*pVertices)[pSectionIndex+2]);
polygon.push_back((*pVertices)[pSectionIndex+3]);
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
return;
}
// Calculate the maximum and minimum extents of the polygons
// joining the CrossSections at pSectionIndex->pSectionIndex+3 and
// pSectionIndex+4->pSectionIndex7
//
// in the List pVertices, within the boundaries of the voxel limits pVoxelLimit
//
// If the minimum is <pMin pMin is set to the new minimum
// If the maximum is >pMax pMax is set to the new maximum
//
// No modifications are made to pVertices
void G4VSolid::ClipBetweenSections(G4ThreeVectorList* pVertices,
const G4int pSectionIndex,
const G4VoxelLimits& pVoxelLimit,
const EAxis pAxis,
G4double& pMin, G4double& pMax) const
{
G4ThreeVectorList polygon;
polygon.push_back((*pVertices)[pSectionIndex]);
polygon.push_back((*pVertices)[pSectionIndex+4]);
polygon.push_back((*pVertices)[pSectionIndex+5]);
polygon.push_back((*pVertices)[pSectionIndex+1]);
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
polygon.clear();
polygon.push_back((*pVertices)[pSectionIndex+1]);
polygon.push_back((*pVertices)[pSectionIndex+5]);
polygon.push_back((*pVertices)[pSectionIndex+6]);
polygon.push_back((*pVertices)[pSectionIndex+2]);
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
polygon.clear();
polygon.push_back((*pVertices)[pSectionIndex+2]);
polygon.push_back((*pVertices)[pSectionIndex+6]);
polygon.push_back((*pVertices)[pSectionIndex+7]);
polygon.push_back((*pVertices)[pSectionIndex+3]);
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
polygon.clear();
polygon.push_back((*pVertices)[pSectionIndex+3]);
polygon.push_back((*pVertices)[pSectionIndex+7]);
polygon.push_back((*pVertices)[pSectionIndex+4]);
polygon.push_back((*pVertices)[pSectionIndex]);
CalculateClippedPolygonExtent(polygon,pVoxelLimit,pAxis,pMin,pMax);
return;
}
// Clip the convex polygon described by the vertices at
// pSectionIndex ->pSectionIndex+3 within pVertices to the limits pVoxelLimit
//
@@ -200,155 +248,146 @@ void G4VSolid::ClipBetweenSections(G4ThreeVectorList* pVertices,
// Modifications to the polygon are made
//
// NOTE: Execessive copying during clipping
void G4VSolid::ClipPolygon(G4ThreeVectorList& pPolygon,
const G4VoxelLimits& pVoxelLimit) const
void G4VSolid::ClipPolygon( G4ThreeVectorList& pPolygon,
const G4VoxelLimits& pVoxelLimit,
const EAxis pAxis ) const
{
G4ThreeVectorList outputPolygon;
if (pVoxelLimit.IsLimited())
{
if (pVoxelLimit.IsXLimited())
{
G4VoxelLimits simpleLimit1;
simpleLimit1.AddLimit(kXAxis,pVoxelLimit.GetMinXExtent(),kInfinity);
ClipPolygonToSimpleLimits(pPolygon,outputPolygon,
simpleLimit1);
pPolygon.clear();
if (!outputPolygon.size())
{
return;
}
G4ThreeVectorList outputPolygon;
G4VoxelLimits simpleLimit2;
simpleLimit2.AddLimit(kXAxis,-kInfinity,pVoxelLimit.GetMaxXExtent());
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
if (!pPolygon.size())
{
return;
}
else
{
outputPolygon.clear();
}
}
if ( pVoxelLimit.IsLimited() )
{
if (pVoxelLimit.IsXLimited() && pAxis != kXAxis)
{
G4VoxelLimits simpleLimit1;
simpleLimit1.AddLimit(kXAxis,pVoxelLimit.GetMinXExtent(),kInfinity);
// G4cout<<"MinXExtent()"<<G4endl;
ClipPolygonToSimpleLimits(pPolygon,outputPolygon,simpleLimit1);
pPolygon.clear();
if (pVoxelLimit.IsYLimited())
{
G4VoxelLimits simpleLimit1;
simpleLimit1.AddLimit(kYAxis,pVoxelLimit.GetMinYExtent(),kInfinity);
ClipPolygonToSimpleLimits(pPolygon,outputPolygon,
simpleLimit1);
// Must always clear pPolygon - for clip to simpleLimit2 and incase of
if ( !outputPolygon.size() ) return;
G4VoxelLimits simpleLimit2;
// G4cout<<"MaxXExtent()"<<G4endl;
simpleLimit2.AddLimit(kXAxis,-kInfinity,pVoxelLimit.GetMaxXExtent());
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
if ( !pPolygon.size() ) return;
else outputPolygon.clear();
}
if ( pVoxelLimit.IsYLimited() && pAxis != kYAxis)
{
G4VoxelLimits simpleLimit1;
simpleLimit1.AddLimit(kYAxis,pVoxelLimit.GetMinYExtent(),kInfinity);
ClipPolygonToSimpleLimits(pPolygon,outputPolygon,simpleLimit1);
// Must always clear pPolygon - for clip to simpleLimit2 and in case of
// early exit
pPolygon.clear();
if (!outputPolygon.size())
{
return;
}
G4VoxelLimits simpleLimit2;
simpleLimit2.AddLimit(kYAxis,-kInfinity,pVoxelLimit.GetMaxYExtent());
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
if (!pPolygon.size())
{
return;
}
else
{
outputPolygon.clear();
}
}
pPolygon.clear();
if (pVoxelLimit.IsZLimited())
{
G4VoxelLimits simpleLimit1;
simpleLimit1.AddLimit(kZAxis,pVoxelLimit.GetMinZExtent(),kInfinity);
ClipPolygonToSimpleLimits(pPolygon,outputPolygon,
simpleLimit1);
// Must always clear pPolygon - for clip to simpleLimit2 and incase of
if ( !outputPolygon.size() ) return;
G4VoxelLimits simpleLimit2;
simpleLimit2.AddLimit(kYAxis,-kInfinity,pVoxelLimit.GetMaxYExtent());
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
if ( !pPolygon.size() ) return;
else outputPolygon.clear();
}
if ( pVoxelLimit.IsZLimited() && pAxis != kZAxis)
{
G4VoxelLimits simpleLimit1;
simpleLimit1.AddLimit(kZAxis,pVoxelLimit.GetMinZExtent(),kInfinity);
ClipPolygonToSimpleLimits(pPolygon,outputPolygon,simpleLimit1);
// Must always clear pPolygon - for clip to simpleLimit2 and in case of
// early exit
pPolygon.clear();
if (!outputPolygon.size())
{
return;
}
G4VoxelLimits simpleLimit2;
simpleLimit2.AddLimit(kZAxis,-kInfinity,pVoxelLimit.GetMaxZExtent());
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
pPolygon.clear();
if ( !outputPolygon.size() ) return;
G4VoxelLimits simpleLimit2;
simpleLimit2.AddLimit(kZAxis,-kInfinity,pVoxelLimit.GetMaxZExtent());
ClipPolygonToSimpleLimits(outputPolygon,pPolygon,simpleLimit2);
// Return after final clip - no cleanup
}
}
}
}
}
////////////////////////////////////////////////////////////////////////////
//
// pVoxelLimits must be only limited along one axis, and either the maximum
// along the axis must be +kInfinity, or the minimum -kInfinity
void G4VSolid::ClipPolygonToSimpleLimits(G4ThreeVectorList& pPolygon,
G4ThreeVectorList& outputPolygon,
const G4VoxelLimits& pVoxelLimit) const
void G4VSolid::ClipPolygonToSimpleLimits( G4ThreeVectorList& pPolygon,
G4ThreeVectorList& outputPolygon,
const G4VoxelLimits& pVoxelLimit ) const
{
G4int i;
G4int noVertices=pPolygon.size();
G4ThreeVector vEnd,vStart;
for (i=0;i<noVertices;i++)
{
vStart=pPolygon[i];
if (i==noVertices-1)
{
vEnd=pPolygon[0];
}
else
{
vEnd=pPolygon[i+1];
}
G4int i;
G4int noVertices=pPolygon.size();
G4ThreeVector vEnd,vStart;
if (pVoxelLimit.Inside(vStart))
{
if (pVoxelLimit.Inside(vEnd))
{
for (i = 0 ; i < noVertices ; i++ )
{
vStart = pPolygon[i];
// G4cout<<"i = "<<i<<G4endl;
if ( i == noVertices-1 ) vEnd = pPolygon[0];
else vEnd = pPolygon[i+1];
if ( pVoxelLimit.Inside(vStart) )
{
if (pVoxelLimit.Inside(vEnd))
{
// vStart and vEnd inside -> output end point
outputPolygon.push_back(vEnd);
}
else
{
outputPolygon.push_back(vEnd);
}
else
{
// vStart inside, vEnd outside -> output crossing point
pVoxelLimit.ClipToLimits(vStart,vEnd);
outputPolygon.push_back(vEnd);
}
}
else
{
if (pVoxelLimit.Inside(vEnd))
{
// G4cout<<"vStart inside, vEnd outside"<<G4endl;
pVoxelLimit.ClipToLimits(vStart,vEnd);
outputPolygon.push_back(vEnd);
}
}
else
{
if (pVoxelLimit.Inside(vEnd))
{
// vStart outside, vEnd inside -> output inside section
pVoxelLimit.ClipToLimits(vStart,vEnd);
outputPolygon.push_back(vStart);
outputPolygon.push_back(vEnd);
}
else
// Both point outside -> no output
{
}
}
}
// G4cout<<"vStart outside, vEnd inside"<<G4endl;
pVoxelLimit.ClipToLimits(vStart,vEnd);
outputPolygon.push_back(vStart);
outputPolygon.push_back(vEnd);
}
else // Both point outside -> no output
{
// outputPolygon.push_back(vStart);
// outputPolygon.push_back(vEnd);
}
}
}
}
const G4VSolid* G4VSolid::GetConstituentSolid(G4int no) const
const G4VSolid* G4VSolid::GetConstituentSolid(G4int no) const
{ return 0; }
G4VSolid* G4VSolid::GetConstituentSolid(G4int no)
G4VSolid* G4VSolid::GetConstituentSolid(G4int no)
{ return 0; }
const G4DisplacedSolid* G4VSolid::GetDisplacedSolidPtr() const
const G4DisplacedSolid* G4VSolid::GetDisplacedSolidPtr() const
{ return 0; }
G4DisplacedSolid* G4VSolid::GetDisplacedSolidPtr()
G4DisplacedSolid* G4VSolid::GetDisplacedSolidPtr()
{ return 0; }
G4VisExtent G4VSolid::GetExtent () const {
G4VisExtent G4VSolid::GetExtent () const
{
G4VisExtent extent;
G4VoxelLimits voxelLimits; // Defaults to "infinite" limits.
G4AffineTransform affineTransform;
+202 -217
View File
@@ -21,61 +21,69 @@
// ********************************************************************
//
//
// $Id: G4VoxelLimits.cc,v 1.4 2001/07/11 09:59:22 gunter Exp $
// GEANT4 tag $Name: geant4-04-00 $
// $Id: G4VoxelLimits.cc,v 1.7 2002/04/19 08:20:23 gcosmo Exp $
// GEANT4 tag $Name: geant4-04-01 $
//
// class G4VoxelLimits
//
// Implementation
//
// History:
//
// 14.03.02 V. Grichine, cosmetics
// 13.07.95 P.Kent Initial version
#include "G4VoxelLimits.hh"
#include "G4ios.hh"
///////////////////////////////////////////////////////////////////////////
//
// Empty constructor and destructor
//
G4VoxelLimits::G4VoxelLimits()
: fxAxisMin(-kInfinity),fxAxisMax(kInfinity),
fyAxisMin(-kInfinity),fyAxisMax(kInfinity),
fzAxisMin(-kInfinity),fzAxisMax(kInfinity)
{
}
G4VoxelLimits::~G4VoxelLimits()
{
}
///////////////////////////////////////////////////////////////////////////
//
// Further restrict limits
// No checks for illegal restrictions
void G4VoxelLimits::AddLimit(const EAxis pAxis, const G4double pMin,
const G4double pMax)
{
if (pAxis==kXAxis)
{
if (pMin>fxAxisMin)
{
fxAxisMin=pMin;
}
if (pMax<fxAxisMax)
{
fxAxisMax=pMax;
}
}
else if (pAxis==kYAxis)
{
if (pMin>fyAxisMin)
{
fyAxisMin=pMin;
}
if (pMax<fyAxisMax)
{
fyAxisMax=pMax;
}
}
else
{
assert(pAxis==kZAxis);
if (pMin>fzAxisMin)
{
fzAxisMin=pMin;
}
if (pMax<fzAxisMax)
{
fzAxisMax=pMax;
}
}
}
//
void G4VoxelLimits::AddLimit( const EAxis pAxis,
const G4double pMin,
const G4double pMax )
{
if ( pAxis == kXAxis )
{
if ( pMin > fxAxisMin ) fxAxisMin = pMin ;
if ( pMax < fxAxisMax ) fxAxisMax = pMax ;
}
else if ( pAxis == kYAxis )
{
if ( pMin > fyAxisMin ) fyAxisMin = pMin ;
if ( pMax < fyAxisMax ) fyAxisMax = pMax ;
}
else
{
assert( pAxis == kZAxis ) ;
if ( pMin > fzAxisMin ) fzAxisMin = pMin ;
if ( pMax < fzAxisMax ) fzAxisMax = pMax ;
}
}
///////////////////////////////////////////////////////////////////////////
//
// ClipToLimits
//
// Clip the line segment pStart->pEnd to the volume described by the
@@ -87,160 +95,158 @@ void G4VoxelLimits::AddLimit(const EAxis pAxis, const G4double pMin,
// Use Cohen-Sutherland clipping in 3D
// [Fundamentals of Interactive Computer Graphics,Foley & Van Dam]
//
G4bool G4VoxelLimits::ClipToLimits(G4ThreeVector& pStart,
G4ThreeVector& pEnd) const
G4bool G4VoxelLimits::ClipToLimits( G4ThreeVector& pStart,
G4ThreeVector& pEnd ) const
{
G4int sCode,eCode;
G4bool remainsAfterClip;
G4int sCode, eCode ;
G4bool remainsAfterClip ;
// Determine if line is trivially inside (both outcodes==0) or outside
// (logical AND of outcodes !=0)
sCode=OutCode(pStart);
eCode=OutCode(pEnd);
if (sCode&eCode)
{
sCode = OutCode(pStart) ;
eCode = OutCode(pEnd) ;
if ( sCode & eCode )
{
// Trivially outside, no intersection with region
remainsAfterClip=false;
}
else if (sCode==0&&eCode==0)
{
remainsAfterClip = false;
}
else if ( sCode == 0 && eCode == 0 )
{
// Trivially inside, no intersections
remainsAfterClip=true;
}
else
{
remainsAfterClip = true ;
}
else
{
// Line segment *may* cut volume boundaries
// At most, one end point is inside
G4double x1,y1,z1,x2,y2,z2;
x1=pStart.x();
y1=pStart.y();
z1=pStart.z();
x2=pEnd.x();
y2=pEnd.y();
z2=pEnd.z();
while (sCode!=eCode)
{
G4double x1, y1, z1, x2, y2, z2 ;
x1 = pStart.x() ;
y1 = pStart.y() ;
z1 = pStart.z() ;
x2 = pEnd.x() ;
y2 = pEnd.y() ;
z2 = pEnd.z() ;
/*
if( abs(x1-x2) < kCarTolerance*kCarTolerance)
{
G4cout<<"x1 = "<<x1<<"\t"<<"x2 = "<<x2<<G4endl;
}
if( abs(y1-y2) < kCarTolerance*kCarTolerance)
{
G4cout<<"y1 = "<<y1<<"\t"<<"y2 = "<<y2<<G4endl;
}
if( abs(z1-z2) < kCarTolerance*kCarTolerance)
{
G4cout<<"z1 = "<<z1<<"\t"<<"z2 = "<<z2<<G4endl;
}
*/
while ( sCode != eCode )
{
// Copy vectors to work variables x1-z1,x2-z2
// Ensure x1-z1 lies outside volume, swapping vectors and outcodes
// if necessary
if (sCode)
{
if (sCode&0x01)
{
// Clip against fxAxisMin
z1+=(fxAxisMin-x1)*(z2-z1)/(x2-x1);
y1+=(fxAxisMin-x1)*(y2-y1)/(x2-x1);
x1=fxAxisMin;
}
else if (sCode&0x02)
{
// Clip against fxAxisMax
z1+=(fxAxisMax-x1)*(z2-z1)/(x2-x1);
y1+=(fxAxisMax-x1)*(y2-y1)/(x2-x1);
x1=fxAxisMax;
}
else if (sCode&0x04)
{
// Clip against fyAxisMin
x1+=(fyAxisMin-y1)*(x2-x1)/(y2-y1);
z1+=(fyAxisMin-y1)*(z2-z1)/(y2-y1);
y1=fyAxisMin;
}
else if (sCode&0x08)
{
// Clip against fyAxisMax
x1+=(fyAxisMax-y1)*(x2-x1)/(y2-y1);
z1+=(fyAxisMax-y1)*(z2-z1)/(y2-y1);
y1=fyAxisMax;
}
else if (sCode&0x10)
{
// Clip against fzAxisMin
x1+=(fzAxisMin-z1)*(x2-x1)/(z2-z1);
y1+=(fzAxisMin-z1)*(y2-y1)/(z2-z1);
z1=fzAxisMin;
}
else if (sCode&0x20)
{
// Clip against fzAxisMax
x1+=(fzAxisMax-z1)*(x2-x1)/(z2-z1);
y1+=(fzAxisMax-z1)*(y2-y1)/(z2-z1);
z1=fzAxisMax;
}
}
if (eCode)
{
// Clip 2nd end: repeat of 1st, but 1<>2
if (eCode&0x01)
{
// Clip against fxAxisMin
z2+=(fxAxisMin-x2)*(z1-z2)/(x1-x2);
y2+=(fxAxisMin-x2)*(y1-y2)/(x1-x2);
x2=fxAxisMin;
}
else if (eCode&0x02)
{
// Clip against fxAxisMax
z2+=(fxAxisMax-x2)*(z1-z2)/(x1-x2);
y2+=(fxAxisMax-x2)*(y1-y2)/(x1-x2);
x2=fxAxisMax;
}
else if (eCode&0x04)
{
// Clip against fyAxisMin
x2+=(fyAxisMin-y2)*(x1-x2)/(y1-y2);
z2+=(fyAxisMin-y2)*(z1-z2)/(y1-y2);
y2=fyAxisMin;
}
else if (eCode&0x08)
{
// Clip against fyAxisMax
x2+=(fyAxisMax-y2)*(x1-x2)/(y1-y2);
z2+=(fyAxisMax-y2)*(z1-z2)/(y1-y2);
y2=fyAxisMax;
}
else if (eCode&0x10)
{
// Clip against fzAxisMin
x2+=(fzAxisMin-z2)*(x1-x2)/(z1-z2);
y2+=(fzAxisMin-z2)*(y1-y2)/(z1-z2);
z2=fzAxisMin;
}
else if (eCode&0x20)
{
// Clip against fzAxisMax
x2+=(fzAxisMax-z2)*(x1-x2)/(z1-z2);
y2+=(fzAxisMax-z2)*(y1-y2)/(z1-z2);
z2=fzAxisMax;
}
}
pStart=G4ThreeVector(x1,y1,z1);
pEnd=G4ThreeVector(x2,y2,z2);
sCode=OutCode(pStart);
eCode=OutCode(pEnd);
}
if (sCode==0&&eCode==0)
{
remainsAfterClip=true;
}
else
{
remainsAfterClip=false;
}
if ( sCode )
{
if ( sCode & 0x01 ) // Clip against fxAxisMin
{
z1 += (fxAxisMin-x1)*(z2-z1)/(x2-x1);
y1 += (fxAxisMin-x1)*(y2-y1)/(x2-x1);
x1 = fxAxisMin;
}
return remainsAfterClip;
else if ( sCode & 0x02 ) // Clip against fxAxisMax
{
z1 += (fxAxisMax-x1)*(z2-z1)/(x2-x1);
y1 += (fxAxisMax-x1)*(y2-y1)/(x2-x1);
x1 = fxAxisMax ;
}
else if ( sCode & 0x04 ) // Clip against fyAxisMin
{
x1 += (fyAxisMin-y1)*(x2-x1)/(y2-y1);
z1 += (fyAxisMin-y1)*(z2-z1)/(y2-y1);
y1 = fyAxisMin;
}
else if ( sCode & 0x08 ) // Clip against fyAxisMax
{
x1 += (fyAxisMax-y1)*(x2-x1)/(y2-y1);
z1 += (fyAxisMax-y1)*(z2-z1)/(y2-y1);
y1 = fyAxisMax;
}
else if ( sCode & 0x10 ) // Clip against fzAxisMin
{
x1 += (fzAxisMin-z1)*(x2-x1)/(z2-z1);
y1 += (fzAxisMin-z1)*(y2-y1)/(z2-z1);
z1 = fzAxisMin;
}
else if ( sCode & 0x20 ) // Clip against fzAxisMax
{
x1 += (fzAxisMax-z1)*(x2-x1)/(z2-z1);
y1 += (fzAxisMax-z1)*(y2-y1)/(z2-z1);
z1 = fzAxisMax;
}
}
if ( eCode ) // Clip 2nd end: repeat of 1st, but 1<>2
{
if ( eCode & 0x01 ) // Clip against fxAxisMin
{
z2 += (fxAxisMin-x2)*(z1-z2)/(x1-x2);
y2 += (fxAxisMin-x2)*(y1-y2)/(x1-x2);
x2 = fxAxisMin;
}
else if ( eCode & 0x02 ) // Clip against fxAxisMax
{
z2 += (fxAxisMax-x2)*(z1-z2)/(x1-x2);
y2 += (fxAxisMax-x2)*(y1-y2)/(x1-x2);
x2 = fxAxisMax;
}
else if ( eCode & 0x04 ) // Clip against fyAxisMin
{
x2 += (fyAxisMin-y2)*(x1-x2)/(y1-y2);
z2 += (fyAxisMin-y2)*(z1-z2)/(y1-y2);
y2 = fyAxisMin;
}
else if (eCode&0x08) // Clip against fyAxisMax
{
x2 += (fyAxisMax-y2)*(x1-x2)/(y1-y2);
z2 += (fyAxisMax-y2)*(z1-z2)/(y1-y2);
y2 = fyAxisMax;
}
else if ( eCode & 0x10 ) // Clip against fzAxisMin
{
x2 += (fzAxisMin-z2)*(x1-x2)/(z1-z2);
y2 += (fzAxisMin-z2)*(y1-y2)/(z1-z2);
z2 = fzAxisMin;
}
else if ( eCode & 0x20 ) // Clip against fzAxisMax
{
x2 += (fzAxisMax-z2)*(x1-x2)/(z1-z2);
y2 += (fzAxisMax-z2)*(y1-y2)/(z1-z2);
z2 = fzAxisMax;
}
}
// G4endl; G4cout<<"x1 = "<<x1<<"\t"<<"x2 = "<<x2<<G4endl<<G4endl;
pStart = G4ThreeVector(x1,y1,z1);
pEnd = G4ThreeVector(x2,y2,z2);
sCode = OutCode(pStart);
eCode = OutCode(pEnd);
}
if ( sCode == 0 && eCode == 0 ) remainsAfterClip = true;
else remainsAfterClip = false;
}
return remainsAfterClip;
}
////////////////////////////////////////////////////////////////////////////
//
// Calculate the `outcode' for the specified vector:
// The following bits are set:
// 0 pVec.x()<fxAxisMin && IsXLimited()
@@ -249,46 +255,31 @@ G4bool G4VoxelLimits::ClipToLimits(G4ThreeVector& pStart,
// 3 pVec.y()>fyAxisMax && IsYLimited()
// 4 pVec.z()<fzAxisMin && IsZLimited()
// 5 pVec.z()>fzAxisMax && IsZLimited()
//
G4int G4VoxelLimits::OutCode(const G4ThreeVector& pVec) const
G4int G4VoxelLimits::OutCode( const G4ThreeVector& pVec ) const
{
G4int code=0; // The outcode
if (IsXLimited())
{
if (pVec.x()<fxAxisMin)
{
code|=0x01;
}
if (pVec.x()>fxAxisMax)
{
code|=0x02;
}
}
if (IsYLimited())
{
if (pVec.y()<fyAxisMin)
{
code|=0x04;
}
if (pVec.y()>fyAxisMax)
{
code|=0x08;
}
}
if (IsZLimited())
{
if (pVec.z()<fzAxisMin)
{
code|=0x10;
}
if (pVec.z()>fzAxisMax)
{
code|=0x20;
}
}
return code;
G4int code = 0 ; // The outcode
if ( IsXLimited() )
{
if ( pVec.x() < fxAxisMin ) code |= 0x01 ;
if ( pVec.x() > fxAxisMax ) code |= 0x02 ;
}
if ( IsYLimited() )
{
if ( pVec.y() < fyAxisMin ) code |= 0x04 ;
if ( pVec.y() > fyAxisMax ) code |= 0x08 ;
}
if (IsZLimited())
{
if ( pVec.z() < fzAxisMin ) code |= 0x10 ;
if ( pVec.z() > fzAxisMax ) code |= 0x20 ;
}
return code;
}
///////////////////////////////////////////////////////////////////////////////
G4std::ostream& operator << (G4std::ostream& os, const G4VoxelLimits& pLim)
{
@@ -323,9 +314,3 @@ G4std::ostream& operator << (G4std::ostream& os, const G4VoxelLimits& pLim)
os << "}";
return os;
}