UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SampledScalarField2.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 "MathUtil.h"
9#include "VectorTypes.h"
10#include "DenseGrid2.h"
11
12namespace UE
13{
14namespace Geometry
15{
16
17using namespace UE::Math;
18
27template<typename RealType, typename ValueType>
29{
30public:
32
35
45
47 {
48 GridValues.Resize(OtherField.GridValues.Width(), OtherField.GridValues.Height());
49 GridOrigin = OtherField.GridOrigin;
50 CellDimensions = OtherField.CellDimensions;
51 }
52
56 void Resize(int64 Width, int64 Height, const ValueType& InitValue)
57 {
59 GridValues.AssignAll(InitValue);
60 }
61
62 int32 Width() const
63 {
64 return (int32)GridValues.Width();
65 }
66
67 int32 Height() const
68 {
69 return (int32)GridValues.Height();
70 }
71
72 int64 Num() const
73 {
74 return GridValues.Size();
75 }
76
80 void SetPosition(const TVector2<RealType>& Origin)
81 {
82 GridOrigin = Origin;
83 }
84
88 void SetCellSize(RealType CellSize)
89 {
90 CellDimensions.X = CellDimensions.Y = CellSize;
91 }
92
99 {
100 // transform Position into grid coordinates
104
105 // compute integer grid coordinates
106 int64 x0 = (int64)GridPoint.X;
107 int64 x1 = x0 + 1;
108 int64 y0 = (int64)GridPoint.Y;
109 int64 y1 = y0 + 1;
110
111 // clamp to valid range
113 x0 = FMath::Clamp(x0, (int64)0, Width - 1);
114 x1 = FMath::Clamp(x1, (int64)0, Width - 1);
115 y0 = FMath::Clamp(y0, (int64)0, Height - 1);
116 y1 = FMath::Clamp(y1, (int64)0, Height - 1);
117
118 // convert real-valued grid coords to [0,1] range
119 RealType fAx = FMath::Clamp(GridPoint.X - (RealType)x0, (RealType)0, (RealType)1);
120 RealType fAy = FMath::Clamp(GridPoint.Y - (RealType)y0, (RealType)0, (RealType)1);
121 RealType OneMinusfAx = (RealType)1 - fAx;
122 RealType OneMinusfAy = (RealType)1 - fAy;
123
124 // fV## is grid cell corner index
125 const ValueType& fV00 = GridValues[y0*Width + x0];
126 const ValueType& fV10 = GridValues[y0*Width + x1];
127 const ValueType& fV01 = GridValues[y1*Width + x0];
128 const ValueType& fV11 = GridValues[y1*Width + x1];
129
130 return
132 (OneMinusfAx * fAy) * fV01 +
133 (fAx * OneMinusfAy) * fV10 +
134 (fAx * fAy) * fV11;
135 }
136
137
138
139
146 {
147 // transform Position into grid coordinates
151
152 // compute integer grid coordinates
153 int64 x0 = (int64)GridPoint.X;
154 int64 x1 = x0 + 1;
155 int64 y0 = (int64)GridPoint.Y;
156 int64 y1 = y0 + 1;
157
158 // clamp to valid range
160 x0 = FMath::Clamp(x0, (int64)0, Width - 1);
161 x1 = FMath::Clamp(x1, (int64)0, Width - 1);
162 y0 = FMath::Clamp(y0, (int64)0, Height - 1);
163 y1 = FMath::Clamp(y1, (int64)0, Height - 1);
164
165 // convert real-valued grid coords to [0,1] range
166 RealType fAx = FMath::Clamp(GridPoint.X - (RealType)x0, (RealType)0, (RealType)1);
167 RealType fAy = FMath::Clamp(GridPoint.Y - (RealType)y0, (RealType)0, (RealType)1);
168 RealType OneMinusfAx = (RealType)1 - fAx;
169 RealType OneMinusfAy = (RealType)1 - fAy;
170
171 // fV## is grid cell corner index
172 const ValueType& fV00 = GridValues[y0 * Width + x0];
173 const ValueType& fV10 = GridValues[y0 * Width + x1];
174 const ValueType& fV01 = GridValues[y1 * Width + x0];
175 const ValueType& fV11 = GridValues[y1 * Width + x1];
176
177 GradXOut =
178 -fV00 * (OneMinusfAy) +
179 -fV01 * (fAy) +
180 fV10 * (OneMinusfAy) +
181 fV11 * (fAy);
182
183 GradYOut =
184 -fV00 * (OneMinusfAx) +
185 fV01 * (OneMinusfAx) +
186 -fV10 * (fAx) +
187 fV11 * (fAx);
188 }
189
190};
191
194
195} // end namespace UE::Geometry
196} // end namespace UE
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
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 DenseGrid2.h:23
void AssignAll(ElemType Value)
Definition DenseGrid2.h:78
int64 Height() const
Definition DenseGrid2.h:56
int64 Width() const
Definition DenseGrid2.h:51
int64 Size() const
Definition DenseGrid2.h:46
void Resize(int32 DimX, int32 DimY, EAllowShrinking AllowShrinking=EAllowShrinking::Default)
Definition DenseGrid2.h:66
Definition SampledScalarField2.h:29
TSampledScalarField2()
Definition SampledScalarField2.h:39
int32 Width() const
Definition SampledScalarField2.h:62
int32 Height() const
Definition SampledScalarField2.h:67
TDenseGrid2< ValueType > GridValues
Definition SampledScalarField2.h:31
int64 Num() const
Definition SampledScalarField2.h:72
void BilinearSampleGradientClamped(const TVector2< RealType > &Position, ValueType &GradXOut, ValueType &GradYOut) const
Definition SampledScalarField2.h:145
TVector2< RealType > CellDimensions
Definition SampledScalarField2.h:34
void SetCellSize(RealType CellSize)
Definition SampledScalarField2.h:88
TVector2< RealType > GridOrigin
Definition SampledScalarField2.h:33
void CopyConfiguration(const TSampledScalarField2< RealType, ValueType > &OtherField)
Definition SampledScalarField2.h:46
ValueType BilinearSampleClamped(const TVector2< RealType > &Position) const
Definition SampledScalarField2.h:98
void Resize(int64 Width, int64 Height, const ValueType &InitValue)
Definition SampledScalarField2.h:56
void SetPosition(const TVector2< RealType > &Origin)
Definition SampledScalarField2.h:80
TSampledScalarField2< float, float > FSampledScalarField2f
Definition SampledScalarField2.h:193
TSampledScalarField2< double, double > FSampledScalarField2d
Definition SampledScalarField2.h:192
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592
Definition Vector2D.h:38
static TVector2< T > One()
Definition Vector2D.h:80
T Y
Definition Vector2D.h:52
static TVector2< T > Zero()
Definition Vector2D.h:79
T X
Definition Vector2D.h:49