Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebukam committed Sep 13, 2024
1 parent bd7ed1c commit b1fccec
Show file tree
Hide file tree
Showing 48 changed files with 362 additions and 632 deletions.
Binary file modified PCGExtendedToolkit.uplugin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ namespace PCGExPruneEdges
return true;
}

void FProcessor::ProcessSingleEdge(PCGExGraph::FIndexedEdge& Edge)
void FProcessor::ProcessSingleEdge(const int32 EdgeIndex, PCGExGraph::FIndexedEdge& Edge, const int32 LoopIdx, const int32 Count)
{
Edge.bValid = FMath::IsWithin(EdgeLengths[Edge.EdgeIndex], ReferenceMin, ReferenceMax);
}

void FProcessor::ProcessSingleRangeIteration(const int32 Iteration) { ProcessSingleEdge(IndexedEdges[Iteration]); }
void FProcessor::ProcessSingleRangeIteration(const int32 Iteration, const int32 LoopIdx, const int32 Count) { ProcessSingleEdge(Iteration, IndexedEdges[Iteration], LoopIdx, Count); }

void FProcessor::CompleteWork()
{
Expand Down
98 changes: 61 additions & 37 deletions Source/PCGExtendedToolkit/Private/Graph/Edges/PCGExRefineEdges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "Graph/PCGExGraph.h"
#include "Graph/Edges/Refining/PCGExEdgeRefinePrimMST.h"
#include "Graph/Filters/PCGExClusterFilter.h"

#define LOCTEXT_NAMESPACE "PCGExRefineEdges"
#define PCGEX_NAMESPACE RefineEdges
Expand All @@ -13,7 +14,12 @@ TArray<FPCGPinProperties> UPCGExRefineEdgesSettings::InputPinProperties() const
{
TArray<FPCGPinProperties> PinProperties = Super::InputPinProperties();
if (Refinement && Refinement->RequiresHeuristics()) { PCGEX_PIN_PARAMS(PCGExGraph::SourceHeuristicsLabel, "Heuristics may be required by some refinements.", Required, {}) }
PCGEX_PIN_PARAMS(PCGExRefineEdges::SourceProtectEdgeFilters, "Filters used to preserve specific edges.", Advanced, {})
if (Refinement && Refinement->SupportFilters())
{
PCGEX_PIN_PARAMS(PCGExRefineEdges::SourceVtxFilters, "Filters used to check if a vtx should be processed.", Normal, {})
PCGEX_PIN_PARAMS(PCGExRefineEdges::SourceEdgeFilters, "Filters used to check if an edge should be processed.", Normal, {})
}

return PinProperties;
}

Expand Down Expand Up @@ -56,7 +62,11 @@ bool FPCGExRefineEdgesElement::Boot(FPCGExContext* InContext) const
return false;
}

GetInputFactories(Context, PCGExRefineEdges::SourceProtectEdgeFilters, Context->PreserveEdgeFilterFactories, PCGExFactories::PointFilters, false);
if (Context->Refinement->SupportFilters())
{
GetInputFactories(Context, PCGExRefineEdges::SourceVtxFilters, Context->VtxFilterFactories, PCGExFactories::ClusterNodeFilters, false);
GetInputFactories(Context, PCGExRefineEdges::SourceEdgeFilters, Context->EdgeFilterFactories, PCGExFactories::ClusterEdgeFilters, false);
}

return true;
}
Expand Down Expand Up @@ -123,7 +133,7 @@ namespace PCGExRefineEdges
FProcessor::~FProcessor()
{
PCGEX_DELETE_OPERATION(Refinement)
PCGEX_DELETE(FilterManager);
PCGEX_DELETE(EdgeFilterManager);
}

bool FProcessor::Process(PCGExMT::FTaskManager* AsyncManager)
Expand All @@ -137,21 +147,62 @@ namespace PCGExRefineEdges

Refinement = TypedContext->Refinement->CopyOperation<UPCGExEdgeRefineOperation>();
Refinement->PrepareForCluster(Cluster, HeuristicsHandler);

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

if (!TypedContext->EdgeFilterFactories.IsEmpty())
{
EdgeFilterManager = new PCGExClusterFilter::TManager(Cluster, VtxDataFacade, EdgeDataFacade);
if (!EdgeFilterManager->Init(Context, TypedContext->EdgeFilterFactories)) { return false; }
}

if (EdgeFilterManager)
{
const int32 PLI = GetDefault<UPCGExGlobalSettings>()->GetClusterBatchChunkSize();

PCGEX_ASYNC_GROUP(AsyncManagerPtr, FilteredLoop)
FilteredLoop->SetOnCompleteCallback([&]() { StartRefinement(); });
FilteredLoop->StartRanges(
[&](const int32 Index, const int32 Count, const int32 LoopIdx)
{
EdgeFilterCache[Index] = EdgeFilterManager->Test(Index);
}, EdgesIO->GetNum(), PLI);
}
else
{
StartRefinement();
}

