UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SparseGrid3.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Port of geometry3Sharp DSparseGrid3
4
5#pragma once
6
7#include "CoreMinimal.h"
8#include "BoxTypes.h"
9#include "IntBoxTypes.h"
10
11namespace UE
12{
13namespace Geometry
14{
15
25template<typename ElemType>
27{
28protected:
33
34public:
35
43
48 {
49 FreeAll();
50 }
51
52
56 {
57 Other.Elements.Reset();
58 }
60 {
61 if (this != &Other)
62 {
63 Elements = MoveTemp(Other.Elements);
64 Bounds = MoveTemp(Other.Bounds);
65 Other.Elements.Reset();
66 }
67 return *this;
68 }
69
74 bool Has(const FVector3i& Index) const
75 {
76 return Elements.Contains(Index);
77 }
78
79
85 const ElemType* Get(const FVector3i& Index) const
86 {
87 return Elements.FindRef(Index);
88 }
89
90
97 ElemType* Get(const FVector3i& Index, bool bAllocateIfMissing)
98 {
99 ElemType* result = Elements.FindRef(Index);
100 if (result != nullptr)
101 {
102 return result;
103 }
104 if (bAllocateIfMissing == true)
105 {
106 return Allocate(Index);
107 }
108 return nullptr;
109 }
110
116 bool Free(const FVector3i& Index)
117 {
118 if (Elements.Contains(Index))
119 {
120 delete Elements[Index];
121 Elements.Remove(Index);
122 return true;
123 }
124 return false;
125 }
126
130 void FreeAll()
131 {
132 for (auto pair : Elements)
133 {
134 delete pair.Value;
135 }
136 Elements.Reset();
137 }
138
142 int GetCount() const
143 {
144 return Elements.Num();
145 }
146
150 float GetDensity() const
151 {
152 return (float)Elements.Num() / (float)Bounds.Volume();
153 }
154
159 {
160 return Bounds;
161 }
162
167 {
168 return Bounds.Diagonal() + FVector3i::One();
169 }
170
171
175 template<typename Func>
177 {
178 for (auto Pair : Elements)
179 {
180 ElementFunc(Pair.Value);
181 }
182 }
183
184
189 template<typename Func>
190 void RangeIteration(FVector3i MinIndex, FVector3i MaxIndex, Func ElementFunc) const
191 {
192 for (int32 zi = MinIndex.Z; zi <= MaxIndex.Z; ++zi)
193 {
194 for (int32 yi = MinIndex.Y; yi <= MaxIndex.Y; ++yi)
195 {
196 for (int32 xi = MinIndex.X; xi <= MaxIndex.X; ++xi)
197 {
198 const ElemType* Found = Elements.FindRef(FVector3i(xi,yi,zi));
199 if (Found != nullptr)
200 {
202 }
203 }
204 }
205 }
206 }
207
208
209
210protected:
211
212 ElemType* Allocate(const FVector3i& index)
213 {
214 ElemType* NewElem = new ElemType();
215 Elements.Add(index, NewElem);
216 Bounds.Contain(index);
217 return NewElem;
218 }
219};
220
221} // end namespace UE::Geometry
222} // end namespace UE
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition UnrealString.h.inl:34
Definition SparseGrid3.h:27
TSparseGrid3 & operator=(const TSparseGrid3 &Other)=delete
FVector3i GetDimensions() const
Definition SparseGrid3.h:166
void AllocatedIteration(Func ElementFunc) const
Definition SparseGrid3.h:176
TSparseGrid3()
Definition SparseGrid3.h:39
float GetDensity() const
Definition SparseGrid3.h:150
FAxisAlignedBox3i Bounds
Definition SparseGrid3.h:32
ElemType * Get(const FVector3i &Index, bool bAllocateIfMissing)
Definition SparseGrid3.h:97
const ElemType * Get(const FVector3i &Index) const
Definition SparseGrid3.h:85
TSparseGrid3(const TSparseGrid3 &Other)=delete
TSparseGrid3 & operator=(TSparseGrid3 &&Other) noexcept
Definition SparseGrid3.h:59
FAxisAlignedBox3i GetBoundsInclusive() const
Definition SparseGrid3.h:158
TSparseGrid3(TSparseGrid3 &&Other) noexcept
Definition SparseGrid3.h:55
~TSparseGrid3()
Definition SparseGrid3.h:47
void RangeIteration(FVector3i MinIndex, FVector3i MaxIndex, Func ElementFunc) const
Definition SparseGrid3.h:190
ElemType * Allocate(const FVector3i &index)
Definition SparseGrid3.h:212
int GetCount() const
Definition SparseGrid3.h:142
bool Free(const FVector3i &Index)
Definition SparseGrid3.h:116
TMap< FVector3i, ElemType * > Elements
Definition SparseGrid3.h:30
void FreeAll()
Definition SparseGrid3.h:130
bool Has(const FVector3i &Index) const
Definition SparseGrid3.h:74
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
Definition IntBoxTypes.h:184
static FAxisAlignedBox3i Empty()
Definition IntBoxTypes.h:279
int32 Volume() const
Definition IntBoxTypes.h:223
void Contain(const FVector3i &V)
Definition IntBoxTypes.h:238
FVector3i Diagonal() const
Definition IntBoxTypes.h:228
Definition IntVectorTypes.h:252
static FVector3i One()
Definition IntVectorTypes.h:330
int32 Z
Definition IntVectorTypes.h:257
int32 X
Definition IntVectorTypes.h:257
int32 Y
Definition IntVectorTypes.h:257