UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SpatialPhotoSet.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5// HEADER_UNIT_SKIP - Bad include. Some headers are in Engine
6
7#include "VectorTypes.h"
8#include "FrameTypes.h"
9#include "SceneView.h"
10#include "Image/ImageBuilder.h"
12
13
14namespace UE
15{
16namespace Geometry
17{
18
20{
23
30 double NearPlaneDist = 1.0;
31
33 double HorzFOVDegrees = 90.0;
34
37
39 {
40 return Frame.Origin == Other.Frame.Origin &&
41 static_cast<const FVector4d>(Frame.Rotation) == static_cast<const FVector4d>(Other.Frame.Rotation) &&
42 NearPlaneDist == Other.NearPlaneDist &&
43 HorzFOVDegrees == Other.HorzFOVDegrees &&
44 Dimensions == Other.Dimensions;
45 }
46};
47
52template<typename PixelType>
70
71
72
78template<typename PixelType, typename RealType>
80{
81public:
82
89
91 int32 Num() const { return Photos.Num(); }
92
94 void Empty() { return Photos.Empty(); }
95
97 const TSpatialPhoto<PixelType>& Get(int32 Index) const { return *Photos[Index]; }
98
112 PixelType ComputeSample(
113 const FVector3d& Position,
114 const FVector3d& Normal,
116 const PixelType& DefaultValue
117 ) const;
118
119 PixelType ComputeSample(
120 const int& PhotoIndex,
121 const FVector2d& PhotoCoords,
122 const PixelType& DefaultValue
123 ) const;
124
125 PixelType ComputeSampleNearest(
126 const int& PhotoIndex,
127 const FVector2d& PhotoCoords,
128 const PixelType& DefaultValue
129 ) const;
130
132 const FVector3d& Position,
133 const FVector3d& Normal,
135 int& PhotoIndex,
137 ) const;
138
139protected:
141};
145
146template<typename PixelType, typename RealType>
148 const FVector3d& Position,
149 const FVector3d& Normal,
151 int& PhotoIndex,
152 FVector2d& PhotoCoords) const
153{
154 double DotTolerance = -0.1; // dot should be negative for normal pointing towards photo
155
157 PhotoCoords = FVector2d(0., 0.);
158
159 double MinDot = 1.0;
160
161 int32 NumPhotos = Num();
162 for (int32 Index = 0; Index < NumPhotos; ++Index)
163 {
164 const TSpatialPhoto<PixelType>& Photo = *Photos[Index];
165 check(Photo.Dimensions.IsSquare());
166
167 FVector3d ViewDirection = Photo.Frame.X();
168 double ViewDot = ViewDirection.Dot(Normal);
170 {
171 continue;
172 }
173
174 FFrame3d ViewPlane = Photo.Frame;
175 ViewPlane.Origin += Photo.NearPlaneDist * ViewDirection;
176
177 double ViewPlaneWidthWorld = Photo.NearPlaneDist * FMathd::Tan(Photo.HorzFOVDegrees * 0.5 * FMathd::DegToRad);
179
180 FVector3d RayOrigin = Photo.Frame.Origin;
181 FVector3d RayDir = Normalized(Position - RayOrigin);
183 bool bHit = ViewPlane.RayPlaneIntersection(RayOrigin, RayDir, 0, HitPoint);
184 if (bHit)
185 {
186 bool bVisible = VisibilityFunction(Position, HitPoint);
187 if ( bVisible )
188 {
189 double PlaneX = (HitPoint - ViewPlane.Origin).Dot(ViewPlane.Y());
190 double PlaneY = (HitPoint - ViewPlane.Origin).Dot(ViewPlane.Z());
191
192 //FVector2d PlanePos = ViewPlane.ToPlaneUV(HitPoint, 0);
193 double u = PlaneX / ViewPlaneWidthWorld;
194 double v = -(PlaneY / ViewPlaneHeightWorld);
195 if (FMathd::Abs(u) < 1 && FMathd::Abs(v) < 1)
196 {
197 PhotoCoords.X = (u/2.0 + 0.5) * (double)Photo.Dimensions.GetWidth();
198 PhotoCoords.Y = (v/2.0 + 0.5) * (double)Photo.Dimensions.GetHeight();
200 MinDot = ViewDot;
201 }
202 }
203 }
204 }
205
207}
208
209template<typename PixelType, typename RealType>
211 const FVector3d& Position,
212 const FVector3d& Normal,
214 const PixelType& DefaultValue ) const
215{
216 PixelType Result = DefaultValue;
217
218 int PhotoIndex;
220 if (ComputeSampleLocation(Position, Normal, VisibilityFunction, PhotoIndex, PhotoCoords))
221 {
222 // TODO This bilinear sampling causes artefacts when it blends pixels from different depths (hence unrelated
223 // values), we could fix this with some kind of rejection strategy. Search :BilinearSamplingDepthArtefacts
224 const TSpatialPhoto<PixelType>& Photo = *Photos[PhotoIndex];
225 Result = Photo.Image.template BilinearSample<RealType>(PhotoCoords, DefaultValue);
226 }
227
228 return Result;
229}
230
231template<typename PixelType, typename RealType>
233 const int& PhotoIndex,
234 const FVector2d& PhotoCoords,
235 const PixelType& DefaultValue) const
236{
237 // TODO See the task tagged :BilinearSamplingDepthArtefacts
238 const TSpatialPhoto<PixelType>& Photo = *Photos[PhotoIndex];
239 return Photo.Image.template BilinearSample<RealType>(PhotoCoords, DefaultValue);
240}
241
242
243template<typename PixelType, typename RealType>
245 const int& PhotoIndex,
246 const FVector2d& PhotoCoords,
247 const PixelType& DefaultValue) const
248{
249 const TSpatialPhoto<PixelType>& Photo = *Photos[PhotoIndex];
250
252 UVCoords.X = PhotoCoords.X / Photo.Image.GetDimensions().GetWidth();
253 UVCoords.Y = PhotoCoords.Y / Photo.Image.GetDimensions().GetHeight();
254 if (UVCoords.X < 0. || UVCoords.X > 1. || UVCoords.Y < 0. || UVCoords.Y > 1.)
255 {
256 return DefaultValue;
257 }
258
259 return Photo.Image.NearestSampleUV(UVCoords);
260}
261
262
263
264} // end namespace UE::Geometry
265} // end namespace UE
@ Normal
Definition AndroidInputInterface.h:116
#define check(expr)
Definition AssertionMacros.h:314
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
UE::Math::TVector2< double > FVector2d
Definition MathFwd.h:61
@ Num
Definition MetalRHIPrivate.h:234
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition Array.h:670
Definition AssetRegistryState.h:50
static RealType Tan(const RealType Value)
Definition MathUtil.h:354
static RealType Abs(const RealType Value)
Definition MathUtil.h:215
Definition SharedPointer.h:692
Definition ImageDimensions.h:18
Definition ImageBuilder.h:26
Definition SpatialPhotoSet.h:80
const TSpatialPhoto< PixelType > & Get(int32 Index) const
Definition SpatialPhotoSet.h:97
int32 Num() const
Definition SpatialPhotoSet.h:91
PixelType ComputeSampleNearest(const int &PhotoIndex, const FVector2d &PhotoCoords, const PixelType &DefaultValue) const
Definition SpatialPhotoSet.h:244
void Empty()
Definition SpatialPhotoSet.h:94
void Add(TSpatialPhoto< PixelType > &&Photo)
Definition SpatialPhotoSet.h:84
TArray< TSharedPtr< TSpatialPhoto< PixelType >, ESPMode::ThreadSafe > > Photos
Definition SpatialPhotoSet.h:140
bool ComputeSampleLocation(const FVector3d &Position, const FVector3d &Normal, TFunctionRef< bool(const FVector3d &, const FVector3d &)> VisibilityFunction, int &PhotoIndex, FVector2d &PhotoCoords) const
Definition SpatialPhotoSet.h:147
PixelType ComputeSample(const FVector3d &Position, const FVector3d &Normal, TFunctionRef< bool(const FVector3d &, const FVector3d &)> VisibilityFunction, const PixelType &DefaultValue) const
Definition SpatialPhotoSet.h:210
constexpr int InvalidID
Definition IndexTypes.h:13
TSpatialPhotoSet< FVector3f, float > FSpatialPhotoSet3f
Definition SpatialPhotoSet.h:143
TSpatialPhoto< FVector3f > FSpatialPhoto3f
Definition SpatialPhotoSet.h:68
TSpatialPhotoSet< float, float > FSpatialPhotoSet1f
Definition SpatialPhotoSet.h:144
TSpatialPhoto< float > FSpatialPhoto1f
Definition SpatialPhotoSet.h:69
TSpatialPhoto< FVector4f > FSpatialPhoto4f
Definition SpatialPhotoSet.h:67
TSpatialPhotoSet< FVector4f, float > FSpatialPhotoSet4f
Definition SpatialPhotoSet.h:142
Definition AdvancedWidgetsModule.cpp:13
float v
Definition radaudio_mdct.cpp:62
U16 Index
Definition radfft.cpp:71
Definition SpatialPhotoSet.h:20
FImageDimensions Dimensions
Definition SpatialPhotoSet.h:36
FFrame3d Frame
Definition SpatialPhotoSet.h:22
double HorzFOVDegrees
Definition SpatialPhotoSet.h:33
bool operator==(const FSpatialPhotoParams &Other) const
Definition SpatialPhotoSet.h:38
double NearPlaneDist
Definition SpatialPhotoSet.h:30
TVector< RealType > Origin
Definition FrameTypes.h:31
TQuaternion< RealType > Rotation
Definition FrameTypes.h:36
Definition SpatialPhotoSet.h:54
TImageBuilder< PixelType > Image
Definition SpatialPhotoSet.h:65
FFrame3d Frame
Definition SpatialPhotoSet.h:56
double HorzFOVDegrees
Definition SpatialPhotoSet.h:61
FImageDimensions Dimensions
Definition SpatialPhotoSet.h:63
double NearPlaneDist
Definition SpatialPhotoSet.h:59
T X
Definition Vector2D.h:49
T X
Definition Vector.h:62
UE_FORCEINLINE_HINT T Dot(const TVector< T > &V) const
Definition Vector.h:1553