return true;
}

void FProcessor::StartRefinement()
{
if (Refinement->InvalidateAllEdgesBeforeProcessing())
{
for (PCGExGraph::FIndexedEdge& Edge : *Cluster->Edges) { Edge.bValid = false; }
TArray<PCGExGraph::FIndexedEdge>& Edges = *Cluster->Edges;
for (int i = 0; i < Cluster->Edges->Num(); i++)
{
PCGExGraph::FIndexedEdge& Edge = Edges[i];
Edge.bValid = !EdgeFilterCache[i];
}
}

if (Refinement->RequiresIndividualNodeProcessing()) { StartParallelLoopForNodes(); }
else if (Refinement->RequiresIndividualEdgeProcessing()) { StartParallelLoopForEdges(); }
else { Refinement->Process(); }
return true;
}

void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node) { Refinement->ProcessNode(Node); }
void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node, const int32 LoopIdx, const int32 Count)
{
Refinement->ProcessNode(Node);
}

void FProcessor::ProcessSingleEdge(PCGExGraph::FIndexedEdge& Edge) { Refinement->ProcessEdge(Edge); }
void FProcessor::ProcessSingleEdge(const int32 EdgeIndex, PCGExGraph::FIndexedEdge& Edge, const int32 LoopIdx, const int32 Count)
{
Refinement->ProcessEdge(Edge);
}

void FProcessor::Sanitize()
{
Expand Down Expand Up @@ -188,35 +239,8 @@ namespace PCGExRefineEdges
{
PCGEX_TYPED_CONTEXT_AND_SETTINGS(RefineEdges)

if (!TypedContext->PreserveEdgeFilterFactories.IsEmpty())
{
PCGEX_ASYNC_GROUP(AsyncManagerPtr, FilterTaskGroup)
FilterTaskGroup->SetOnCompleteCallback(
[&]()
{
if (Settings->Sanitization == EPCGExRefineSanitization::None)
{
InsertEdges();
return;
}

Sanitize();
});

FilterManager = new PCGExPointFilter::TManager(EdgeDataFacade);
FilterManager->Init(Context, TypedContext->PreserveEdgeFilterFactories);
FilterTaskGroup->StartRanges<FFilterRangeTask>(
NumEdges, GetDefault<UPCGExGlobalSettings>()->GetPointsBatchChunkSize(),
nullptr, this);
}
else if (Settings->Sanitization != EPCGExRefineSanitization::None)
{
Sanitize();
}
else
{
InsertEdges();
}
if (Settings->Sanitization != EPCGExRefineSanitization::None) { Sanitize(); }
else { InsertEdges(); }
}

bool FFilterRangeTask::ExecuteTask()
Expand All @@ -227,7 +251,7 @@ namespace PCGExRefineEdges
for (int i = 0; i < NumIterations; ++i)
{
PCGExGraph::FIndexedEdge& Edge = *(Processor->Cluster->Edges->GetData() + StartIndex + i);
if (!Edge.bValid) { Edge.bValid = Processor->FilterManager->Test(Edge.EdgeIndex); }
if (!Edge.bValid) { Edge.bValid = Processor->EdgeFilterManager->Test(Edge.EdgeIndex); }
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ namespace PCGExRelaxClusters
nullptr, this);
}

void FProcessor::ProcessSingleRangeIteration(const int32 Iteration)
void FProcessor::ProcessSingleRangeIteration(const int32 Iteration, const int32 LoopIdx, const int32 Count)
{
(*ExpandedNodes)[Iteration] = new PCGExCluster::FExpandedNode(Cluster, Iteration);
}

