Geant4 11.1.1
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 ()
 
virtual ~G4TessellatedSolid ()
 
 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
 
virtual EInside Inside (const G4ThreeVector &p) const
 
virtual G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const
 
virtual G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const
 
virtual G4double DistanceToIn (const G4ThreeVector &p) const
 
virtual G4double DistanceToOut (const G4ThreeVector &p) const
 
virtual G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm, G4bool *validNorm, G4ThreeVector *norm) const
 
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
 
virtual G4GeometryType GetEntityType () const
 
virtual std::ostream & StreamInfo (std::ostream &os) const
 
virtual G4VSolidClone () const
 
virtual G4ThreeVector GetPointOnSurface () const
 
virtual G4double GetSurfaceArea ()
 
virtual G4double GetCubicVolume ()
 
void SetSolidClosed (const G4bool t)
 
G4bool GetSolidClosed () const
 
G4int CheckStructure () const
 
void SetMaxVoxels (G4int max)
 
G4VoxelizerGetVoxels ()
 
virtual G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const
 
void BoundingLimits (G4ThreeVector &pMin, G4ThreeVector &pMax) const
 
G4double GetMinXExtent () const
 
G4double GetMaxXExtent () const
 
G4double GetMinYExtent () const
 
G4double GetMaxYExtent () const
 
G4double GetMinZExtent () const
 
G4double GetMaxZExtent () const
 
virtual G4PolyhedronCreatePolyhedron () const
 
virtual G4PolyhedronGetPolyhedron () const
 
virtual void DescribeYourselfTo (G4VGraphicsScene &scene) const
 
virtual G4VisExtent GetExtent () const
 
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 BoundingLimits (G4ThreeVector &pMin, G4ThreeVector &pMax) const
 
virtual G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const =0
 
virtual EInside Inside (const G4ThreeVector &p) const =0
 
virtual G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const =0
 
virtual G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const =0
 
virtual G4double DistanceToIn (const G4ThreeVector &p) const =0
 
virtual G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const =0
 
virtual G4double DistanceToOut (const G4ThreeVector &p) const =0
 
virtual void ComputeDimensions (G4VPVParameterisation *p, const G4int n, const G4VPhysicalVolume *pRep)
 
virtual G4double GetCubicVolume ()
 
virtual G4double GetSurfaceArea ()
 
virtual G4GeometryType GetEntityType () const =0
 
virtual G4ThreeVector GetPointOnSurface () const
 
virtual G4VSolidClone () const
 
virtual std::ostream & StreamInfo (std::ostream &os) const =0
 
void DumpInfo () const
 
virtual void DescribeYourselfTo (G4VGraphicsScene &scene) const =0
 
virtual G4VisExtent GetExtent () const
 
virtual G4PolyhedronCreatePolyhedron () const
 
virtual G4PolyhedronGetPolyhedron () 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 86 of file G4TessellatedSolid.cc.

86 : G4VSolid("dummy")
87{
88 Initialize();
89}

Referenced by Clone().

◆ ~G4TessellatedSolid()

G4TessellatedSolid::~G4TessellatedSolid ( )
virtual

Definition at line 116 of file G4TessellatedSolid.cc.

117{
118 DeleteObjects();
119}

◆ G4TessellatedSolid() [2/4]

G4TessellatedSolid::G4TessellatedSolid ( const G4String name)

Definition at line 96 of file G4TessellatedSolid.cc.

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

◆ G4TessellatedSolid() [3/4]

G4TessellatedSolid::G4TessellatedSolid ( __void__ &  a)

Definition at line 107 of file G4TessellatedSolid.cc.

107 : G4VSolid(a)
108{
109 Initialize();
110 fMinExtent.set(0,0,0);
111 fMaxExtent.set(0,0,0);
112}
void set(double x, double y, double z)

◆ G4TessellatedSolid() [4/4]

G4TessellatedSolid::G4TessellatedSolid ( const G4TessellatedSolid ts)

Definition at line 125 of file G4TessellatedSolid.cc.

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

Member Function Documentation

◆ AddFacet()

G4bool G4TessellatedSolid::AddFacet ( G4VFacet aFacet)

Definition at line 207 of file G4TessellatedSolid.cc.

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

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

Referenced by DisplayAllocatedMemory().

◆ AllocatedMemoryWithoutVoxels()

G4int G4TessellatedSolid::AllocatedMemoryWithoutVoxels ( )

Definition at line 2216 of file G4TessellatedSolid.cc.

2217{
2218 G4int base = sizeof(*this);
2219 base += fVertexList.capacity() * sizeof(G4ThreeVector);
2220 base += fRandir.capacity() * sizeof(G4ThreeVector);
2221
2222 std::size_t limit = fFacets.size();
2223 for (std::size_t i = 0; i < limit; ++i)
2224 {
2225 G4VFacet& facet = *fFacets[i];
2226 base += facet.AllocatedMemory();
2227 }
2228
2229 for (auto it = fExtremeFacets.cbegin(); it != fExtremeFacets.cend(); ++it)
2230 {
2231 G4VFacet &facet = *(*it);
2232 base += facet.AllocatedMemory();
2233 }
2234 return base;
2235}
CLHEP::Hep3Vector G4ThreeVector
virtual G4int AllocatedMemory()=0

Referenced by AllocatedMemory(), and DisplayAllocatedMemory().

◆ BoundingLimits()

void G4TessellatedSolid::BoundingLimits ( G4ThreeVector pMin,
G4ThreeVector pMax 
) const
virtual

Reimplemented from G4VSolid.

Definition at line 1973 of file G4TessellatedSolid.cc.

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

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1999 of file G4TessellatedSolid.cc.

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

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

Referenced by SetSolidClosed().

◆ Clone()

G4VSolid * G4TessellatedSolid::Clone ( ) const
virtual

Reimplemented from G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1777 of file G4TessellatedSolid.cc.

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

◆ CreatePolyhedron()

G4Polyhedron * G4TessellatedSolid::CreatePolyhedron ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1922 of file G4TessellatedSolid.cc.

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

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

◆ DescribeYourselfTo()

void G4TessellatedSolid::DescribeYourselfTo ( G4VGraphicsScene scene) const
virtual

Implements G4VSolid.

Definition at line 1915 of file G4TessellatedSolid.cc.

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

Referenced by G4GenericTrap::DescribeYourselfTo().

◆ DisplayAllocatedMemory()

void G4TessellatedSolid::DisplayAllocatedMemory ( )

Definition at line 581 of file G4TessellatedSolid.cc.

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

Referenced by SetSolidClosed().

◆ DistanceToIn() [1/2]

G4double G4TessellatedSolid::DistanceToIn ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1823 of file G4TessellatedSolid.cc.

1824{
1825 return SafetyFromOutside(p, false);
1826}
virtual G4double SafetyFromOutside(const G4ThreeVector &p, G4bool aAccurate=false) const

◆ DistanceToIn() [2/2]

G4double G4TessellatedSolid::DistanceToIn ( const G4ThreeVector p,
const G4ThreeVector v 
) const
virtual

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1830 of file G4TessellatedSolid.cc.

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

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

◆ DistanceToOut() [1/2]

G4double G4TessellatedSolid::DistanceToOut ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1858 of file G4TessellatedSolid.cc.

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

Referenced by G4ExtrudedSolid::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
virtual

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1881 of file G4TessellatedSolid.cc.

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

◆ GetCubicVolume()

G4double G4TessellatedSolid::GetCubicVolume ( )
virtual

Reimplemented from G4VSolid.

Definition at line 2113 of file G4TessellatedSolid.cc.

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

◆ GetEntityType()

G4GeometryType G4TessellatedSolid::GetEntityType ( ) const
virtual

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1747 of file G4TessellatedSolid.cc.

1748{
1749 return fGeometryType;
1750}

◆ GetExtent()

G4VisExtent G4TessellatedSolid::GetExtent ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 2104 of file G4TessellatedSolid.cc.

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

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

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

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

