UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UE::Geometry::FSparseDynamicPointOctree3 Class Reference

#include <SparseDynamicPointOctree3.h>

+ Inheritance diagram for UE::Geometry::FSparseDynamicPointOctree3:

Classes

struct  FStatistics
 

Public Member Functions

void ConfigureFromPointCountEstimate (double MaxBoundsDimension, int CountEstimate)
 
bool ContainsPoint (int32 PointID) const
 
void InsertPoint (int32 PointID, const FVector3d &Position)
 
void InsertPoint_DynamicExpand (int32 PointID, TFunctionRef< FVector3d(int)> GetPositionFunc)
 
void ParallelInsertDensePointSet (int32 MaxPointID, TFunctionRef< FVector3d(int)> GetPositionFunc)
 
bool RemovePoint (int32 PointID)
 
void RemovePointUnsafe (int32 PointID)
 
void ReinsertPoint (int32 PointID, const FVector3d &NewPosition)
 
int32 FindNearestHitPoint (const FRay3d &Ray, TFunctionRef< double(int, const FRay3d &)> HitPointDistFunc, double MaxDistance=TNumericLimits< double >::Max()) const
 
GEOMETRYCORE_API int32 FindClosestPoint (FVector3d QueryPt, double DistanceThreshold, TFunctionRef< bool(int32)> PredicateFunc, TFunctionRef< double(int32)> DistSqFunc, TArray< const FSparsePointOctreeCell * > *TempBuffer=nullptr) const
 
void FindKClosestPoints (FVector3d QueryPt, double DistanceThreshold, int32 NumToFind, TArray< TPair< int32, double > > &FoundPoints, TFunctionRef< bool(int32)> PredicateFunc, TFunctionRef< double(int32)> DistSqFunc, TArray< const FSparsePointOctreeCell * > *TempBuffer=nullptr) const
 
void RangeQuery (const FAxisAlignedBox3d &Bounds, TFunctionRef< bool(int)> PredicateFunc, TArray< int > &PointIDsOut, TArray< const FSparsePointOctreeCell * > *TempBuffer=nullptr) const
 
void ParallelRangeQuery (const FAxisAlignedBox3d &Bounds, TFunctionRef< bool(int)> PredicateFunc, TArray< int > &PointIDsOut, TArray< const FSparsePointOctreeCell * > *TempBuffer=nullptr) const
 
void CheckValidity (TFunctionRef< bool(int)> IsValidPointIDFunc, TFunctionRef< FVector3d(int)> GetPointFunc, EValidityCheckFailMode FailMode=EValidityCheckFailMode::Check, bool bVerbose=false, bool bFailOnMissingPoints=false) const
 
void ComputeStatistics (FStatistics &StatsOut) const
 

Public Attributes

double RootDimension = 1000.0
 
int MaxTreeDepth = 10
 
int MaxPointsPerCell = 1000
 

Protected Member Functions

double GetCellWidth (uint32 Level) const
 
FAxisAlignedBox3d GetCellBox (uint32 Level, const FVector3i &Index) const
 
FAxisAlignedBox3d GetCellBox (const FSparsePointOctreeCell &Cell) const
 
FVector3d GetCellCenter (uint32 Level, const FVector3i &Index) const
 
FVector3d GetCellCenter (const FSparsePointOctreeCell &Cell) const
 
FVector3i PointToIndex (uint32 Level, const FVector3d &Position) const
 
int ToChildCellIndex (uint32 Level, const FVector3i &Index, const FVector3d &Position) const
 
int ToChildCellIndex (const FSparsePointOctreeCell &Cell, const FVector3d &Position) const
 
bool CellContains (const FSparsePointOctreeCell &Cell, const FVector3d &Position) const
 
uint32 GetCellForPoint (int32 PointID) const
 
FSparsePointOctreeCell FindCurrentContainingCell (const FVector3d &Position) const
 
uint32 CreateNewRootCell (FSparsePointOctreeCell NewRootCell, bool bInitializeCellPointList)
 
void Insert_NewRoot (int32 PointID, const FVector3d &Position, FSparsePointOctreeCell NewRootCell)
 
void Insert_ToCell (int32 PointID, const FVector3d &Position, const FSparsePointOctreeCell &ExistingCell)
 
void Insert_NewChildCell (int32 PointID, const FVector3d &Position, int ParentCellID, FSparsePointOctreeCell NewChildCell, int ChildIdx)
 
double FindNearestRayCellIntersection (const FSparsePointOctreeCell &Cell, const FRay3d &Ray) const
 

Protected Attributes

FRefCountVector CellRefCounts
 
TDynamicVector< FSparsePointOctreeCellCells
 
TSparseListSet< int32CellPointLists
 
TDynamicVector< uint32PointIDToCellMap
 
TSparseGrid3< uint32RootCells
 

Static Protected Attributes

static constexpr uint32 InvalidCellID = FSparsePointOctreeCell::InvalidID
 

Detailed Description

FSparseDynamicPointOctree3 sorts Points 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 Points and their bounding-boxes are not stored in the tree. You must have an integer identifier (PointID) for each Point, and call Insert(PointID, BoundingBox). Some query functions will require you to provide a lambda/etc that can be called to retrieve the bounding box for a given PointID.

By default Points are currently inserted at the maximum possible depth, ie smallest cell that will contain them, or MaxTreeDepth.

The octree is dynamic. Points can be removed and re-inserted.

Member Function Documentation

◆ CellContains()

bool UE::Geometry::FSparseDynamicPointOctree3::CellContains ( const FSparsePointOctreeCell Cell,
const FVector3d Position 
) const
inlineprotected

◆ CheckValidity()

void UE::Geometry::FSparseDynamicPointOctree3::CheckValidity ( TFunctionRef< bool(int)>  IsValidPointIDFunc,
TFunctionRef< FVector3d(int)>  GetPointFunc,
EValidityCheckFailMode  FailMode = EValidityCheckFailMode::Check,
bool  bVerbose = false,
bool  bFailOnMissingPoints = false 
) const
inline

Check that the octree is internally valid

Parameters
IsValidPointIDFuncfunction that returns true if given PointID is valid
GetPointFuncfunction that returns point position identified by PointID
FailModehow should validity checks fail
bVerboseif true, print some debug info via UE_LOG
bFailOnMissingPointsif true, assume PointIDs are dense and that all PointIDs must be in the tree

◆ ComputeStatistics()

void UE::Geometry::FSparseDynamicPointOctree3::ComputeStatistics ( FStatistics StatsOut) const
inline

Populate given FStatistics with info about the octree

◆ ConfigureFromPointCountEstimate()

void UE::Geometry::FSparseDynamicPointOctree3::ConfigureFromPointCountEstimate ( double  MaxBoundsDimension,
int  CountEstimate 
)
inline

Do a rough ballpark configuration of the RootDimension, MaxTreeDepth, and MaxPointsPerCell tree config values, given a bounding-box dimension and estimate of the total number of points that will be inserted. This is primarily intended to be used with ParallelInsertDensePointSet()

◆ ContainsPoint()

bool UE::Geometry::FSparseDynamicPointOctree3::ContainsPoint ( int32  PointID) const
inline

Test if an Point is stored in the tree

Parameters
PointIDID of the Point
Returns
true if PointID is stored in this octree

◆ CreateNewRootCell()

uint32 UE::Geometry::FSparseDynamicPointOctree3::CreateNewRootCell ( FSparsePointOctreeCell  NewRootCell,
bool  bInitializeCellPointList 
)
inlineprotected

◆ FindClosestPoint()

int32 UE::Geometry::FSparseDynamicPointOctree3::FindClosestPoint ( FVector3d  QueryPt,
double  DistanceThreshold,
TFunctionRef< bool(int32)>  PredicateFunc,
TFunctionRef< double(int32)>  DistSqFunc,
TArray< const FSparsePointOctreeCell * > *  TempBuffer = nullptr 
) const

Find closest point in the tree, relative to a query point, within a search distance

Parameters
QueryPtFind the point closest to this query point
DistanceThresholdLimit the search to this distance
PredicateFuncReturn true if point should be included (i.e., this is a filter)
DistSqFuncUser-provided squared distance between the point with the given ID and the QueryPt
TempBufferOptional temporary buffer to store a queue of cells (to avoid memory allocations)
Returns
The ID of the closest point, or INDEX_NONE if no point was found

◆ FindCurrentContainingCell()

FSparsePointOctreeCell UE::Geometry::FSparseDynamicPointOctree3::FindCurrentContainingCell ( const FVector3d Position) const
inlineprotected

◆ FindKClosestPoints()

void UE::Geometry::FSparseDynamicPointOctree3::FindKClosestPoints ( FVector3d  QueryPt,
double  DistanceThreshold,
int32  NumToFind,
TArray< TPair< int32, double > > &  FoundPoints,
TFunctionRef< bool(int32)>  PredicateFunc,
TFunctionRef< double(int32)>  DistSqFunc,
TArray< const FSparsePointOctreeCell * > *  TempBuffer = nullptr 
) const

Find the K closest point in the tree, relative to a query point, within a search distance

Parameters
QueryPtFind the points closest to this query point
DistanceThresholdLimit the search to this distance
NumToFindThe maximum number of closest points to find
FoundPointsThe found closest points will be added to this array
PredicateFuncReturn true if point should be included (i.e., this is a filter)
DistSqFuncUser-provided squared distance between the point with the given ID and the QueryPt
TempBufferOptional temporary buffer to store a queue of cells (to avoid memory allocations)

◆ FindNearestHitPoint()

int32 UE::Geometry::FSparseDynamicPointOctree3::FindNearestHitPoint ( const FRay3d Ray,
TFunctionRef< double(int, const FRay3d &)>  HitPointDistFunc,
double  MaxDistance = TNumericLimits<double>::Max() 
) const
inline

Find nearest ray-hit point with Points in tree

Parameters
Raythe ray
HitPointDistFuncfunction that returns distance along ray to hit-point on Point identified by PointID (or TNumericLimits<double>::Max() on miss)
MaxDistancemaximum hit distance
Returns
PointID of hit Point, or -1 on miss

◆ FindNearestRayCellIntersection()

double UE::Geometry::FSparseDynamicPointOctree3::FindNearestRayCellIntersection ( const FSparsePointOctreeCell Cell,
const FRay3d Ray 
) const
inlineprotected

◆ GetCellBox() [1/2]

FAxisAlignedBox3d UE::Geometry::FSparseDynamicPointOctree3::GetCellBox ( const FSparsePointOctreeCell Cell) const
inlineprotected

◆ GetCellBox() [2/2]

FAxisAlignedBox3d UE::Geometry::FSparseDynamicPointOctree3::GetCellBox ( uint32  Level,
const FVector3i Index 
) const
inlineprotected

◆ GetCellCenter() [1/2]

FVector3d UE::Geometry::FSparseDynamicPointOctree3::GetCellCenter ( const FSparsePointOctreeCell Cell) const
inlineprotected

◆ GetCellCenter() [2/2]

FVector3d UE::Geometry::FSparseDynamicPointOctree3::GetCellCenter ( uint32  Level,
const FVector3i Index 
) const
inlineprotected

◆ GetCellForPoint()

uint32 UE::Geometry::FSparseDynamicPointOctree3::GetCellForPoint ( int32  PointID) const
inlineprotected

◆ GetCellWidth()

double UE::Geometry::FSparseDynamicPointOctree3::GetCellWidth ( uint32  Level) const
inlineprotected

◆ Insert_NewChildCell()

void UE::Geometry::FSparseDynamicPointOctree3::Insert_NewChildCell ( int32  PointID,
const FVector3d Position,
int  ParentCellID,
FSparsePointOctreeCell  NewChildCell,
int  ChildIdx 
)
inlineprotected

◆ Insert_NewRoot()

void UE::Geometry::FSparseDynamicPointOctree3::Insert_NewRoot ( int32  PointID,
const FVector3d Position,
FSparsePointOctreeCell  NewRootCell 
)
inlineprotected

◆ Insert_ToCell()

void UE::Geometry::FSparseDynamicPointOctree3::Insert_ToCell ( int32  PointID,
const FVector3d Position,
const FSparsePointOctreeCell ExistingCell 
)
inlineprotected

◆ InsertPoint()

void UE::Geometry::FSparseDynamicPointOctree3::InsertPoint ( int32  PointID,
const FVector3d Position 
)
inline

Insert PointID into the Octree at maximum depth. Currently only expands at most one depth-level per insertion. This is sub-optimal.

Parameters
PointIDID of the Point to insert
Positionposition of the Point

◆ InsertPoint_DynamicExpand()

void UE::Geometry::FSparseDynamicPointOctree3::InsertPoint_DynamicExpand ( int32  PointID,
TFunctionRef< FVector3d(int)>  GetPositionFunc 
)
inline

Insert PointID into the Octree. Dynamically expands cells that have more than MaxPointsPerCell

Parameters
PointIDID of the Point to insert
GetPositionFuncfunction that returns position of point (Required to reinsert points on expand)

◆ ParallelInsertDensePointSet()

void UE::Geometry::FSparseDynamicPointOctree3::ParallelInsertDensePointSet ( int32  MaxPointID,
TFunctionRef< FVector3d(int)>  GetPositionFunc 
)
inline

Insert a set of dense points with IDs in range [0, MaxPointID-1], in parallel. The points are only inserted in leaf nodes, at MaxTreeDepth level, so that value should be set conservatively. Parallel insertion is across root cells, so if the RootDimension is larger than the point set bounds, this will be slower than incremental construction. ConfigureFromPointCountEstimate() provides reasonable values for large point sets.

Parameters
GetPositionFuncfunction that returns position of point (Required to reinsert points on expand)

◆ ParallelRangeQuery()

void UE::Geometry::FSparseDynamicPointOctree3::ParallelRangeQuery ( const FAxisAlignedBox3d Bounds,
TFunctionRef< bool(int)>  PredicateFunc,
TArray< int > &  PointIDsOut,
TArray< const FSparsePointOctreeCell * > *  TempBuffer = nullptr 
) const
inline

Collect PointIDs from all the cells with bounding boxes that intersect Bounds, where PredicateFunc passes Query is parallelized across Root cells. So if there is only one Root cell, it's actually slower than RangeQuery() due to internal temp buffers.

Parameters
Boundsquery box
PredicateFuncreturn true if point should be included (ie this is a filter)
PointIDsOutcollected PointIDs are stored here
TempBufferoptional temporary buffer to store a queue of cells (to avoid memory allocations)

◆ PointToIndex()

FVector3i UE::Geometry::FSparseDynamicPointOctree3::PointToIndex ( uint32  Level,
const FVector3d Position 
) const
inlineprotected

◆ RangeQuery()

void UE::Geometry::FSparseDynamicPointOctree3::RangeQuery ( const FAxisAlignedBox3d Bounds,
TFunctionRef< bool(int)>  PredicateFunc,
TArray< int > &  PointIDsOut,
TArray< const FSparsePointOctreeCell * > *  TempBuffer = nullptr 
) const
inline

Collect PointIDs from all the cells with bounding boxes that intersect Bounds, where PredicateFunc passes

Parameters
Boundsquery box
PredicateFuncreturn true if point should be included (ie this is a filter)
PointIDsOutcollected PointIDs are stored here
TempBufferoptional temporary buffer to store a queue of cells (to avoid memory allocations)

◆ ReinsertPoint()

void UE::Geometry::FSparseDynamicPointOctree3::ReinsertPoint ( int32  PointID,
const FVector3d NewPosition 
)
inline

Update the position of an Point in the octree. This is more efficient than doing a remove+insert

Parameters
PointIDID of the Point
NewBoundsenw bounding box of the Point

◆ RemovePoint()

bool UE::Geometry::FSparseDynamicPointOctree3::RemovePoint ( int32  PointID)
inline

Remove a Point from the octree

Parameters
PointIDID of the Point
Returns
true if the Point was in the tree and removed

◆ RemovePointUnsafe()

void UE::Geometry::FSparseDynamicPointOctree3::RemovePointUnsafe ( int32  PointID)
inline

Remove a Point from the octree. This function must only be called with PointIDs that are certain to be in the tree.

Parameters
PointIDID of the Point.

◆ ToChildCellIndex() [1/2]

int UE::Geometry::FSparseDynamicPointOctree3::ToChildCellIndex ( const FSparsePointOctreeCell Cell,
const FVector3d Position 
) const
inlineprotected

◆ ToChildCellIndex() [2/2]

int UE::Geometry::FSparseDynamicPointOctree3::ToChildCellIndex ( uint32  Level,
const FVector3i Index,
const FVector3d Position 
) const
inlineprotected

Member Data Documentation

◆ CellPointLists

TSparseListSet<int32> UE::Geometry::FSparseDynamicPointOctree3::CellPointLists
protected

◆ CellRefCounts

FRefCountVector UE::Geometry::FSparseDynamicPointOctree3::CellRefCounts
protected

◆ Cells

TDynamicVector<FSparsePointOctreeCell> UE::Geometry::FSparseDynamicPointOctree3::Cells
protected

◆ InvalidCellID

constexpr uint32 UE::Geometry::FSparseDynamicPointOctree3::InvalidCellID = FSparsePointOctreeCell::InvalidID
staticconstexprprotected

◆ MaxPointsPerCell

int UE::Geometry::FSparseDynamicPointOctree3::MaxPointsPerCell = 1000

if using the InsertPoint_DynamicExpand() insertion path, then when a cell gets to this many points, and has depth < MaxTreeDepth, it will be expanded and its points moved down

◆ MaxTreeDepth

int UE::Geometry::FSparseDynamicPointOctree3::MaxTreeDepth = 10

Points will not be inserted more than this many levels deep from a Root cell

◆ PointIDToCellMap

TDynamicVector<uint32> UE::Geometry::FSparseDynamicPointOctree3::PointIDToCellMap
protected

◆ RootCells

TSparseGrid3<uint32> UE::Geometry::FSparseDynamicPointOctree3::RootCells
protected

◆ RootDimension

double UE::Geometry::FSparseDynamicPointOctree3::RootDimension = 1000.0

Size of the Root cells of the octree.


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