UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LandscapeUtilsPrivate.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "CoreMinimal.h"
7
9class ULandscapeComponent;
10class ULandscapeInfo;
12
14{
19
20#if WITH_EDITOR
23
26
28#endif
29
35 template <typename ValueType, typename KeyFuncs>
37 {
38 public:
40 {
42
44 const int32 NumValues = InValues.Num();
45 AllKeys.AddDefaulted(NumValues);
46
47 // First, we need the bound of all values so that we can properly size the linear array :
48 for (int32 Index = 0; Index < NumValues; ++Index)
49 {
50 const ValueType& Value = InValues[Index];
51 FIntPoint Key = KeyFuncs::GetKey(Value);
52 AllKeys[Index] = Key;
53 MinMaxKeys.Include(Key);
54 }
55 if (!AllKeys.IsEmpty())
56 {
57 KeyExclusiveBounds = FIntRect(MinMaxKeys.Min, MinMaxKeys.Max + 1);
58 }
59
60 // Now we can properly size the array and fill it :
61 int32 NumEntries = KeyExclusiveBounds.Area();
62 AllValues.AddDefaulted(NumEntries);
63 ValidValueBitIndices.Init(false, NumEntries);
64 for (int32 Index = 0; Index < NumValues; ++Index)
65 {
67 AllValues[ValueIndex] = InValues[Index];
68 ValidValueBitIndices[ValueIndex] = true;
69 }
70 }
71 virtual ~T2DIndexer() = default;
72 T2DIndexer(const T2DIndexer& Other) = default;
76
77 bool IsValidKey(const FIntPoint& InKey) const
78 {
79 return KeyExclusiveBounds.Contains(InKey);
80 }
81
83 {
84 return AllValues.IsValidIndex(InIndex);
85 }
86
87 ValueType& GetValueForKey(const FIntPoint& InKey) const
88 {
89 return AllValues[GetValueIndexForKey(InKey)];
90 }
91
92 ValueType& GetValueForKeySafe(const FIntPoint& InKey) const
93 {
94 return IsValidKey(InKey) ? AllValues[GetValueIndexForKey(InKey)] : nullptr;
95 }
96
97 ValueType& GetValueForKeyChecked(const FIntPoint& InKey) const
98 {
100 return AllValues[GetValueIndexForKey(InKey)];
101 }
102
104 {
105 FIntPoint RelativeKey = InKey - KeyExclusiveBounds.Min;
106 return RelativeKey.Y * KeyExclusiveBounds.Width() + RelativeKey.X;
107 }
108
113
119
121 {
122 const int32 Stride = KeyExclusiveBounds.Width();
123 return KeyExclusiveBounds.Min + FIntPoint(InIndex % Stride, InIndex / Stride);
124 }
125
130
136
137 int32 GetValueIndex(const ValueType& InValue) const
138 {
139 return GetValueIndexForKey(KeyFuncs::GetKey(InValue));
140 }
141
142 int32 GetValueIndexSafe(const ValueType& InValue) const
143 {
144 return GetValueIndexForKeySafe(KeyFuncs::GetKey(InValue));
145 }
146
147 int32 GetValueIndexChecked(const ValueType& InValue) const
148 {
149 return GetValueIndexForKeyChecked(KeyFuncs::GetKey(InValue));
150 }
151
152 bool IsValidValue(const FIntPoint& InKey) const
153 {
154 return ValidValueBitIndices[GetValueIndexForKey(InKey)];
155 }
156
158 {
159 return IsValidKey(InKey) ? ValidValueBitIndices[GetValueIndexForKey(InKey)] : false;
160 }
161
163 {
165 return ValidValueBitIndices[GetValueIndexForKey(InKey)];
166 }
167
169 {
170 FIntRect LocalBounds = InBounds;
171 // Convert to exclusive bounds if necessary :
173 {
174 LocalBounds.Max += FIntPoint(1, 1);
175 }
176 // Intersect with the current key bounds in order to limit the test to only the tracked area :
177 LocalBounds.Clip(KeyExclusiveBounds);
178 if (LocalBounds.Area() <= 0)
179 {
180 return false;
181 }
182
183 for (int32 Y = LocalBounds.Min.Y; (Y < LocalBounds.Max.Y); ++Y)
184 {
185 for (int32 X = LocalBounds.Min.X; (X < LocalBounds.Max.X); ++X)
186 {
187 if (IsValidValue(FIntPoint(X, Y)))
188 {
189 return true;
190 }
191 }
192 }
193
194 return false;
195 }
196
198 {
199 TBitArray<> Result(false, ValidValueBitIndices.Num());
200
201 FIntRect LocalBounds = InBounds;
202 // Convert to inclusive bounds if necessary :
204 {
205 LocalBounds.Max += FIntPoint(1, 1);
206 }
207 // Intersect with the current key bounds in order to limit the test to only the tracked area :
208 LocalBounds.Clip(KeyExclusiveBounds);
209 if (LocalBounds.Area() <= 0)
210 {
211 return Result;
212 }
213
214 for (int32 Y = LocalBounds.Min.Y; (Y < LocalBounds.Max.Y); ++Y)
215 {
216 for (int32 X = LocalBounds.Min.X; (X < LocalBounds.Max.X); ++X)
217 {
218 int32 ValueIndex = GetValueIndexForKey(FIntPoint(X, Y));
219 Result[ValueIndex] = ValidValueBitIndices[ValueIndex];
220 }
221 }
222
223 return Result;
224 }
225
227 {
228 // Intersect the list and the list of valid elements :
229 check(InBitIndices.Num() == ValidValueBitIndices.Num());
231
232 TArray<ValueType> Result;
233 Result.Reserve(InBitIndices.CountSetBits());
234 for (TConstSetBitIterator It(LocalBitIndices); It; ++It)
235 {
236 Result.Add(AllValues[It.GetIndex()]);
237 }
238 return Result;
239 }
240
242 {
243 // Intersect the list and the list of valid elements :
244 check(InBitIndices.Num() == ValidValueBitIndices.Num());
246 if (LocalBitIndices.IsEmpty())
247 {
248 return FIntRect();
249 }
250
251 const int32 FirstSetBitIndex = InBitIndices.Find(true);
252 const int32 LastSetBitIndex = InBitIndices.FindLast(true);
254 {
256 return FIntRect();
257 }
258
259 bool bIsValid = false;
260 const int32 Stride = KeyExclusiveBounds.Width();
263 for (int32 Y = FirstSetBitIndex / Stride; Y < YMax; ++Y)
264 {
265 const int32 LineFirstSetBitIndex = LocalBitIndices.FindFrom(true, Y * Stride);
267 {
268 const int32 LineLastSetBitIndex = LocalBitIndices.FindLastFrom(true, (Y + 1) * Stride - 1);
272 Bounds.Min = Bounds.Min.ComponentMin(LineMinKey);
273 Bounds.Max = Bounds.Max.ComponentMax(LineMaxKey);
274 bIsValid = true;
275 }
276 }
277
279 {
280 Bounds.Max += FIntPoint(1, 1);
281 }
282
283 check(bIsValid);
284 return Bounds;
285 }
286
288 {
289 TArray<ValueType> Result;
290 Result.Reserve(ValidValueBitIndices.CountSetBits());
291 for (TConstSetBitIterator It(ValidValueBitIndices); It; ++It)
292 {
293 Result.Add(AllValues[It.GetIndex()]);
294 }
295 return Result;
296 }
297
298 const TArray<ValueType>& GetAllValues() const { return AllValues; }
299 const TBitArray<>& GetValidValueBitIndices() const { return ValidValueBitIndices; }
300
301 private:
302 FIntRect KeyExclusiveBounds;
303 TArray<ValueType> AllValues;
304 TBitArray<> ValidValueBitIndices;
305 };
306
308 {
309 static FIntPoint GetKey(ULandscapeComponent* InComponent);
310 };
311
314
315
317 {
318 int32 BufferSize = 0; // Buffer size in elements.
319 int32 Stride = 0; // Buffer stride in elements. i.e. the distance between the start of each row.
320 FIntRect Rect; // The 2D region represented by this buffer. Rect.Area() should be <= BufferSize.
321 };
322
323 /* Copy height values from the R+G channels of the source buffer into a plain uint16 dest buffer. The source and destination buffers
324 * represent sub-regions of a shared 2D coordinate system expressed in the Rect parameters. ClipRect is the desired area of that
325 * shared coordinate space to limit the operation to. Copies only values in the the intersection of Src.Rect, Dest.Rect, and ClipRect.
326 * All FIntRect params are treated as half-open. .Min is included. .Max is excluded.
327 * @param DestBuffer destination buffer
328 * @param Dest description of the destination buffer
329 * @param SrcBuffer source buffer
330 * @param Src description of the source buffer
331 * @param ClipRect The operation will be limited to this region, in the same shared coordinate space of the rects from the buffer descriptions.
332 * @return number of elements copied.
333 */
334 int32 BlitHeightChannelsToUint16(uint16* DestBuffer, const FBlitBuffer2DDesc& Dest, uint32* SrcBuffer, const FBlitBuffer2DDesc& Src, FIntRect ClipRect);
335
336
337 /* Copy 16-bit weight values from the R+G channels of the source buffer, scaled down into a plain uint8 dest buffer. The source and destination buffers
338 * represent sub-regions of a shared 2D coordinate system expressed in the Rect parameters. ClipRect is the desired area of that
339 * shared coordinate space to limit the operation to. Copies only values in the the intersection of Src.Rect, Dest.Rect, and ClipRect.
340 * All FIntRect params are treated as half-open. .Min is included. .Max is excluded.
341 * @param DestBuffer destination buffer
342 * @param Dest description of the destination buffer
343 * @param SrcBuffer source buffer
344 * @param Src description of the source buffer
345 * @param ClipRect The operation will be limited to this region, in the same shared coordinate space of the rects from the buffer descriptions.
346 * @return number of elements copied.
347 */
348 int32 BlitWeightChannelsToUint8(uint8* DestBuffer, const FBlitBuffer2DDesc& Dest, uint32* SrcBuffer, const FBlitBuffer2DDesc& Src, FIntRect ClipRect);
349
350} // end namespace UE::Landscape::Private
@ YMax
Definition Aabb.h:10
#define check(expr)
Definition AssertionMacros.h:314
@ INDEX_NONE
Definition CoreMiscDefines.h:150
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
#define X(Name, Desc)
Definition FormatStringSan.h:47
UE::Math::TIntRect< int32 > FIntRect
Definition MathFwd.h:133
FInt32Point FIntPoint
Definition MathFwd.h:124
#define MAX_int32
Definition NumericLimits.h:25
#define MIN_int32
Definition NumericLimits.h:16
EShaderPlatform
Definition RHIShaderPlatform.h:11
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
SizeType AddDefaulted()
Definition Array.h:2795
UE_NODEBUG UE_FORCEINLINE_HINT bool IsValidIndex(SizeType Index) const
Definition Array.h:1122
UE_FORCEINLINE_HINT int32 Num() const
Definition BitArray.h:1466
int32 CountSetBits(int32 FromIndex=0, int32 ToIndex=INDEX_NONE) const
Definition BitArray.h:1378
UE_FORCEINLINE_HINT void Init(bool bValue, int32 InNumBits)
Definition BitArray.h:828
static TBitArray BitwiseAND(const TBitArray< AllocatorA > &A, const TBitArray< AllocatorB > &B, EBitwiseOperatorFlags InFlags)
Definition BitArray.h:1290
Definition BitArray.h:1944
WITH_EDITOR.
Definition LandscapeUtilsPrivate.h:37
bool IsValidValueIndex(int32 InIndex) const
Definition LandscapeUtilsPrivate.h:82
bool IsValidKey(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:77
T2DIndexer(T2DIndexer &&Other)=default
T2DIndexer(TConstArrayView< ValueType > InValues)
Definition LandscapeUtilsPrivate.h:39
T2DIndexer & operator=(const T2DIndexer &Other)=default
int32 GetValueIndex(const ValueType &InValue) const
Definition LandscapeUtilsPrivate.h:137
TArray< ValueType > GetValidValues()
Definition LandscapeUtilsPrivate.h:287
FIntPoint GetValueKeyForIndexSafe(int32 InIndex) const
Definition LandscapeUtilsPrivate.h:126
TBitArray GetValidValueBitIndicesInBounds(const FIntRect &InBounds, bool bInInclusiveBounds)
Definition LandscapeUtilsPrivate.h:197
bool HasValidValueInBounds(const FIntRect &InBounds, bool bInInclusiveBounds)
Definition LandscapeUtilsPrivate.h:168
int32 GetValueIndexChecked(const ValueType &InValue) const
Definition LandscapeUtilsPrivate.h:147
int32 GetValueIndexForKeySafe(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:109
bool IsValidValueSafe(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:157
T2DIndexer & operator=(T2DIndexer &&Other)=default
FIntRect GetValidValuesBoundsForBitIndices(const TBitArray<> &InBitIndices, bool bInInclusiveBounds)
Definition LandscapeUtilsPrivate.h:241
int32 GetValueIndexForKeyChecked(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:114
ValueType & GetValueForKeySafe(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:92
T2DIndexer(const T2DIndexer &Other)=default
int32 GetValueIndexForKey(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:103
FIntPoint GetValueKeyForIndexChecked(int32 InIndex) const
Definition LandscapeUtilsPrivate.h:131
const TArray< ValueType > & GetAllValues() const
Definition LandscapeUtilsPrivate.h:298
TArray< ValueType > GetValidValuesForBitIndices(const TBitArray<> &InBitIndices)
Definition LandscapeUtilsPrivate.h:226
bool IsValidValueChecked(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:162
bool IsValidValue(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:152
const TBitArray & GetValidValueBitIndices() const
Definition LandscapeUtilsPrivate.h:299
ValueType & GetValueForKeyChecked(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:97
int32 GetValueIndexSafe(const ValueType &InValue) const
Definition LandscapeUtilsPrivate.h:142
FIntPoint GetValueKeyForIndex(int32 InIndex) const
Definition LandscapeUtilsPrivate.h:120
ValueType & GetValueForKey(const FIntPoint &InKey) const
Definition LandscapeUtilsPrivate.h:87
CORE_API void Reserve(int32 CharacterCount)
Definition String.cpp.inl:307
Definition LandscapeInfo.h:109
Definition Landscape.cpp:3469
int32 BlitHeightChannelsToUint16(uint16 *DestBuffer, const FBlitBuffer2DDesc &Dest, uint32 *SrcBuffer, const FBlitBuffer2DDesc &Src, FIntRect ClipRect)
Definition LandscapeUtilsPrivate.cpp:160
int32 ComputeMipToMipMaxDeltasIndex(int32 InSourceMipIndex, int32 InDestinationMipIndex, int32 InNumRelevantMips)
Definition LandscapeUtilsPrivate.cpp:45
int32 ComputeMaxDeltasOffsetForMip(int32 InMipIndex, int32 InNumRelevantMips)
Definition LandscapeUtilsPrivate.cpp:30
int32 ComputeMipToMipMaxDeltasCount(int32 InNumRelevantMips)
Definition LandscapeUtilsPrivate.cpp:52
int32 ComputeMaxDeltasCountForMip(int32 InMipIndex, int32 InNumRelevantMips)
Definition LandscapeUtilsPrivate.cpp:40
int32 BlitWeightChannelsToUint8(uint8 *DestBuffer, const FBlitBuffer2DDesc &Dest, uint32 *SrcBuffer, const FBlitBuffer2DDesc &Src, FIntRect ClipRect)
Definition LandscapeUtilsPrivate.cpp:168
FLandscapeComponent2DIndexer CreateLandscapeComponent2DIndexer(const ULandscapeInfo *InInfo)
Definition LandscapeUtilsPrivate.cpp:107
U16 Index
Definition radfft.cpp:71
Definition LandscapeComponent.h:327
static constexpr UE_FORCEINLINE_HINT T DivideAndRoundDown(T Dividend, T Divisor)
Definition UnrealMathUtility.h:701
Definition LandscapeUtilsPrivate.h:317
int32 BufferSize
Definition LandscapeUtilsPrivate.h:318
int32 Stride
Definition LandscapeUtilsPrivate.h:319
FIntRect Rect
Definition LandscapeUtilsPrivate.h:320
static FIntPoint GetKey(ULandscapeComponent *InComponent)
WITH_EDITOR.
Definition LandscapeUtilsPrivate.cpp:102
Definition IntPoint.h:25
TIntPoint ComponentMax(const TIntPoint &Other) const
Definition IntPoint.h:343
IntType Y
Definition IntPoint.h:37
TIntPoint ComponentMin(const TIntPoint &Other) const
Definition IntPoint.h:333
static const TIntPoint NoneValue
Definition IntPoint.h:48
IntType X
Definition IntPoint.h:34
IntType Width() const
Definition IntRect.h:469
bool Contains(IntPointType P) const
Definition IntRect.h:338
IntPointType Max
Definition IntRect.h:37
IntPointType Min
Definition IntRect.h:34
void Clip(const TIntRect &R)
Definition IntRect.h:294
IntType Area() const
Definition IntRect.h:272