Geant4 11.3.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4TessellatedSolid Class Reference

#include <G4TessellatedSolid.hh>

+ Inheritance diagram for G4TessellatedSolid:

Public Member Functions

 G4TessellatedSolid ()
 
 ~G4TessellatedSolid () override
 
 G4TessellatedSolid (const G4String &name)
 
 G4TessellatedSolid (__void__ &)
 
 G4TessellatedSolid (const G4TessellatedSolid &ts)
 
G4TessellatedSolidoperator= (const G4TessellatedSolid &right)
 
G4TessellatedSolidoperator+= (const G4TessellatedSolid &right)
 
G4bool AddFacet (G4VFacet *aFacet)
 
G4VFacetGetFacet (G4int i) const
 
G4int GetNumberOfFacets () const
 
G4int GetFacetIndex (const G4ThreeVector &p) const
 
EInside Inside (const G4ThreeVector &p) const override
 
G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const override
 
G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const override
 
G4double DistanceToIn (const G4ThreeVector &p) const override
 
G4double DistanceToOut (const G4ThreeVector &p) const override
 
G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm, G4bool *validNorm, G4ThreeVector *norm) const override
 
virtual G4bool Normal (const G4ThreeVector &p, G4ThreeVector &n) const
 
virtual G4double SafetyFromOutside (const G4ThreeVector &p, G4bool aAccurate=false) const
 
virtual G4double SafetyFromInside (const G4ThreeVector &p, G4bool aAccurate=false) const
 
G4GeometryType GetEntityType () const override
 
G4bool IsFaceted () const override
 
std::ostream & StreamInfo (std::ostream &os) const override
 
G4VSolidClone () const override
 
G4ThreeVector GetPointOnSurface () const override
 
G4double GetSurfaceArea () override
 
G4double GetCubicVolume () override
 
void SetSolidClosed (const G4bool t)
 
G4bool GetSolidClosed () const
 
G4int CheckStructure () const
 
void SetMaxVoxels (G4int max)
 
G4VoxelizerGetVoxels ()
 
G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const override
 
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
 
G4PolyhedronCreatePolyhedron () const override
 
G4PolyhedronGetPolyhedron () const override
 
void DescribeYourselfTo (G4VGraphicsScene &scene) const override
 
G4VisExtent GetExtent () const override
 
G4int AllocatedMemoryWithoutVoxels ()
 
G4int AllocatedMemory ()
 
void DisplayAllocatedMemory ()
 
- Public Member Functions inherited from G4VSolid
 G4VSolid (const G4String &name)
 
virtual ~G4VSolid ()
 
G4bool operator== (const G4VSolid &s) const
 
G4String GetName () const
 
void SetName (const G4String &name)
 
G4double GetTolerance () const
 
