UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ImageInfilling.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "IntVectorTypes.h"
6#include "Templates/Tuple.h"
7#include "Util/IndexUtil.h"
8#include "VectorTypes.h"
10#include "Image/ImageBuilder.h"
12
13namespace UE
14{
15namespace Geometry
16{
17
18
27template<typename PixelType>
29{
30public:
31 // Encoding of infill operations, so that they can be applied to multiple images
32 // Values are [ NumPixels, Pixel1Count, Pixel1X, Pixel1Y, Pixel1Nbr1X, Pixel1Nbr1Y, ...
34
35
44 PixelType MissingValue,
45 TFunctionRef<PixelType(PixelType SumOfNbrValues, int NbrCount)> NormalizeFunc)
46 {
49
50 // clear all missing values
51 for (int32 k = 0; k < MissingPixels.Num(); ++k)
52 {
53 Image.SetPixel(MissingPixels[k], MissingValue);
54 }
55
56 // march inward from hole boundary and compute fill values. This is probably not the
57 // right way to go and a smooth interpolant (eg mean-value) would be preferable
60 for (int32 k = 0; k < MissingPixels.Num(); ++k)
61 {
62 int32 Count = 0;
64 for (int32 j = 0; j < 8; ++j)
65 {
67 if ( Image.ContainsPixel(NbrCoords) && Image.GetPixel(NbrCoords) != MissingValue)
68 {
69 Count++;
70 }
71 }
72 ActiveSetQueue.Insert(k, float(8 - Count));
74 }
75
76
77 while (ActiveSetQueue.GetCount() > 0)
78 {
79 int32 Index = ActiveSetQueue.Dequeue();
81
86 InfillSequence[0]++;
87
88 // accumulate neighbour values in 8-neighbourhood
89 PixelType ValidNbrAvg = PixelType::Zero();
90 int32 ValidCount = 0;
91 for (int32 j = 0; j < 8; ++j)
92 {
94 if (Image.ContainsPixel(NbrCoords))
95 {
96 PixelType PixelColor = Image.GetPixel(NbrCoords);
98 {
100 ++ValidCount;
104 }
105 }
106 }
107
108 if (ValidCount > 0)
109 {
110 // update center pixel
111 PixelType InfillValue = NormalizeFunc(ValidNbrAvg, ValidCount);
112 Image.SetPixel(CenterCoords, InfillValue);
113
114 // Update queue for nbrs. We set one pixel so we subtract one from
115 // all those neighbours
116 for (int32 j = 0; j < 8; ++j)
117 {
119 if (Image.ContainsPixel(NbrCoords) && Image.GetPixel(NbrCoords) == MissingValue)
120 {
121 const int32* FoundIndex = PixelToIndexMap.Find(NbrCoords);
122 if (FoundIndex != nullptr && ActiveSetQueue.Contains(*FoundIndex))
123 {
124 float CurPriority = ActiveSetQueue.GetPriority(*FoundIndex);
125 ActiveSetQueue.Update(*FoundIndex, CurPriority - 1.0f);
126 }
127 }
128 }
129 }
130 }
131 }
132
133
138 template<typename OtherPixelType>
142 {
144 int32 i = 1;
145 for (int32 pi = 0; pi < InfillPixels; ++pi)
146 {
151 if (PixelCount > 1)
152 {
153 OtherPixelType NbrSum = OtherPixelType::Zero();
154 int32 NbrCount = 0;
155 for (int32 j = 1; j < PixelCount; ++j)
156 {
159 NbrCoords.Y = InfillSequence[i++];
160 NbrSum += Image.GetPixel(NbrCoords);
161 NbrCount++;
162 }
164 Image.SetPixel(CenterCoords, InfillValue);
165 }
166 }
167 };
168
169
180
181};
182
183
184
185
186
187} // end namespace UE::Geometry
188} // 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
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
Definition AssetRegistryState.h:50
Definition UnrealString.h.inl:34
Definition IndexPriorityQueue.h:22
Definition ImageBuilder.h:26
Definition ImageInfilling.h:29
TArray< int32 > InfillSequence
Definition ImageInfilling.h:33
void ComputeInfill(TImageBuilder< PixelType > &Image, const TArray< FVector2i > &MissingPixels, PixelType MissingValue, TFunctionRef< PixelType(PixelType SumOfNbrValues, int NbrCount)> NormalizeFunc)
Definition ImageInfilling.h:41
void ApplyInfill(TImageBuilder< PixelType > &Image, TFunctionRef< PixelType(PixelType SumOfNbrValues, int NbrCount)> NormalizeFunc) const
Definition ImageInfilling.h:174
void ApplyInfill(TImageBuilder< OtherPixelType > &Image, TFunctionRef< OtherPixelType(OtherPixelType SumOfNbrValues, int NbrCount)> NormalizeFunc) const
Definition ImageInfilling.h:139
GEOMETRYCORE_API const FVector2i GridOffsets8[8]
Definition IndexUtil.cpp:15
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
Definition IntVectorTypes.h:20
int32 X
Definition IntVectorTypes.h:25