Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
 
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)
 
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().

◆ ~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}
void set(double x, double y, double z)

◆ 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)
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:299

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

◆ AllocatedMemory()

G4int G4TessellatedSolid::AllocatedMemory ( )

Definition at line 2238 of file G4TessellatedSolid.cc.

2239{
2241 G4int sizeInsides = fInsides.GetNbytes();
2242 G4int sizeVoxels = fVoxels.AllocatedMemory();
2243 size += sizeInsides + sizeVoxels;
2244 return size;
2245}
unsigned int GetNbytes() const
Definition G4SurfBits.hh:93
G4int AllocatedMemory()

Referenced by DisplayAllocatedMemory().

◆ AllocatedMemoryWithoutVoxels()

G4int G4TessellatedSolid::AllocatedMemoryWithoutVoxels ( )

Definition at line 2215 of file G4TessellatedSolid.cc.

2216{
2217 G4int base = sizeof(*this);
2218 base += fVertexList.capacity() * sizeof(G4ThreeVector);
2219 base += fRandir.capacity() * sizeof(G4ThreeVector);
2220
2221 std::size_t limit = fFacets.size();
2222 for (std::size_t i = 0; i < limit; ++i)
2223 {
2224 G4VFacet& facet = *fFacets[i];
2225 base += facet.AllocatedMemory();
2226 }
2227
2228 for (const auto & fExtremeFacet : fExtremeFacets)
2229 {
2230 G4VFacet &facet = *fExtremeFacet;
2231 base += facet.AllocatedMemory();
2232 }
2233 return base;
2234}
CLHEP::Hep3Vector G4ThreeVector
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 1972 of file G4TessellatedSolid.cc.

1974{
1975 pMin = fMinExtent;
1976 pMax = fMaxExtent;
1977
1978 // Check correctness of the bounding box
1979 //
1980 if (pMin.x() >= pMax.x() || pMin.y() >= pMax.y() || pMin.z() >= pMax.z())
1981 {
1982 std::ostringstream message;
1983 message << "Bad bounding box (min >= max) for solid: "
1984 << GetName() << " !"
1985 << "\npMin = " << pMin
1986 << "\npMax = " << pMax;
1987 G4Exception("G4TessellatedSolid::BoundingLimits()",
1988 "GeomMgt0001", JustWarning, message);
1989 DumpInfo();
1990 }
1991}
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 1998 of file G4TessellatedSolid.cc.

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

1777{
1778 return new G4TessellatedSolid(*this);
1779}

◆ CreatePolyhedron()

G4Polyhedron * G4TessellatedSolid::CreatePolyhedron ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 1921 of file G4TessellatedSolid.cc.

1922{
1923 auto nVertices = (G4int)fVertexList.size();
1924 auto nFacets = (G4int)fFacets.size();
1925 auto polyhedron = new G4Polyhedron(nVertices, nFacets);
1926 for (auto i = 0; i < nVertices; ++i)
1927 {
1928 polyhedron->SetVertex(i+1, fVertexList[i]);
1929 }
1930
1931 for (auto i = 0; i < nFacets; ++i)
1932 {
1933 G4VFacet* facet = fFacets[i];
1934 G4int v[4] = {0};
1935 G4int n = facet->GetNumberOfVertices();
1936 if (n > 4) n = 4;
1937 for (auto j = 0; j < n; ++j)
1938 {
1939 v[j] = facet->GetVertexIndex(j) + 1;
1940 }
1941 polyhedron->SetFacet(i+1, v[0], v[1], v[2], v[3]);
1942 }
1943 polyhedron->SetReferences();
1944
1945 return polyhedron;
1946}

Referenced by G4GenericTrap::CreatePolyhedron(), and GetPolyhedron().

◆ DescribeYourselfTo()

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

Implements G4VSolid.

Definition at line 1914 of file G4TessellatedSolid.cc.

1915{
1916 scene.AddSolid (*this);
1917}
virtual void AddSolid(const G4Box &)=0

Referenced by G4GenericTrap::DescribeYourselfTo().

◆ 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 1822 of file G4TessellatedSolid.cc.

1823{
1824 return SafetyFromOutside(p, false);
1825}
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 1829 of file G4TessellatedSolid.cc.

