47template <
class TriangleMeshType>
153 NumObjects.fetch_add(1, std::memory_order_relaxed);
189 int32 i =
Num.fetch_add(1, std::memory_order_relaxed);;
196 for (
int32 i = 0; i < NumBlocks; ++i)
206 for (
int32 i = 0; i < NumBlocks; ++i)
416 template <
typename FunctorType>
420 for (ijk[2] = start[2]; ijk[2] <=
inclusive_end[2]; ++ijk[2])
422 for (ijk[1] = start[1]; ijk[1] <=
inclusive_end[1]; ++ijk[1])
424 for (ijk[0] = start[0]; ijk[0] <=
inclusive_end[0]; ++ijk[0])
439 float upper_bound(
const FVector3i&
GridDimensions,
float DX)
const
466 const int32 ElemCount = FloatBlockData3Type::ElemCount;
467 for (
int32 LocalIndex = 0; LocalIndex < ElemCount; ++LocalIndex)
486 const int32 NumBlocks = Distances.GetNumBlocks();
491 if (!Distances.IsBlockAllocated(
BlockIJK))
493 const FVector3i BlockOrigin = FloatBlockData3Type::BlockSize * BlockIJK;
494 const FVector3d BlockOriginPos((float)BlockOrigin.X * DX + Origin.X, (float)BlockOrigin.Y * DX + Origin.Y, (float)BlockOrigin.Z * DX + Origin.Z);
495 const FVector3d Pos = BlockOriginPos + BlockCenter;
496 if (this->IsInsideFunction(Pos))
498 Distances.ProcessBlockDefaultValue(BlockIJK, [](float& value) {value = -value; });
524 const double invdx = 1.0 / DX;
525 const FVector3d org((
double)Origin[0], (
double)Origin[1], (
double)Origin[2]);
552 if (!Mesh->IsTriangle(TID)) return;
554 FVector3i& BoxMin = TriBBoxes.GetData()[TID].BoxMin;
555 FVector3i& BoxMax = TriBBoxes.GetData()[TID].BoxMax;
556 ComputeTriBoundingBox(TID, BoxMin, BoxMax);
565 bool bCancel =
false;
582 bCancel = this->CancelF();
601 }, !this->bUseParallel);
619 bCancel = this->CancelF();
638 }, !this->bUseParallel);
667 const double invdx = 1.0 / DX;
668 const FVector3d org((
double)Origin[0], (
double)Origin[1], (
double)Origin[2]);
714 [&](
const FVector3i& ijk)
716 const FVector3i local_coords = ijk - BlockMin;
717 const int32 local_index = DistanceBlock.ToLinear(local_coords[0], local_coords[1], local_coords[2]);
718 const FVector3d cellpos((double)ijk[0], (double)ijk[1], (double)ijk[2]);
719 float d = float(DX * PointTriangleDistance(cellpos, fp, fq, fr));
721 float& grid_dist = DistanceBlock.At(local_index);
725 ClosestTriBlock.At(local_index) = TID;
730 }, !this->bUseParallel);
779 FBlockedGrid3b::BlockData3Type
BitBlock(
false, -1);
798 [&](
const FVector3i& ijk)
800 const FVector3i local_coords = ijk - BlockMin;
801 const int32 local_index = DistanceBlock.ToLinear(local_coords[0], local_coords[1], local_coords[2]);
802 BitBlock.At(local_index) = true;
823 const float dist = (
float)FMath::Sqrt(
dsqr);
831 }, !this->bUseParallel);
846 const double invdx = 1.0 / DX;
873 bool bCancel =
false;
876 const double ox = (double)Origin[0], oy = (double)Origin[1], oz = (double)Origin[2];
877 const double invdx = 1.0 / DX;
879 if (!Mesh->IsVertex(VID))
885 bCancel = this->CancelF();
902 }, !this->bUseParallel);
964 const float dist = (
float)FMath::Sqrt(
dsqr);
1001 const float dist = (
float)FMath::Sqrt(
dsqr);
1023 !this->bUseParallel);
1038 void CleanupUnwanted()
1040 if (!bWantClosestTriGrid)
1042 ClosestTriGrid.
Reset();
1045 if (!bWantIntersectionsGrid)
1047 IntersectionsGrid.
Reset();
1058 struct FAtomicGrid3i :
public TBlockedGrid3Layout<FBlockedGrid3f::BlockSize>
1061 typedef TBlockedGrid3Layout<FBlockedGrid3f::BlockSize> MyLayout;
1064 : MyLayout(
Grid3f.GetDimensions())
1067 Blocks.SetNum(NumBlocks);
1071 if (
Grid3f.GetBlockData(i).IsValid())
1073 Blocks[i] = MakeUnique<BlockAtomicData>();
1074 BlockAtomicData& Data= *Blocks[i];
1075 for (int32 j = 0; j < FBlockedGrid3i::BlockElemCount; ++j)
1085 bool bCancel=
false;
1092 double ox = (double)Origin[0], oy = (double)Origin[1], oz = (double)Origin[2];
1093 double invdx = 1.0 / DX;
1095 if (!Mesh->IsTriangle(TID))
1099 if (
TID % 100 == 0 && CancelF() ==
true)
1113 if (InsideMode == EInsideModes::WindingCount)
1138 std::atomic<int32>& value =
ABlock[LocalIndex];
1141 value.fetch_sub(1, std::memory_order_relaxed);
1145 value.fetch_add(1, std::memory_order_relaxed);
1150 for (
int K = k0; K <= k1; ++K)
1152 for (
int J =
j0; J <=
j1; ++J)
1155 if (
PointInTriangle2d(J, K,
fjp,
fkp,
fjq,
fkq,
fjr,
fkr,
A,
B,
C))
1174 }, !this->bUseParallel);
1185 FVector3i BlockIJK = AtomicGrid3i.BlockIndexToBlockIJK(blockid);
1186 FBlockedGrid3i::BlockData3Type& BlockData = IntersectionCountGrid.TouchBlockData(BlockIJK);
1187 const typename FAtomicGrid3i::BlockAtomicData& AtomicBlockData = *AtomicBlockPtr;
1189 for (int32 j = 0; j < FBlockedGrid3i::BlockElemCount; ++j)
1191 const int32 Count = AtomicBlockData[j];
1192 BlockData.At(j) = Count;
1199 }, !this->bUseParallel);
1208 bool bCancel =
false;
1210 const FVector3i
BlockDims = Distances.GetBlockDimensions();
1214 const FVector3i GridDims = Distances.GetDimensions();
1215 if (BlockRowID % 10 == 0 && CancelF() == true)
1225 constexpr int32 BlockSize = FBlockedGrid3f::BlockSize;
1227 for (
int32 i = 0, I = BlockSize * BlockSize; i < I; ++i)
1238 if (Distances.IsBlockAllocated(
BlockIJK))
1247 for (
int32 k = 0; k < BlockSize; ++k)
1249 for (
int32 j = 0; j < BlockSize; ++j)
1253 for (
int32 i = 0; i < BlockSize; ++i)
1255 const int32 LocalIndex = TBlockData3Layout<BlockSize>::ToLinear(i, j, k);
1260 (InsideMode == EInsideModes::WindingCount && total_count > 0) ||
1261 (InsideMode == EInsideModes::CrossingCount && total_count % 2 == 1)
1289 (InsideMode == EInsideModes::WindingCount && total_count > 0) ||
1290 (InsideMode == EInsideModes::CrossingCount && total_count % 2 == 1)
1306 case (BlockSize * BlockSize):
1310 Distances.ProcessBlockDefaultValue(
BlockIJK, [](
float& value) {value = -FMath::Abs(value); });
1318 for (
int32 k = 0; k < BlockSize; ++k)
1320 for (
int32 j = 0; j < BlockSize; ++j)
1324 for (
int32 i = 0; i < BlockSize; ++i)
1326 const int32 LocalIndex = TBlockData3Layout<BlockSize>::ToLinear(i, j, k);
1329 (InsideMode == EInsideModes::WindingCount && total_count > 0) ||
1330 (InsideMode == EInsideModes::CrossingCount && total_count % 2 == 1)
1348 }, !this->bUseParallel);
1353 for (
int K = 0; K <
NK; ++K)
1360 for (
int J = 0; J <
NJ; ++J)
1362 int total_count = 0;
1363 for (
int I = 0; I <
NI; ++I)
1367 (InsideMode == EInsideModes::WindingCount && total_count > 0) ||
1368 (InsideMode == EInsideModes::CrossingCount && total_count % 2 == 1)
1372 Distances.ProcessValue(I, J, K, [](
float& value){value = -value;});
#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
UE::Math::TVector< float > FVector3f
Definition MathFwd.h:73
const bool
Definition NetworkReplayStreaming.h:178
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
int BlockIndex
Definition binka_ue_decode_test.cpp:38
if(Failed) console_printf("Failed.\n")
UE_FORCEINLINE_HINT SizeType AddUninitialized()
Definition Array.h:1664
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
void SetNum(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2308
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition AndroidPlatformMisc.h:14
Definition StaticArray.h:26
Definition FunctionFwd.h:19
Definition UniquePtr.h:107
void Reset(T *InPtr=nullptr)
Definition UniquePtr.h:346
bool PreAllocateFromSourceGrid(const TBasicBlockedDenseGrid3< OtherElemType, BlockSize > &SourceGrid)
Definition BlockedDenseGrid3.h:383
ElemType GetValue(int32 I, int32 J, int32 K) const
Definition BlockedDenseGrid3.h:319
void Reset()
Definition BlockedDenseGrid3.h:301
Definition BlockedLayout3.h:50
const FVector3i & GetDimensions() const
Definition BlockedLayout3.h:89
const FVector3i & GetBlockDimensions() const
Definition BlockedLayout3.h:97
TUniquePtr< BlockData3Type > & GetBlockData(const FVector3i &BlockIJK)
Definition BlockedDenseGrid3.h:632
BlockData3Type & TouchBlockData(const FVector3i &BlockIJK)
Definition BlockedDenseGrid3.h:622
TBlockData3< float, BlockSize_ > BlockData3Type
Definition BlockedDenseGrid3.h:436
static constexpr int32 BlockSize
Definition BlockedDenseGrid3.h:439
Definition MeshAABBTree3.h:61
virtual int FindNearestTriangle(const FVector3d &P, double &NearestDistSqr, const FQueryOptions &Options=FQueryOptions()) const override
Definition MeshAABBTree3.h:159
Definition SparseNarrowBandMeshSDF.h:49
const TriangleMeshType * Mesh
Definition SparseNarrowBandMeshSDF.h:53
FVector3i Dimensions() const
Definition SparseNarrowBandMeshSDF.h:368
float operator[](const FVector3i &ijk) const
Definition SparseNarrowBandMeshSDF.h:394
EInsideModes InsideMode
Definition SparseNarrowBandMeshSDF.h:102
FVector3f GridOrigin
Definition SparseNarrowBandMeshSDF.h:119
int ApproxMaxCellsPerDimension
Definition SparseNarrowBandMeshSDF.h:72
EComputeModes
Definition SparseNarrowBandMeshSDF.h:76
@ NarrowBandOnly
Definition SparseNarrowBandMeshSDF.h:77
@ NarrowBand_SpatialFloodFill
Definition SparseNarrowBandMeshSDF.h:78
TMeshAABBTree3< TriangleMeshType > * Spatial
Definition SparseNarrowBandMeshSDF.h:54
bool bComputeSigns
Definition SparseNarrowBandMeshSDF.h:89
TUniqueFunction< bool(const FVector3d &)> IsInsideFunction
Definition SparseNarrowBandMeshSDF.h:55
bool bWantClosestTriGrid
Definition SparseNarrowBandMeshSDF.h:106
const FBlockedGrid3i & GetClosestTriGrid() const
Definition SparseNarrowBandMeshSDF.h:374
FBlockedGrid3f Grid
Definition SparseNarrowBandMeshSDF.h:120
double NarrowBandMaxDistance
Definition SparseNarrowBandMeshSDF.h:86
int ExactBandWidth
Definition SparseNarrowBandMeshSDF.h:62
TTriLinearGridInterpolant< TSparseNarrowBandMeshSDF > MakeInterpolant()
Definition SparseNarrowBandMeshSDF.h:258
float CellSize
Definition SparseNarrowBandMeshSDF.h:58
static bool ShouldUseSpatial(int32 ExactCells, double CellSize, double AvgEdgeLen)
Definition SparseNarrowBandMeshSDF.h:272
const FBlockedGrid3i & GetIntersectionsGrid() const
Definition SparseNarrowBandMeshSDF.h:381
EInsideModes
Definition SparseNarrowBandMeshSDF.h:98
@ WindingCount
Definition SparseNarrowBandMeshSDF.h:100
@ CrossingCount
Definition SparseNarrowBandMeshSDF.h:99
TSparseNarrowBandMeshSDF(const TriangleMeshType *Mesh=nullptr, float CellSize=1.f, TMeshAABBTree3< TriangleMeshType > *Spatial=nullptr)
Definition SparseNarrowBandMeshSDF.h:250
float At(int32 I, int32 J, int32 K) const
Definition SparseNarrowBandMeshSDF.h:388
bool bUseParallel
Definition SparseNarrowBandMeshSDF.h:69
EComputeModes ComputeMode
Definition SparseNarrowBandMeshSDF.h:80
FBlockedGrid3i ClosestTriGrid
Definition SparseNarrowBandMeshSDF.h:124
TFunction< bool()> CancelF
Definition SparseNarrowBandMeshSDF.h:112
FVector3f CellCenter(int32 I, int32 J, int32 K) const
Definition SparseNarrowBandMeshSDF.h:406
bool bWantIntersectionsGrid
Definition SparseNarrowBandMeshSDF.h:109
float GetValue(const FVector3i &ijk) const
Definition SparseNarrowBandMeshSDF.h:400
bool Compute(FAxisAlignedBox3d Bounds)
Definition SparseNarrowBandMeshSDF.h:301
bool Validate(const FAxisAlignedBox3d &Bounds)
Definition SparseNarrowBandMeshSDF.h:279
FVector3d ExpandBounds
Definition SparseNarrowBandMeshSDF.h:66
FBlockedGrid3i IntersectionsGrid
Definition SparseNarrowBandMeshSDF.h:126
Definition GridInterpolant.h:29
constexpr int InvalidID
Definition IndexTypes.h:13
Definition IndexUtil.h:18
GEOMETRYCORE_API const FVector3i GridOffsets26[26]
Definition IndexUtil.cpp:32
void AtomicIncDec(FDenseGrid2i &Grid, int32 i, int32 j, bool bDecrement=false)
Definition DenseGrid2.h:207
constexpr T MaxElement(const UE::Math::TVector< T > &Vector)
Definition VectorTypes.h:298
TBlockedGrid3< bool, 8 > FBlockedGrid3b
Definition BlockedDenseGrid3.h:718
TBlockedGrid3< int, 8 > FBlockedGrid3i
Definition BlockedDenseGrid3.h:715
GEOMETRYCORE_API bool PointInTriangle2d(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3, double &A, double &B, double &C)
Definition SDFCalculationUtils.cpp:84
TBlockedGrid3< float, 8 > FBlockedGrid3f
Definition BlockedDenseGrid3.h:713
Definition AdvancedWidgetsModule.cpp:13
float v
Definition radaudio_mdct.cpp:62
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592
static constexpr UE_FORCEINLINE_HINT T Min3(const T A, const T B, const T C)
Definition UnrealMathUtility.h:558
static constexpr UE_FORCEINLINE_HINT T Max3(const T A, const T B, const T C)
Definition UnrealMathUtility.h:551
Definition IntVectorTypes.h:252
TVector< RealType > Max
Definition BoxTypes.h:249
bool IsEmpty() const
Definition BoxTypes.h:613
RealType MaxDim() const
Definition BoxTypes.h:598
TVector< RealType > Min
Definition BoxTypes.h:248
Definition SparseNarrowBandMeshSDF.h:134
void AtomicIncrement(const int32 BlockIndex)
Definition SparseNarrowBandMeshSDF.h:150
FScatterCounter(const FVector3i &Dims, bool bInitParallel)
Definition SparseNarrowBandMeshSDF.h:136
TArray< std::atomic< int > > NumObjectsPerBlock
Definition SparseNarrowBandMeshSDF.h:156
TBlockedGrid3Layout< FBlockedGrid3f::BlockSize > MyLayout
Definition SparseNarrowBandMeshSDF.h:135
Definition SparseNarrowBandMeshSDF.h:221
FVector3i BoxMax
Definition SparseNarrowBandMeshSDF.h:223
FVector3i BoxMin
Definition SparseNarrowBandMeshSDF.h:222
void Clamp(const FVector3i &OtherMin, const FVector3i &OtherMax)
Definition SparseNarrowBandMeshSDF.h:231
bool IsValid() const
Definition SparseNarrowBandMeshSDF.h:225
Definition SparseNarrowBandMeshSDF.h:161
TBlockedGrid3Layout< FBlockedGrid3f::BlockSize > MyLayout
Definition SparseNarrowBandMeshSDF.h:162
TArray< TArray< int32 > > TrisInBlock
Definition SparseNarrowBandMeshSDF.h:217
FTriIDBlockGrid(const FScatterCounter &TriCounter, bool bInitParallel)
Definition SparseNarrowBandMeshSDF.h:164
TArray< int32 > GetOccupiedBlockIDs() const
Definition SparseNarrowBandMeshSDF.h:192
void AddTriID(const int32 &BlockIndex, const int32 &TriId)
Definition SparseNarrowBandMeshSDF.h:184
TArray< std::atomic< int > > PerBlockNum
Definition SparseNarrowBandMeshSDF.h:216
static TVector< float > One()
Definition Vector.h:115
T Z
Definition Vector.h:68
static TVector< double > Zero()
Definition Vector.h:112
T Y
Definition Vector.h:65
T X
Definition Vector.h:62