Skip to content

Commit

Permalink
Merge pull request #73 from Nebukam/edge-refinements-tweaks
Browse files Browse the repository at this point in the history
Edge refinements tweaks
  • Loading branch information
Nebukam authored Oct 9, 2024
2 parents be61c09 + 306ec07 commit 183787b
Show file tree
Hide file tree
Showing 138 changed files with 2,361 additions and 1,244 deletions.
12 changes: 11 additions & 1 deletion Config/DefaultPCGExtendedToolkit.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@
+PropertyRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExPointPointIntersectionDetails.IsPointCompoundAttributeName",NewName="/Script/PCGExtendedToolkit.PCGExPointPointIntersectionDetails.IsPointUnionAttributeName")
+PropertyRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExPointPointIntersectionDetails.bWritePointCompoundSize",NewName="/Script/PCGExtendedToolkit.PCGExPointPointIntersectionDetails.bWritePointUnionSize")
+PropertyRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExPointPointIntersectionDetails.PointCompoundSizeAttributeName",NewName="/Script/PCGExtendedToolkit.PCGExPointPointIntersectionDetails.PointUnionSizeAttributeName")
+ClassRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExEdgeRemoveLineTrace",NewName="/Script/PCGExtendedToolkit.PCGExEdgeRefineLineTrace")
+ClassRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExEdgeRemoveLineTrace",NewName="/Script/PCGExtendedToolkit.PCGExEdgeRefineLineTrace")
+StructRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExEdgeDirectionFilterConfig",NewName="/Script/PCGExtendedToolkit.PCGExAdjacentEdgeDirectionFilterConfig")
+ClassRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExEdgeDirectionFilterProviderSettings",NewName="/Script/PCGExtendedToolkit.PCGExAdjacentEdgeDirectionFilterProviderSettings")
+StructRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExAdjacencyFilterConfig",NewName="/Script/PCGExtendedToolkit.PCGExNodeAdjacencyFilterConfig")
+ClassRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExAdjacencyFilterProviderSettings",NewName="/Script/PCGExtendedToolkit.PCGExNodeAdjacencyFilterProviderSettings")
+ClassRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExAdjacencyFilterProviderSettings",NewName="/Script/PCGExtendedToolkit.PCGExNodeAdjacencyFilterProviderSettings")
+StructRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExAdjacencyFilterConfig",NewName="/Script/PCGExtendedToolkit.PCGExNodeAdjacencyFilterConfig")
+ClassRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExNeighborsCountFilterProviderSettings",NewName="/Script/PCGExtendedToolkit.PCGExNodeNeighborsCountFilterProviderSettings")
+StructRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExNeighborsCountFilterConfig",NewName="/Script/PCGExtendedToolkit.PCGExNodeNeighborsCountFilterConfig")
+StructRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExEdgeDirectionFilterConfig",NewName="/Script/PCGExtendedToolkit.PCGExNodeEdgeDirectionFilterConfig")
+ClassRedirects=(OldName="/Script/PCGExtendedToolkit.PCGExEdgeDirectionFilterProviderSettings",NewName="/Script/PCGExtendedToolkit.PCGExNodeEdgeDirectionFilterProviderSettings")
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool FPCGExAssetCollectionToSetElement::ExecuteInternal(FPCGContext* Context) co

UPCGParamData* OutputSet = NewObject<UPCGParamData>();

auto OutputToPin = [&]()
auto OutputToPin = [Context, OutputSet]()
{
FPCGTaggedData& OutData = Context->OutputData.TaggedData.Emplace_GetRef();
OutData.Pin = FName("AttributeSet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ namespace PCGExDataBlending
}
}

void FUnionBlender::AddSources(const TArray<TSharedPtr<PCGExData::FFacade>>& InFacades)
void FUnionBlender::AddSources(const TArray<TSharedRef<PCGExData::FFacade>>& InFacades)
{
for (TSharedPtr<PCGExData::FFacade> Facade : InFacades) { AddSource(Facade); }
for (TSharedRef<PCGExData::FFacade> Facade : InFacades) { AddSource(Facade); }
}