1831{
1832 G4double dist = DistanceToInCore(p,v,kInfinity);
1833#ifdef G4SPECSDEBUG
1834 if (dist < kInfinity)
1835 {
1836 if (Inside(p + dist*v) != kSurface)
1837 {
1838 std::ostringstream message;
1839 message << "Invalid response from facet in solid '" << GetName() << "',"
1840 << G4endl
1841 << "at point: " << p << "and direction: " << v;
1842 G4Exception("G4TessellatedSolid::DistanceToIn(p,v)",
1843 "GeomSolids1002", JustWarning, message);
1844 }
1845 }
1846#endif
1847 return dist;
1848}
EInside Inside(const G4ThreeVector &p) const override
@ kSurface
Definition geomdefs.hh:69

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

◆ DistanceToOut() [1/2]

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

Implements G4VSolid.

Definition at line 1857 of file G4TessellatedSolid.cc.

1858{
1859 return SafetyFromInside(p, false);
1860}
virtual G4double SafetyFromInside(const G4ThreeVector &p, G4bool aAccurate=false) const

Referenced by G4ExtrudedSolid::DistanceToOut(), G4ExtrudedSolid::DistanceToOut(), G4GenericTrap::DistanceToOut(), G4GenericTrap::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 1880 of file G4TessellatedSolid.cc.

1885{
1887 G4bool valid;
1888
1889 G4double dist = DistanceToOutCore(p, v, n, valid);
1890 if (calcNorm)
1891 {
1892 *norm = n;
1893 *validNorm = valid;
1894 }
1895#ifdef G4SPECSDEBUG
1896 if (dist < kInfinity)
1897 {
1898 if (Inside(p + dist*v) != kSurface)
1899 {
1900 std::ostringstream message;
1901 message << "Invalid response from facet in solid '" << GetName() << "',"
1902 << G4endl
1903 << "at point: " << p << "and direction: " << v;
1904 G4Exception("G4TessellatedSolid::DistanceToOut(p,v,..)",
1905 "GeomSolids1002", JustWarning, message);
1906 }
1907 }
1908#endif
1909 return dist;
1910}

◆ GetCubicVolume()

G4double G4TessellatedSolid::GetCubicVolume ( )
overridevirtual

Reimplemented from G4VSolid.

Definition at line 2112 of file G4TessellatedSolid.cc.

2113{
2114 if (fCubicVolume != 0.) return fCubicVolume;
2115
2116 // For explanation of the following algorithm see:
2117 // https://en.wikipedia.org/wiki/Polyhedron#Volume
2118 // http://wwwf.imperial.ac.uk/~rn/centroid.pdf
2119
2120 std::size_t size = fFacets.size();
2121 for (std::size_t i = 0; i < size; ++i)
2122 {
2123 G4VFacet &facet = *fFacets[i];
2124 G4double area = facet.GetArea();
2125 G4ThreeVector unit_normal = facet.GetSurfaceNormal();
2126 fCubicVolume += area * (facet.GetVertex(0).dot(unit_normal));
2127 }
2128 fCubicVolume /= 3.;
2129 return fCubicVolume;
2130}

◆ 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 2103 of file G4TessellatedSolid.cc.

2104{
2105 return { fMinExtent.x(), fMaxExtent.x(),
2106 fMinExtent.y(), fMaxExtent.y(),
2107 fMinExtent.z(), fMaxExtent.z() };
2108}

Referenced by G4GenericTrap::GetExtent().

◆ GetFacet()

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

Definition at line 304 of file G4TessellatedSolid.hh.

305{
306 return fFacets[i];
307}

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
long long GetCountOfVoxels() const
void GetVoxel(std::vector< G4int > &curVoxel, const G4ThreeVector &point) const
const std::vector< G4int > & GetCandidates(std::vector< G4int > &curVoxel) const

◆ GetMaxXExtent()

G4double G4TessellatedSolid::GetMaxXExtent ( ) const

Definition at line 2068 of file G4TessellatedSolid.cc.

2069{
2070 return fMaxExtent.x();
2071}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMaxYExtent()

G4double G4TessellatedSolid::GetMaxYExtent ( ) const

Definition at line 2082 of file G4TessellatedSolid.cc.

2083{
2084 return fMaxExtent.y();
2085}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMaxZExtent()

G4double G4TessellatedSolid::GetMaxZExtent ( ) const

Definition at line 2096 of file G4TessellatedSolid.cc.

2097{
2098 return fMaxExtent.z();
2099}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMinXExtent()

G4double G4TessellatedSolid::GetMinXExtent ( ) const

Definition at line 2061 of file G4TessellatedSolid.cc.

2062{
2063 return fMinExtent.x();
2064}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMinYExtent()

G4double G4TessellatedSolid::GetMinYExtent ( ) const

Definition at line 2075 of file G4TessellatedSolid.cc.

2076{
2077 return fMinExtent.y();
2078}

Referenced by G4ExtrudedSolid::Inside().

