G4OCCT 0.1.0
Geant4 interface to Open CASCADE Technology (OCCT) geometry definitions
Loading...
Searching...
No Matches
G4OCCTSolid Class Reference

Geant4 solid wrapping an Open CASCADE Technology (OCCT) TopoDS_Shape. More...

#include <G4OCCTSolid.hh>

Inheritance diagram for G4OCCTSolid:

Public Member Functions

 G4OCCTSolid (const G4String &name, const TopoDS_Shape &shape)
 
 ~G4OCCTSolid () override
 
EInside Inside (const G4ThreeVector &p) const override
 Return kInside, kSurface, or kOutside for point p.
 
G4ThreeVector SurfaceNormal (const G4ThreeVector &p) const override
 Return the outward unit normal at surface point p.
 
G4double DistanceToIn (const G4ThreeVector &p, const G4ThreeVector &v) const override
 
G4double DistanceToIn (const G4ThreeVector &p) const override
 
G4double DistanceToOut (const G4ThreeVector &p, const G4ThreeVector &v, const G4bool calcNorm=false, G4bool *validNorm=nullptr, G4ThreeVector *n=nullptr) const override
 
G4double DistanceToOut (const G4ThreeVector &p) const override
 
G4ThreeVector GetPointOnSurface () const override
 
G4double ExactDistanceToIn (const G4ThreeVector &p) const
 
G4double ExactDistanceToOut (const G4ThreeVector &p) const
 
G4double GetCubicVolume () override
 
G4double GetSurfaceArea () override
 
G4GeometryType GetEntityType () const override
 Return a string identifying the entity type.
 
G4VisExtent GetExtent () const override
 Return the axis-aligned bounding box extent.
 
void BoundingLimits (G4ThreeVector &pMin, G4ThreeVector &pMax) const override
 Return the axis-aligned bounding box limits.
 
G4bool CalculateExtent (const EAxis pAxis, const G4VoxelLimits &pVoxelLimit, const G4AffineTransform &pTransform, G4double &pMin, G4double &pMax) const override
 Calculate the extent of the solid in the given axis.
 
void DescribeYourselfTo (G4VGraphicsScene &scene) const override
 Describe the solid to the graphics scene.
 
G4Polyhedron * CreatePolyhedron () const override
 Create a polyhedron representation for visualisation.
 
std::ostream & StreamInfo (std::ostream &os) const override
 Stream a human-readable description.
 
const TopoDS_Shape & GetOCCTShape () const
 Read access to the underlying OCCT shape.
 
void SetOCCTShape (const TopoDS_Shape &shape)
 

Static Public Member Functions

static G4OCCTSolidFromSTEP (const G4String &name, const std::string &path)
 

Detailed Description

Geant4 solid wrapping an Open CASCADE Technology (OCCT) TopoDS_Shape.

Wraps an Open CASCADE Technology (OCCT) TopoDS_Shape as a Geant4 solid (G4VSolid). The OCCT shape is stored by value and is queried directly for Geant4 navigation, extent, and visualisation requests.

In OCCT the closest analogue to G4VSolid is TopoDS_Shape, which is the root of the Boundary-Representation topology hierarchy and can describe any shape from a simple box to a complex multi-face shell. The mapping is discussed in detail in docs/geometry_mapping.md.

Thread safety and caching

G4OCCTSolid is shared read-only across all Geant4 worker threads once the geometry is constructed. OCCT algorithm objects such as BRepClass3d_SolidClassifier and IntCurvesFace_Intersector hold mutable internal state and must not be shared between threads. Per-thread caches of both algorithm objects are maintained via G4Cache so that the one-time O(N_faces) initialisation cost is paid only once per thread rather than on every navigation call.

A monotonically increasing fShapeGeneration counter is incremented by SetOCCTShape(). Each per-thread cache entry records the generation at which it was built; GetOrCreateClassifier() and GetOrCreateIntersector() rebuild the entry whenever the stored generation is stale. This ensures that all worker threads automatically pick up a new shape on their next navigation call, even if SetOCCTShape() is invoked after some threads have already initialised their caches.

Definition at line 70 of file G4OCCTSolid.hh.

Constructor & Destructor Documentation

◆ G4OCCTSolid()

G4OCCTSolid::G4OCCTSolid ( const G4String &  name,
const TopoDS_Shape &  shape 
)

Construct with a Geant4 solid name and an OCCT shape.

