75 ((ChildIndex & 1) != 0) ? 1 : 0,
76 ((ChildIndex & 2) != 0) ? 1 : 0,
77 ((ChildIndex & 4) != 0) ? 1 : 0);
328 double Divisor = (
double)( (
uint64)1 << (Level & 0x1F) );
436 this->MaxTreeDepth = 2;
440 this->MaxTreeDepth = 3;
445 this->MaxTreeDepth = 4;
450 this->MaxTreeDepth = 5;
456 this->MaxPointsPerCell = 250;
600 for (
int32 k = 0; k < MaxPointID; ++k)
660 FSparsePointOctreeCell& RootCell = *RootCellPtrs[Index];
663 TArray<TArray<FParentChildCell>> LevelCells;
664 LevelCells.SetNum(MaxTreeDepth);
667 TDynamicVector<int>& PointIndices = *RootCellPointIndices[Index];
668 for ( int32 PointIndex : PointIndices)
670 int32 PointID = PointInfos[PointIndex].PointID;
671 FVector3d Position = GetPositionFunc(PointID);
674 int32 LastInsertIndex = 0;
675 FSparsePointOctreeCell CurrentCell = RootCell;
676 while (CurLevel < MaxTreeDepth)
678 int ChildIndex = ToChildCellIndex(CurrentCell, Position);
679 FSparsePointOctreeCell NextLevelCell = CurrentCell.MakeChildCell(ChildIndex);
680 LastInsertIndex = LevelCells[CurLevel].AddUnique( FParentChildCell{ CurrentCell.Index, NextLevelCell.Index, ChildIndex, 0, InvalidCellID } );
682 CurrentCell = NextLevelCell;
685 PointInfos[PointIndex].LeafCellIndex = LastInsertIndex;
686 LevelCells[CurLevel-1][LastInsertIndex].NumPoints++;
770void FSparseDynamicPointOctree3::InsertPoint_DynamicExpand(
774 if (ContainsPoint(PointID))
823 InsertToChildLocalFunc(MovePointID);
837bool FSparseDynamicPointOctree3::RemovePoint(
int32 PointID)
839 if (ContainsPoint(PointID) ==
false)
844 uint32 CellID = GetCellForPoint(PointID);
845 if (CellID == InvalidCellID)
850 PointIDToCellMap[PointID] = InvalidCellID;
858void FSparseDynamicPointOctree3::RemovePointUnsafe(
int32 PointID)
860 uint32 CellID = PointIDToCellMap[PointID];
861 if (CellID != InvalidCellID)
863 PointIDToCellMap[PointID] = InvalidCellID;
864 CellPointLists.
Remove(CellID, PointID);
873 if (ContainsPoint(PointID))
875 uint32 CellID = GetCellForPoint(PointID);
876 if (CellID != InvalidCellID)
887 RemovePoint(PointID);
900 if (FIntrRay3AxisAlignedBox3d::FindIntersection(Ray,
Box,
ray_t))
913int32 FSparseDynamicPointOctree3::FindNearestHitPoint(
const FRay3d& Ray,
936 while (Queue.
Num() > 0)
953 for (
int k = 0; k < 8; ++k)
976void FSparseDynamicPointOctree3::RangeQuery(
984 (TempBuffer ==
nullptr) ? InternalBuffer : *TempBuffer;
996 while (Queue.
Num() > 0)
1005 if (PredicateFunc(PointID))
1007 PointIDs.Add(PointID);
1012 for (
int k = 0; k < 8; ++k)
1017 if (GetCellBox(*ChildCell).Intersects(Bounds))
1031void FSparseDynamicPointOctree3::ParallelRangeQuery(
1039 (TempBuffer ==
nullptr) ? InternalBuffer : *TempBuffer;
1055 const FSparsePointOctreeCell* RootCell = ProcessRootCells[idx];
1056 TArray<const FSparsePointOctreeCell*, TInlineAllocator<128>> Queue;
1057 Queue.Add(RootCell);
1059 TArray<int, TInlineAllocator<256>> LocalPointIDs;
1061 while (Queue.Num() > 0)
1063 const FSparsePointOctreeCell* CurCell = Queue.Pop(EAllowShrinking::No);
1066 CellPointLists.Enumerate(CurCell->CellID, [&](int PointID)
1068 if (PredicateFunc(PointID))
1070 LocalPointIDs.Add(PointID);
1074 for (int k = 0; k < 8; ++k)
1076 if (CurCell->HasChild(k))
1078 const FSparsePointOctreeCell* ChildCell = &Cells[CurCell->GetChildCellID(k)];
1079 if (GetCellBox(*ChildCell).Intersects(Bounds))
1081 Queue.Add(ChildCell);
1090 for (int ObjID : LocalPointIDs )
1092 PointIDs.Add(ObjID);
1094 OutputLock.Unlock();
1151void FSparseDynamicPointOctree3::CheckValidity(
1163 if (
FailMode == EValidityCheckFailMode::Check)
1167 checkf(b,
TEXT(
"FSparseDynamicPointOctree3::CheckValidity failed!"));
1171 else if (
FailMode == EValidityCheckFailMode::Ensure)
1175 ensureMsgf(b,
TEXT(
"FSparseDynamicPointOctree3::CheckValidity failed!"));
1204 uint32 CellID = PointIDToCellMap[PointID];
1211 if (CellID == InvalidCellID)
1233 MaxLevel = FMath::Max(MaxLevel,
Cell.Level);
1239 for (
uint32 k = 0; k <= MaxLevel; ++k)
1274FString FSparseDynamicPointOctree3::FStatistics::ToString()
const
1276 FString Result = FString::Printf(
1277 TEXT(
"Levels %2d\r\n"), Levels);
1278 for (
int k = 0; k < Levels; ++k)
1280 Result += FString::Printf(
TEXT(
" Level %2d: Cells %8d Objs %8d AvgObjs %5.3f MaxObjs %8d Dimension %5.5f\r\n"),
1281 k, LevelBoxCounts[k], LevelObjCounts[k], ((
float)LevelObjCounts[k] / (
float)LevelBoxCounts[k]), LevelMaxObjCounts[k], LevelCellSizes[k] );
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
#define ensure( InExpression)
Definition AssertionMacros.h:464
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
void ParallelFor(int32 Num, TFunctionRef< void(int32)> Body, bool bForceSingleThread, bool bPumpRenderingThread=false)
Definition ParallelFor.h:481
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
UE::Math::TVector< double > FVector3d
Definition MathFwd.h:60
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
UE_FORCEINLINE_HINT TUniquePtr< T > MakeUnique(TArgs &&... Args)
Definition UniquePtr.h:918
if(Failed) console_printf("Failed.\n")
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
void SetNum(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2308
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
void Init(const ElementType &Element, SizeType Number)
Definition Array.h:3043
UE_NODEBUG UE_FORCEINLINE_HINT bool Find(const ElementType &Item, SizeType &Index) const
Definition Array.h:1302
ElementType Pop(EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:1196
void SetNumUninitialized(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2369
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition AssetRegistryState.h:50
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
static RealType Floor(const RealType Value)
Definition MathUtil.h:384
Definition StaticArray.h:26
Definition RefCountVector.h:25
bool IsValid(int Index) const
Definition RefCountVector.h:66
int Allocate()
Definition RefCountVector.h:102
IndexEnumerable Indices() const
Definition RefCountVector.h:458
Definition SparseDynamicPointOctree3.h:107
FSparsePointOctreeCell FindCurrentContainingCell(const FVector3d &Position) const
Definition SparseDynamicPointOctree3.h:1107
FRefCountVector CellRefCounts
Definition SparseDynamicPointOctree3.h:311
int MaxPointsPerCell
Definition SparseDynamicPointOctree3.h:137
void RemovePointUnsafe(int32 PointID)
Definition SparseDynamicPointOctree3.h:858
FAxisAlignedBox3d GetCellBox(uint32 Level, const FVector3i &Index) const
Definition SparseDynamicPointOctree3.h:334
TDynamicVector< uint32 > PointIDToCellMap
Definition SparseDynamicPointOctree3.h:318
FVector3d GetCellCenter(const FSparsePointOctreeCell &Cell) const
Definition SparseDynamicPointOctree3.h:358
int ToChildCellIndex(const FSparsePointOctreeCell &Cell, const FVector3d &Position) const
Definition SparseDynamicPointOctree3.h:393
uint32 GetCellForPoint(int32 PointID) const
Definition SparseDynamicPointOctree3.h:404
double GetCellWidth(uint32 Level) const
Definition SparseDynamicPointOctree3.h:326
TDynamicVector< FSparsePointOctreeCell > Cells
Definition SparseDynamicPointOctree3.h:314
void ParallelInsertDensePointSet(int32 MaxPointID, TFunctionRef< FVector3d(int)> GetPositionFunc)
Definition SparseDynamicPointOctree3.h:567
void ConfigureFromPointCountEstimate(double MaxBoundsDimension, int CountEstimate)
Definition SparseDynamicPointOctree3.h:430
GEOMETRYCORE_API int32 FindClosestPoint(FVector3d QueryPt, double DistanceThreshold, TFunctionRef< bool(int32)> PredicateFunc, TFunctionRef< double(int32)> DistSqFunc, TArray< const FSparsePointOctreeCell * > *TempBuffer=nullptr) const
Definition SparseDynamicPointOctree3.cpp:154
TSparseListSet< int32 > CellPointLists
Definition SparseDynamicPointOctree3.h:316
int ToChildCellIndex(uint32 Level, const FVector3i &Index, const FVector3d &Position) const
Definition SparseDynamicPointOctree3.h:384
FVector3d GetCellCenter(uint32 Level, const FVector3i &Index) const
Definition SparseDynamicPointOctree3.h:349
void ComputeStatistics(FStatistics &StatsOut) const
Definition SparseDynamicPointOctree3.h:1249
void InsertPoint(int32 PointID, const FVector3d &Position)
Definition SparseDynamicPointOctree3.h:466
void CheckValidity(TFunctionRef< bool(int)> IsValidPointIDFunc, TFunctionRef< FVector3d(int)> GetPointFunc, EValidityCheckFailMode FailMode=EValidityCheckFailMode::Check, bool bVerbose=false, bool bFailOnMissingPoints=false) const
Definition SparseDynamicPointOctree3.h:1151
static constexpr uint32 InvalidCellID
Definition SparseDynamicPointOctree3.h:307
void FindKClosestPoints(FVector3d QueryPt, double DistanceThreshold, int32 NumToFind, TArray< TPair< int32, double > > &FoundPoints, TFunctionRef< bool(int32)> PredicateFunc, TFunctionRef< double(int32)> DistSqFunc, TArray< const FSparsePointOctreeCell * > *TempBuffer=nullptr) const
Definition SparseDynamicPointOctree3.cpp:66
double FindNearestRayCellIntersection(const FSparsePointOctreeCell &Cell, const FRay3d &Ray) const
Definition SparseDynamicPointOctree3.h:896
bool ContainsPoint(int32 PointID) const
Definition SparseDynamicPointOctree3.h:460
FAxisAlignedBox3d GetCellBox(const FSparsePointOctreeCell &Cell) const
Definition SparseDynamicPointOctree3.h:344
void RangeQuery(const FAxisAlignedBox3d &Bounds, TFunctionRef< bool(int)> PredicateFunc, TArray< int > &PointIDsOut, TArray< const FSparsePointOctreeCell * > *TempBuffer=nullptr) const
Definition SparseDynamicPointOctree3.h:976
void ReinsertPoint(int32 PointID, const FVector3d &NewPosition)
Definition SparseDynamicPointOctree3.h:871
double RootDimension
Definition SparseDynamicPointOctree3.h:126
uint32 CreateNewRootCell(FSparsePointOctreeCell NewRootCell, bool bInitializeCellPointList)
Definition SparseDynamicPointOctree3.h:548
void Insert_ToCell(int32 PointID, const FVector3d &Position, const FSparsePointOctreeCell &ExistingCell)
Definition SparseDynamicPointOctree3.h:526
int MaxTreeDepth
Definition SparseDynamicPointOctree3.h:131
void ParallelRangeQuery(const FAxisAlignedBox3d &Bounds, TFunctionRef< bool(int)> PredicateFunc, TArray< int > &PointIDsOut, TArray< const FSparsePointOctreeCell * > *TempBuffer=nullptr) const
Definition SparseDynamicPointOctree3.h:1031
bool RemovePoint(int32 PointID)
Definition SparseDynamicPointOctree3.h:837
int32 FindNearestHitPoint(const FRay3d &Ray, TFunctionRef< double(int, const FRay3d &)> HitPointDistFunc, double MaxDistance=TNumericLimits< double >::Max()) const
Definition SparseDynamicPointOctree3.h:913
FVector3i PointToIndex(uint32 Level, const FVector3d &Position) const
Definition SparseDynamicPointOctree3.h:364
void InsertPoint_DynamicExpand(int32 PointID, TFunctionRef< FVector3d(int)> GetPositionFunc)
Definition SparseDynamicPointOctree3.h:770
void Insert_NewRoot(int32 PointID, const FVector3d &Position, FSparsePointOctreeCell NewRootCell)
Definition SparseDynamicPointOctree3.h:540
bool CellContains(const FSparsePointOctreeCell &Cell, const FVector3d &Position) const
Definition SparseDynamicPointOctree3.h:398
void Insert_NewChildCell(int32 PointID, const FVector3d &Position, int ParentCellID, FSparsePointOctreeCell NewChildCell, int ChildIdx)
Definition SparseDynamicPointOctree3.h:504
TSparseGrid3< uint32 > RootCells
Definition SparseDynamicPointOctree3.h:322
Definition DynamicVector.h:27
void InsertAt(const Type &Data, unsigned int Index)
Definition DynamicVector.h:747
size_t Num() const
Definition DynamicVector.h:147
void SetNum(unsigned int Count)
Definition DynamicVector.h:143
Definition SparseGrid3.h:27
void AllocatedIteration(Func ElementFunc) const
Definition SparseGrid3.h:176
const ElemType * Get(const FVector3i &Index) const
Definition SparseGrid3.h:85
void RangeIteration(FVector3i MinIndex, FVector3i MaxIndex, Func ElementFunc) const
Definition SparseGrid3.h:190
bool Has(const FVector3i &Index) const
Definition SparseGrid3.h:74
TAxisAlignedBox3< double > FAxisAlignedBox3d
Definition BoxTypes.h:885
EValidityCheckFailMode
Definition GeometryTypes.h:72
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592
Definition NumericLimits.h:41
Definition SparseDynamicPointOctree3.h:291
FString ToString() const
Definition SparseDynamicPointOctree3.h:1274
int32 Levels
Definition SparseDynamicPointOctree3.h:292
TArray< int32 > LevelMaxObjCounts
Definition SparseDynamicPointOctree3.h:295
TArray< int32 > LevelObjCounts
Definition SparseDynamicPointOctree3.h:294
TArray< float > LevelCellSizes
Definition SparseDynamicPointOctree3.h:296
TArray< int32 > LevelBoxCounts
Definition SparseDynamicPointOctree3.h:293
Definition SparseDynamicPointOctree3.h:27
bool HasChild(int ChildIndex) const
Definition SparseDynamicPointOctree3.h:62
uint8 Level
Definition SparseDynamicPointOctree3.h:35
FSparsePointOctreeCell MakeChildCell(int ChildIndex) const
Definition SparseDynamicPointOctree3.h:72
bool IsExistingCell() const
Definition SparseDynamicPointOctree3.h:57
FVector3i Index
Definition SparseDynamicPointOctree3.h:38
static constexpr uint32 InvalidID
Definition SparseDynamicPointOctree3.h:28
TStaticArray< uint32, 8 > Children
Definition SparseDynamicPointOctree3.h:41
static constexpr uint8 InvalidLevel
Definition SparseDynamicPointOctree3.h:29
void SetChild(uint32 ChildIndex, const FSparsePointOctreeCell &ChildCell)
Definition SparseDynamicPointOctree3.h:81
FSparsePointOctreeCell(uint8 LevelIn, const FVector3i &IndexIn)
Definition SparseDynamicPointOctree3.h:50
FSparsePointOctreeCell()
Definition SparseDynamicPointOctree3.h:43
uint32 CellID
Definition SparseDynamicPointOctree3.h:32
uint32 GetChildCellID(int ChildIndex) const
Definition SparseDynamicPointOctree3.h:67
Definition IntVectorTypes.h:252
bool Contains(const TVector< RealType > &V) const
Definition BoxTypes.h:492
TVector< RealType > Max
Definition BoxTypes.h:249
TVector< RealType > Min
Definition BoxTypes.h:248
Definition SparseListSet.h:39
bool Remove(int32 ListIndex, ElementType Value)
Definition SparseListSet.h:325
void SetValues(int32 ListIndex, const TArray< ElementType > &Values)
Definition SparseListSet.h:111
void Clear(int32 ListIndex)
Definition SparseListSet.h:138
FListHandle AllocateAt(int32 ListIndex)
Definition SparseListSet.h:79
void Insert(int32 ListIndex, ElementType Value)
Definition SparseListSet.h:92
bool IsAllocated(int32 ListIndex) const
Definition SparseListSet.h:64
int32 GetCount(int32 ListIndex) const
Definition SparseListSet.h:149
bool Contains(int32 ListIndex, ElementType Value) const
Definition SparseListSet.h:386
void Enumerate(int32 ListIndex, FuncType Func) const
Definition SparseListSet.h:168