◆ GetMinZExtent()

G4double G4TessellatedSolid::GetMinZExtent ( ) const

Definition at line 2089 of file G4TessellatedSolid.cc.

2090{
2091 return fMinExtent.z();
2092}

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 2149 of file G4TessellatedSolid.cc.

2150{
2151 // Select randomly a facet and return a random point on it
2152
2153 auto i = (G4int) G4RandFlat::shoot(0., fFacets.size());
2154 return fFacets[i]->GetPointOnFace();
2155}

Referenced by G4GenericTrap::GetPointOnSurface().

◆ GetPolyhedron()

G4Polyhedron * G4TessellatedSolid::GetPolyhedron ( ) const
overridevirtual

Reimplemented from G4VSolid.

Definition at line 1952 of file G4TessellatedSolid.cc.

1953{
1954 if (fpPolyhedron == nullptr ||
1955 fRebuildPolyhedron ||
1957 fpPolyhedron->GetNumberOfRotationSteps())
1958 {
1959 G4AutoLock l(&polyhedronMutex);
1960 delete fpPolyhedron;
1961 fpPolyhedron = CreatePolyhedron();
1962 fRebuildPolyhedron = false;
1963 l.unlock();
1964 }
1965 return fpPolyhedron;
1966}
G4int GetNumberOfRotationStepsAtTimeOfCreation() const
G4Polyhedron * CreatePolyhedron() const override
static G4int GetNumberOfRotationSteps()

Referenced by G4GenericTrap::GetPolyhedron().

◆ 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 2134 of file G4TessellatedSolid.cc.

2135{
2136 if (fSurfaceArea != 0.) return fSurfaceArea;
2137
2138 std::size_t size = fFacets.size();
2139 for (std::size_t i = 0; i < size; ++i)
2140 {
2141 G4VFacet &facet = *fFacets[i];
2142 fSurfaceArea += facet.GetArea();
2143 }
2144 return fSurfaceArea;
2145}

◆ GetVoxels()

G4Voxelizer & G4TessellatedSolid::GetVoxels ( )
inline

Definition at line 314 of file G4TessellatedSolid.hh.

315{
316 return fVoxels;
317}

◆ Inside()

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

Implements G4VSolid.

Definition at line 1791 of file G4TessellatedSolid.cc.

1792{
1793 EInside location;
1794
1795 if (fVoxels.GetCountOfVoxels() > 1)
1796 {
1797 location = InsideVoxels(aPoint);
1798 }
1799 else
1800 {
1801 location = InsideNoVoxels(aPoint);
1802 }
1803 return location;
1804}
EInside
Definition geomdefs.hh:67

Referenced by DistanceToIn(), DistanceToOut(), G4GenericTrap::Inside(), SafetyFromInside(), and SafetyFromOutside().

◆ 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}
unsigned int GetNbits() const
Definition G4SurfBits.hh:92
G4double DistanceToOut(const G4ThreeVector &p) const override
G4double DistanceToBoundingBox(const G4ThreeVector &point) const
G4int GetPointIndex(const G4ThreeVector &p) const
@ kInside
Definition geomdefs.hh:70

Referenced by DistanceToIn().

◆ SetMaxVoxels()

void G4TessellatedSolid::SetMaxVoxels ( G4int max)
inline

Definition at line 309 of file G4TessellatedSolid.hh.

310{
311 fVoxels.SetMaxVoxels(max);
312}
void SetMaxVoxels(G4int max)

◆ 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 1753 of file G4TessellatedSolid.cc.

1754{
1755 os << G4endl;
1756 os << "Solid name = " << GetName() << G4endl;
1757 os << "Geometry Type = " << fGeometryType << G4endl;
1758 os << "Number of facets = " << fFacets.size() << G4endl;
1759
1760 std::size_t size = fFacets.size();
1761 for (std::size_t i = 0; i < size; ++i)
1762 {
1763 os << "FACET # = " << i + 1 << G4endl;
1764 G4VFacet &facet = *fFacets[i];
1765 facet.StreamInfo(os);
1766 }
1767 os << G4endl;
1768
1769 return os;
1770}

◆ SurfaceNormal()

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

Implements G4VSolid.

Definition at line 1808 of file G4TessellatedSolid.cc.

1809{
1811 Normal(p, n);
1812 return n;
1813}
virtual G4bool Normal(const G4ThreeVector &p, G4ThreeVector &n) const

Referenced by G4ExtrudedSolid::SurfaceNormal(), and G4GenericTrap::SurfaceNormal().

Member Data Documentation

◆ kCarToleranceHalf


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