Import Geant4 11.4.0 source tree
This commit is contained in:
@@ -28,19 +28,19 @@
|
||||
//
|
||||
// Class description:
|
||||
//
|
||||
// G4TessellatedSolid is a special Geant4 solid defined by a number of
|
||||
// facets (UVFacet). It is important that the supplied facets shall form a
|
||||
// fully enclose space which is the solid.
|
||||
// At the moment only two types of facet can be used for the construction of
|
||||
// a G4TessellatedSolid, i.e. the G4TriangularFacet and G4QuadrangularFacet.
|
||||
// G4TessellatedSolid is a special Geant4 solid defined by a number of
|
||||
// facets (UVFacet). It is important that the supplied facets shall form a
|
||||
// fully enclose space which is the solid.
|
||||
// At the moment only two types of facet can be used for the construction of
|
||||
// a G4TessellatedSolid, i.e. the G4TriangularFacet and G4QuadrangularFacet.
|
||||
//
|
||||
// How to contruct a G4TessellatedSolid:
|
||||
// How to contruct a G4TessellatedSolid:
|
||||
//
|
||||
// First declare a tessellated solid:
|
||||
//
|
||||
// G4TessellatedSolid* solidTarget = new G4TessellatedSolid("Solid_name");
|
||||
//
|
||||
// Define the facets which form the solid
|
||||
// Define the facets which form the solid:
|
||||
//
|
||||
// G4double targetSiz = 10*cm ;
|
||||
// G4TriangularFacet *facet1 = new
|
||||
@@ -82,11 +82,11 @@
|
||||
//
|
||||
// solidTarget->SetSolidClosed(true);
|
||||
|
||||
// 31.10.2004, P R Truscott, QinetiQ Ltd, UK - Created.
|
||||
// 12.10.2012, M Gayer, CERN - New implementation with voxelization of surfaces.
|
||||
// Author: P.R.Truscott (QinetiQ Ltd, UK), 31.10.2004 - Created.
|
||||
// M.Gayer (CERN), 12.10.2012 - New implementation with voxelization.
|
||||
// --------------------------------------------------------------------
|
||||
#ifndef G4TESSELLATEDSOLID_HH
|
||||
#define G4TESSELLATEDSOLID_HH 1
|
||||
#define G4TESSELLATEDSOLID_HH
|
||||
|
||||
#include "G4GeomTypes.hh"
|
||||
|
||||
@@ -117,37 +117,85 @@ struct G4VertexInfo
|
||||
|
||||
class G4VertexComparator
|
||||
{
|
||||
public:
|
||||
G4bool operator() (const G4VertexInfo& l, const G4VertexInfo& r) const
|
||||
{
|
||||
return l.mag2 == r.mag2 ? l.id < r.id : l.mag2 < r.mag2;
|
||||
}
|
||||
public:
|
||||
|
||||
G4bool operator() (const G4VertexInfo& l, const G4VertexInfo& r) const
|
||||
{
|
||||
return l.mag2 == r.mag2 ? l.id < r.id : l.mag2 < r.mag2;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief G4TessellatedSolid is a solid defined by a number of facets.
|
||||
* It is important that the supplied facets shall form a fully enclose space
|
||||
* which is the solid. The facets can be of two types, G4TriangularFacet and
|
||||
* G4QuadrangularFacet.
|
||||
*/
|
||||
|
||||
class G4TessellatedSolid : public G4VSolid
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*/
|
||||
G4TessellatedSolid ();
|
||||
~G4TessellatedSolid () override;
|
||||
|
||||
/**
|
||||
* Constructor with solid's name.
|
||||
* @param[in] name The name of the solid.
|
||||
*/
|
||||
G4TessellatedSolid (const G4String& name);
|
||||
|
||||
/**
|
||||
* Destructor. Clearing all allocated facets and data.
|
||||
*/
|
||||
~G4TessellatedSolid () override;
|
||||
|
||||
/**
|
||||
* Fake default constructor for usage restricted to direct object
|
||||
* persistency for clients requiring preallocation of memory for
|
||||
* persistifiable objects.
|
||||
*/
|
||||
G4TessellatedSolid(__void__&);
|
||||
// Fake default constructor for usage restricted to direct object
|
||||
// persistency for clients requiring preallocation of memory for
|
||||
// persistifiable objects.
|
||||
|
||||
/**
|
||||
* Copy constructor and assignment operator.
|
||||
*/
|
||||
G4TessellatedSolid (const G4TessellatedSolid& ts);
|
||||
G4TessellatedSolid &operator= (const G4TessellatedSolid& right);
|
||||
G4TessellatedSolid &operator+= (const G4TessellatedSolid& right);
|
||||
G4TessellatedSolid& operator= (const G4TessellatedSolid& right);
|
||||
|
||||
/**
|
||||
* Operator +=, allowing to add two tessellated solids together, so
|
||||
* that the solid on the left includes all of the facets in the solid
|
||||
* on the right. To note that copies of the facets are generated, rather
|
||||
* than using the original facet set of the solid on the right.
|
||||
*/
|
||||
G4TessellatedSolid& operator+= (const G4TessellatedSolid& right);
|
||||
|
||||
/**
|
||||
* Methods for adding or retrieving a facet given an index.
|
||||
*/
|
||||
G4bool AddFacet (G4VFacet* aFacet);
|
||||
inline G4VFacet* GetFacet (G4int i) const;
|
||||
|
||||
/**
|
||||
* Accessors.
|
||||
*/
|
||||
G4int GetNumberOfFacets () const;
|
||||
G4int GetFacetIndex (const G4ThreeVector& p) const;
|
||||
G4double GetMinXExtent () const;
|
||||
G4double GetMaxXExtent () const;
|
||||
G4double GetMinYExtent () const;
|
||||
G4double GetMaxYExtent () const;
|
||||
G4double GetMinZExtent () const;
|
||||
G4double GetMaxZExtent () const;
|
||||
|
||||
|
||||
/**
|
||||
* Concrete implementations of the expected query interfaces for
|
||||
* solids, as defined in the base class G4VSolid.
|
||||
*/
|
||||
EInside Inside (const G4ThreeVector& p) const override;
|
||||
G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
|
||||
G4double DistanceToIn(const G4ThreeVector& p,
|
||||
@@ -160,57 +208,147 @@ class G4TessellatedSolid : public G4VSolid
|
||||
G4bool* validNorm,
|
||||
G4ThreeVector* norm) const override;
|
||||
|
||||
/**
|
||||
* Returns the outwards pointing unit normal of the shape for the
|
||||
* surface closest to the point at offset 'p'.
|
||||
* @param[in] p The point coordinates.
|
||||
* @param[out] n The returned normal vector.
|
||||
* @returns false if not a valid normal.
|
||||
*/
|
||||
virtual G4bool Normal (const G4ThreeVector& p, G4ThreeVector& n) const;
|
||||
|
||||
/**
|
||||
* Returns the the safety distance from outside the solid at a point 'p'.
|
||||
* @param[in] p The point coordinates.
|
||||
* @param[in] aAccurate Accuracy flag, if false quickly computes and
|
||||
* returns the distance to the voxels bounding-box.
|
||||
* @returns The safety distance.
|
||||
*/
|
||||
virtual G4double SafetyFromOutside(const G4ThreeVector& p,
|
||||
G4bool aAccurate = false) const;
|
||||
|
||||
/**
|
||||
* Returns the the safety distance from inside the solid at a point 'p'.
|
||||
* @param[in] p The point coordinates.
|
||||
* @param[in] aAccurate Not used.
|
||||
* @returns The safety distance.
|
||||
*/
|
||||
virtual G4double SafetyFromInside (const G4ThreeVector& p,
|
||||
G4bool aAccurate = false) const;
|
||||
|
||||
/**
|
||||
* Returns the type ID, "G4TessellatedSolid" of the solid.
|
||||
*/
|
||||
G4GeometryType GetEntityType () const override;
|
||||
|
||||
/**
|
||||
* Returns true as the solid has only planar faces.
|
||||
*/
|
||||
G4bool IsFaceted () const override;
|
||||
|
||||
/**
|
||||
* Streams the object contents to an output stream.
|
||||
*/
|
||||
std::ostream& StreamInfo(std::ostream& os) const override;
|
||||
|
||||
/**
|
||||
* Makes a clone of the object for use in multi-treading.
|
||||
* @returns A pointer to the new cloned allocated solid.
|
||||
*/
|
||||
G4VSolid* Clone() const override;
|
||||
|
||||
/**
|
||||
* Returns a random point located and uniformly distributed on the
|
||||
* surface of the solid.
|
||||
*/
|
||||
G4ThreeVector GetPointOnSurface() const override;
|
||||
|
||||
/**
|
||||
* Returning an estimation of the solid volume (capacity) and
|
||||
* surface area, in internal units.
|
||||
*/
|
||||
G4double GetSurfaceArea() override;
|
||||
G4double GetCubicVolume() override;
|
||||
|
||||
/**
|
||||
* Modifier and accessor to close/finalise the solid.
|
||||
*/
|
||||
void SetSolidClosed (const G4bool t);
|
||||
G4bool GetSolidClosed () const;
|
||||
|
||||
/**
|
||||
* Checks the structure of the solid.
|
||||
* @returns A value, sum of the following defect indicators, if any
|
||||
* (0 means no defects):
|
||||
* 1 - cubic volume is negative, wrong orientation of facets;
|
||||
* 2 - some facets have wrong orientation;
|
||||
* 4 - holes in the surface.
|
||||
*/
|
||||
G4int CheckStructure() const;
|
||||
|
||||
/**
|
||||
* Allowing to tune the maximum number of voxels to use for optimisation.
|
||||
*/
|
||||
inline void SetMaxVoxels(G4int max);
|
||||
|
||||
/**
|
||||
* Returns the voxels structure.
|
||||
*/
|
||||
inline G4Voxelizer& GetVoxels();
|
||||
|
||||
/**
|
||||
* Calculates the minimum and maximum extent of the solid, when under the
|
||||
* specified transform, and within the specified limits.
|
||||
* @param[in] pAxis The axis along which compute the extent.
|
||||
* @param[in] pVoxelLimit The limiting space dictated by voxels.
|
||||
* @param[in] pTransform The internal transformation applied to the solid.
|
||||
* @param[out] pMin The minimum extent value.
|
||||
* @param[out] pMax The maximum extent value.
|
||||
* @returns True if the solid is intersected by the extent region.
|
||||
*/
|
||||
G4bool CalculateExtent(const EAxis pAxis,
|
||||
const G4VoxelLimits& pVoxelLimit,
|
||||
const G4AffineTransform& pTransform,
|
||||
G4double& pMin, G4double& pMax) const override;
|
||||
|
||||
/**
|
||||
* Computes the bounding limits of the solid.
|
||||
* @param[out] pMin The minimum bounding limit point.
|
||||
* @param[out] pMax The maximum bounding limit point.
|
||||
*/
|
||||
void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
|
||||
|
||||
G4double GetMinXExtent () const;
|
||||
G4double GetMaxXExtent () const;
|
||||
G4double GetMinYExtent () const;
|
||||
G4double GetMaxYExtent () const;
|
||||
G4double GetMinZExtent () const;
|
||||
G4double GetMaxZExtent () const;
|
||||
|
||||
G4Polyhedron* CreatePolyhedron () const override;
|
||||
G4Polyhedron* GetPolyhedron () const override;
|
||||
void DescribeYourselfTo (G4VGraphicsScene& scene) const override;
|
||||
G4VisExtent GetExtent () const override;
|
||||
/**
|
||||
* Methods for creating graphical representations (i.e. for visualisation).
|
||||
*/
|
||||
G4Polyhedron* CreatePolyhedron() const override;
|
||||
G4Polyhedron* GetPolyhedron() const override;
|
||||
void DescribeYourselfTo(G4VGraphicsScene& scene) const override;
|
||||
G4VisExtent GetExtent() const override;
|
||||
|
||||
/**
|
||||
* Loggers reporting the total allocated memory.
|
||||
*/
|
||||
G4int AllocatedMemoryWithoutVoxels();
|
||||
G4int AllocatedMemory();
|
||||
void DisplayAllocatedMemory();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Initialisation/reset of data, used in constructors and operators.
|
||||
*/
|
||||
void Initialize();
|
||||
|
||||
/**
|
||||
* Resetting/copying data, used in constructors and operators.
|
||||
*/
|
||||
void DeleteObjects ();
|
||||
void CopyObjects (const G4TessellatedSolid& s);
|
||||
|
||||
/**
|
||||
* Internal methods used for computing distances with or without voxels.
|
||||
*/
|
||||
G4double DistanceToOutNoVoxels(const G4ThreeVector& p,
|
||||
const G4ThreeVector& v,
|
||||
G4ThreeVector& aNormalVector,
|
||||
@@ -228,19 +366,6 @@ class G4TessellatedSolid : public G4VSolid
|
||||
G4double DistanceToInNoVoxels(const G4ThreeVector& p,
|
||||
const G4ThreeVector& v,
|
||||
G4double aPstep = kInfinity) const;
|
||||
void SetExtremeFacets();
|
||||
|
||||
EInside InsideNoVoxels (const G4ThreeVector& p) const;
|
||||
EInside InsideVoxels(const G4ThreeVector& aPoint) const;
|
||||
|
||||
void Voxelize();
|
||||
|
||||
void CreateVertexList();
|
||||
|
||||
void PrecalculateInsides();
|
||||
|
||||
void SetRandomVectors();
|
||||
|
||||
G4double DistanceToInCore(const G4ThreeVector &p, const G4ThreeVector& v,
|
||||
G4double aPstep = kInfinity) const;
|
||||
G4double DistanceToOutCore(const G4ThreeVector& p, const G4ThreeVector& v,
|
||||
@@ -248,19 +373,65 @@ class G4TessellatedSolid : public G4VSolid
|
||||
G4bool& aConvex,
|
||||
G4double aPstep = kInfinity) const;
|
||||
|
||||
/**
|
||||
* Finds those facets that have surface planes that bound the volume.
|
||||
* To note that this is going to reject concave surfaces as being extreme.
|
||||
*/
|
||||
void SetExtremeFacets();
|
||||
|
||||
/**
|
||||
* Internal methods used for checking if a point 'p' is inside the solid
|
||||
* in presence or not of voxels.
|
||||
*/
|
||||
EInside InsideNoVoxels (const G4ThreeVector& p) const;
|
||||
EInside InsideVoxels(const G4ThreeVector& p) const;
|
||||
|
||||
/**
|
||||
* Performs the voxelisation of the shape, building the optimisation
|
||||
* structure, according to the specified parameters.
|
||||
*/
|
||||
void Voxelize();
|
||||
|
||||
/**
|
||||
* Creates a list of vertices with an additional sorted list, where all
|
||||
* the items are sorted by magnitude of vertices vector.
|
||||
*/
|
||||
void CreateVertexList();
|
||||
|
||||
/**
|
||||
* Utilities for preparation of voxels indeces. Used in Voxelize() function.
|
||||
*/
|
||||
void PrecalculateInsides();
|
||||
G4int SetAllUsingStack(const std::vector<G4int>& voxel,
|
||||
const std::vector<G4int>& max,
|
||||
G4bool status, G4SurfBits& checked);
|
||||
|
||||
void DeleteObjects ();
|
||||
void CopyObjects (const G4TessellatedSolid& s);
|
||||
|
||||
/**
|
||||
* Utility to compare sorted voxels.
|
||||
*/
|
||||
static G4bool CompareSortedVoxel(const std::pair<G4int, G4double>& l,
|
||||
const std::pair<G4int, G4double>& r);
|
||||
|
||||
|
||||
/**
|
||||
* Prepares a set of predefined random vectors, used to generate rays
|
||||
* from a user-defined point. Used in Inside() function to determine
|
||||
* whether the point is inside or outside of the tessellated solid.
|
||||
* All vectors should be unit vectors.
|
||||
*/
|
||||
void SetRandomVectors();
|
||||
|
||||
/**
|
||||
* Computes the minimum distance of a point 'p' from a 'facet'.
|
||||
*/
|
||||
G4double MinDistanceFacet(const G4ThreeVector& p, G4bool simple,
|
||||
G4VFacet* &facet) const;
|
||||
|
||||
/**
|
||||
* Computes if a point 'p' is outside or not of the computed extent,
|
||||
* given a 'tolerance'. Used internally in Inside() functions.
|
||||
* @returns true if the point is within the extent.
|
||||
*/
|
||||
inline G4bool OutsideOfExtent(const G4ThreeVector& p,
|
||||
G4double tolerance = 0.0) const;
|
||||
|
||||
@@ -299,10 +470,10 @@ class G4TessellatedSolid : public G4VSolid
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Inlined Methods
|
||||
// Inline Methods
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline G4VFacet *G4TessellatedSolid::GetFacet (G4int i) const
|
||||
inline G4VFacet* G4TessellatedSolid::GetFacet (G4int i) const
|
||||
{
|
||||
return fFacets[i];
|
||||
}
|
||||
@@ -312,7 +483,7 @@ inline void G4TessellatedSolid::SetMaxVoxels(G4int max)
|
||||
fVoxels.SetMaxVoxels(max);
|
||||
}
|
||||
|
||||
inline G4Voxelizer &G4TessellatedSolid::GetVoxels()
|
||||
inline G4Voxelizer& G4TessellatedSolid::GetVoxels()
|
||||
{
|
||||
return fVoxels;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user