void FUnionBlender::PrepareMerge(
Expand Down
47 changes: 44 additions & 3 deletions Source/PCGExtendedToolkit/Private/Data/PCGExData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,35 @@ namespace PCGExData

void FFacade::Write(const TSharedPtr<PCGExMT::FTaskManager>& AsyncManager)
{
if (!AsyncManager) { return; }
if (!AsyncManager || !AsyncManager->IsAvailable()) { return; }

for (const TSharedPtr<FBufferBase>& Buffer : Buffers)
//UE_LOG(LogTemp, Warning, TEXT("{%lld} Facade -> Write"), AsyncManager->Context->GetInputSettings<UPCGSettings>()->UID)

for (const TSharedPtr<FBufferBase> Buffer : Buffers)
{
if (Buffer->IsWritable()) { PCGExMT::Write(AsyncManager, Buffer); }
if (!Buffer.IsValid() || !Buffer->IsWritable()) { continue; }
PCGExMT::Write(AsyncManager, Buffer);
}

Flush();
}

void FFacade::WriteBuffersAsCallbacks(const TSharedPtr<PCGExMT::FTaskGroup>& TaskGroup)
{
// !!! Requires manual flush !!!

if (!TaskGroup)
{
Flush();
return;
}

for (const TSharedPtr<FBufferBase> Buffer : Buffers)
{
if (Buffer->IsWritable()) { TaskGroup->AddSimpleCallback([BufferRef = Buffer]() { BufferRef->Write(); }); }
}
}

void FUnionData::ComputeWeights(
const TArray<TSharedPtr<FFacade>>& Sources, const TMap<uint32, int32>& SourcesIdx, const FPCGPoint& Target,
const FPCGExDistanceDetails& InDistanceDetails, TArray<int32>& OutIOIdx, TArray<int32>& OutPointsIdx, TArray<double>& OutWeights) const
Expand Down Expand Up @@ -103,6 +122,28 @@ namespace PCGExData
return H;
}

FUnionData* FUnionMetadata::NewEntry(const int32 IOIndex, const int32 ItemIndex)
{
FUnionData* NewUnionData = Entries.Add_GetRef(new FUnionData());
//NewUnionData->Index = Items.Num() - 1;
NewUnionData->IOIndices.Add(IOIndex);
const uint64 H = PCGEx::H64(IOIndex, ItemIndex);
NewUnionData->ItemHashSet.Add(H);

return NewUnionData;
}

uint64 FUnionMetadata::Append(const int32 Index, const int32 IOIndex, const int32 ItemIndex)
{
return Entries[Index]->Add(IOIndex, ItemIndex);
}

bool FUnionMetadata::IOIndexOverlap(const int32 InIdx, const TSet<int32>& InIndices)
{
const TSet<int32> Overlap = Entries[InIdx]->IOIndices.Intersect(InIndices);
return Overlap.Num() > 0;
}


#pragma endregion
}
5 changes: 4 additions & 1 deletion Source/PCGExtendedToolkit/Private/Data/PCGExDataForward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ namespace PCGExData
// 'template' spec required for clang on mac, not sure why.
// ReSharper disable once CppRedundantTemplateKeyword
const FPCGMetadataAttribute<T>* SourceAtt = SourceDataFacade->GetIn()->Metadata->template GetConstTypedAttribute<T>(Identity.Name);

if (!SourceAtt) { return; }

TSharedPtr<TBuffer<T>> Writer = InTargetDataFacade->GetWritable<T>(SourceAtt, true);