void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node)
void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node, const int32 LoopIdx, const int32 Count)
{
RelaxOperation->ProcessExpandedNode(*(ExpandedNodes->GetData() + Index));

Expand Down Expand Up @@ -200,7 +200,7 @@ namespace PCGExRelaxClusters
for (int i = 0; i < NumIterations; ++i)
{
const int32 Index = StartIndex + i;
Processor->ProcessSingleNode(Index, *(Processor->Cluster->Nodes->GetData() + Index));
Processor->ProcessSingleNode(Index, *(Processor->Cluster->Nodes->GetData() + Index), TaskIndex, NumIterations);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace PCGExWriteEdgeProperties
return true;
}

void FProcessor::ProcessSingleEdge(PCGExGraph::FIndexedEdge& Edge)
void FProcessor::ProcessSingleEdge(const int32 EdgeIndex, PCGExGraph::FIndexedEdge& Edge, const int32 LoopIdx, const int32 Count)
{
uint32 EdgeStartPtIndex = Edge.Start;
uint32 EdgeEndPtIndex = Edge.End;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace PCGExWriteVtxProperties
return true;
}

void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node)
void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node, const int32 LoopIdx, const int32 Count)
{
if (VtxEdgeCountWriter) { VtxEdgeCountWriter->Values[Node.PointIndex] = Node.Adjacency.Num(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void UPCGExEdgeKeepHighestScore::ProcessNode(PCGExCluster::FNode& Node)
uint32 EdgeIndex;
PCGEx::H64(AdjacencyHash, OtherNodeIndex, EdgeIndex);

if (!*(EdgesFilters->GetData() + EdgeIndex)) { continue; }

const double Score = Heuristics->GetEdgeScore(Node, *(Cluster->Nodes->GetData() + OtherNodeIndex), *(Cluster->Edges->GetData() + EdgeIndex), Node, *(Cluster->Nodes->GetData() + OtherNodeIndex));
if (Score > HighestScore)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ void UPCGExEdgeKeepLongest::ProcessNode(PCGExCluster::FNode& Node)

for (const uint64 AdjacencyHash : Node.Adjacency)
{
const double Dist = Cluster->GetDistSquared(Node.NodeIndex, PCGEx::H64A(AdjacencyHash));
uint32 OtherNodeIndex;
uint32 EdgeIndex;
PCGEx::H64(AdjacencyHash, OtherNodeIndex, EdgeIndex);

if (!*(EdgesFilters->GetData() + EdgeIndex)) { continue; }

const double Dist = Cluster->GetDistSquared(Node.NodeIndex, OtherNodeIndex);
if (Dist > LongestDist)
{
LongestDist = Dist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void UPCGExEdgeKeepLowestScore::ProcessNode(PCGExCluster::FNode& Node)
uint32 OtherNodeIndex;
uint32 EdgeIndex;
PCGEx::H64(AdjacencyHash, OtherNodeIndex, EdgeIndex);

if (!*(EdgesFilters->GetData() + EdgeIndex)) { continue; }

const double Score = Heuristics->GetEdgeScore(Node, *(Cluster->Nodes->GetData() + OtherNodeIndex), *(Cluster->Edges->GetData() + EdgeIndex), Node, *(Cluster->Nodes->GetData() + OtherNodeIndex));
if (Score < LowestScore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ void UPCGExEdgeKeepShortest::ProcessNode(PCGExCluster::FNode& Node)

for (const uint64 AdjacencyHash : Node.Adjacency)
{
const double Dist = Cluster->GetDistSquared(Node.NodeIndex, PCGEx::H64A(AdjacencyHash));
uint32 OtherNodeIndex;
uint32 EdgeIndex;
PCGEx::H64(AdjacencyHash, OtherNodeIndex, EdgeIndex);

if (!*(EdgesFilters->GetData() + EdgeIndex)) { continue; }

const double Dist = Cluster->GetDistSquared(Node.NodeIndex, OtherNodeIndex);
if (Dist < ShortestDist)
{
ShortestDist = Dist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void UPCGExEdgeRemoveHighestScore::ProcessNode(PCGExCluster::FNode& Node)
uint32 OtherNodeIndex;
uint32 EdgeIndex;
PCGEx::H64(AdjacencyHash, OtherNodeIndex, EdgeIndex);

if (!*(EdgesFilters->GetData() + EdgeIndex)) { continue; }

const double Score = Heuristics->GetEdgeScore(Node, *(Cluster->Nodes->GetData() + OtherNodeIndex), *(Cluster->Edges->GetData() + EdgeIndex), Node, *(Cluster->Nodes->GetData() + OtherNodeIndex));
if (Score > HighestScore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ void UPCGExEdgeRemoveLineTrace::CopySettingsFrom(const UPCGExOperation* Other)

void UPCGExEdgeRemoveLineTrace::ProcessEdge(PCGExGraph::FIndexedEdge& Edge)
{
if (!*(EdgesFilters->GetData() + Edge.PointIndex)) { return; }

Super::ProcessEdge(Edge);

const FVector From = Cluster->GetPos((*Cluster->NodeIndexLookup)[Edge.Start]);
const FVector To = Cluster->GetPos((*Cluster->NodeIndexLookup)[Edge.End]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ void UPCGExEdgeRemoveLongest::ProcessNode(PCGExCluster::FNode& Node)

for (const uint64 AdjacencyHash : Node.Adjacency)
{
const double Dist = Cluster->GetDistSquared(Node.NodeIndex, PCGEx::H64A(AdjacencyHash));
uint32 OtherNodeIndex;
uint32 EdgeIndex;
PCGEx::H64(AdjacencyHash, OtherNodeIndex, EdgeIndex);

if (!*(EdgesFilters->GetData() + EdgeIndex)) { continue; }

const double Dist = Cluster->GetDistSquared(Node.NodeIndex, OtherNodeIndex);
if (Dist > LongestDist)
{
LongestDist = Dist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void UPCGExEdgeRemoveLowestScore::ProcessNode(PCGExCluster::FNode& Node)
uint32 OtherNodeIndex;
uint32 EdgeIndex;
PCGEx::H64(AdjacencyHash, OtherNodeIndex, EdgeIndex);

if (!*(EdgesFilters->GetData() + EdgeIndex)) { continue; }

const double Score = Heuristics->GetEdgeScore(Node, *(Cluster->Nodes->GetData() + OtherNodeIndex), *(Cluster->Edges->GetData() + EdgeIndex), Node, *(Cluster->Nodes->GetData() + OtherNodeIndex));
if (Score < LowestScore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ void UPCGExEdgeRemoveShortest::ProcessNode(PCGExCluster::FNode& Node)

for (const uint64 AdjacencyHash : Node.Adjacency)
{
const double Dist = Cluster->GetDistSquared(Node.NodeIndex, PCGEx::H64A(AdjacencyHash));
uint32 OtherNodeIndex;
uint32 EdgeIndex;
PCGEx::H64(AdjacencyHash, OtherNodeIndex, EdgeIndex);

if (!*(EdgesFilters->GetData() + EdgeIndex)) { continue; }

const double Dist = Cluster->GetDistSquared(Node.NodeIndex, OtherNodeIndex);
if (Dist < ShortestDist)
{
ShortestDist = Dist;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ namespace PCGExBevelVertices
return true;
}

void FProcessor::ProcessSingleRangeIteration(const int32 Iteration)
void FProcessor::ProcessSingleRangeIteration(const int32 Iteration, const int32 LoopIdx, const int32 Count)
{
(*ExpandedNodes)[Iteration] = new PCGExCluster::FExpandedNode(Cluster, Iteration);
}

void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node)
void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node, const int32 LoopIdx, const int32 Count)
{
FilterManager->Test(Node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace PCGExBreakClustersToPaths
}
}

void FProcessor::ProcessSingleRangeIteration(const int32 Iteration)
void FProcessor::ProcessSingleRangeIteration(const int32 Iteration, const int32 LoopIdx, const int32 Count)
{
PCGExCluster::FNodeChain* Chain = Chains[Iteration];
if (!Chain) { return; }
Expand All @@ -156,7 +156,7 @@ namespace PCGExBreakClustersToPaths
PathIO->InitializeNum(ChainSize, true);
}

void FProcessor::ProcessSingleEdge(PCGExGraph::FIndexedEdge& Edge)
void FProcessor::ProcessSingleEdge(const int32 EdgeIndex, PCGExGraph::FIndexedEdge& Edge, const int32 LoopIdx, const int32 Count)
{
const PCGExData::FPointIO* PathIO = LocalTypedContext->Paths->Emplace_GetRef<UPCGPointData>(VtxIO, PCGExData::EInit::NewOutput);
TArray<FPCGPoint>& MutablePoints = PathIO->GetOut()->GetMutablePoints();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace PCGExBridgeClusters
return true;
}

void FProcessor::ProcessSingleEdge(PCGExGraph::FIndexedEdge& Edge)
void FProcessor::ProcessSingleEdge(const int32 EdgeIndex, PCGExGraph::FIndexedEdge& Edge, const int32 LoopIdx, const int32 Count)
{
PCGEX_SETTINGS(ConnectClusters)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool FPCGExEdgesProcessorContext::ProcessClusters()
{
if (!IsAsyncWorkComplete()) { return false; }

CompleteBatch(GetAsyncManager(), CurrentBatch);
CurrentBatch->CompleteWork();
SetAsyncState(PCGExClusterMT::MTState_ClusterCompletingWork);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ namespace PCGExMergeVertices
return true;
}

void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node)
void FProcessor::ProcessSingleNode(const int32 Index, PCGExCluster::FNode& Node, const int32 LoopIdx, const int32 Count)
{
Node.PointIndex += StartIndexOffset;
}

void FProcessor::ProcessSingleEdge(PCGExGraph::FIndexedEdge& Edge)
void FProcessor::ProcessSingleEdge(const int32 EdgeIndex, PCGExGraph::FIndexedEdge& Edge, const int32 LoopIdx, const int32 Count)
{
Edge.Start += StartIndexOffset;
Edge.End += StartIndexOffset;
Expand Down
Loading

0 comments on commit b1fccec

Please sign in to comment.