59 static G4double
Infinity() { return ::kInfinity; }
77 std::uint64_t
generation{std::numeric_limits<std::uint64_t>::max()};
87 std::uint64_t
generation{std::numeric_limits<std::uint64_t>::max()};
103 std::uint64_t
generation{std::numeric_limits<std::uint64_t>::max()};
146 void SetShape(
const TopoDS_Shape& shape);
149 const TopoDS_Shape&
Shape()
const {
return fShape; }
152 std::uint64_t
ShapeGeneration()
const {
return fShapeGeneration.load(std::memory_order_acquire); }
159 IntersectorCache& intersectorCache,
160 SphereCacheData& sphereCache)
const;
166 G4double
DistanceToIn(
const G4ThreeVector& p,
const G4ThreeVector& v,
167 IntersectorCache& intersectorCache)
const;
170 G4double
DistanceToIn(
const G4ThreeVector& p, ClassifierCache& classifierCache)
const;
173 G4double
DistanceToOut(
const G4ThreeVector& p,
const G4ThreeVector& v,
174 IntersectorCache& intersectorCache,
const G4bool calcNorm =
false,
175 G4bool* validNorm =
nullptr, G4ThreeVector* n =
nullptr)
const;
178 G4double
DistanceToOut(
const G4ThreeVector& p, SphereCacheData& sphereCache)
const;
181 G4double
ExactDistanceToIn(
const G4ThreeVector& p, ClassifierCache& classifierCache)
const;
208 BRepAdaptor_Surface adaptor;
209 std::optional<gp_Pln> plane;
210 std::vector<gp_Pnt2d> uvPolygon;
211 std::optional<G4ThreeVector> outwardNormal;
215 struct ClosestFaceMatch {
218 std::size_t faceIndex{0};
219 std::optional<std::pair<Standard_Real, Standard_Real>> uv;
223 BRepClass3d_SolidClassifier& GetOrCreateClassifier(ClassifierCache& cache)
const;
226 IntersectorCache& GetOrCreateIntersector(IntersectorCache& cache)
const;
229 SphereCacheData& GetOrInitSphereCache(SphereCacheData& cache)
const;
232 void TryInsertSphere(SphereCacheData& cache,
const G4ThreeVector& centre, G4double d)
const;
235 void ComputeBounds();
238 void ComputeInitialSpheres();
241 G4double AABBLowerBound(
const G4ThreeVector& p)
const;
244 G4double BVHLowerBoundDistance(
const G4ThreeVector& p)
const;
247 G4double PlanarFaceLowerBoundDistance(
const G4ThreeVector& p)
const;
250 static std::optional<ClosestFaceMatch>
251 TryFindClosestFace(
const std::vector<FaceBounds>& faceBoundsCache,
const G4ThreeVector& point,
257 AxisAlignedBounds fCachedBounds;
259 std::vector<FaceBounds> fFaceBoundsCache;
261 std::vector<InscribedSphere> fInitialSpheres;
263 Handle(BRepExtrema_TriangleSet) fTriangleSet;
265 G4double fBVHDeflection{0.0};
267 std::vector<G4double> fFaceDeflections;
269 bool fAllFacesPlanar{
false};
271 std::atomic<std::uint64_t> fShapeGeneration{0};
273 mutable std::optional<G4double> fCachedVolume;
275 mutable std::optional<G4double> fCachedSurfaceArea;
276 mutable std::mutex fVolumeAreaMutex;
278 mutable std::optional<SurfaceSamplingCache> fSurfaceCache;
280 mutable std::uint64_t fSurfaceCacheGeneration{std::numeric_limits<std::uint64_t>::max()};
282 mutable bool fSurfaceCacheBuilding{
false};
283 mutable std::mutex fSurfaceCacheMutex;
285 mutable std::condition_variable fSurfaceCacheCV;
G4double DistanceToOut(const G4ThreeVector &p, const G4ThreeVector &v, IntersectorCache &intersectorCache, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const
Exact ray distance from an interior point to the first exit intersection.
PointClassification ClassifyPoint(const G4ThreeVector &p, ClassifierCache &classifierCache, IntersectorCache &intersectorCache, SphereCacheData &sphereCache) const
Classify a point as inside, on, or outside the solid.