const T ForwardValue = SourceAtt->GetValueFromItemKey(SourceDataFacade->Source->GetInPoint(SourceIndex).MetadataEntry);
Expand All @@ -121,6 +122,8 @@ namespace PCGExData
// 'template' spec required for clang on mac, not sure why.
// ReSharper disable once CppRedundantTemplateKeyword
const FPCGMetadataAttribute<T>* SourceAtt = SourceDataFacade->GetIn()->Metadata->template GetConstTypedAttribute<T>(Identity.Name);
if (!SourceAtt) { return; }

InTargetDataFacade->Source->DeleteAttribute(Identity.Name);
FPCGMetadataAttribute<T>* Mark = InTargetDataFacade->Source->FindOrCreateAttribute<T>(
Identity.Name,
Expand Down
14 changes: 10 additions & 4 deletions Source/PCGExtendedToolkit/Private/Data/PCGExFilterGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#include "Data/PCGExFilterGroup.h"








#include "Graph/PCGExCluster.h"

namespace PCGExFilterGroup
Expand All @@ -14,7 +20,7 @@ namespace PCGExFilterGroup
return InitManaged(InContext);
}

bool TFilterGroup::Init(const FPCGContext* InContext, const TSharedPtr<PCGExCluster::FCluster>& InCluster, const TSharedPtr<PCGExData::FFacade>& InPointDataFacade, const TSharedPtr<PCGExData::FFacade>& InEdgeDataFacade)
bool TFilterGroup::Init(const FPCGContext* InContext, const TSharedRef<PCGExCluster::FCluster>& InCluster, const TSharedRef<PCGExData::FFacade>& InPointDataFacade, const TSharedRef<PCGExData::FFacade>& InEdgeDataFacade)
{
bInitForCluster = true;
Cluster = InCluster;
Expand Down Expand Up @@ -57,13 +63,13 @@ namespace PCGExFilterGroup
if (bInitForCluster)
{
TFilterGroup* FilterGroup = static_cast<TFilterGroup*>(Filter.Get());
return FilterGroup->Init(InContext, Cluster, PointDataFacade, EdgeDataCache);
return FilterGroup->Init(InContext, Cluster.ToSharedRef(), PointDataFacade.ToSharedRef(), EdgeDataCache.ToSharedRef());
}

return Filter->Init(InContext, PointDataFacade);
}

if (Filter->GetFilterType() == PCGExFilters::EType::Node)
if ( PCGExFactories::ClusterSpecificFilters.Contains(Filter->Factory->GetFactoryType()))
{
if (!bInitForCluster)
{
Expand All @@ -73,7 +79,7 @@ namespace PCGExFilterGroup
}

TFilter* ClusterFilter = static_cast<TFilter*>(Filter.Get());
return ClusterFilter->Init(InContext, Cluster, PointDataFacade, EdgeDataCache);
return ClusterFilter->Init(InContext, Cluster.ToSharedRef(), PointDataFacade.ToSharedRef(), EdgeDataCache.ToSharedRef());
}

return false;
Expand Down
8 changes: 6 additions & 2 deletions Source/PCGExtendedToolkit/Private/Data/PCGExPointFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ namespace PCGExPointFilter
Results.Init(false, NumResults);
}

bool TFilter::Test(const int32 Index) const { return DefaultResult; }
bool TFilter::Test(const int32 Index) const PCGEX_NOT_IMPLEMENTED_RET(TFilter::Test(const int32 Index), false)
bool TFilter::Test(const PCGExCluster::FNode& Node) const { return Test(Node.PointIndex); }
bool TFilter::Test(const PCGExGraph::FIndexedEdge& Edge) const { return Test(Edge.PointIndex); }

TManager::TManager(const TSharedPtr<PCGExData::FFacade>& InPointDataFacade)
bool TSimpleFilter::Test(const int32 Index) const PCGEX_NOT_IMPLEMENTED_RET(TEdgeFilter::Test(const PCGExCluster::FNode& Node), false)
bool TSimpleFilter::Test(const PCGExCluster::FNode& Node) const { return Test(Node.PointIndex); }
bool TSimpleFilter::Test(const PCGExGraph::FIndexedEdge& Edge) const { return Test(Edge.PointIndex); }

