![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <SparseDynamicOctree3.h>
Inheritance diagram for UE::Geometry::FSparseDynamicOctree3:Classes | |
| struct | FStatistics |
Public Attributes | |
| double | RootDimension = 1000.0 |
| double | MaxExpandFactor = 0.25 |
Static Public Attributes | |
| static constexpr uint32 | MaxSupportedTreeDepth = 0x1F |
Protected Attributes | |
| int | MaxTreeDepth = 10 |
| FRefCountVector | CellRefCounts |
| TDynamicVector< FSparseOctreeCell > | Cells |
| FSmallListSet | CellObjectLists |
| TSet< int32 > | SpillObjectSet |
| TDynamicVector< uint32 > | ObjectIDToCellMap |
| FDynamicFlagArray | ValidObjectIDs |
| TSparseGrid3< uint32 > | RootCells |
Static Protected Attributes | |
| static constexpr uint32 | InvalidCellID = FSparseOctreeCell::InvalidID |
| static constexpr uint32 | SpillCellID = InvalidCellID - 1 |
FSparseDynamicOctree3 sorts objects with axis-aligned bounding boxes into a dynamic sparse octree of axis-aligned uniform grid cells. At the top level we have an infinite grid of "root cells" of size RootDimension, which then contain 8 children, and so on. (So in fact each cell is a separate octree, and we have a uniform grid of octrees)
The objects and their bounding-boxes are not stored in the tree. You must have an integer identifier (ObjectID) for each object, and call Insert(ObjectID, BoundingBox). Some query functions will require you to provide a lambda/etc that can be called to retrieve the bounding box for a given ObjectID.
Objects are currently inserted at the maximum possible depth, ie smallest cell that will contain them, or MaxTreeDepth. The tree boxes are expanded by MaxExpandFactor to allow for deeper insertion. If MaxExpandFactor > 0 then the tree does not strictly partition space, IE adjacent cells overlap.
The octree is dynamic. Objects can be removed and re-inserted.
|
protected |
|
inlineprotected |
| bool FSparseDynamicOctree3::CheckIfObjectNeedsReinsert | ( | int32 | ObjectID, |
| const FAxisAlignedBox3d & | NewBounds, | ||
| uint32 & | CellIDOut | ||
| ) | const |
Check if the object needs to be reinserted, if it has NewBounds.
| ObjectID | ID of the object |
| NewBounds | new bounding box of the object |
| CellIDOut | returned CellID of the object, if it is in the tree. This can be passed to ReinsertObject() to save some computation. |
| void FSparseDynamicOctree3::CheckValidity | ( | TFunctionRef< bool(int)> | IsValidObjectIDFunc, |
| TFunctionRef< FAxisAlignedBox3d(int)> | GetObjectBoundsFunc, | ||
| EValidityCheckFailMode | FailMode = EValidityCheckFailMode::Check, |
||
| bool | bVerbose = false, |
||
| bool | bFailOnMissingObjects = false |
||
| ) | const |
Check that the octree is internally valid
| IsValidObjectIDFunc | function that returns true if given ObjectID is valid |
| GetObjectBoundSFunc | function that returns bounding box of object identified by ObjectID |
| FailMode | how should validity checks fail |
| bVerbose | if true, print some debug info via UE_LOG |
| bFailOnMissingObjects | if true, assume ObjectIDs are dense and that all ObjectIDs must be in the tree |
| void FSparseDynamicOctree3::ComputeStatistics | ( | FStatistics & | StatsOut | ) | const |
Populate given FStatistics with info about the octree
| void FSparseDynamicOctree3::ContainmentQuery | ( | const FVector3d & | Point, |
| TFunctionRef< void(int)> | ObjectIDFunc | ||
| ) | const |
Process ObjectIDs from all the cells with bounding boxes that contain query point
| Point | query point |
| ObjectIDFunc | this function is called for each ObjectID |
| bool FSparseDynamicOctree3::ContainmentQueryCancellable | ( | const FVector3d & | Point, |
| TFunctionRef< bool(int)> | ObjectIDFunc | ||
| ) | const |
Process ObjectIDs from all the cells with bounding boxes that contain query point
| Point | query point |
| ObjectIDFunc | this function is called for each ObjectID. Returns true to continue query and false to abort |
Test if an object is stored in the tree
| ObjectID | ID of the object |
|
protected |
| int32 FSparseDynamicOctree3::FindNearestHitObject | ( | const FRay3d & | Ray, |
| TFunctionRef< FAxisAlignedBox3d(int)> | GetObjectBoundsFunc, | ||
| TFunctionRef< double(int, const FRay3d &)> | HitObjectDistFunc, | ||
| double | MaxDistance = TNumericLimits<double>::Max() |
||
| ) | const |
Find nearest ray-hit point with objects in tree
| Ray | the ray |
| GetObjectBoundsFunc | function that returns bounding box of object identified by ObjectID |
| HitObjectDistFunc | function that returns distance along ray to hit-point on object identified by ObjectID (or TNumericLimits<double>::Max() on miss) |
| MaxDistance | maximum hit distance |
|
protected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
|
inline |
|
protected |
|
protected |
|
protected |
|
protected |
| void FSparseDynamicOctree3::InsertObject | ( | int32 | ObjectID, |
| const FAxisAlignedBox3d & | Bounds | ||
| ) |
Insert ObjectID into the Octree
| ObjectID | ID of the object to insert |
| Bounds | bounding box of the object |
|
inline |
Find any overlap between a caller-defined query and any object ID. Returns the first overlap it finds.
| ShapeBounds | Overall bounds of the custom query shape |
| ObjectOverlapFn | Custom function that indicates if the given ObjectID overlaps the query shape |
| int FSparseDynamicOctree3::ParallelOverlapAnyQuery | ( | const FAxisAlignedBox3d & | ShapeBounds, |
| TFunctionRef< bool(int32)> | ObjectOverlapFn, | ||
| TFunctionRef< bool(const FAxisAlignedBox3d &)> | BoundsOverlapFn | ||
| ) | const |
Find any overlap between a caller-defined query and any object ID. Returns the first overlap it finds.
| ShapeBounds | Overall bounds of the custom query shape |
| ObjectOverlapFn | Custom function that indicates if the given ObjectID overlaps the query shape |
| BoundsOverlapFn | Optional custom function that indicates if the given bounding box overlaps the query shape, used to filter the octree search. Note the bounds overlap with ShapeBounds will already be called before calling this; only provide this if a more accurate overlap can be quickly checked. |
| void FSparseDynamicOctree3::ParallelRangeQuery | ( | const FAxisAlignedBox3d & | Bounds, |
| TArray< int > & | ObjectIDsOut | ||
| ) | const |
Collect ObjectIDs from all the cells with bounding boxes that intersect Bounds. Current implementation creates a separate TArray for each thread.
| Bounds | query box |
| ObjectIDsOut | collected ObjectIDs are stored here |
| void FSparseDynamicOctree3::ParallelRangeQuery | ( | const FAxisAlignedBox3d & | RangeBoundsHint, |
| TFunctionRef< bool(const FAxisAlignedBox3d &CellBounds)> | BoundsOverlapFn, | ||
| TArray< int32 > & | ObjectIDs | ||
| ) | const |
Collect ObjectIDs from all the leaf cells that have bounding boxes that pass BoundsOverlapFn
| RangeBoundsHint | A box to potentially limit the iteration range across cells. Note that this might be ignored if the allocation of cells is such that trying to check for cells in that range would take more time than just iterating over all allocated cells. |
| BoundsOverlapFn | Must be thread-safe. Used to determine if the cell is part of the desired range. |
| ObjectIDsOut | collected ObjectIDs are stored here |
|
inlineprotected |
| void FSparseDynamicOctree3::RangeQuery | ( | const FAxisAlignedBox3d & | Bounds, |
| TArray< int > & | ObjectIDsOut | ||
| ) | const |
Collect ObjectIDs from all the cells with bounding boxes that intersect Bounds
| Bounds | query box |
| ObjectIDsOut | collected ObjectIDs are stored here |
| void FSparseDynamicOctree3::RangeQuery | ( | const FAxisAlignedBox3d & | Bounds, |
| TFunctionRef< void(int)> | ObjectIDFunc | ||
| ) | const |
Process ObjectIDs from all the cells with bounding boxes that intersect Bounds
| Bounds | query box |
| ObjectIDFunc | this function is called for each ObjectID |
| bool FSparseDynamicOctree3::ReinsertObject | ( | int32 | ObjectID, |
| const FAxisAlignedBox3d & | NewBounds, | ||
| uint32 | CellIDHint = InvalidCellID |
||
| ) |
Update the position of an object in the octree. This is more efficient than doing a remove+insert
| ObjectID | ID of the object |
| NewBounds | new bounding box of the object |
Remove an object from the octree
| ObjectID | ID of the object |
|
inline |
Sets max tree depth w/ protection against setting beyond supported max
|
inlineprotected |
|
protected |
|
protected |
|
protected |
|
staticconstexprprotected |
| double UE::Geometry::FSparseDynamicOctree3::MaxExpandFactor = 0.25 |
Fraction we expand the dimension of any cell, to allow extra space to fit objects.
|
protected |
Objects will not be inserted more than this many levels deep from a Root cell
|
protected |
|
protected |
| double UE::Geometry::FSparseDynamicOctree3::RootDimension = 1000.0 |
Size of the Root cells of the octree. Objects that don't fit in a Root cell are added to a "Spill set"
|
staticconstexprprotected |
|
protected |
|
protected |