Parameters
nameName registered with the Geant4 solid store.
shapeOCCT boundary-representation shape to wrap.
Exceptions
std::invalid_argumentif shape is null or has no computable bounding box.

Definition at line 481 of file G4OCCTSolid.cc.

◆ ~G4OCCTSolid()

G4OCCTSolid::~G4OCCTSolid ( )
override

Definition at line 489 of file G4OCCTSolid.cc.

Member Function Documentation

◆ BoundingLimits()

void G4OCCTSolid::BoundingLimits ( G4ThreeVector &  pMin,
G4ThreeVector &  pMax 
) const
override

Return the axis-aligned bounding box limits.

Definition at line 1564 of file G4OCCTSolid.cc.

◆ CalculateExtent()

G4bool G4OCCTSolid::CalculateExtent ( const EAxis  pAxis,
const G4VoxelLimits &  pVoxelLimit,
const G4AffineTransform &  pTransform,
G4double &  pMin,
G4double &  pMax 
) const
override

Calculate the extent of the solid in the given axis.

Definition at line 1569 of file G4OCCTSolid.cc.

◆ CreatePolyhedron()

G4Polyhedron * G4OCCTSolid::CreatePolyhedron ( ) const
override

Create a polyhedron representation for visualisation.

Definition at line 1578 of file G4OCCTSolid.cc.

◆ DescribeYourselfTo()

void G4OCCTSolid::DescribeYourselfTo ( G4VGraphicsScene &  scene) const
override

Describe the solid to the graphics scene.

Definition at line 1576 of file G4OCCTSolid.cc.

◆ DistanceToIn() [1/2]

G4double G4OCCTSolid::DistanceToIn ( const G4ThreeVector &  p) const
override

A lower bound on the shortest distance from external point p to the solid surface.

Uses a two-stage acceleration pipeline:

Tier 0 (O(1)): If p is outside the cached axis-aligned bounding box by more than IntersectionTolerance(), the AABB distance is returned immediately. This is always a valid conservative lower bound and avoids any OCCT call for distant exterior points.

Fallback: Points within IntersectionTolerance() of the AABB fall through to ExactDistanceToIn(p).

For the exact shortest distance, use ExactDistanceToIn(p).

Definition at line 1282 of file G4OCCTSolid.cc.

References ExactDistanceToIn().

◆ DistanceToIn() [2/2]

G4double G4OCCTSolid::DistanceToIn ( const G4ThreeVector &  p,
const G4ThreeVector &  v 
) const
override

Distance from external point p along direction v to solid surface.

Parameters
pPoint outside (or on) the solid surface.
vNon-zero unit direction vector (precondition required by the G4VSolid contract).

Definition at line 1175 of file G4OCCTSolid.cc.

◆ DistanceToOut() [1/2]

G4double G4OCCTSolid::DistanceToOut ( const G4ThreeVector &  p) const
override

A lower bound on the shortest distance from internal point p to the solid surface. For the exact shortest distance, use ExactDistanceToOut(p).

Definition at line 1392 of file G4OCCTSolid.cc.

References ExactDistanceToOut().

◆ DistanceToOut() [2/2]

G4double G4OCCTSolid::DistanceToOut ( const G4ThreeVector &  p,
const G4ThreeVector &  v,
const G4bool  calcNorm = false,
G4bool *  validNorm = nullptr,
G4ThreeVector *  n = nullptr 
) const
override

Distance from internal point p along direction v to solid surface.

Parameters
pPoint inside (or on) the solid surface.
vNon-zero unit direction vector (precondition required by the G4VSolid contract).

Definition at line 1305 of file G4OCCTSolid.cc.

◆ ExactDistanceToIn()

G4double G4OCCTSolid::ExactDistanceToIn ( const G4ThreeVector &  p) const

Exact shortest distance from external point p to the solid surface. Returns 0 if p is on or inside the surface, or kInfinity if the calculation fails.

Definition at line 1212 of file G4OCCTSolid.cc.

Referenced by DistanceToIn().

◆ ExactDistanceToOut()

G4double G4OCCTSolid::ExactDistanceToOut ( const G4ThreeVector &  p) const

Exact shortest distance from internal point p to the solid surface. Returns 0 if p is within IntersectionTolerance() of the surface, or if the calculation fails. For points outside the solid, returns the positive distance to the nearest surface.

Definition at line 1381 of file G4OCCTSolid.cc.

Referenced by DistanceToOut().

◆ FromSTEP()

G4OCCTSolid * G4OCCTSolid::FromSTEP ( const G4String &  name,
const std::string &  path 
)
static

Load a STEP file and construct a G4OCCTSolid from the first shape found.

Convenience factory that combines STEP file reading with solid construction. Equivalent to constructing a G4OCCTSolid from the shape returned by a STEPControl_Reader.

Parameters
nameName registered with the Geant4 solid store.
pathFilesystem path to the STEP file.
Returns
Pointer to a newly heap-allocated G4OCCTSolid (owned by the caller).
Exceptions
std::runtime_errorif the file cannot be read or yields a null shape.

Definition at line 503 of file G4OCCTSolid.cc.

Referenced by G4OCCTDetectorConstruction::Construct(), and G4OCCT_ImportSTEPSolid().

◆ GetCubicVolume()

G4double G4OCCTSolid::GetCubicVolume ( )
override

Compute and return the cubic volume of the solid. The result is cached; repeated calls return the cached value.

Definition at line 1415 of file G4OCCTSolid.cc.

◆ GetEntityType()

G4GeometryType G4OCCTSolid::GetEntityType ( ) const
override

Return a string identifying the entity type.

Definition at line 1557 of file G4OCCTSolid.cc.

◆ GetExtent()

G4VisExtent G4OCCTSolid::GetExtent ( ) const
override

Return the axis-aligned bounding box extent.

Definition at line 1559 of file G4OCCTSolid.cc.

◆ GetOCCTShape()

const TopoDS_Shape & G4OCCTSolid::GetOCCTShape ( ) const
inline

Read access to the underlying OCCT shape.

Definition at line 206 of file G4OCCTSolid.hh.

Referenced by G4OCCT_ImportSTEPSolid().

◆ GetPointOnSurface()

G4ThreeVector G4OCCTSolid::GetPointOnSurface ( ) const
override

Return a point sampled uniformly at random from the solid's surface.

The OCCT shape is tessellated with a relative chord deflection of 1 % and each mesh triangle is selected with probability proportional to its (planar) area. A random point within the selected triangle is then generated using standard barycentric-coordinate sampling and projected back to the nearest point on the triangle's originating analytical OCCT face surface via GeomAPI_ProjectPointOnSurf. This projection step places the returned point on the analytical surface for curved faces (spheres, cylinders, cones, tori, etc.), rather than inside the solid at a chord midpoint of the tessellation mesh. If projection fails (e.g. for a degenerate or null surface), the raw tessellation point is returned as a fallback; such a point may lie slightly inside the solid.

The distribution is area-weighted over the triangulated surface, which approximates the uniform distribution over the true analytic surface; the bias is proportional to the curvature and the 1 % chord-height error. The tessellation is cached per shape generation so repeated calls only require an O(log N_triangles) area selection plus one surface projection.

Emits a JustWarning G4Exception and returns the origin if the tessellation produces no valid triangles.

Definition at line 1500 of file G4OCCTSolid.cc.

◆ GetSurfaceArea()

G4double G4OCCTSolid::GetSurfaceArea ( )
override

Compute and return the surface area of the solid. The result is cached; repeated calls return the cached value.

Definition at line 1425 of file G4OCCTSolid.cc.

◆ Inside()

EInside G4OCCTSolid::Inside ( const G4ThreeVector &  p) const
override

Return kInside, kSurface, or kOutside for point p.

Definition at line 880 of file G4OCCTSolid.cc.

◆ SetOCCTShape()

void G4OCCTSolid::SetOCCTShape ( const TopoDS_Shape &  shape)
inline

Replace the underlying OCCT shape.

Note
Increments an internal generation counter so that every worker thread automatically reloads its per-thread classifier and intersector on its next navigation call. The shape update itself is not atomic with respect to ongoing navigation; avoid calling this while a simulation run is in progress.
Exceptions
std::invalid_argumentif shape is null or has no computable bounding box.

Definition at line 215 of file G4OCCTSolid.hh.

◆ StreamInfo()

std::ostream & G4OCCTSolid::StreamInfo ( std::ostream &  os) const
override

Stream a human-readable description.

Definition at line 1689 of file G4OCCTSolid.cc.

◆ SurfaceNormal()

G4ThreeVector G4OCCTSolid::SurfaceNormal ( const G4ThreeVector &  p) const
override

Return the outward unit normal at surface point p.

Definition at line 1074 of file G4OCCTSolid.cc.


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