Project
Loading...
Searching...
No Matches
o2::cad::O2FlatCSG Class Reference

#include <O2FlatCSG.h>

Inherits TGeoBBox.

Public Member Functions

 O2FlatCSG ()
 
 O2FlatCSG (const char *name)
 
 ~O2FlatCSG () override
 
 O2FlatCSG (const O2FlatCSG &)=delete
 
O2FlatCSGoperator= (const O2FlatCSG &)=delete
 
int AddQuadric (double sign, const double coeff[10])
 Append a quadric halfspace; returns its index. sign is +1 or -1, inside is sign*Q <= 0.
 
int AddTorus (double sign, const double *centre, const double *axis, double major, double minor)
 Append a torus halfspace, inside sign * (sqrt((rho - major)^2 + z^2) - minor) <= 0 about unit axis; returns its index.
 
int AddCell (int first, int count, double volume)
 Append a cell over [first, first + count) of the halfspace array; returns its index.
 
int GetNhalfspaces () const
 
int GetNcells () const
 
const FlatCSGHalfspaceGetHalfspace (int index) const
 
const FlatCSGCellGetCell (int index) const
 
void SetCellBBox (int cell, const double *lo, const double *hi)
 
void GetCellBBox (int cell, double *lo, double *hi) const
 
void CloseShape ()
 Build the sub-cell boxes and their BVH. Call once, after the last AddCell.
 
bool IsClosed () const
 
size_t GetBVHMemory () const
 Bytes held by the BVH nodes and the primitive-index permutation.
 
int GetNboxes () const
 
const FlatCSGBoxGetBox (int index) const
 
int GetActive (int index) const
 For the tests: the box structure is the thing being proved sound, so it has to be readable.
 
bool CellContains (int index, const double *point) const
 True when every halfspace of cell index contains point.
 
void SetSplitDepth (int depth)
 Subdivision depth cap. See fSplitDepth for where the default comes from.
 
void SetMinBoxFraction (double fraction)
 
int CellIntervals (int cell, const int *active, int nActive, const double *origin, const double *dir, double tlo, double thi, double *out, int maxOut) const
 
Bool_t Contains (const Double_t *point) const override
 
