Import Geant4 10.4.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2017-06-30 11:12:01 +02:00
parent 1a1316fea4
commit 2cce0e189d
238 changed files with 0 additions and 62655 deletions
@@ -1,105 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * 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. 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 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:$
//
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
//
// G4UMultiUnion
//
// Class description:
//
// Wrapper class for G4UMultiUnion to make use of it from USolids module.
// History:
// 30.10.13 G.Cosmo, T.Nikitina, CERN/PH
// --------------------------------------------------------------------
#ifndef G4UMULTIUNION_HH
#define G4UMULTIUNION_HH
#include <CLHEP/Vector/Rotation.h>
#if defined(G4GEOM_USE_USOLIDS)
#include "G4USolid.hh"
#include "UMultiUnion.hh"
#include "G4Transform3D.hh"
#include "G4RotationMatrix.hh"
#include "HepPolyhedronProcessor.h"
class G4UMultiUnion : public G4USolid
{
public: // with description
G4UMultiUnion(const G4String& name);
~G4UMultiUnion();
inline UMultiUnion* GetShape() const;
void AddNode(G4VSolid& solid, G4Transform3D& trans);
// Build the multiple union by adding nodes
G4Transform3D* GetTransformation(G4int index) const;
G4VSolid* GetSolid(G4int index) const;
G4int GetNumberOfSolids()const;
void Voxelize();
public: // without description
G4UMultiUnion(__void__&);
// Fake default constructor for usage restricted to direct object
// persistency for clients requiring preallocation of memory for
// persistifiable objects.
G4UMultiUnion( const G4UMultiUnion& source );
G4UMultiUnion& operator=(const G4UMultiUnion& source);
// Copy constructor and assignment operator.
void Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const;
G4bool CalculateExtent(const EAxis pAxis,
const G4VoxelLimits& pVoxelLimit,
const G4AffineTransform& pTransform,
G4double& pMin, G4double& pMax) const;
G4Polyhedron* CreatePolyhedron() const;
// Called by visualization engine
};
// --------------------------------------------------------------------
// Inline methods
// --------------------------------------------------------------------
inline UMultiUnion* G4UMultiUnion::GetShape() const
{
return (UMultiUnion*) fShape;
}
#endif // G4GEOM_USE_USOLIDS
#endif
@@ -1,228 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * 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. 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 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:$
//
//
// Implementation of G4UMultiUnion wrapper class
// --------------------------------------------------------------------
#include "G4UMultiUnion.hh"
#if defined(G4GEOM_USE_USOLIDS)
#include "G4VoxelLimits.hh"
#include "G4BoundingEnvelope.hh"
#include "G4Polyhedron.hh"
#include "G4DisplacedSolid.hh"
#include "G4RotationMatrix.hh"
////////////////////////////////////////////////////////////////////////
//
// Constructor (generic parameters)
//
G4UMultiUnion::G4UMultiUnion(const G4String& name)
: G4USolid(name, new UMultiUnion(name))
{
}
////////////////////////////////////////////////////////////////////////
//
// Fake default constructor - sets only member data and allocates memory
// for usage restricted to object persistency.
//
G4UMultiUnion::G4UMultiUnion(__void__& a)
: G4USolid(a)
{
}
//////////////////////////////////////////////////////////////////////////
//
// Destructor
//
G4UMultiUnion::~G4UMultiUnion()
{
}
//////////////////////////////////////////////////////////////////////////
//
// Copy constructor
//
G4UMultiUnion::G4UMultiUnion(const G4UMultiUnion &source)
: G4USolid(source)
{
}
//////////////////////////////////////////////////////////////////////////
//
// Assignment operator
//
G4UMultiUnion& G4UMultiUnion::operator=(const G4UMultiUnion &source)
{
if (this == &source) return *this;
G4USolid::operator=( source );
return *this;
}
//////////////////////////////////////////////////////////////////////////
//
// Accessors & modifiers
//
void G4UMultiUnion::AddNode(G4VSolid& solid, G4Transform3D& trans)
{
HepGeom::Rotate3D rot;
HepGeom::Translate3D transl ;
HepGeom::Scale3D scale;
trans.getDecomposition(scale,rot,transl);
G4ThreeVector pos = transl.getTranslation();
UTransform3D tr;
tr.fRot[0] = rot.xx(); tr.fRot[1] = rot.xy(); tr.fRot[2] = rot.xz();
tr.fRot[3] = rot.yx(); tr.fRot[4] = rot.yy(); tr.fRot[5] = rot.yz();
tr.fRot[6] = rot.zx(); tr.fRot[7] = rot.zy(); tr.fRot[8] = rot.zz();
tr.fTr = UVector3(pos.x(), pos.y(), pos.z());
GetShape()->AddNode(*(static_cast<G4USolid&>(solid).GetSolid()), tr);
}
G4Transform3D* G4UMultiUnion::GetTransformation(G4int index) const
{
UTransform3D tr = GetShape()->GetTransformation(index);
G4RotationMatrix
rot(CLHEP::HepRep3x3(tr.fRot[0], tr.fRot[1], tr.fRot[2],
tr.fRot[3], tr.fRot[4], tr.fRot[5],
tr.fRot[6], tr.fRot[7], tr.fRot[8]));
G4ThreeVector transl(tr.fTr.x(), tr.fTr.y(), tr.fTr.z());
return new G4Transform3D(rot, transl);
}
G4VSolid* G4UMultiUnion::GetSolid(G4int index) const
{
VUSolid* solid = GetShape()->GetSolid(index);
return new G4USolid(solid->GetName(), solid);
}
G4int G4UMultiUnion::GetNumberOfSolids()const
{
return GetShape()->GetNumberOfSolids();
}
void G4UMultiUnion::Voxelize()
{
GetShape()->Voxelize();
}
//////////////////////////////////////////////////////////////////////////
//
// Get bounding box
void G4UMultiUnion::Extent(G4ThreeVector& pMin, G4ThreeVector& pMax) const
{
UVector3 vmin, vmax;
GetShape()->Extent(vmin,vmax);
pMin.set(vmin.x(),vmin.y(),vmin.z());
pMax.set(vmax.x(),vmax.y(),vmax.z());
// Check correctness of the bounding box
//
if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
{
std::ostringstream message;
message << "Bad bounding box (min >= max) for solid: "
<< GetName() << " !"
<< "\npMin = " << pMin
<< "\npMax = " << pMax;
G4Exception("G4UMultiUnion::Extent()", "GeomMgt0001", JustWarning, message);
DumpInfo();
}
}
//////////////////////////////////////////////////////////////////////////
//
// Calculate extent under transform and specified limit
G4bool
G4UMultiUnion::CalculateExtent(const EAxis pAxis,
const G4VoxelLimits& pVoxelLimit,
const G4AffineTransform& pTransform,
G4double& pMin, G4double& pMax) const
{
G4ThreeVector bmin, bmax;
// Get bounding box
Extent(bmin,bmax);
// Find extent
G4BoundingEnvelope bbox(bmin,bmax);
return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
}
//////////////////////////////////////////////////////////////////////////
//
// CreatePolyhedron
//
G4Polyhedron* G4UMultiUnion::CreatePolyhedron() const
{
HepPolyhedronProcessor processor;
HepPolyhedronProcessor::Operation operation = HepPolyhedronProcessor::UNION;
G4VSolid* solidA = GetSolid(0);
const G4Transform3D* transform0=GetTransformation(0);
G4RotationMatrix rot0=(*transform0).getRotation();
const G4ThreeVector transl0 = (*transform0).getTranslation();
G4DisplacedSolid dispSolidA("placedA",solidA,&rot0,transl0);
delete transform0;
G4Polyhedron* top = new G4Polyhedron(*dispSolidA.GetPolyhedron());
for(G4int i=1; i<GetNumberOfSolids(); ++i)
{
G4VSolid* solidB = GetSolid(i);
const G4Transform3D* transform=GetTransformation(i);
G4RotationMatrix rot=(*transform).getRotation();
const G4ThreeVector transl = (*transform).getTranslation();
G4DisplacedSolid dispSolidB("placedB",solidB,&rot,transl);
G4Polyhedron* operand = dispSolidB.GetPolyhedron();
processor.push_back (operation, *operand);
delete transform;
}
if (processor.execute(*top)) { return top; }
else { return 0; }
}
#endif // G4GEOM_USE_USOLIDS
@@ -1,255 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * 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. 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 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: G4SurfaceVoxelizer.hh 91755 2015-08-05 08:17:56Z gcosmo $
// GEANT4 tag $Name: not supported by cvs2svn $
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
// G4SurfaceVoxelizer
//
// Class description:
//
// Voxelizer for tessellated surfaces, used in G4TessellatedSolid.
// History:
// 19.10.12 Marek Gayer, created
// --------------------------------------------------------------------
#ifndef G4SurfaceVoxelizer_HH
#define G4SurfaceVoxelizer_HH
#include <vector>
#include <string>
#include <map>
#include "G4SurfBits.hh"
#include "G4Box.hh"
#include "G4VFacet.hh"
struct G4VoxelBox
{
G4ThreeVector hlen; // half length of the box
G4ThreeVector pos; // position of the box
};
struct G4VoxelInfo
{
G4int count;
G4int previous;
G4int next;
};
class G4SurfaceVoxelizer
{
public:
template <typename T>
static inline G4int BinarySearch(const std::vector<T> &vec, T value);
void Voxelize(std::vector<G4VFacet *> &facets);
void DisplayVoxelLimits();
void DisplayBoundaries();
void DisplayListNodes() const;
G4SurfaceVoxelizer();
~G4SurfaceVoxelizer();
void GetCandidatesVoxel(std::vector<G4int> &voxels);
// Method displaying the nodes located in a voxel characterized
// by its three indexes.
G4int GetCandidatesVoxelArray(const G4ThreeVector &point,
std::vector<G4int> &list,
G4SurfBits *crossed=0) const;
// Method returning in a vector container the nodes located in a voxel
// characterized by its three indexes.
G4int GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
const G4SurfBits bitmasks[],
std::vector<G4int> &list,
G4SurfBits *crossed=0) const;
G4int GetCandidatesVoxelArray(const std::vector<G4int> &voxels,
std::vector<G4int> &list,
G4SurfBits *crossed=0)const;
inline const std::vector<G4VoxelBox> &GetBoxes() const;
// Method returning the pointer to the array containing the
// characteristics of each box.
inline const std::vector<G4double> &GetBoundary(G4int index) const;
G4bool UpdateCurrentVoxel(const G4ThreeVector &point,
const G4ThreeVector &direction,
std::vector<G4int> &curVoxel) const;
inline void GetVoxel(std::vector<G4int> &curVoxel,
const G4ThreeVector &point) const;
inline G4int GetBitsPerSlice () const;
G4bool Contains(const G4ThreeVector &point) const;
G4double DistanceToNext(const G4ThreeVector &point,
const G4ThreeVector &direction,
const std::vector<G4int> &curVoxel) const;
G4double DistanceToFirst(const G4ThreeVector &point,
const G4ThreeVector &direction) const;
G4double DistanceToBoundingBox(const G4ThreeVector &point) const;
inline G4int GetVoxelsIndex(G4int x, G4int y, G4int z) const;
inline G4int GetVoxelsIndex(const std::vector<G4int> &voxels) const;
inline G4int GetPointIndex(const G4ThreeVector &p) const;
inline const G4SurfBits &Empty() const;
inline G4bool IsEmpty(G4int index) const;
void SetMaxVoxels(G4int max);
void SetMaxVoxels(const G4ThreeVector &reductionRatio);
inline G4int GetMaxVoxels(G4ThreeVector &ratioOfReduction);
G4int AllocatedMemory();
inline long long GetCountOfVoxels() const;
inline long long CountVoxels(std::vector<G4double> boundaries[]) const;
inline const std::vector<G4int> &
GetCandidates(std::vector<G4int> &curVoxel) const;
inline G4int GetVoxelBoxesSize() const;
inline const G4VoxelBox &GetVoxelBox(G4int i) const;
inline const std::vector<G4int> &GetVoxelBoxCandidates(G4int i) const;
inline G4int GetTotalCandidates() const;
static G4double MinDistanceToBox (const G4ThreeVector &aPoint,
const G4ThreeVector &f);
static G4int SetDefaultVoxelsCount(G4int count);
static G4int GetDefaultVoxelsCount();
private:
class G4VoxelComparator
{
public:
std::vector<G4VoxelInfo> &fVoxels;
G4VoxelComparator(std::vector<G4VoxelInfo> &voxels) : fVoxels(voxels) {}
G4bool operator()(const G4int& l, const G4int& r) const
{
G4VoxelInfo &lv = fVoxels[l], &rv = fVoxels[r];
G4int left = lv.count + fVoxels[lv.next].count;
G4int right = rv.count + fVoxels[rv.next].count;
return (left == right) ? l < r : left < right;
}
};
private:
static G4ThreadLocal G4int fDefaultVoxelsCount;
void BuildEmpty ();
G4String GetCandidatesAsString(const G4SurfBits &bits) const;
void CreateSortedBoundary(std::vector<G4double> &boundaryRaw, G4int axis);
void BuildBoundaries();
void BuildReduceVoxels(std::vector<G4double> fBoundaries[],
G4ThreeVector reductionRatio);
void BuildReduceVoxels2(std::vector<G4double> fBoundaries[],
G4ThreeVector reductionRatio);
void BuildVoxelLimits(std::vector<G4VFacet *> &facets);
void DisplayBoundaries(std::vector<G4double> &fBoundaries);
void BuildBitmasks(std::vector<G4double> fBoundaries[],
G4SurfBits bitmasks[], G4bool countsOnly=false);
void BuildBoundingBox();
void SetReductionRatio(G4int maxVoxels, G4ThreeVector &reductionRatio);
void CreateMiniVoxels(std::vector<G4double> fBoundaries[],
G4SurfBits bitmasks[]);
static void FindComponentsFastest(unsigned int mask,
std::vector<G4int> &list, G4int i);
private:
std::vector<G4VoxelBox> fVoxelBoxes;
std::vector<std::vector<G4int> > fVoxelBoxesCandidates;
mutable std::map<G4int, std::vector<G4int> > fCandidates;
const std::vector<G4int> fNoCandidates;
long long fCountOfVoxels;
G4int fNPerSlice;
std::vector<G4VoxelBox> fBoxes;
// Array of box limits on the 3 cartesian axis
std::vector<G4double> fBoundaries[3];
// Sorted and if need skimmed fBoundaries along X,Y,Z axis
std::vector<G4int> fCandidatesCounts[3];
G4int fTotalCandidates;
G4SurfBits fBitmasks[3];
G4ThreeVector fBoundingBoxCenter;
G4Box fBoundingBox;
G4ThreeVector fBoundingBoxSize;
G4ThreeVector fReductionRatio;
G4int fMaxVoxels;
G4double fTolerance;
G4SurfBits fEmpty;
};
#include "G4SurfaceVoxelizer.icc"
#endif
@@ -1,182 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * 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. 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 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: G4SurfaceVoxelizer.icc 91755 2015-08-05 08:17:56Z gcosmo $
// GEANT4 tag $Name: not supported by cvs2svn $
//
// --------------------------------------------------------------------
// GEANT 4 class header file
//
// G4SurfaceVoxelizer inline methods
//
// History:
// 19.10.12 Marek Gayer, created
// --------------------------------------------------------------------
template <typename T> inline
G4int G4SurfaceVoxelizer::BinarySearch(const std::vector<T> &vec, T value)
{
typename std::vector<T>::const_iterator begin=vec.begin(), end=vec.end();
G4int res = std::upper_bound(begin, end, value) - begin - 1;
return res;
}
inline
const std::vector<G4VoxelBox> &G4SurfaceVoxelizer::GetBoxes() const
{
return fBoxes;
}
inline
const std::vector<G4double> &G4SurfaceVoxelizer::GetBoundary(G4int index) const
{
return fBoundaries[index];
}
inline
void G4SurfaceVoxelizer::GetVoxel(std::vector<G4int> &curVoxel,
const G4ThreeVector &point) const
{
for (G4int i=0; i<=2; ++i)
{
const std::vector<double> &boundary = GetBoundary(i);
G4int n = BinarySearch(boundary, point[i]);
if (n == -1)
{ n = 0; }
else if (n == G4int(boundary.size()) - 1)
{ n--; }
curVoxel[i] = n;
}
}
inline
G4int G4SurfaceVoxelizer::GetBitsPerSlice () const
{
return fNPerSlice*8*sizeof(unsigned int);
}
inline
G4int G4SurfaceVoxelizer::GetVoxelsIndex(G4int x, G4int y, G4int z) const
{
if (x < 0 || y < 0 || z < 0) { return -1; }
G4int maxX = fBoundaries[0].size();
G4int maxY = fBoundaries[1].size();
G4int index = x + y*maxX + z*maxX*maxY;
return index;
}
inline
G4int G4SurfaceVoxelizer::GetVoxelsIndex(const std::vector<G4int> &voxels) const
{
return GetVoxelsIndex(voxels[0], voxels[1], voxels[2]);
}
inline
G4int G4SurfaceVoxelizer::GetPointIndex(const G4ThreeVector &p) const
{
G4int maxX = fBoundaries[0].size();
G4int maxY = fBoundaries[1].size();
G4int x = BinarySearch(fBoundaries[0], p[0]);
G4int y = BinarySearch(fBoundaries[1], p[1]);
G4int z = BinarySearch(fBoundaries[2], p[2]);
G4int index = x + y*maxX + z*maxX*maxY;
return index;
}
inline
const G4SurfBits &G4SurfaceVoxelizer::Empty() const
{
return fEmpty;
}
inline
G4bool G4SurfaceVoxelizer::IsEmpty(G4int index) const
{
return fEmpty[index];
}
inline
G4int G4SurfaceVoxelizer::GetMaxVoxels(G4ThreeVector &ratioOfReduction)
{
ratioOfReduction = fReductionRatio;
return fMaxVoxels;
}
inline
long long G4SurfaceVoxelizer::GetCountOfVoxels() const
{
return fCountOfVoxels;
}
inline
long long G4SurfaceVoxelizer::CountVoxels(std::vector<G4double> boundaries[]) const
{
long long sx = boundaries[0].size() - 1;
long long sy = boundaries[1].size() - 1;
long long sz = boundaries[2].size() - 1;
return sx * sy *sz;
}
inline
const std::vector<G4int>&
G4SurfaceVoxelizer::GetCandidates(std::vector<G4int> &curVoxel) const
{
G4int voxelsIndex = GetVoxelsIndex(curVoxel);
if (voxelsIndex >= 0 && !fEmpty[voxelsIndex])
{
return fCandidates[voxelsIndex];
}
return fNoCandidates;
}
inline
G4int G4SurfaceVoxelizer::GetTotalCandidates() const
{
return fTotalCandidates;
}
inline
G4int G4SurfaceVoxelizer::GetVoxelBoxesSize() const
{
return fVoxelBoxes.size();
}
inline
const G4VoxelBox &G4SurfaceVoxelizer::GetVoxelBox(G4int i) const
{
return fVoxelBoxes[i];
}
inline
const std::vector<G4int>&
G4SurfaceVoxelizer::GetVoxelBoxCandidates(G4int i) const
{
return fVoxelBoxesCandidates[i];
}
File diff suppressed because it is too large Load Diff