TManager::TManager(const TSharedRef<PCGExData::FFacade>& InPointDataFacade)
: PointDataFacade(InPointDataFacade)
{
}
Expand Down
17 changes: 8 additions & 9 deletions Source/PCGExtendedToolkit/Private/Data/PCGExPointIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ namespace PCGExData
{
FWriteScopeLock WriteScopeLock(OutKeysLock);
if (OutKeys) { return OutKeys; }
const TArrayView<FPCGPoint> View(Out->GetMutablePoints());
const TArrayView<FPCGPoint> MutablePoints = MakeArrayView(Out->GetMutablePoints());

if (bEnsureValidKeys)
{
UPCGMetadata* Metadata = Out->Metadata;
for (FPCGPoint& Pt : View) { if (Pt.MetadataEntry == PCGInvalidEntryKey) { Metadata->InitializeOnSet(Pt.MetadataEntry); } }
UPCGMetadata* OutMetadata = Out->Metadata;
for (FPCGPoint& Pt : MutablePoints) { OutMetadata->InitializeOnSet(Pt.MetadataEntry); }
}

OutKeys = MakeShared<FPCGAttributeAccessorKeysPoints>(View);
OutKeys = MakeShared<FPCGAttributeAccessorKeysPoints>(MutablePoints);
}

return OutKeys;
Expand Down Expand Up @@ -198,8 +198,7 @@ namespace PCGExData

FPointIOCollection::~FPointIOCollection()
{
PCGEX_LOG_DTR(FPointIOCollection)
Flush();
PCGEX_LOG_DTR(FPointIOCollection);
}

void FPointIOCollection::Initialize(
Expand Down Expand Up @@ -281,14 +280,14 @@ namespace PCGExData
{
Sort();
Context->StagedOutputReserve(Pairs.Num());
for (const TSharedPtr<FPointIO>& Pair : Pairs) { Pair->StageOutput(); }
for (int i = 0; i < Pairs.Num(); i++) { Pairs[i]->StageOutput(); }
}

void FPointIOCollection::StageOutputs(const int32 MinPointCount, const int32 MaxPointCount)
{
Sort();
Context->StagedOutputReserve(Pairs.Num());
for (const TSharedPtr<FPointIO>& Pair : Pairs) { Pair->StageOutput(MinPointCount, MaxPointCount); }
for (int i = 0; i < Pairs.Num(); i++) { Pairs[i]->StageOutput(MinPointCount, MaxPointCount); }
}

void FPointIOCollection::Sort()
Expand Down
4 changes: 2 additions & 2 deletions Source/PCGExtendedToolkit/Private/Data/PCGExPointIOMerger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void FPCGExPointIOMerger::Append(const TArray<TSharedPtr<PCGExData::FPointIO>>&
for (const TSharedPtr<PCGExData::FPointIO>& PointIO : InData) { Append(PointIO); }
}

void FPCGExPointIOMerger::Append(PCGExData::FPointIOCollection* InCollection)
void FPCGExPointIOMerger::Append(const TSharedRef<PCGExData::FPointIOCollection>& InCollection)
{
for (const TSharedPtr<PCGExData::FPointIO>& PointIO : InCollection->Pairs) { Append(PointIO); }
}
Expand Down Expand Up @@ -134,7 +134,7 @@ namespace PCGExPointIOMerger
if (!Attribute) { continue; } // Missing attribute
if (!Identity.IsA(Attribute->GetTypeId())) { continue; } // Type mismatch

AsyncManager->Start<FWriteAttributeScopeTask<T>>(-1, SourceIO, Merger->Scopes[i], Identity, TypedBuffer->GetOutValues());
InternalStart<FWriteAttributeScopeTask<T>>(-1, SourceIO, Merger->Scopes[i], Identity, TypedBuffer->GetOutValues());
}
});