Double_t DistFromOutside (const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const override
 
Double_t DistFromInside (const Double_t *point, const Double_t *dir, Int_t iact=1, Double_t step=TGeoShape::Big(), Double_t *safe=nullptr) const override
 
Double_t Safety (const Double_t *point, Bool_t in=kTRUE) const override
 A lower bound on the distance to the boundary from the box structure: outside the nearest box, inside the faces of a solid box, else 0.
 
void ComputeBBox () override
 The union of the retained sub-cell boxes, tighter than the union of the cell AABBs.
 
Double_t Capacity () const override
 
void ComputeNormal (const Double_t *point, const Double_t *dir, Double_t *norm) const override
 The normal of the halfspace nearest to equality at point, oriented along dir.
 
Bool_t GetPointsOnSegments (Int_t npoints, Double_t *array) const override
 Points on the solid's own boundary, for the overlap checkers; kFALSE if fewer than npoints were found.
 
Bool_t Contains_Loop (const Double_t *point) const
 
Double_t DistFromOutside_Loop (const Double_t *point, const Double_t *dir, Double_t step=TGeoShape::Big()) const
 
Double_t DistFromInside_Loop (const Double_t *point, const Double_t *dir, Double_t step=TGeoShape::Big()) const
 
Double_t Safety_Loop (const Double_t *point, Bool_t in=kTRUE) const
 Safety's twin over all boxes: it must equal Safety and be a sound bound.
 

Static Public Member Functions

static double EvalHalfspace (const FlatCSGHalfspace &halfspace, const double *point)
 sign * f(point); the halfspace contains the point when this is <= 0.
 
static void HalfspaceRange (const FlatCSGHalfspace &halfspace, const double *lo, const double *hi, double &rangeLo, double &rangeHi)
 
static int HalfspaceRoots (const FlatCSGHalfspace &halfspace, const double *origin, const double *dir, double *roots)
 Real roots of sign * f(origin + t*dir) = 0, unsorted, at most four; returns the count.
 
static void ResetUnprunedRetryCounter ()
 Per-thread count of DistFromInside queries whose pruned traversal had to be redone unpruned.
 
static long long GetUnprunedRetryCount ()
 

Protected Types

enum class  RayBound { kNone , kEntry , kExit }
 

Protected Member Functions

void EnsureCellBBoxStorage ()
 Grow the per-cell bounding-box storage to the cell count.
 
Double_t DistFromOutsideBVH (const Double_t *point, const Double_t *dir, Double_t step) const
 The accelerated DistFromOutside/DistFromInside bodies; each clips the ray to a box before using its active list.
 
Double_t DistFromInsideBVH (const Double_t *point, const Double_t *dir, Double_t step) const
 DistFromInsideBVH – the far end of the union's interval containing t = 0, merged across cells with the twin's glue.
 
bool GatherRayPieces (const Double_t *point, const Double_t *dir, Double_t step, std::vector< double > &pairs, std::vector< int > &cells, RayBound bound, double &smallestPruned) const
 GatherRayPieces – each box's window is its own slab intersected with [0, step], never pooled across boxes.
 
void SplitBox (int cell, const double *lo, const double *hi, const std::vector< int > &active, int depth, double minSize, int cubifyBudget)
 

Protected Attributes

std::vector< FlatCSGHalfspacefHalfspaces
 the flat halfspace array
 
std::vector< FlatCSGCellfCells
 the DNF's cells, indexing into it
 
std::vector< FlatCSGBoxfBoxes
 The sub-cell boxes, rebuilt by CloseShape; not streamed.
 
std::vector< intfActive
 
std::vector< double > fCellLo
 each cell's AABB low corner, 3 doubles per cell
 
std::vector< double > fCellHi
 
std::vector< bool > fCellBBoxSet
 
bool fClosed = false
 Set by a successful CloseShape; not streamed. The #pragma read rule closes every shape ROOT reads back.
 
int fSplitDepth = 4
 
double fMinBoxFraction = 0.05
 
voidfBVH = nullptr
 The BVH over fBoxes, rebuilt by CloseShape; not streamed.
 

Detailed Description

A solid stored as a union of intersection cells over signed implicit halfspaces, the flat DNF of a decomposed part. Every accelerated query has a bit-identical _Loop twin over all cells and halfspaces.

Definition at line 55 of file O2FlatCSG.h.

Member Enumeration Documentation

◆ RayBound

enum class o2::cad::O2FlatCSG::RayBound
strongprotected

What the running bound prunes against: nothing, the nearest entry so far (DistFromOutside) or the far end of the interval holding t = 0 so far (DistFromInside).

Enumerator
kNone 
kEntry 
kExit 

Definition at line 171 of file O2FlatCSG.h.

Constructor & Destructor Documentation

◆ O2FlatCSG() [1/3]

o2::cad::O2FlatCSG::O2FlatCSG ( )

Definition at line 285 of file O2FlatCSG.cxx.

◆ O2FlatCSG() [2/3]

o2::cad::O2FlatCSG::O2FlatCSG ( const char name)
explicit

Definition at line 287 of file O2FlatCSG.cxx.

◆ ~O2FlatCSG()

o2::cad::O2FlatCSG::~O2FlatCSG ( )
override

Definition at line 289 of file O2FlatCSG.cxx.

◆ O2FlatCSG() [3/3]

o2::cad::O2FlatCSG::O2FlatCSG ( const O2FlatCSG )
delete

Member Function Documentation

◆ AddCell()

int o2::cad::O2FlatCSG::AddCell ( int  first,
int  count,
double  volume 
)

Append a cell over [first, first + count) of the halfspace array; returns its index.

Definition at line 335 of file O2FlatCSG.cxx.

◆ AddQuadric()

int o2::cad::O2FlatCSG::AddQuadric ( double  sign,
const double  coeff[10] 
)

Append a quadric halfspace; returns its index. sign is +1 or -1, inside is sign*Q <= 0.

Definition at line 304 of file O2FlatCSG.cxx.

◆ AddTorus()

int o2::cad::O2FlatCSG::AddTorus ( double  sign,
const double *  centre,
const double *  axis,
double  major,
double  minor 
)

Append a torus halfspace, inside sign * (sqrt((rho - major)^2 + z^2) - minor) <= 0 about unit axis; returns its index.

Definition at line 316 of file O2FlatCSG.cxx.

◆ Capacity()

Double_t o2::cad::O2FlatCSG::Capacity ( ) const
override

The sum of the cells' own volumes. The cells of a decomposition are disjoint by construction (decompose's volume guard checks it), so there is no inclusion-exclusion to do.

Definition at line 1329 of file O2FlatCSG.cxx.

◆ CellContains()

bool o2::cad::O2FlatCSG::CellContains ( int  index,
const double *  point 
) const

True when every halfspace of cell index contains point.

Definition at line 463 of file O2FlatCSG.cxx.

◆ CellIntervals()

int o2::cad::O2FlatCSG::CellIntervals ( int  cell,
const int active,
int  nActive,
const double *  origin,
const double *  dir,
double  tlo,
double  thi,
double *  out,
int  maxOut 
) const

The occupancy of cell cell along the ray within [tlo, thi], as [enter, exit] pairs in out; a null active uses every halfspace. Returns the pair count, or a negative value when maxOut is too small.

Definition at line 857 of file O2FlatCSG.cxx.

◆ CloseShape()

void o2::cad::O2FlatCSG::CloseShape ( )

Build the sub-cell boxes and their BVH. Call once, after the last AddCell.

Definition at line 535 of file O2FlatCSG.cxx.

◆ ComputeBBox()

void o2::cad::O2FlatCSG::ComputeBBox ( )
override

The union of the retained sub-cell boxes, tighter than the union of the cell AABBs.

Definition at line 1415 of file O2FlatCSG.cxx.

◆ ComputeNormal()

void o2::cad::O2FlatCSG::ComputeNormal ( const Double_t *  point,
const Double_t *  dir,
Double_t *  norm 
) const
override

The normal of the halfspace nearest to equality at point, oriented along dir.

ComputeNormal – the halfspace with the smallest first-order distance |f| / |grad f| among the active list of the box holding point, which HalfspaceRange's 64-eps pad makes every halfspace that can be at equality there.

Definition at line 1340 of file O2FlatCSG.cxx.

◆ Contains()

Bool_t o2::cad::O2FlatCSG::Contains ( const Double_t *  point) const
override

Definition at line 751 of file O2FlatCSG.cxx.

◆ Contains_Loop()

Bool_t o2::cad::O2FlatCSG::Contains_Loop ( const Double_t *  point) const

Definition at line 664 of file O2FlatCSG.cxx.

◆ DistFromInside()

Double_t o2::cad::O2FlatCSG::DistFromInside ( const Double_t *  point,
const Double_t *  dir,
Int_t  iact = 1,
Double_t  step = TGeoShape::Big(),
Double_t *  safe = nullptr 
) const
override

Definition at line 1209 of file O2FlatCSG.cxx.

◆ DistFromInside_Loop()

Double_t o2::cad::O2FlatCSG::DistFromInside_Loop ( const Double_t *  point,
const Double_t *  dir,
Double_t  step = TGeoShape::Big() 
) const

Definition at line 989 of file O2FlatCSG.cxx.

◆ DistFromInsideBVH()

Double_t o2::cad::O2FlatCSG::DistFromInsideBVH ( const Double_t *  point,
const Double_t *  dir,
Double_t  step 
) const
protected

DistFromInsideBVH – the far end of the union's interval containing t = 0, merged across cells with the twin's glue.

Definition at line 1145 of file O2FlatCSG.cxx.

◆ DistFromOutside()

Double_t o2::cad::O2FlatCSG::DistFromOutside ( const Double_t *  point,
const Double_t *  dir,
Int_t  iact = 1,
Double_t  step = TGeoShape::Big(),
Double_t *  safe = nullptr 
) const
override

Definition at line 1189 of file O2FlatCSG.cxx.

◆ DistFromOutside_Loop()

Double_t o2::cad::O2FlatCSG::DistFromOutside_Loop ( const Double_t *  point,
const Double_t *  dir,
Double_t  step = TGeoShape::Big() 
) const

Definition at line 963 of file O2FlatCSG.cxx.

◆ DistFromOutsideBVH()

Double_t o2::cad::O2FlatCSG::DistFromOutsideBVH ( const Double_t *  point,
const Double_t *  dir,
Double_t  step 
) const
protected

The accelerated DistFromOutside/DistFromInside bodies; each clips the ray to a box before using its active list.

DistFromOutsideBVH – the pieces are rejoined per cell, never across cells, as the twin's per-cell intervals.

Definition at line 1094 of file O2FlatCSG.cxx.

◆ EnsureCellBBoxStorage()

void o2::cad::O2FlatCSG::EnsureCellBBoxStorage ( )
protected

Grow the per-cell bounding-box storage to the cell count.

Definition at line 345 of file O2FlatCSG.cxx.

◆ EvalHalfspace()

double o2::cad::O2FlatCSG::EvalHalfspace ( const FlatCSGHalfspace halfspace,
const double *  point 
)
static

sign * f(point); the halfspace contains the point when this is <= 0.

Definition at line 380 of file O2FlatCSG.cxx.

◆ GatherRayPieces()

bool o2::cad::O2FlatCSG::GatherRayPieces ( const Double_t *  point,
const Double_t *  dir,
Double_t  step,
std::vector< double > &  pairs,
std::vector< int > &  cells,
RayBound  bound,
double &  smallestPruned 
) const
protected

GatherRayPieces – each box's window is its own slab intersected with [0, step], never pooled across boxes.

Each box's own occupancy pieces along the ray within [0, step]: [enter, exit] in pairs and its cell in cells, unmerged. False when a CellIntervals call overflowed. smallestPruned reports the nearest entry the exit bound skipped, Big if it skipped nothing or if the bound is not kExit.

Definition at line 1026 of file O2FlatCSG.cxx.

◆ GetActive()

int o2::cad::O2FlatCSG::GetActive ( int  index) const
inline

For the tests: the box structure is the thing being proved sound, so it has to be readable.

Definition at line 97 of file O2FlatCSG.h.

◆ GetBox()

const FlatCSGBox & o2::cad::O2FlatCSG::GetBox ( int  index) const
inline

Definition at line 95 of file O2FlatCSG.h.

◆ GetBVHMemory()

size_t o2::cad::O2FlatCSG::GetBVHMemory ( ) const

Bytes held by the BVH nodes and the primitive-index permutation.

Definition at line 295 of file O2FlatCSG.cxx.

◆ GetCell()

const FlatCSGCell & o2::cad::O2FlatCSG::GetCell ( int  index) const
inline

Definition at line 78 of file O2FlatCSG.h.

◆ GetCellBBox()

void o2::cad::O2FlatCSG::GetCellBBox ( int  cell,
double *  lo,
double *  hi 
) const

The AABB SetCellBBox recorded for cell cell, for the sidecar writer. Reads back zeros for a cell whose box was never set.

Definition at line 370 of file O2FlatCSG.cxx.

◆ GetHalfspace()

const FlatCSGHalfspace & o2::cad::O2FlatCSG::GetHalfspace ( int  index) const
inline

Definition at line 77 of file O2FlatCSG.h.

◆ GetNboxes()

int o2::cad::O2FlatCSG::GetNboxes ( ) const
inline

Definition at line 94 of file O2FlatCSG.h.

◆ GetNcells()

int o2::cad::O2FlatCSG::GetNcells ( ) const
inline

Definition at line 76 of file O2FlatCSG.h.

◆ GetNhalfspaces()

int o2::cad::O2FlatCSG::GetNhalfspaces ( ) const
inline

Definition at line 75 of file O2FlatCSG.h.

◆ GetPointsOnSegments()

Bool_t o2::cad::O2FlatCSG::GetPointsOnSegments ( Int_t  npoints,
Double_t *  array 
) const
override

Points on the solid's own boundary, for the overlap checkers; kFALSE if fewer than npoints were found.

Contains – inside its box a box's active list is the cell, so the point must first be in the box's own bounds.

< cm either side of a point at which Contains must change

Definition at line 677 of file O2FlatCSG.cxx.

◆ GetUnprunedRetryCount()

long long o2::cad::O2FlatCSG::GetUnprunedRetryCount ( )
static

Definition at line 1184 of file O2FlatCSG.cxx.

◆ HalfspaceRange()

void o2::cad::O2FlatCSG::HalfspaceRange ( const FlatCSGHalfspace halfspace,
const double *  lo,
const double *  hi,
double &  rangeLo,
double &  rangeHi 
)
static

A rigorous enclosure [rangeLo, rangeHi] of sign * f over the box [lo, hi], padded outward. Requires lo[i] <= hi[i] and finite bounds, which CloseShape enforces; it does not check them.

Definition at line 403 of file O2FlatCSG.cxx.

◆ HalfspaceRoots()

int o2::cad::O2FlatCSG::HalfspaceRoots ( const FlatCSGHalfspace halfspace,
const double *  origin,
const double *  dir,
double *  roots 
)
static

Real roots of sign * f(origin + t*dir) = 0, unsorted, at most four; returns the count.

Definition at line 774 of file O2FlatCSG.cxx.

◆ IsClosed()

bool o2::cad::O2FlatCSG::IsClosed ( ) const
inline

Definition at line 89 of file O2FlatCSG.h.

◆ operator=()

O2FlatCSG & o2::cad::O2FlatCSG::operator= ( const O2FlatCSG )
delete

◆ ResetUnprunedRetryCounter()

void o2::cad::O2FlatCSG::ResetUnprunedRetryCounter ( )
static

Per-thread count of DistFromInside queries whose pruned traversal had to be redone unpruned.

Definition at line 1179 of file O2FlatCSG.cxx.

◆ Safety()

Double_t o2::cad::O2FlatCSG::Safety ( const Double_t *  point,
Bool_t  in = kTRUE 
) const
override

A lower bound on the distance to the boundary from the box structure: outside the nearest box, inside the faces of a solid box, else 0.

Safety – Safety_Loop's computation through the BVH; the pruning never drops the nearest box.

< the node box's squared distance, computed once when pushed

Definition at line 1252 of file O2FlatCSG.cxx.

◆ Safety_Loop()

Double_t o2::cad::O2FlatCSG::Safety_Loop ( const Double_t *  point,
Bool_t  in = kTRUE 
) const

Safety's twin over all boxes: it must equal Safety and be a sound bound.

Safety_Loop – outside the distance to the nearest box; inside the distance to the faces of a wholly-inside box, else 0.

Definition at line 1230 of file O2FlatCSG.cxx.

◆ SetCellBBox()

void o2::cad::O2FlatCSG::SetCellBBox ( int  cell,
const double *  lo,
const double *  hi 
)

The AABB of cell cell. The halfspaces alone do not bound a cell – an intersection of halfspaces can be unbounded – so the converter supplies the box the decomposition measured.

Definition at line 354 of file O2FlatCSG.cxx.

◆ SetMinBoxFraction()

void o2::cad::O2FlatCSG::SetMinBoxFraction ( double  fraction)
inline

Stop splitting a box narrower than this fraction of the part's bounding-box diagonal. See fMinBoxFraction for where the default comes from.

Definition at line 105 of file O2FlatCSG.h.

◆ SetSplitDepth()

void o2::cad::O2FlatCSG::SetSplitDepth ( int  depth)
inline

Subdivision depth cap. See fSplitDepth for where the default comes from.

Definition at line 102 of file O2FlatCSG.h.

◆ SplitBox()

void o2::cad::O2FlatCSG::SplitBox ( int  cell,
const double *  lo,
const double *  hi,
const std::vector< int > &  active,
int  depth,
double  minSize,
int  cubifyBudget 
)
protected

Recursively split [lo, hi] for cell, dropping the halfspaces the range bound decides and the boxes it proves outside. A split of a far-from-cubic box draws on cubifyBudget, any other on depth.

Definition at line 474 of file O2FlatCSG.cxx.

Member Data Documentation

◆ fActive

std::vector<int> o2::cad::O2FlatCSG::fActive
protected

The boxes' active-halfspace lists, concatenated. Derived alongside fBoxes; not streamed for the same reason.

Definition at line 194 of file O2FlatCSG.h.

◆ fBoxes

std::vector<FlatCSGBox> o2::cad::O2FlatCSG::fBoxes
protected

The sub-cell boxes, rebuilt by CloseShape; not streamed.

Definition at line 191 of file O2FlatCSG.h.

◆ fBVH

void* o2::cad::O2FlatCSG::fBVH = nullptr
protected

The BVH over fBoxes, rebuilt by CloseShape; not streamed.

Definition at line 208 of file O2FlatCSG.h.

◆ fCellBBoxSet

std::vector<bool> o2::cad::O2FlatCSG::fCellBBoxSet
protected

Whether SetCellBBox was ever called for a given cell; CloseShape refuses to build a solid missing one rather than silently drop that cell – see CloseShape's implementation.

Definition at line 199 of file O2FlatCSG.h.

◆ fCellHi

std::vector<double> o2::cad::O2FlatCSG::fCellHi
protected

each cell's AABB high corner, 3 doubles per cell

Definition at line 196 of file O2FlatCSG.h.

◆ fCellLo

std::vector<double> o2::cad::O2FlatCSG::fCellLo
protected

each cell's AABB low corner, 3 doubles per cell

Definition at line 195 of file O2FlatCSG.h.

◆ fCells

std::vector<FlatCSGCell> o2::cad::O2FlatCSG::fCells
protected

the DNF's cells, indexing into it

Definition at line 188 of file O2FlatCSG.h.

◆ fClosed

bool o2::cad::O2FlatCSG::fClosed = false
protected

Set by a successful CloseShape; not streamed. The #pragma read rule closes every shape ROOT reads back.

Definition at line 201 of file O2FlatCSG.h.

◆ fHalfspaces

std::vector<FlatCSGHalfspace> o2::cad::O2FlatCSG::fHalfspaces
protected

the flat halfspace array

Definition at line 187 of file O2FlatCSG.h.

◆ fMinBoxFraction

double o2::cad::O2FlatCSG::fMinBoxFraction = 0.05
protected

Definition at line 205 of file O2FlatCSG.h.

◆ fSplitDepth

int o2::cad::O2FlatCSG::fSplitDepth = 4
protected

Subdivision depth cap, and the minimum box size as a fraction of the part's bounding-box diagonal, chosen for query cost on the shipped parts.

Definition at line 204 of file O2FlatCSG.h.


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