virtual void ComputeDimensions (G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
virtual G4int GetNumOfConstituents () const
 
void DumpInfo () const
 
virtual const G4VSolidGetConstituentSolid (G4int no) const
 
virtual G4VSolidGetConstituentSolid (G4int no)
 
virtual const G4DisplacedSolidGetDisplacedSolidPtr () const
 
virtual G4DisplacedSolidGetDisplacedSolidPtr ()
 
 G4VSolid (__void__ &)
 
 G4VSolid (const G4VSolid &rhs)
 
G4VSolidoperator= (const G4VSolid &rhs)
 
G4double EstimateCubicVolume (G4int nStat, G4double epsilon) const
 
G4double EstimateSurfaceArea (G4int nStat, G4double ell) const
 

Protected Attributes

G4double kCarToleranceHalf
 
- Protected Attributes inherited from G4VSolid
G4double kCarTolerance
 

Additional Inherited Members

- Protected Member Functions inherited from G4VSolid
void CalculateClippedPolygonExtent (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipCrossSection (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipBetweenSections (G4ThreeVectorList *pVertices, const G4int pSectionIndex, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis, G4double &pMin, G4double &pMax) const
 
void ClipPolygon (G4ThreeVectorList &pPolygon, const G4VoxelLimits &pVoxelLimit, const EAxis pAxis) const
 

Detailed Description

Definition at line 127 of file G4TessellatedSolid.hh.

Constructor & Destructor Documentation

◆ G4TessellatedSolid() [1/4]

G4TessellatedSolid::G4TessellatedSolid ( )

Definition at line 85 of file G4TessellatedSolid.cc.

85 : G4VSolid("dummy")
86{
87 Initialize();
88}
G4VSolid(const G4String &name)
Definition G4VSolid.cc:57

Referenced by Clone(), G4ExtrudedSolid::G4ExtrudedSolid(), G4ExtrudedSolid::G4ExtrudedSolid(), G4ExtrudedSolid::G4ExtrudedSolid(), G4TessellatedSolid(), operator+=(), and operator=().

◆ ~G4TessellatedSolid()

G4TessellatedSolid::~G4TessellatedSolid ( )
override

Definition at line 115 of file G4TessellatedSolid.cc.

116{
117 DeleteObjects();
118}

◆ G4TessellatedSolid() [2/4]

G4TessellatedSolid::G4TessellatedSolid ( const G4String & name)

Definition at line 95 of file G4TessellatedSolid.cc.

96 : G4VSolid(name)
97{
98 Initialize();
99}

◆ G4TessellatedSolid() [3/4]

G4TessellatedSolid::G4TessellatedSolid ( __void__ & a)

Definition at line 106 of file G4TessellatedSolid.cc.

106 : G4VSolid(a)
107{
108 Initialize();
109 fMinExtent.set(0,0,0);
110 fMaxExtent.set(0,0,0);
111}

◆ G4TessellatedSolid() [4/4]

G4TessellatedSolid::G4TessellatedSolid ( const G4TessellatedSolid & ts)

Definition at line 124 of file G4TessellatedSolid.cc.

125 : G4VSolid(ts)
126{
127 Initialize();
128
129 CopyObjects(ts);
130}

Member Function Documentation

◆ AddFacet()

G4bool G4TessellatedSolid::AddFacet ( G4VFacet * aFacet)

Definition at line 206 of file G4TessellatedSolid.cc.

207{
208 // Add the facet to the vector.
209 //
210 if (fSolidClosed)
211 {
212 G4Exception("G4TessellatedSolid::AddFacet()", "GeomSolids1002",
213 JustWarning, "Attempt to add facets when solid is closed.");
214 return false;
215 }
216 else if (aFacet->IsDefined())
217 {
218 set<G4VertexInfo,G4VertexComparator>::iterator begin
219 = fFacetList.begin(), end = fFacetList.end(), pos, it;
220 G4ThreeVector p = aFacet->GetCircumcentre();
221 G4VertexInfo value;
222 value.id = (G4int)fFacetList.size();
223 value.mag2 = p.x() + p.y() + p.z();
224
225 G4bool found = false;
226 if (!OutsideOfExtent(p, kCarTolerance))
227 {
228 G4double kCarTolerance3 = 3 * kCarTolerance;
229 pos = fFacetList.lower_bound(value);
230
231 it = pos;
232 while (!found && it != end) // Loop checking, 13.08.2015, G.Cosmo
233 {
234 G4int id = (*it).id;
235 G4VFacet *facet = fFacets[id];
236 G4ThreeVector q = facet->GetCircumcentre();
237 if ((found = (facet == aFacet))) break;
238 G4double dif = q.x() + q.y() + q.z() - value.mag2;
239 if (dif > kCarTolerance3) break;
240 it++;
241 }
242
243 if (fFacets.size() > 1)
244 {
245 it = pos;
246 while (!found && it != begin) // Loop checking, 13.08.2015, G.Cosmo
247 {
248 --it;
249 G4int id = (*it).id;
250 G4VFacet *facet = fFacets[id];
251 G4ThreeVector q = facet->GetCircumcentre();
252 found = (facet == aFacet);
253 if (found) break;
254 G4double dif = value.mag2 - (q.x() + q.y() + q.z());
255 if (dif > kCarTolerance3) break;
256 }
257 }
258 }
259
260 if (!found)
261 {
262 fFacets.push_back(aFacet);
263 fFacetList.insert(value);
264 }
265 return true;
266 }
267 else
268 {
269 G4Exception("G4TessellatedSolid::AddFacet()", "GeomSolids1002",
270 JustWarning, "Attempt to add facet not properly defined.");
271 aFacet->StreamInfo(G4cout);
272 return false;
273 }
274}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cout
double z() const
double x() const
double y() const
virtual G4ThreeVector GetCircumcentre() const =0
std::ostream & StreamInfo(std::ostream &os) const
Definition G4VFacet.cc:94
virtual G4bool IsDefined() const =0
G4double kCarTolerance
Definition G4VSolid.hh:306

Referenced by G4tgbVolume::FindOrConstructG4Solid(), operator+=(), and G4GDMLReadSolids::TessellatedRead().

◆ AllocatedMemory()

G4int G4TessellatedSolid::AllocatedMemory ( )

Definition at line 2247 of file G4TessellatedSolid.cc.

2248{
2250 G4int sizeInsides = fInsides.GetNbytes();
2251 G4int sizeVoxels = fVoxels.AllocatedMemory();
2252 size += sizeInsides + sizeVoxels;
2253 return size;
2254}

Referenced by DisplayAllocatedMemory().

◆ AllocatedMemoryWithoutVoxels()

G4int G4TessellatedSolid::AllocatedMemoryWithoutVoxels ( )

Definition at line 2224 of file G4TessellatedSolid.cc.

2225{
2226 G4int base = sizeof(*this);
2227 base += fVertexList.capacity() * sizeof(G4ThreeVector);
2228 base += fRandir.capacity() * sizeof(G4ThreeVector);
2229
2230 std::size_t limit = fFacets.size();
2231 for (std::size_t i = 0; i < limit; ++i)
2232 {
2233 G4VFacet& facet = *fFacets[i];
2234 base += facet.AllocatedMemory();
2235 }
2236
2237 for (const auto & fExtremeFacet : fExtremeFacets)
2238 {
2239 G4VFacet &facet = *fExtremeFacet;
2240 base += facet.AllocatedMemory();
2241 }
2242 return base;
2243}
virtual G4int AllocatedMemory()=0

Referenced by AllocatedMemory(), and DisplayAllocatedMemory().

◆ BoundingLimits()

void G4TessellatedSolid::BoundingLimits ( G4ThreeVector & pMin,
G4ThreeVector & pMax ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 1981 of file G4TessellatedSolid.cc.

1983{
1984 pMin = fMinExtent;
1985 pMax = fMaxExtent;
1986
1987 // Check correctness of the bounding box
1988 //
1989 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
1990 {
1991 std::ostringstream message;
1992 message << "Bad bounding box (min >= max) for solid: "
1993 << GetName() << " !"
1994 << "\npMin = " << pMin
1995 << "\npMax = " << pMax;
1996 G4Exception("G4TessellatedSolid::BoundingLimits()",
1997 "GeomMgt0001", JustWarning, message);
1998 DumpInfo();
1999 }
2000}
G4String GetName() const
void DumpInfo() const

Referenced by CalculateExtent().

◆ CalculateExtent()

G4bool G4TessellatedSolid::CalculateExtent ( const EAxis pAxis,
const G4VoxelLimits & pVoxelLimit,
const G4AffineTransform & pTransform,
G4double & pMin,
G4double & pMax ) const
overridevirtual

Implements G4VSolid.

Definition at line 2007 of file G4TessellatedSolid.cc.

2011{
2012 G4ThreeVector bmin, bmax;
2013
2014 // Check bounding box (bbox)
2015 //
2016 BoundingLimits(bmin,bmax);
2017 G4BoundingEnvelope bbox(bmin,bmax);
2018
2019 // Use simple bounding-box to help in the case of complex meshes
2020 //
2021 return bbox.CalculateExtent(pAxis,pVoxelLimit,pTransform,pMin,pMax);
2022
2023#if 0
2024 // Precise extent computation (disabled by default for this shape)
2025 //
2026 if (bbox.BoundingBoxVsVoxelLimits(pAxis,pVoxelLimit,pTransform,pMin,pMax))
2027 {
2028 return (pMin < pMax) ? true : false;
2029 }
2030
2031 // The extent is calculated as cumulative extent of the pyramids
2032 // formed by facets and the center of the bounding box.
2033 //
2034 G4double eminlim = pVoxelLimit.GetMinExtent(pAxis);
2035 G4double emaxlim = pVoxelLimit.GetMaxExtent(pAxis);
2036
2037 G4ThreeVectorList base;
2038 G4ThreeVectorList apex(1);
2039 std::vector<const G4ThreeVectorList *> pyramid(2);
2040 pyramid[0] = &base;
2041 pyramid[1] = &apex;
2042 apex[0] = (bmin+bmax)*0.5;
2043
2044 // main loop along facets
2045 pMin = kInfinity;
2046 pMax = -kInfinity;
2047 for (G4int i=0; i<GetNumberOfFacets(); ++i)
2048 {
2049 G4VFacet* facet = GetFacet(i);
2050 if (std::abs((facet->GetSurfaceNormal()).dot(facet->GetVertex(0)-apex[0]))
2051 < kCarToleranceHalf) continue;
2052
2053 G4int nv = facet->GetNumberOfVertices();
2054 base.resize(nv);
2055 for (G4int k=0; k<nv; ++k) { base[k] = facet->GetVertex(k); }
2056
2057 G4double emin,emax;
2058 G4BoundingEnvelope benv(pyramid);
2059 if (!benv.CalculateExtent(pAxis,pVoxelLimit,pTransform,emin,emax)) continue;
2060 if (emin < pMin) pMin = emin;
2061 if (emax > pMax) pMax = emax;
2062 if (eminlim > pMin && emaxlim < pMax) break; // max possible extent
2063 }
2064 return (pMin < pMax);
2065#endif
2066}
std::vector< G4ThreeVector > G4ThreeVectorList
G4int GetNumberOfFacets() const
G4VFacet * GetFacet(G4int i) const
void BoundingLimits(G4ThreeVector &pMin, G4ThreeVector &pMax) const override
virtual G4ThreeVector GetSurfaceNormal() const =0
virtual G4ThreeVector GetVertex(G4int i) const =0
virtual G4int GetNumberOfVertices() const =0
G4double GetMinExtent(const EAxis pAxis) const
G4double GetMaxExtent(const EAxis pAxis) const

◆ CheckStructure()

G4int G4TessellatedSolid::CheckStructure ( ) const

Definition at line 670 of file G4TessellatedSolid.cc.

671{
672 G4int nedge = 0;
673 std::size_t nface = fFacets.size();
674
675 // Calculate volume
676 //
677 G4double volume = 0.;
678 for (std::size_t i = 0; i < nface; ++i)
679 {
680 G4VFacet& facet = *fFacets[i];
681 nedge += facet.GetNumberOfVertices();
682 volume += facet.GetArea()*(facet.GetVertex(0).dot(facet.GetSurfaceNormal()));
683 }
684 auto ivolume = static_cast<G4int>(volume <= 0.);
685
686 // Create sorted vector of edges
687 //
688 std::vector<int64_t> iedge(nedge);
689 G4int kk = 0;
690 for (std::size_t i = 0; i < nface; ++i)
691 {
692 G4VFacet& facet = *fFacets[i];
693 G4int nnode = facet.GetNumberOfVertices();
694 for (G4int k = 0; k < nnode; ++k)
695 {
696 int64_t i1 = facet.GetVertexIndex((k == 0) ? nnode - 1 : k - 1);
697 int64_t i2 = facet.GetVertexIndex(k);
698 auto inverse = static_cast<int64_t>(i2 > i1);
699 if (inverse != 0) std::swap(i1, i2);
700 iedge[kk++] = i1*1000000000 + i2*2 + inverse;
701 }
702 }
703 std::sort(iedge.begin(), iedge.end());
704
705 // Check edges, correct structure should consist of paired edges
706 // with different orientation
707 //
708 G4int iorder = 0;
709 G4int ihole = 0;
710 G4int i = 0;
711 while (i < nedge - 1)
712 {
713 if (iedge[i + 1] - iedge[i] == 1) // paired edges with different orientation
714 {
715 i += 2;
716 }
717 else if (iedge[i + 1] == iedge[i]) // paired edges with the same orientation
718 {
719 iorder = 2;
720 i += 2;
721 }
722 else // unpaired edge
723 {
724 ihole = 4;
725 i++;
726 }
727 }
728 return ivolume + iorder + ihole;
729}
virtual G4double GetArea() const =0
virtual G4int GetVertexIndex(G4int i) const =0

Referenced by SetSolidClosed().

◆ Clone()

G4VSolid * G4TessellatedSolid::Clone ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 1785 of file G4TessellatedSolid.cc.

1786{
1787 return new G4TessellatedSolid(*this);
1788}

◆ CreatePolyhedron()

G4Polyhedron * G4TessellatedSolid::CreatePolyhedron ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 1930 of file G4TessellatedSolid.cc.

1931{
1932 auto nVertices = (G4int)fVertexList.size();
1933 auto nFacets = (G4int)fFacets.size();
1934 auto polyhedron = new G4Polyhedron(nVertices, nFacets);
1935 for (auto i = 0; i < nVertices; ++i)
1936 {
1937 polyhedron->SetVertex(i+1, fVertexList[i]);
1938 }
1939
1940 for (auto i = 0; i < nFacets; ++i)
1941 {
1942 G4VFacet* facet = fFacets[i];
1943 G4int v[4] = {0};
1944 G4int n = facet->GetNumberOfVertices();
1945 if (n > 4) n = 4;
1946 for (auto j = 0; j < n; ++j)
1947 {
1948 v[j] = facet->GetVertexIndex(j) + 1;
1949 }
1950 polyhedron->SetFacet(i+1, v[0], v[1], v[2], v[3]);
1951 }
1952 polyhedron->SetReferences();
1953
1954 return polyhedron;
1955}

Referenced by GetPolyhedron().

◆ DescribeYourselfTo()

void G4TessellatedSolid::DescribeYourselfTo ( G4VGraphicsScene & scene) const
overridevirtual

Implements G4VSolid.

Definition at line 1923 of file G4TessellatedSolid.cc.

1924{
1925 scene.AddSolid (*this);
1926}
virtual void AddSolid(const G4Box &)=0

◆ DisplayAllocatedMemory()

void G4TessellatedSolid::DisplayAllocatedMemory ( )

Definition at line 580 of file G4TessellatedSolid.cc.

581{
583 G4int with = AllocatedMemory();
584 G4double ratio = (G4double) with / without;
585 G4cout << "G4TessellatedSolid - Allocated memory without voxel overhead "
586 << without << "; with " << with << "; ratio: " << ratio << G4endl;
587}
#define G4endl
Definition G4ios.hh:67

Referenced by SetSolidClosed().

◆ DistanceToIn() [1/2]

G4double G4TessellatedSolid::DistanceToIn ( const G4ThreeVector & p) const
overridevirtual

Implements G4VSolid.

Definition at line 1831 of file G4TessellatedSolid.cc.

1832{
1833 return SafetyFromOutside(p, false);
1834}
virtual G4double SafetyFromOutside(const G4ThreeVector &p, G4bool aAccurate=false) const

◆ DistanceToIn() [2/2]

G4double G4TessellatedSolid::DistanceToIn ( const G4ThreeVector & p,
const G4ThreeVector & v ) const
overridevirtual

Implements G4VSolid.

Definition at line 1838 of file G4TessellatedSolid.cc.

1840{
1841 G4double dist = DistanceToInCore(p,v,kInfinity);
1842#ifdef G4SPECSDEBUG
1843 if (dist < kInfinity)
1844 {
1845 if (Inside(p + dist*v) != kSurface)
1846 {
1847 std::ostringstream message;
1848 message << "Invalid response from facet in solid '" << GetName() << "',"
1849 << G4endl
1850 << "at point: " << p << "and direction: " << v;
1851 G4Exception("G4TessellatedSolid::DistanceToIn(p,v)",
1852 "GeomSolids1002", JustWarning, message);
1853 }
1854 }
1855#endif
1856 return dist;
1857}
EInside Inside(const G4ThreeVector &p) const override
@ kSurface
Definition geomdefs.hh:69

Referenced by G4ExtrudedSolid::DistanceToIn(), G4ExtrudedSolid::DistanceToIn(), and SafetyFromInside().

◆ DistanceToOut() [1/2]

G4double G4TessellatedSolid::DistanceToOut ( const G4ThreeVector & p) const
overridevirtual

Implements G4VSolid.

Definition at line 1866 of file G4TessellatedSolid.cc.

1867{
1868 return SafetyFromInside(p, false);
1869}
virtual G4double SafetyFromInside(const G4ThreeVector &p, G4bool aAccurate=false) const

Referenced by G4ExtrudedSolid::DistanceToOut(), G4ExtrudedSolid::DistanceToOut(), and SafetyFromOutside().

◆ DistanceToOut() [2/2]

G4double G4TessellatedSolid::DistanceToOut ( const G4ThreeVector & p,
const G4ThreeVector & v,
const G4bool calcNorm,
G4bool * validNorm,
G4ThreeVector * norm ) const
overridevirtual

Implements G4VSolid.

Definition at line 1889 of file G4TessellatedSolid.cc.

1894{
1896 G4bool valid;
1897
1898 G4double dist = DistanceToOutCore(p, v, n, valid);
1899 if (calcNorm)
1900 {
1901 *norm = n;
1902 *validNorm = valid;
1903 }
1904#ifdef G4SPECSDEBUG
1905 if (dist < kInfinity)
1906 {
1907 if (Inside(p + dist*v) != kSurface)
1908 {
1909 std::ostringstream message;
1910 message << "Invalid response from facet in solid '" << GetName() << "',"
1911 << G4endl
1912 << "at point: " << p << "and direction: " << v;
1913 G4Exception("G4TessellatedSolid::DistanceToOut(p,v,..)",
1914 "GeomSolids1002", JustWarning, message);
1915 }
1916 }
1917#endif
1918 return dist;
1919}

◆ GetCubicVolume()

G4double G4TessellatedSolid::GetCubicVolume ( )
overridevirtual

Reimplemented from G4VSolid.

Definition at line 2121 of file G4TessellatedSolid.cc.

2122{
2123 if (fCubicVolume != 0.) return fCubicVolume;
2124
2125 // For explanation of the following algorithm see:
2126 // https://en.wikipedia.org/wiki/Polyhedron#Volume
2127 // http://wwwf.imperial.ac.uk/~rn/centroid.pdf
2128
2129 std::size_t size = fFacets.size();
2130 for (std::size_t i = 0; i < size; ++i)
2131 {
2132 G4VFacet &facet = *fFacets[i];
2133 G4double area = facet.GetArea();
2134 G4ThreeVector unit_normal = facet.GetSurfaceNormal();
2135 fCubicVolume += area * (facet.GetVertex(0).dot(unit_normal));
2136 }
2137 fCubicVolume /= 3.;
2138 return fCubicVolume;
2139}

◆ GetEntityType()

G4GeometryType G4TessellatedSolid::GetEntityType ( ) const
overridevirtual

Implements G4VSolid.

Definition at line 1746 of file G4TessellatedSolid.cc.

1747{
1748 return fGeometryType;
1749}

◆ GetExtent()

G4VisExtent G4TessellatedSolid::GetExtent ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 2112 of file G4TessellatedSolid.cc.

2113{
2114 return { fMinExtent.x(), fMaxExtent.x(),
2115 fMinExtent.y(), fMaxExtent.y(),
2116 fMinExtent.z(), fMaxExtent.z() };
2117}

◆ GetFacet()

G4VFacet * G4TessellatedSolid::GetFacet ( G4int i) const
inline

Definition at line 305 of file G4TessellatedSolid.hh.

306{
307 return fFacets[i];
308}

Referenced by CalculateExtent(), operator+=(), and G4GDMLWriteSolids::TessellatedWrite().

◆ GetFacetIndex()

G4int G4TessellatedSolid::GetFacetIndex ( const G4ThreeVector & p) const

Definition at line 1098 of file G4TessellatedSolid.cc.

1099{
1100 G4int index = -1;
1101
1102 if (fVoxels.GetCountOfVoxels() > 1)
1103 {
1104 vector<G4int> curVoxel(3);
1105 fVoxels.GetVoxel(curVoxel, p);
1106 const vector<G4int> &candidates = fVoxels.GetCandidates(curVoxel);
1107 if (auto limit = (G4int)candidates.size())
1108 {
1109 G4double minDist = kInfinity;
1110 for(G4int i = 0 ; i < limit ; ++i)
1111 {
1112 G4int candidate = candidates[i];
1113 G4VFacet& facet = *fFacets[candidate];
1114 G4double dist = facet.Distance(p, minDist);
1115 if (dist <= kCarToleranceHalf) return index = candidate;
1116 if (dist < minDist)
1117 {
1118 minDist = dist;
1119 index = candidate;
1120 }
1121 }
1122 }
1123 }
1124 else
1125 {
1126 G4double minDist = kInfinity;
1127 std::size_t size = fFacets.size();
1128 for (std::size_t i = 0; i < size; ++i)
1129 {
1130 G4VFacet& facet = *fFacets[i];
1131 G4double dist = facet.Distance(p, minDist);
1132 if (dist < minDist)
1133 {
1134 minDist = dist;
1135 index = (G4int)i;
1136 }
1137 }
1138 }
1139 return index;
1140}
virtual G4double Distance(const G4ThreeVector &, G4double)=0

◆ GetMaxXExtent()

G4double G4TessellatedSolid::GetMaxXExtent ( ) const

Definition at line 2077 of file G4TessellatedSolid.cc.

2078{
2079 return fMaxExtent.x();
2080}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMaxYExtent()

G4double G4TessellatedSolid::GetMaxYExtent ( ) const

Definition at line 2091 of file G4TessellatedSolid.cc.

2092{
2093 return fMaxExtent.y();
2094}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMaxZExtent()

G4double G4TessellatedSolid::GetMaxZExtent ( ) const

Definition at line 2105 of file G4TessellatedSolid.cc.

2106{
2107 return fMaxExtent.z();
2108}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMinXExtent()

G4double G4TessellatedSolid::GetMinXExtent ( ) const

Definition at line 2070 of file G4TessellatedSolid.cc.

2071{
2072 return fMinExtent.x();
2073}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMinYExtent()

G4double G4TessellatedSolid::GetMinYExtent ( ) const

Definition at line 2084 of file G4TessellatedSolid.cc.

2085{
2086 return fMinExtent.y();
2087}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMinZExtent()

G4double G4TessellatedSolid::GetMinZExtent ( ) const

Definition at line 2098 of file G4TessellatedSolid.cc.

2099{
2100 return fMinExtent.z();
2101}

Referenced by G4ExtrudedSolid::Inside().

◆ GetNumberOfFacets()

G4int G4TessellatedSolid::GetNumberOfFacets ( ) const

Definition at line 754 of file G4TessellatedSolid.cc.

755{
756 return (G4int)fFacets.size();
757}

Referenced by CalculateExtent(), operator+=(), and G4GDMLWriteSolids::TessellatedWrite().

◆ GetPointOnSurface()

G4ThreeVector G4TessellatedSolid::GetPointOnSurface ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 2158 of file G4TessellatedSolid.cc.

2159{
2160 // Select randomly a facet and return a random point on it
2161
2162 auto i = (G4int) G4RandFlat::shoot(0., fFacets.size());
2163 return fFacets[i]->GetPointOnFace();
2164}

◆ GetPolyhedron()

G4Polyhedron * G4TessellatedSolid::GetPolyhedron ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 1961 of file G4TessellatedSolid.cc.

1962{
1963 if (fpPolyhedron == nullptr ||
1964 fRebuildPolyhedron ||
1965 fpPolyhedron->GetNumberOfRotationStepsAtTimeOfCreation() !=
1966 fpPolyhedron->GetNumberOfRotationSteps())
1967 {
1968 G4AutoLock l(&polyhedronMutex);
1969 delete fpPolyhedron;
1970 fpPolyhedron = CreatePolyhedron();
1971 fRebuildPolyhedron = false;
1972 l.unlock();
1973 }
1974 return fpPolyhedron;
1975}
G4TemplateAutoLock< G4Mutex > G4AutoLock
G4Polyhedron * CreatePolyhedron() const override

◆ GetSolidClosed()

G4bool G4TessellatedSolid::GetSolidClosed ( ) const

Definition at line 655 of file G4TessellatedSolid.cc.

656{
657 return fSolidClosed;
658}

◆ GetSurfaceArea()

G4double G4TessellatedSolid::GetSurfaceArea ( )
overridevirtual

Reimplemented from G4VSolid.

Definition at line 2143 of file G4TessellatedSolid.cc.

2144{
2145 if (fSurfaceArea != 0.) return fSurfaceArea;
2146
2147 std::size_t size = fFacets.size();
2148 for (std::size_t i = 0; i < size; ++i)
2149 {
2150 G4VFacet &facet = *fFacets[i];
2151 fSurfaceArea += facet.GetArea();
2152 }
2153 return fSurfaceArea;
2154}

◆ GetVoxels()

G4Voxelizer & G4TessellatedSolid::GetVoxels ( )
inline

Definition at line 315 of file G4TessellatedSolid.hh.

316{
317 return fVoxels;
318}

◆ Inside()

EInside G4TessellatedSolid::Inside ( const G4ThreeVector & p) const
overridevirtual

Implements G4VSolid.

Definition at line 1800 of file G4TessellatedSolid.cc.

1801{
1802 EInside location;
1803
1804 if (fVoxels.GetCountOfVoxels() > 1)
1805 {
1806 location = InsideVoxels(aPoint);
1807 }
1808 else
1809 {
1810 location = InsideNoVoxels(aPoint);
1811 }
1812 return location;
1813}
EInside
Definition geomdefs.hh:67

Referenced by DistanceToIn(), DistanceToOut(), SafetyFromInside(), and SafetyFromOutside().

◆ IsFaceted()

G4bool G4TessellatedSolid::IsFaceted ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 1755 of file G4TessellatedSolid.cc.

1756{
1757 return true;
1758}

◆ Normal()

G4bool G4TessellatedSolid::Normal ( const G4ThreeVector & p,
G4ThreeVector & n ) const
virtual

Definition at line 1147 of file G4TessellatedSolid.cc.

1149{
1150 G4double minDist;
1151 G4VFacet* facet = nullptr;
1152
1153 if (fVoxels.GetCountOfVoxels() > 1)
1154 {
1155 vector<G4int> curVoxel(3);
1156 fVoxels.GetVoxel(curVoxel, p);
1157 const vector<G4int> &candidates = fVoxels.GetCandidates(curVoxel);
1158 // fVoxels.GetCandidatesVoxelArray(p, candidates, 0);
1159
1160 if (auto limit = (G4int)candidates.size())
1161 {
1162 minDist = kInfinity;
1163 for(G4int i = 0 ; i < limit ; ++i)
1164 {
1165 G4int candidate = candidates[i];
1166 G4VFacet &fct = *fFacets[candidate];
1167 G4double dist = fct.Distance(p,minDist);
1168 if (dist < minDist) minDist = dist;
1169 if (dist <= kCarToleranceHalf)
1170 {
1171 aNormal = fct.GetSurfaceNormal();
1172 return true;
1173 }
1174 }
1175 }
1176 minDist = MinDistanceFacet(p, true, facet);
1177 }
1178 else
1179 {
1180 minDist = kInfinity;
1181 std::size_t size = fFacets.size();
1182 for (std::size_t i = 0; i < size; ++i)
1183 {
1184 G4VFacet& f = *fFacets[i];
1185 G4double dist = f.Distance(p, minDist);
1186 if (dist < minDist)
1187 {
1188 minDist = dist;
1189 facet = &f;
1190 }
1191 }
1192 }
1193
1194 if (minDist != kInfinity)
1195 {
1196 if (facet != nullptr) { aNormal = facet->GetSurfaceNormal(); }
1197 return minDist <= kCarToleranceHalf;
1198 }
1199 else
1200 {
1201#ifdef G4VERBOSE
1202 std::ostringstream message;
1203 message << "Point p is not on surface !?" << G4endl
1204 << " No facets found for point: " << p << " !" << G4endl
1205 << " Returning approximated value for normal.";
1206
1207 G4Exception("G4TessellatedSolid::SurfaceNormal(p)",
1208 "GeomSolids1002", JustWarning, message );
1209#endif
1210 aNormal = (p.z() > 0 ? G4ThreeVector(0,0,1) : G4ThreeVector(0,0,-1));
1211 return false;
1212 }
1213}

Referenced by SurfaceNormal().

◆ operator+=()

G4TessellatedSolid & G4TessellatedSolid::operator+= ( const G4TessellatedSolid & right)

Definition at line 741 of file G4TessellatedSolid.cc.

742{
743 G4int size = right.GetNumberOfFacets();
744 for (G4int i = 0; i < size; ++i)
745 AddFacet(right.GetFacet(i)->GetClone());
746
747 return *this;
748}
G4bool AddFacet(G4VFacet *aFacet)
virtual G4VFacet * GetClone()=0

◆ operator=()

G4TessellatedSolid & G4TessellatedSolid::operator= ( const G4TessellatedSolid & right)

Definition at line 137 of file G4TessellatedSolid.cc.

138{
139 if (&ts == this) return *this;
140
141 // Copy base class data
143
144 DeleteObjects ();
145
146 Initialize();
147
148 CopyObjects (ts);
149
150 return *this;
151}
G4VSolid & operator=(const G4VSolid &rhs)
Definition G4VSolid.cc:107

Referenced by G4ExtrudedSolid::operator=().

◆ SafetyFromInside()

G4double G4TessellatedSolid::SafetyFromInside ( const G4ThreeVector & p,
G4bool aAccurate = false ) const
virtual

Definition at line 1697 of file G4TessellatedSolid.cc.

1698{
1699#if G4SPECSDEBUG
1700 if ( Inside(p) == kOutside )
1701 {
1702 std::ostringstream message;
1703 G4int oldprc = message.precision(16) ;
1704 message << "Point p is already outside!?" << G4endl
1705 << "Position:" << G4endl << G4endl
1706 << "p.x() = " << p.x()/mm << " mm" << G4endl
1707 << "p.y() = " << p.y()/mm << " mm" << G4endl
1708 << "p.z() = " << p.z()/mm << " mm" << G4endl
1709 << "DistanceToIn(p) == " << DistanceToIn(p);
1710 message.precision(oldprc) ;
1711 G4Exception("G4TriangularFacet::DistanceToOut(p)",
1712 "GeomSolids1002", JustWarning, message);
1713 }
1714#endif
1715
1716 G4double minDist;
1717
1718 if (OutsideOfExtent(p, kCarTolerance)) return 0.0;
1719
1720 if (fVoxels.GetCountOfVoxels() > 1)
1721 {
1722 G4VFacet* facet;
1723 minDist = MinDistanceFacet(p, true, facet);
1724 }
1725 else
1726 {
1727 minDist = kInfinity;
1728 G4double dist = 0.0;
1729 std::size_t size = fFacets.size();
1730 for (std::size_t i = 0; i < size; ++i)
1731 {
1732 G4VFacet& facet = *fFacets[i];
1733 dist = facet.Distance(p,minDist);
1734 if (dist < minDist) minDist = dist;
1735 }
1736 }
1737 return minDist;
1738}
G4double DistanceToIn(const G4ThreeVector &p, const G4ThreeVector &v) const override
@ kOutside
Definition geomdefs.hh:68

Referenced by DistanceToOut().

◆ SafetyFromOutside()

G4double G4TessellatedSolid::SafetyFromOutside ( const G4ThreeVector & p,
G4bool aAccurate = false ) const
virtual

Definition at line 1638 of file G4TessellatedSolid.cc.

1640{
1641#if G4SPECSDEBUG
1642 if ( Inside(p) == kInside )
1643 {
1644 std::ostringstream message;
1645 G4int oldprc = message.precision(16) ;
1646 message << "Point p is already inside!?" << G4endl
1647 << "Position:" << G4endl << G4endl
1648 << "p.x() = " << p.x()/mm << " mm" << G4endl
1649 << "p.y() = " << p.y()/mm << " mm" << G4endl
1650 << "p.z() = " << p.z()/mm << " mm" << G4endl
1651 << "DistanceToOut(p) == " << DistanceToOut(p);
1652 message.precision(oldprc) ;
1653 G4Exception("G4TriangularFacet::DistanceToIn(p)",
1654 "GeomSolids1002", JustWarning, message);
1655 }
1656#endif
1657
1658 G4double minDist;
1659
1660 if (fVoxels.GetCountOfVoxels() > 1)
1661 {
1662 if (!aAccurate)
1663 return fVoxels.DistanceToBoundingBox(p);
1664
1665 if (!OutsideOfExtent(p, kCarTolerance))
1666 {
1667 vector<G4int> startingVoxel(3);
1668 fVoxels.GetVoxel(startingVoxel, p);
1669 const vector<G4int> &candidates = fVoxels.GetCandidates(startingVoxel);
1670 if (candidates.empty() && (fInsides.GetNbits() != 0u))
1671 {
1672 G4int index = fVoxels.GetPointIndex(p);
1673 if (fInsides[index]) return 0.;
1674 }
1675 }
1676
1677 G4VFacet* facet;
1678 minDist = MinDistanceFacet(p, true, facet);
1679 }
1680 else
1681 {
1682 minDist = kInfinity;
1683 std::size_t size = fFacets.size();
1684 for (std::size_t i = 0; i < size; ++i)
1685 {
1686 G4VFacet& facet = *fFacets[i];
1687 G4double dist = facet.Distance(p,minDist);
1688 if (dist < minDist) minDist = dist;
1689 }
1690 }
1691 return minDist;
1692}
G4double DistanceToOut(const G4ThreeVector &p) const override
@ kInside
Definition geomdefs.hh:70

Referenced by DistanceToIn().

◆ SetMaxVoxels()

void G4TessellatedSolid::SetMaxVoxels ( G4int max)
inline

Definition at line 310 of file G4TessellatedSolid.hh.

311{
312 fVoxels.SetMaxVoxels(max);
313}

◆ SetSolidClosed()

void G4TessellatedSolid::SetSolidClosed ( const G4bool t)

Definition at line 591 of file G4TessellatedSolid.cc.

592{
593 if (t)
594 {
595#ifdef G4SPECSDEBUG
596 G4cout << "Creating vertex list..." << G4endl;
597#endif
598 CreateVertexList();
599
600#ifdef G4SPECSDEBUG
601 G4cout << "Setting extreme facets..." << G4endl;
602#endif
603 SetExtremeFacets();
604
605#ifdef G4SPECSDEBUG
606 G4cout << "Voxelizing..." << G4endl;
607#endif
608 Voxelize();
609
610#ifdef G4SPECSDEBUG
612#endif
613
614#ifdef G4SPECSDEBUG
615 G4cout << "Checking Structure..." << G4endl;
616#endif
617 G4int irep = CheckStructure();
618 if (irep != 0)
619 {
620 if ((irep & 1) != 0)
621 {
622 std::ostringstream message;
623 message << "Defects in solid: " << GetName()
624 << " - negative cubic volume, please check orientation of facets!";
625 G4Exception("G4TessellatedSolid::SetSolidClosed()",
626 "GeomSolids1001", JustWarning, message);
627 }
628 if ((irep & 2) != 0)
629 {
630 std::ostringstream message;
631 message << "Defects in solid: " << GetName()
632 << " - some facets have wrong orientation!";
633 G4Exception("G4TessellatedSolid::SetSolidClosed()",
634 "GeomSolids1001", JustWarning, message);
635 }
636 if ((irep & 4) != 0)
637 {
638 std::ostringstream message;
639 message << "Defects in solid: " << GetName()
640 << " - there are holes in the surface!";
641 G4Exception("G4TessellatedSolid::SetSolidClosed()",
642 "GeomSolids1001", JustWarning, message);
643 }
644 }
645 }
646 fSolidClosed = t;
647}

Referenced by G4GDMLReadSolids::TessellatedRead().

◆ StreamInfo()

std::ostream & G4TessellatedSolid::StreamInfo ( std::ostream & os) const
overridevirtual

Implements G4VSolid.

Definition at line 1762 of file G4TessellatedSolid.cc.

1763{
1764 os << G4endl;
1765 os << "Solid name = " << GetName() << G4endl;
1766 os << "Geometry Type = " << fGeometryType << G4endl;
1767 os << "Number of facets = " << fFacets.size() << G4endl;
1768
1769 std::size_t size = fFacets.size();
1770 for (std::size_t i = 0; i < size; ++i)
1771 {
1772 os << "FACET # = " << i + 1 << G4endl;
1773 G4VFacet &facet = *fFacets[i];
1774 facet.StreamInfo(os);
1775 }
1776 os << G4endl;
1777
1778 return os;
1779}

◆ SurfaceNormal()

G4ThreeVector G4TessellatedSolid::SurfaceNormal ( const G4ThreeVector & p) const
overridevirtual

Implements G4VSolid.

Definition at line 1817 of file G4TessellatedSolid.cc.

1818{
1820 Normal(p, n);
1821 return n;
1822}
virtual G4bool Normal(const G4ThreeVector &p, G4ThreeVector &n) const

Referenced by G4ExtrudedSolid::SurfaceNormal().

Member Data Documentation

◆ kCarToleranceHalf


The documentation for this class was generated from the following files: