File indexing completed on 2025-09-18 09:15:45
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 #ifndef G4TESSELLATEDSOLID_HH
0089 #define G4TESSELLATEDSOLID_HH 1
0090
0091 #include "G4GeomTypes.hh"
0092
0093 #if defined(G4GEOM_USE_USOLIDS)
0094 #define G4GEOM_USE_UTESSELLATEDSOLID 1
0095 #endif
0096
0097 #if defined(G4GEOM_USE_UTESSELLATEDSOLID)
0098 #define G4UTessellatedSolid G4TessellatedSolid
0099 #include "G4UTessellatedSolid.hh"
0100 #else
0101
0102 #include <iostream>
0103 #include <vector>
0104 #include <set>
0105 #include <map>
0106
0107 #include "G4Types.hh"
0108 #include "G4VSolid.hh"
0109 #include "G4Voxelizer.hh"
0110 #include "G4VFacet.hh"
0111
0112 struct G4VertexInfo
0113 {
0114 G4int id;
0115 G4double mag2;
0116 };
0117
0118 class G4VertexComparator
0119 {
0120 public:
0121 G4bool operator() (const G4VertexInfo& l, const G4VertexInfo& r) const
0122 {
0123 return l.mag2 == r.mag2 ? l.id < r.id : l.mag2 < r.mag2;
0124 }
0125 };
0126
0127 class G4TessellatedSolid : public G4VSolid
0128 {
0129 public:
0130
0131 G4TessellatedSolid ();
0132 ~G4TessellatedSolid () override;
0133
0134 G4TessellatedSolid (const G4String& name);
0135
0136 G4TessellatedSolid(__void__&);
0137
0138
0139
0140
0141 G4TessellatedSolid (const G4TessellatedSolid& ts);
0142 G4TessellatedSolid &operator= (const G4TessellatedSolid& right);
0143 G4TessellatedSolid &operator+= (const G4TessellatedSolid& right);
0144
0145 G4bool AddFacet (G4VFacet* aFacet);
0146 inline G4VFacet* GetFacet (G4int i) const;
0147
0148 G4int GetNumberOfFacets () const;
0149 G4int GetFacetIndex (const G4ThreeVector& p) const;
0150
0151 EInside Inside (const G4ThreeVector& p) const override;
0152 G4ThreeVector SurfaceNormal(const G4ThreeVector& p) const override;
0153 G4double DistanceToIn(const G4ThreeVector& p,
0154 const G4ThreeVector& v)const override;
0155 G4double DistanceToIn(const G4ThreeVector& p) const override;
0156 G4double DistanceToOut(const G4ThreeVector& p) const override;
0157 G4double DistanceToOut(const G4ThreeVector& p,
0158 const G4ThreeVector& v,
0159 const G4bool calcNorm,
0160 G4bool* validNorm,
0161 G4ThreeVector* norm) const override;
0162
0163 virtual G4bool Normal (const G4ThreeVector& p, G4ThreeVector& n) const;
0164 virtual G4double SafetyFromOutside(const G4ThreeVector& p,
0165 G4bool aAccurate = false) const;
0166 virtual G4double SafetyFromInside (const G4ThreeVector& p,
0167 G4bool aAccurate = false) const;
0168
0169 G4GeometryType GetEntityType () const override;
0170 G4bool IsFaceted () const override;
0171 std::ostream& StreamInfo(std::ostream& os) const override;
0172
0173 G4VSolid* Clone() const override;
0174
0175 G4ThreeVector GetPointOnSurface() const override;
0176 G4double GetSurfaceArea() override;
0177 G4double GetCubicVolume() override;
0178
0179 void SetSolidClosed (const G4bool t);
0180 G4bool GetSolidClosed () const;
0181 G4int CheckStructure() const;
0182
0183 inline void SetMaxVoxels(G4int max);
0184
0185 inline G4Voxelizer& GetVoxels();
0186
0187 G4bool CalculateExtent(const EAxis pAxis,
0188 const G4VoxelLimits& pVoxelLimit,
0189 const G4AffineTransform& pTransform,
0190 G4double& pMin, G4double& pMax) const override;
0191
0192 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0193
0194 G4double GetMinXExtent () const;
0195 G4double GetMaxXExtent () const;
0196 G4double GetMinYExtent () const;
0197 G4double GetMaxYExtent () const;
0198 G4double GetMinZExtent () const;
0199 G4double GetMaxZExtent () const;
0200
0201 G4Polyhedron* CreatePolyhedron () const override;
0202 G4Polyhedron* GetPolyhedron () const override;
0203 void DescribeYourselfTo (G4VGraphicsScene& scene) const override;
0204 G4VisExtent GetExtent () const override;
0205
0206 G4int AllocatedMemoryWithoutVoxels();
0207 G4int AllocatedMemory();
0208 void DisplayAllocatedMemory();
0209
0210 private:
0211
0212 void Initialize();
0213
0214 G4double DistanceToOutNoVoxels(const G4ThreeVector& p,
0215 const G4ThreeVector& v,
0216 G4ThreeVector& aNormalVector,
0217 G4bool& aConvex,
0218 G4double aPstep = kInfinity) const;
0219 G4double DistanceToInCandidates(const std::vector<G4int>& candidates,
0220 const G4ThreeVector& aPoint,
0221 const G4ThreeVector& aDirection) const;
0222 void DistanceToOutCandidates(const std::vector<G4int>& candidates,
0223 const G4ThreeVector& aPoint,
0224 const G4ThreeVector& direction,
0225 G4double& minDist,
0226 G4ThreeVector& minNormal,
0227 G4int& minCandidate) const;
0228 G4double DistanceToInNoVoxels(const G4ThreeVector& p,
0229 const G4ThreeVector& v,
0230 G4double aPstep = kInfinity) const;
0231 void SetExtremeFacets();
0232
0233 EInside InsideNoVoxels (const G4ThreeVector& p) const;
0234 EInside InsideVoxels(const G4ThreeVector& aPoint) const;
0235
0236 void Voxelize();
0237
0238 void CreateVertexList();
0239
0240 void PrecalculateInsides();
0241
0242 void SetRandomVectors();
0243
0244 G4double DistanceToInCore(const G4ThreeVector &p, const G4ThreeVector& v,
0245 G4double aPstep = kInfinity) const;
0246 G4double DistanceToOutCore(const G4ThreeVector& p, const G4ThreeVector& v,
0247 G4ThreeVector& aNormalVector,
0248 G4bool& aConvex,
0249 G4double aPstep = kInfinity) const;
0250
0251 G4int SetAllUsingStack(const std::vector<G4int>& voxel,
0252 const std::vector<G4int>& max,
0253 G4bool status, G4SurfBits& checked);
0254
0255 void DeleteObjects ();
0256 void CopyObjects (const G4TessellatedSolid& s);
0257
0258 static G4bool CompareSortedVoxel(const std::pair<G4int, G4double>& l,
0259 const std::pair<G4int, G4double>& r);
0260
0261 G4double MinDistanceFacet(const G4ThreeVector& p, G4bool simple,
0262 G4VFacet* &facet) const;
0263
0264 inline G4bool OutsideOfExtent(const G4ThreeVector& p,
0265 G4double tolerance = 0.0) const;
0266
0267 protected:
0268
0269 G4double kCarToleranceHalf;
0270
0271 private:
0272
0273 mutable G4bool fRebuildPolyhedron = false;
0274 mutable G4Polyhedron* fpPolyhedron = nullptr;
0275
0276 std::vector<G4VFacet*> fFacets;
0277 std::set<G4VFacet*> fExtremeFacets;
0278
0279
0280 G4GeometryType fGeometryType;
0281 G4double fCubicVolume = 0.0;
0282 G4double fSurfaceArea = 0.0;
0283
0284 std::vector<G4ThreeVector> fVertexList;
0285
0286 std::set<G4VertexInfo,G4VertexComparator> fFacetList;
0287
0288 G4ThreeVector fMinExtent, fMaxExtent;
0289
0290 G4bool fSolidClosed = false;
0291
0292 std::vector<G4ThreeVector> fRandir;
0293
0294 G4int fMaxTries;
0295
0296 G4Voxelizer fVoxels;
0297
0298 G4SurfBits fInsides;
0299 };
0300
0301
0302
0303
0304
0305 inline G4VFacet *G4TessellatedSolid::GetFacet (G4int i) const
0306 {
0307 return fFacets[i];
0308 }
0309
0310 inline void G4TessellatedSolid::SetMaxVoxels(G4int max)
0311 {
0312 fVoxels.SetMaxVoxels(max);
0313 }
0314
0315 inline G4Voxelizer &G4TessellatedSolid::GetVoxels()
0316 {
0317 return fVoxels;
0318 }
0319
0320 inline G4bool G4TessellatedSolid::OutsideOfExtent(const G4ThreeVector& p,
0321 G4double tolerance) const
0322 {
0323 return ( p.x() < fMinExtent.x() - tolerance
0324 || p.x() > fMaxExtent.x() + tolerance
0325 || p.y() < fMinExtent.y() - tolerance
0326 || p.y() > fMaxExtent.y() + tolerance
0327 || p.z() < fMinExtent.z() - tolerance
0328 || p.z() > fMaxExtent.z() + tolerance);
0329 }
0330
0331 #endif
0332
0333 #endif