File indexing completed on 2025-01-18 09:59:09
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 std::ostream& StreamInfo(std::ostream& os) const override;
0171
0172 G4VSolid* Clone() const override;
0173
0174 G4ThreeVector GetPointOnSurface() const override;
0175 G4double GetSurfaceArea() override;
0176 G4double GetCubicVolume() override;
0177
0178 void SetSolidClosed (const G4bool t);
0179 G4bool GetSolidClosed () const;
0180 G4int CheckStructure() const;
0181
0182 inline void SetMaxVoxels(G4int max);
0183
0184 inline G4Voxelizer& GetVoxels();
0185
0186 G4bool CalculateExtent(const EAxis pAxis,
0187 const G4VoxelLimits& pVoxelLimit,
0188 const G4AffineTransform& pTransform,
0189 G4double& pMin, G4double& pMax) const override;
0190
0191 void BoundingLimits(G4ThreeVector& pMin, G4ThreeVector& pMax) const override;
0192
0193 G4double GetMinXExtent () const;
0194 G4double GetMaxXExtent () const;
0195 G4double GetMinYExtent () const;
0196 G4double GetMaxYExtent () const;
0197 G4double GetMinZExtent () const;
0198 G4double GetMaxZExtent () const;
0199
0200 G4Polyhedron* CreatePolyhedron () const override;
0201 G4Polyhedron* GetPolyhedron () const override;
0202 void DescribeYourselfTo (G4VGraphicsScene& scene) const override;
0203 G4VisExtent GetExtent () const override;
0204
0205 G4int AllocatedMemoryWithoutVoxels();
0206 G4int AllocatedMemory();
0207 void DisplayAllocatedMemory();
0208
0209 private:
0210
0211 void Initialize();
0212
0213 G4double DistanceToOutNoVoxels(const G4ThreeVector& p,
0214 const G4ThreeVector& v,
0215 G4ThreeVector& aNormalVector,
0216 G4bool& aConvex,
0217 G4double aPstep = kInfinity) const;
0218 G4double DistanceToInCandidates(const std::vector<G4int>& candidates,
0219 const G4ThreeVector& aPoint,
0220 const G4ThreeVector& aDirection) const;
0221 void DistanceToOutCandidates(const std::vector<G4int>& candidates,
0222 const G4ThreeVector& aPoint,
0223 const G4ThreeVector& direction,
0224 G4double& minDist,
0225 G4ThreeVector& minNormal,
0226 G4int& minCandidate) const;
0227 G4double DistanceToInNoVoxels(const G4ThreeVector& p,
0228 const G4ThreeVector& v,
0229 G4double aPstep = kInfinity) const;
0230 void SetExtremeFacets();
0231
0232 EInside InsideNoVoxels (const G4ThreeVector& p) const;
0233 EInside InsideVoxels(const G4ThreeVector& aPoint) const;
0234
0235 void Voxelize();
0236
0237 void CreateVertexList();
0238
0239 void PrecalculateInsides();
0240
0241 void SetRandomVectors();
0242
0243 G4double DistanceToInCore(const G4ThreeVector &p, const G4ThreeVector& v,
0244 G4double aPstep = kInfinity) const;
0245 G4double DistanceToOutCore(const G4ThreeVector& p, const G4ThreeVector& v,
0246 G4ThreeVector& aNormalVector,
0247 G4bool& aConvex,
0248 G4double aPstep = kInfinity) const;
0249
0250 G4int SetAllUsingStack(const std::vector<G4int>& voxel,
0251 const std::vector<G4int>& max,
0252 G4bool status, G4SurfBits& checked);
0253
0254 void DeleteObjects ();
0255 void CopyObjects (const G4TessellatedSolid& s);
0256
0257 static G4bool CompareSortedVoxel(const std::pair<G4int, G4double>& l,
0258 const std::pair<G4int, G4double>& r);
0259
0260 G4double MinDistanceFacet(const G4ThreeVector& p, G4bool simple,
0261 G4VFacet* &facet) const;
0262
0263 inline G4bool OutsideOfExtent(const G4ThreeVector& p,
0264 G4double tolerance = 0.0) const;
0265
0266 protected:
0267
0268 G4double kCarToleranceHalf;
0269
0270 private:
0271
0272 mutable G4bool fRebuildPolyhedron = false;
0273 mutable G4Polyhedron* fpPolyhedron = nullptr;
0274
0275 std::vector<G4VFacet*> fFacets;
0276 std::set<G4VFacet*> fExtremeFacets;
0277
0278
0279 G4GeometryType fGeometryType;
0280 G4double fCubicVolume = 0.0;
0281 G4double fSurfaceArea = 0.0;
0282
0283 std::vector<G4ThreeVector> fVertexList;
0284
0285 std::set<G4VertexInfo,G4VertexComparator> fFacetList;
0286
0287 G4ThreeVector fMinExtent, fMaxExtent;
0288
0289 G4bool fSolidClosed = false;
0290
0291 std::vector<G4ThreeVector> fRandir;
0292
0293 G4int fMaxTries;
0294
0295 G4Voxelizer fVoxels;
0296
0297 G4SurfBits fInsides;
0298 };
0299
0300
0301
0302
0303
0304 inline G4VFacet *G4TessellatedSolid::GetFacet (G4int i) const
0305 {
0306 return fFacets[i];
0307 }
0308
0309 inline void G4TessellatedSolid::SetMaxVoxels(G4int max)
0310 {
0311 fVoxels.SetMaxVoxels(max);
0312 }
0313
0314 inline G4Voxelizer &G4TessellatedSolid::GetVoxels()
0315 {
0316 return fVoxels;
0317 }
0318
0319 inline G4bool G4TessellatedSolid::OutsideOfExtent(const G4ThreeVector& p,
0320 G4double tolerance) const
0321 {
0322 return ( p.x() < fMinExtent.x() - tolerance
0323 || p.x() > fMaxExtent.x() + tolerance
0324 || p.y() < fMinExtent.y() - tolerance
0325 || p.y() > fMaxExtent.y() + tolerance
0326 || p.z() < fMinExtent.z() - tolerance
0327 || p.z() > fMaxExtent.z() + tolerance);
0328 }
0329
0330 #endif
0331
0332 #endif