32 template <
typename Profile>
35 const typename Profile::FVector ClosestPoint = Profile::FVector::Max(
InBox.Min, Profile::FVector::Min(
InCenter,
InBox.Max));
62 template <
typename Profile>
67 if constexpr (Profile::Is3D)
69 const typename Profile::FVector BoxExtent =
InBox.GetExtent();
74 typename Profile::FVector
D =
InBox.GetCenter() - U;
75 typename Profile::FReal
DSqr =
D |
D;
76 typename Profile::FReal
E =
InAxis |
D;
162template <
typename Profile>
172template <
typename ValueType,
typename Profile,
class SpatialIndexType,
class ElementsSorter>
175 using FBox =
typename Profile::FBox;
179 : SpatialIndex(*this)
194 template <
class Func>
199 SpatialIndex.ForEachElement([
this, &
Invoker](
uint32 ValueIndex)
205 template <
class Func>
216 template <
class Func>
221 SpatialIndex.ForEachIntersectingElement(InSphere, [
this, &
Invoker](
uint32 ValueIndex)
227 template <
class Func>
244 Collector.AddReferencedObject(Element.Value);
252 return Elements.Num();
268 return sizeof(*this) + Elements.GetAllocatedSize() + SpatialIndex.GetAllocatedSize();
272 void InitSpatialIndex()
275 if (ElementsSorter::NeedSort)
295 template <
typename Profile>
307 template <
typename Profile>
308 class TListImpl :
public TImpl<Profile>
310 using FVector =
typename Profile::FVector;
311 using FBox =
typename Profile::FBox;
322 for (
int32 ValueIndex = 0; ValueIndex < this->DataInterface.GetNumBox(); ValueIndex++)
336 for (
int32 ValueIndex = 0; ValueIndex < this->DataInterface.GetNumBox(); ValueIndex++, *(
uint8**)&
Box +=
BoxStride)
356 for (
int32 ValueIndex = 0; ValueIndex < this->DataInterface.GetNumBox(); ValueIndex++, *(
uint8**)&
Box +=
BoxStride)
377 for (
int32 ValueIndex = 0; ValueIndex < this->DataInterface.GetNumBox(); ValueIndex++, *(
uint8**)&
Box +=
BoxStride)
392 return sizeof(*this);
396 template <
typename Profile,
int32 MaxNumElementsPerNode = 16,
int32 MaxNumElementsPerLeaf = 64>
397 class TRTreeImpl :
public TImpl<Profile>
399 using FVector =
typename Profile::FVector;
400 using FBox =
typename Profile::FBox;
409 if (this->DataInterface.GetNumBox())
412 FNode* CurrentNode =
nullptr;
416 for (
int32 ElementIndex = 0; ElementIndex < this->DataInterface.GetNumBox(); ElementIndex++)
418 const FBox&
Element = this->DataInterface.GetBox(ElementIndex);
444 while (Nodes.
Num() > 1)
446 CurrentNode =
nullptr;
449 for (FNode& Node : Nodes)
461 CurrentNode = &
TopNodes.Emplace_GetRef();
486 return ForEachElementRecursive(&RootNode,
InFunc);
491 return ForEachIntersectingElementRecursive(&RootNode,
InBox,
InFunc);
512 uint32 AllocatedSize = BaseSize;
528 return AllocatedSize;
723 template <
typename Profile>
724 class TNodeSorterNoSort
727 enum { NeedSort = 0 };
728 using FBox =
typename Profile::FBox;
733 template <
typename Profile>
734 class TNodeSorterMinX
737 enum { NeedSort = 1 };
738 using FBox =
typename Profile::FBox;
743 template <
typename Profile,
int32 BucketSize>
744 class TNodeSorterMorton
747 enum { NeedSort = 1 };
748 using FBox =
typename Profile::FBox;
749 using FReal =
typename Profile::FReal;
750 using FIntPoint =
typename Profile::FIntPoint;
760 if constexpr (Profile::Is3D)
769 if constexpr (Profile::Is3D)
781 if constexpr (Profile::Is3D)
783 return FMath::MortonCode3(
Point.X) | (FMath::MortonCode3(
Point.Y) << 1) | (FMath::MortonCode3(
Point.Z) << 2);
787 return FMath::MortonCode2(
Point.X) | (FMath::MortonCode2(
Point.Y) << 1);
792 template <
typename Profile,
int32 BucketSize>
793 class TNodeSorterHilbert
796 enum { NeedSort = 1 };
797 using FBox =
typename Profile::FBox;
798 using FReal =
typename Profile::FReal;
799 using FIntPoint =
typename Profile::FIntPoint;
804 const uint32 NumBuckets = FMath::CeilToInt32(
MaxExtent / (FReal)BucketSize);
805 HilbertOrder = 1 + FMath::CeilLogTwo(NumBuckets);
810 const int32 HilbertCodeA = HilbertEncode({
int32(
A.GetCenter().X / (FReal)BucketSize),
int32(
A.GetCenter().Y / (FReal)BucketSize) }, HilbertOrder);
811 const int32 HilbertCodeB = HilbertEncode({
int32(
B.GetCenter().X / (FReal)BucketSize),
int32(
B.GetCenter().Y / (FReal)BucketSize) }, HilbertOrder);
821 for (
int32 i = Order - 1; i >= 0; i--)
825 State = (0x8fe65831 >> 2 * Row) & 3;
835template <
typename ValueType,
typename NodeSorter,
typename Profile>
839template <
typename ValueType,
typename NodeSorter,
typename Profile>
#define check(expr)
Definition AssertionMacros.h:314
@ ForceInit
Definition CoreMiscDefines.h:155
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void Init()
Definition LockFreeList.h:4
UE::Math::TIntVector2< int32 > FIntVector2
Definition MathFwd.h:91
UE::Math::TVector2< double > FVector2D
Definition MathFwd.h:48
FInt32Vector3 FIntVector
Definition MathFwd.h:115
UE::Math::TBox2< double > FBox2D
Definition MathFwd.h:56
#define UE_PI
Definition UnrealMathUtility.h:129
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition UObjectGlobals.h:2492
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_REWRITE SizeType Max() const
Definition Array.h:1161
UE_FORCEINLINE_HINT ElementType & Emplace_GetRef(ArgsType &&... Args) UE_LIFETIMEBOUND
Definition Array.h:2613
Definition AssetRegistryState.h:50
Definition AndroidPlatformMisc.h:14
Definition StaticSpatialIndex.h:837
Definition StaticSpatialIndex.h:841
Definition StaticSpatialIndex.h:174
void Init(const TArray< TPair< FBox, ValueType > > &InElements)
Definition StaticSpatialIndex.h:182
void AddReferencedObjects(FReferenceCollector &Collector)
Definition StaticSpatialIndex.h:238
virtual int32 GetNumBox() const override
Definition StaticSpatialIndex.h:250
void ForEachIntersectingElement(const FStaticSpatialIndex::FCone &InCone, Func InFunc) const
Definition StaticSpatialIndex.h:228
void ForEachIntersectingElement(const FStaticSpatialIndex::FSphere &InSphere, Func InFunc) const
Definition StaticSpatialIndex.h:217
virtual const FBox & GetBox(uint32 InIndex) const override
Definition StaticSpatialIndex.h:255
void ForEachElement(Func InFunc) const
Definition StaticSpatialIndex.h:195
void Init(TArray< TPair< FBox, ValueType > > &&InElements)
Definition StaticSpatialIndex.h:188
void ForEachIntersectingElement(const FBox &InBox, Func InFunc) const
Definition StaticSpatialIndex.h:206
virtual uint32 GetAllocatedSize() const override
Definition StaticSpatialIndex.h:266
TStaticSpatialIndex()
Definition StaticSpatialIndex.h:178
virtual const FBox * GetBoxes(uint32 InIndex, uint32 &OutStride) const override
Definition StaticSpatialIndex.h:260
UE_REWRITE void Sort(RangeType &&Range)
Definition Sort.h:16
void ForEach(InT &&Input, CallableT Callable)
Definition ForEach.h:36
void Init()
Definition LaunchIOS.cpp:473
Definition StaticSpatialIndex.h:13
bool FastSphereAABBIntersection(const typename Profile::FVector &InCenter, const typename Profile::FReal InRadiusSquared, const typename Profile::FBox &InBox)
Definition StaticSpatialIndex.h:33
bool FastConeAABBIntersection(const typename Profile::FVector &InCenter, const typename Profile::FReal InRadiusSquared, const typename Profile::FVector &InAxis, const typename Profile::FReal InAngle, const typename Profile::FReal InSinHalfAngle, const typename Profile::FReal InCosHalfAngle, const typename Profile::FBox &InBox)
Definition StaticSpatialIndex.h:63
SIZE_T GetAllocatedSize(const T &Value)
Definition ManagedArray.h:93
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
@ Element
Definition Visu.h:18
double InSphere(const double *PA, const double *PB, const double *PC, const double *PD, const double *PE)
Definition ExactPredicates.cpp:79
State
Definition PacketHandler.h:88
UE_STRING_CLASS Result(Forward< LhsType >(Lhs), RhsLen)
Definition String.cpp.inl:732
static constexpr UE_FORCEINLINE_HINT T Square(const T A)
Definition UnrealMathUtility.h:578
Definition StaticSpatialIndex.h:51
FVector::FReal Angle
Definition StaticSpatialIndex.h:59
FCone(const FVector &InCenter, const FVector &InAxis, const FVector::FReal InRadius, const FVector::FReal InAngle)
Definition StaticSpatialIndex.h:52
FVector Axis
Definition StaticSpatialIndex.h:58
Definition StaticSpatialIndex.h:15
@ Is3D
Definition StaticSpatialIndex.h:16
FVector2D::FReal FReal
Definition StaticSpatialIndex.h:17
Definition StaticSpatialIndex.h:24
FVector::FReal FReal
Definition StaticSpatialIndex.h:26
FVector FVector
Definition StaticSpatialIndex.h:27
@ Is3D
Definition StaticSpatialIndex.h:25
FBox FBox
Definition StaticSpatialIndex.h:29
Definition StaticSpatialIndex.h:40
FVector::FReal Radius
Definition StaticSpatialIndex.h:47
FSphere(const FVector &InCenter, const FVector::FReal InRadius)
Definition StaticSpatialIndex.h:41
FVector Center
Definition StaticSpatialIndex.h:46
Definition StaticSpatialIndex.h:563
uint32 Value
Definition StaticSpatialIndex.h:568
uint32 operator*() const
Definition StaticSpatialIndex.h:566
bool operator!=(const TIterator &Other) const
Definition StaticSpatialIndex.h:567
uint32 operator++()
Definition StaticSpatialIndex.h:565
TIterator(uint32 InValue)
Definition StaticSpatialIndex.h:564
Definition StaticSpatialIndex.h:539
uint32 Num() const
Definition StaticSpatialIndex.h:559
uint32 GetAllocatedSize() const
Definition StaticSpatialIndex.h:560
uint32 StartIndex
Definition StaticSpatialIndex.h:540
FLeafType()
Definition StaticSpatialIndex.h:543
uint32 NumElements
Definition StaticSpatialIndex.h:541
TIterator begin()
Definition StaticSpatialIndex.h:571
void Add(uint32 InIndex)
Definition StaticSpatialIndex.h:548
TIterator end()
Definition StaticSpatialIndex.h:573
TIterator begin() const
Definition StaticSpatialIndex.h:572
TIterator end() const
Definition StaticSpatialIndex.h:574
Definition StaticSpatialIndex.h:536
FVectorType BoxMax
Definition StaticSpatialIndex.h:582
FVectorType BoxMin
Definition StaticSpatialIndex.h:581
FBoxType GetBox() const
Definition StaticSpatialIndex.h:579
TVariant< FNodeType, FLeafType > Content
Definition StaticSpatialIndex.h:584
typename Profile::FVector FVectorType
Definition StaticSpatialIndex.h:576
typename Profile::FBox FBoxType
Definition StaticSpatialIndex.h:577
Definition ObjectPtr.h:1323
Definition OverrideVoidReturnInvoker.h:16
Definition StaticSpatialIndex.h:164
virtual ~TStaticSpatialIndexDataInterface()
Definition StaticSpatialIndex.h:165
virtual int32 GetNumBox() const =0
virtual const Profile::FBox * GetBoxes(uint32 InIndex, uint32 &OutStride) const =0
virtual const Profile::FBox & GetBox(uint32 InIndex) const =0
virtual uint32 GetAllocatedSize() const =0
void Init()
Definition Box.h:441
IntType X
Definition IntPoint.h:34
static UE_FORCEINLINE_HINT double DotProduct(const TVector2< double > &A, const TVector2< double > &B)
Definition Vector2D.h:929
static UE_FORCEINLINE_HINT double CrossProduct(const TVector2< double > &A, const TVector2< double > &B)
Definition Vector2D.h:947
double FReal
Definition Vector2D.h:42
double FReal
Definition Vector.h:55