Referenced by G4ExtrudedSolid::Inside().

◆ GetMaxYExtent()

G4double G4TessellatedSolid::GetMaxYExtent ( ) const

Definition at line 2083 of file G4TessellatedSolid.cc.

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

Referenced by G4ExtrudedSolid::Inside().

◆ GetMaxZExtent()

G4double G4TessellatedSolid::GetMaxZExtent ( ) const

Definition at line 2097 of file G4TessellatedSolid.cc.

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

Referenced by G4ExtrudedSolid::Inside().

◆ GetMinXExtent()

G4double G4TessellatedSolid::GetMinXExtent ( ) const

Definition at line 2062 of file G4TessellatedSolid.cc.

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

Referenced by G4ExtrudedSolid::Inside().

◆ GetMinYExtent()

G4double G4TessellatedSolid::GetMinYExtent ( ) const

Definition at line 2076 of file G4TessellatedSolid.cc.

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

Referenced by G4ExtrudedSolid::Inside().

◆ GetMinZExtent()

G4double G4TessellatedSolid::GetMinZExtent ( ) const

Definition at line 2090 of file G4TessellatedSolid.cc.

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

Referenced by G4ExtrudedSolid::Inside().

◆ GetNumberOfFacets()

G4int G4TessellatedSolid::GetNumberOfFacets ( ) const

Definition at line 755 of file G4TessellatedSolid.cc.

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

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

◆ GetPointOnSurface()

G4ThreeVector G4TessellatedSolid::GetPointOnSurface ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 2150 of file G4TessellatedSolid.cc.

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

Referenced by G4GenericTrap::GetPointOnSurface().

◆ GetPolyhedron()

G4Polyhedron * G4TessellatedSolid::GetPolyhedron ( ) const
virtual

Reimplemented from G4VSolid.

Definition at line 1953 of file G4TessellatedSolid.cc.

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

Referenced by G4GenericTrap::GetPolyhedron().

◆ GetSolidClosed()

G4bool G4TessellatedSolid::GetSolidClosed ( ) const

Definition at line 656 of file G4TessellatedSolid.cc.

657{
658 return fSolidClosed;
659}

◆ GetSurfaceArea()

G4double G4TessellatedSolid::GetSurfaceArea ( )
virtual

Reimplemented from G4VSolid.

Definition at line 2135 of file G4TessellatedSolid.cc.

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

◆ 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
virtual

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1792 of file G4TessellatedSolid.cc.

1793{
1794 EInside location;
1795
1796 if (fVoxels.GetCountOfVoxels() > 1)
1797 {
1798 location = InsideVoxels(aPoint);
1799 }
1800 else
1801 {
1802 location = InsideNoVoxels(aPoint);
1803 }
1804 return location;
1805}
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 1148 of file G4TessellatedSolid.cc.

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

Referenced by SurfaceNormal().

◆ operator+=()

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

Definition at line 742 of file G4TessellatedSolid.cc.

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

◆ operator=()

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

Definition at line 138 of file G4TessellatedSolid.cc.

139{
140 if (&ts == this) return *this;
141
142 // Copy base class data
144
145 DeleteObjects ();
146
147 Initialize();
148
149 CopyObjects (ts);
150
151 return *this;
152}
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 1698 of file G4TessellatedSolid.cc.

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

Referenced by DistanceToOut().

◆ SafetyFromOutside()

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

Definition at line 1639 of file G4TessellatedSolid.cc.

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

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

Referenced by G4GDMLReadSolids::TessellatedRead().

◆ StreamInfo()

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

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1754 of file G4TessellatedSolid.cc.

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

◆ SurfaceNormal()

G4ThreeVector G4TessellatedSolid::SurfaceNormal ( const G4ThreeVector p) const
virtual

Implements G4VSolid.

Reimplemented in G4ExtrudedSolid.

Definition at line 1809 of file G4TessellatedSolid.cc.

1810{
1812 Normal(p, n);
1813 return n;
1814}
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: