UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
UE::Geometry::TSparseGrid2< ElemType > Class Template Reference

#include <SparseGrid2.h>

Public Member Functions

 TSparseGrid2 ()
 
 ~TSparseGrid2 ()
 
 TSparseGrid2 (const TSparseGrid2 &Other)=delete
 
TSparseGrid2operator= (const TSparseGrid2 &Other)=delete
 
 TSparseGrid2 (TSparseGrid2 &&Other) noexcept
 
TSparseGrid2operator= (TSparseGrid2 &&Other) noexcept
 
bool Has (const FVector2i &Index) const
 
const ElemType * Get (const FVector2i &Index) const
 
ElemType * Get (const FVector2i &Index, bool bAllocateIfMissing)
 
bool Free (const FVector2i &Index)
 
void FreeAll ()
 
int GetCount () const
 
float GetDensity () const
 
FAxisAlignedBox2i GetBoundsInclusive () const
 
FVector2i GetDimensions () const
 
template<typename Func >
void AllocatedIteration (Func ElementFunc) const
 
template<typename Func >
void RangeIteration (FVector2i MinIndex, FVector2i MaxIndex, Func ElementFunc) const
 
SIZE_T GetAllocatedSize () const
 

Protected Member Functions

ElemType * Allocate (const FVector2i &index)
 

Protected Attributes

TMap< FVector2i, ElemType * > Elements
 
FAxisAlignedBox2i Bounds
 

Detailed Description

template<typename ElemType>
class UE::Geometry::TSparseGrid2< ElemType >

Dynamic sparse 2D grid. Useful in cases where we have grid of some type of non-trivial object and we don't want to pre-allocate full grid of them. So we allocate on-demand. This can be used to implement multi-grid schemes, eg for example the ElemType could be sub-grid of fixed dimension.

Constructor & Destructor Documentation

◆ TSparseGrid2() [1/3]

template<typename ElemType >
UE::Geometry::TSparseGrid2< ElemType >::TSparseGrid2 ( )
inline

Create empty grid

◆ ~TSparseGrid2()

template<typename ElemType >
UE::Geometry::TSparseGrid2< ElemType >::~TSparseGrid2 ( )
inline

Deletes all grid elements

◆ TSparseGrid2() [2/3]

template<typename ElemType >
UE::Geometry::TSparseGrid2< ElemType >::TSparseGrid2 ( const TSparseGrid2< ElemType > &  Other)
delete

◆ TSparseGrid2() [3/3]

template<typename ElemType >
UE::Geometry::TSparseGrid2< ElemType >::TSparseGrid2 ( TSparseGrid2< ElemType > &&  Other)
inlinenoexcept

Member Function Documentation

◆ Allocate()

template<typename ElemType >
ElemType * UE::Geometry::TSparseGrid2< ElemType >::Allocate ( const FVector2i index)
inlineprotected

◆ AllocatedIteration()

template<typename ElemType >
template<typename Func >
void UE::Geometry::TSparseGrid2< ElemType >::AllocatedIteration ( Func  ElementFunc) const
inline

Iterate over existing elements and apply ElementFunc(ElementType) to each of them

◆ Free()

template<typename ElemType >
bool UE::Geometry::TSparseGrid2< ElemType >::Free ( const FVector2i Index)
inline

Delete an element in the grid

Parameters
Indexinteger grid index
Returns
true if the element existed, false if it did not

◆ FreeAll()

template<typename ElemType >
void UE::Geometry::TSparseGrid2< ElemType >::FreeAll ( )
inline

Delete all elements in the grid

◆ Get() [1/2]

template<typename ElemType >
const ElemType * UE::Geometry::TSparseGrid2< ElemType >::Get ( const FVector2i Index) const
inline

Get the grid element at this index

Parameters
Indexinteger grid index
Returns
pointer to ElemType instance, or nullptr if element doesn't exist

◆ Get() [2/2]

template<typename ElemType >
ElemType * UE::Geometry::TSparseGrid2< ElemType >::Get ( const FVector2i Index,
bool  bAllocateIfMissing 
)
inline

Get the grid element at this index, and optionally allocate it if it doesn't exist

Parameters
Indexinteger grid index
bAllocateIfMissingif the element at this index is null, allocate a new one
Returns
pointer to ElemType instance, or nullptr if element doesn't exist

◆ GetAllocatedSize()

template<typename ElemType >
SIZE_T UE::Geometry::TSparseGrid2< ElemType >::GetAllocatedSize ( ) const
inline

◆ GetBoundsInclusive()

template<typename ElemType >
FAxisAlignedBox2i UE::Geometry::TSparseGrid2< ElemType >::GetBoundsInclusive ( ) const
inline
Returns
integer range of valid grid indices [min,max] (inclusive)

◆ GetCount()

template<typename ElemType >
int UE::Geometry::TSparseGrid2< ElemType >::GetCount ( ) const
inline
Returns
number of allocated elements in the grid

◆ GetDensity()

template<typename ElemType >
float UE::Geometry::TSparseGrid2< ElemType >::GetDensity ( ) const
inline
Returns
ratio of allocated elements to total number of possible cells for current bounds

◆ GetDimensions()

template<typename ElemType >
FVector2i UE::Geometry::TSparseGrid2< ElemType >::GetDimensions ( ) const
inline
Returns
dimensions of grid along each axis

◆ Has()

template<typename ElemType >
bool UE::Geometry::TSparseGrid2< ElemType >::Has ( const FVector2i Index) const
inline
Parameters
Indexan integer grid index
Returns
true if there is an allocated element at this index

◆ operator=() [1/2]

template<typename ElemType >
TSparseGrid2 & UE::Geometry::TSparseGrid2< ElemType >::operator= ( const TSparseGrid2< ElemType > &  Other)
delete

◆ operator=() [2/2]

template<typename ElemType >
TSparseGrid2 & UE::Geometry::TSparseGrid2< ElemType >::operator= ( TSparseGrid2< ElemType > &&  Other)
inlinenoexcept

◆ RangeIteration()

template<typename ElemType >
template<typename Func >
void UE::Geometry::TSparseGrid2< ElemType >::RangeIteration ( FVector2i  MinIndex,
FVector2i  MaxIndex,
Func  ElementFunc 
) const
inline

Iterate over existing allocated elements within the integer bounds defined by Min and Max (inclusive), and apply ElementFunc(ElementType) to each of them

Member Data Documentation

◆ Bounds

template<typename ElemType >
FAxisAlignedBox2i UE::Geometry::TSparseGrid2< ElemType >::Bounds
protected

accumulated bounds of all indices inserted into Elements. Not currently used internally.

◆ Elements

template<typename ElemType >
TMap<FVector2i, ElemType*> UE::Geometry::TSparseGrid2< ElemType >::Elements
protected

sparse grid of allocated elements


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