UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ImageBlur.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7
8#include "Containers/Array.h"
9#include "Async/ParallelFor.h"
10
11namespace UE {
12namespace Geometry {
13
14/*
15 * Solve diffusion equation u_t = Laplacian(u), u(0) = u_0 until time Sigma^2/2, with Neumann boundary conditions.
16 * This corresponds to Gaussian blur with variance Sigma.
17 *
18 * Applies additive operator splitting and solves one implicit timestep. It converges independently of filtersize
19 * but becomes approximate for large Sigma.
20 */
21template <typename RealType>
23{
24 const int32 Width = Field.Width();
25 const int32 Height = Field.Height();
26
27 const RealType TauX = RealType(0.5) * SigmaX * SigmaX; // Timestep
28 const RealType TauY = RealType(0.5) * SigmaY * SigmaY; // Timestep
29
30 struct FTaskContext
31 {
34 };
35
37
38 // columns
39 {
41 A.Init(-TauY, Height);
42 B.Init(1. + 2. * TauY, Height);
43 C.Init(-TauY, Height);
44
45 C[0] *= 2.;
46 A[Height-1] *= 2.;
47
49
50 ParallelForWithTaskContext(TEXT("HeatEquationImplicitAOS.Columns"), TaskContexts, Width, 32, [&](FTaskContext& TaskContext, int32 X)
51 {
52 TaskContext.Rhs.SetNum(Height);
53 TaskContext.Solution.SetNum(Height);
54
55 for (int32 Y=0; Y<Height; ++Y)
56 {
57 TaskContext.Rhs[Y] = Field.GridValues.At(X, Y);
58 }
59
60 Solver.Solve(TaskContext.Rhs, TaskContext.Solution);
61
62 for (int32 Y=0; Y<Height; ++Y)
63 {
64 Field.GridValues.At(X, Y) = TaskContext.Solution[Y];
65 }
66 });
67 }
68
69 // blur along rows
70 {
73
74 A.Init(-TauX, Width);
75 B.Init(1. + 2. * TauX, Width);
76 C.Init(-TauX, Width);
77
78 C[0] *= 2.;
79 A[Width-1] *= 2.;
80
82
83 ParallelForWithTaskContext(TEXT("HeatEquationImplicitAOS.Rows"), TaskContexts, Height, 32, [&](FTaskContext& TaskContext, int32 Y)
84 {
85 TaskContext.Rhs.SetNum(Width);
86 TaskContext.Solution.SetNum(Width);
87
88 for (int32 X=0; X<Width; ++X)
89 {
90 TaskContext.Rhs[X] = Field.GridValues.At(X, Y);
91 }
92
93 Solver.Solve(TaskContext.Rhs, TaskContext.Solution);
94
95 for (int32 X=0; X<Width; ++X)
96 {
97 Field.GridValues.At(X, Y) = TaskContext.Solution[X];
98 }
99 });
100 }
101}
102
103} // end namespace Geometry
104} // end namespace UE
void ParallelForWithTaskContext(const TCHAR *DebugName, TArray< ContextType, ContextAllocatorType > &OutContexts, int32 Num, const ContextConstructorType &ContextConstructor, const FunctionType &Body, EParallelForFlags Flags=EParallelForFlags::None)
Definition ParallelFor.h:694
#define TEXT(x)
Definition Platform.h:1272
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
Definition Array.h:670
void Init(const ElementType &Element, SizeType Number)
Definition Array.h:3043
Definition SampledScalarField2.h:29
Definition Tridiagonal.h:24
bool Solve(TArray< T > &Rhs, TArray< T > &X)
Definition Tridiagonal.h:44
Definition FieldSystemNoiseAlgo.cpp:6
void HeatEquationImplicitAOS(TSampledScalarField2< RealType, RealType > &Field, const RealType SigmaX, const RealType SigmaY)
Definition ImageBlur.h:22
Definition AdvancedWidgetsModule.cpp:13