Expand Down
4 changes: 2 additions & 2 deletions Source/PCGExtendedToolkit/Private/Data/PCGExPointStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace PCGExPointStates
{
if (!TFilter::Init(InContext, InPointDataFacade)) { return false; }

Manager = MakeUnique<PCGExPointFilter::TManager>(InPointDataFacade);
Manager = MakeShared<PCGExPointFilter::TManager>(InPointDataFacade.ToSharedRef());
Manager->bCacheResults = true;
return true;
}
Expand All @@ -46,7 +46,7 @@ namespace PCGExPointStates
// TODO : Implement
}

FStateManager::FStateManager(const TSharedPtr<TArray<int64>>& InFlags, const TSharedPtr<PCGExData::FFacade>& InPointDataFacade)
FStateManager::FStateManager(const TSharedPtr<TArray<int64>>& InFlags, const TSharedRef<PCGExData::FFacade>& InPointDataFacade)
: TManager(InPointDataFacade)
{
FlagsCache = InFlags;
Expand Down
35 changes: 27 additions & 8 deletions Source/PCGExtendedToolkit/Private/Graph/Edges/PCGExRefineEdges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ bool FPCGExRefineEdgesElement::ExecuteInternal(
{
if (Settings->bOutputOnlyEdgesAsPoints)
{
if (!Context->StartProcessingClusters<PCGExClusterMT::TBatch<PCGExRefineEdges::FProcessor>>(
if (!Context->StartProcessingClusters<PCGExRefineEdges::FProcessorBatch>(
[](const TSharedPtr<PCGExData::FPointIOTaggedEntries>& Entries) { return true; },
[&](const TSharedPtr<PCGExClusterMT::TBatch<PCGExRefineEdges::FProcessor>>& NewBatch)
[&](const TSharedPtr<PCGExRefineEdges::FProcessorBatch>& NewBatch)
{
if (Context->Refinement->RequiresHeuristics()) { NewBatch->SetRequiresHeuristics(true); }
}))
Expand Down Expand Up @@ -146,14 +146,18 @@ namespace PCGExRefineEdges
Sanitization = Settings->Sanitization;

Refinement = Context->Refinement->CopyOperation<UPCGExEdgeRefineOperation>();
Refinement->PrimaryDataFacade = VtxDataFacade;
Refinement->SecondaryDataFacade = EdgeDataFacade;

Refinement->PrepareForCluster(Cluster, HeuristicsHandler);

Refinement->EdgesFilters = &EdgeFilterCache;
EdgeFilterCache.Init(true, EdgeDataFacade->Source->GetNum());

if (!Context->EdgeFilterFactories.IsEmpty())
{
EdgeFilterManager = MakeUnique<PCGExPointFilter::TManager>(EdgeDataFacade);
EdgeFilterManager = MakeShared<PCGExClusterFilter::TManager>(Cluster.ToSharedRef(), VtxDataFacade, EdgeDataFacade);
EdgeFilterManager->bUseEdgeAsPrimary = true;
if (!EdgeFilterManager->Init(ExecutionContext, Context->EdgeFilterFactories)) { return false; }
}
else
Expand All @@ -166,7 +170,8 @@ namespace PCGExRefineEdges
{
if (!Context->SanitizationFilterFactories.IsEmpty())
{
SanitizationFilterManager = MakeUnique<PCGExPointFilter::TManager>(EdgeDataFacade);
SanitizationFilterManager = MakeShared<PCGExClusterFilter::TManager>(Cluster.ToSharedRef(), VtxDataFacade, EdgeDataFacade);
SanitizationFilterManager->bUseEdgeAsPrimary = true;
if (!SanitizationFilterManager->Init(ExecutionContext, Context->SanitizationFilterFactories)) { return false; }
}
}
Expand All @@ -190,7 +195,7 @@ namespace PCGExRefineEdges
EdgeScopeLoop->OnIterationRangeStartCallback =
[&](const int32 StartIndex, const int32 Count, const int32 LoopIdx) { PrepareSingleLoopScopeForEdges(StartIndex, Count); };

EdgeScopeLoop->PrepareRangesOnly(EdgeDataFacade->GetNum(), PLI);
EdgeScopeLoop->StartRangePrepareOnly(EdgeDataFacade->GetNum(), PLI);
}

return true;
Expand All @@ -215,7 +220,7 @@ namespace PCGExRefineEdges
{
for (int i = StartIndex; i < MaxIndex; i++)
{
EdgeFilterCache[i] = EdgeFilterManager->Test(i);
EdgeFilterCache[i] = EdgeFilterManager->Test(Edges[i]);
Edges[i].bValid = bDefaultValidity;
}
}
Expand Down Expand Up @@ -248,9 +253,13 @@ namespace PCGExRefineEdges
[&](const int32 StartIndex, const int32 Count, const int32 LoopIdx)
{
const int32 MaxIndex = StartIndex + Count;
for (int i = StartIndex; i < MaxIndex; i++) { if (SanitizationFilterManager->Test(i)) { (Cluster->Edges->GetData() + i)->bValid = true; } }
for (int i = StartIndex; i < MaxIndex; i++)
{
PCGExGraph::FIndexedEdge& Edge = *(Cluster->Edges->GetData() + i);
if (SanitizationFilterManager->Test(Edge)) { Edge.bValid = true; }
}
};
SanitizeTaskGroup->PrepareRangesOnly(EdgeDataFacade->GetNum(), PLI);
SanitizeTaskGroup->StartRangePrepareOnly(EdgeDataFacade->GetNum(), PLI);
}
else
{
Expand Down Expand Up @@ -291,6 +300,16 @@ namespace PCGExRefineEdges
InsertEdges();
}

void FProcessorBatch::OnProcessingPreparationComplete()
{
PCGEX_TYPED_CONTEXT_AND_SETTINGS(RefineEdges)

VtxDataFacade->bSupportsScopedGet = false; // :(
Context->Refinement->PrepareVtxFacade(VtxDataFacade);

TBatch<FProcessor>::OnProcessingPreparationComplete();
}

bool FSanitizeRangeTask::ExecuteTask(const TSharedPtr<PCGExMT::FTaskManager>& AsyncManager)
{
const int32 StartIndex = PCGEx::H64A(Scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace PCGExRelaxClusters

void FProcessor::ProcessSingleRangeIteration(const int32 Iteration, const int32 LoopIdx, const int32 Count)
{
(*ExpandedNodes)[Iteration] = PCGExCluster::FExpandedNode(Cluster.Get(), Iteration);
*(ExpandedNodes->GetData() + Iteration) = PCGExCluster::FExpandedNode(Cluster, Iteration);
}

void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node, const int32 LoopIdx, const int32 Count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace PCGExWriteEdgeProperties

if (Settings->bEndpointsBlending)
{
MetadataBlender = MakeUnique<PCGExDataBlending::FMetadataBlender>(const_cast<FPCGExBlendingDetails*>(&Settings->BlendingSettings));
MetadataBlender = MakeShared<PCGExDataBlending::FMetadataBlender>(const_cast<FPCGExBlendingDetails*>(&Settings->BlendingSettings));
MetadataBlender->PrepareForData(EdgeDataFacade, VtxDataFacade, PCGExData::ESource::In);
}

Expand Down Expand Up @@ -295,7 +295,7 @@ namespace PCGExWriteEdgeProperties
VtxDataFacade->Fetch(StartIndex, Count);
};

FetchVtxTask->PrepareRangesOnly(VtxDataFacade->GetNum(), PLI);
FetchVtxTask->StartRangePrepareOnly(VtxDataFacade->GetNum(), PLI);
}
}
}
Expand Down
Loading

0 comments on commit 183787b

Please sign in to comment.