Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebukam committed Jan 3, 2025
1 parent 24cd9d8 commit 76f87d2
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 51 deletions.
23 changes: 23 additions & 0 deletions Source/PCGExtendedToolkit/Private/Data/PCGExDataForward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ void FPCGExAttributeToTagDetails::Tag(const int32 TagIndex, const TSharedPtr<PCG
PointIO->Tags->Append(Tags);
}

void FPCGExAttributeToTagDetails::Tag(const int32 TagIndex, UPCGMetadata* InMetadata) const
{
if (bAddIndexTag)
{
if (PCGEx::IsValidName(FName(IndexTagPrefix)))
{
InMetadata->FindOrCreateAttribute<FString>(FName(IndexTagPrefix), IndexTagPrefix + ":" + FString::Printf(TEXT("%d"), TagIndex));
}
}

if (!Getters.IsEmpty())
{
const FPCGPoint& Point = SourceDataFacade->GetIn()->GetPoint(TagIndex);
for (const TSharedPtr<PCGEx::TAttributeBroadcaster<FString>>& Getter : Getters)
{
FString Tag = Getter->SoftGet(TagIndex, Point, TEXT(""));
if (Tag.IsEmpty()) { continue; }
if (bPrefixWithAttributeName) { Tag = Getter->GetName() + ":" + Tag; }
InMetadata->FindOrCreateAttribute<FString>(FName(Getter->GetName()), Tag);
}
}
}

namespace PCGExData
{
FDataForwardHandler::FDataForwardHandler(const FPCGExForwardDetails& InDetails, const TSharedPtr<FFacade>& InSourceDataFacade):
Expand Down
29 changes: 21 additions & 8 deletions Source/PCGExtendedToolkit/Private/Data/PCGExPointIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ namespace PCGExData

bool FPointIO::StageOutput() const
{
// If this hits, it needs to be reported. It means a node is trying to output data that is meant to be transactional only
check(!bTransactional)

if (!bEnabled || !Out || (!bAllowEmptyOutput && Out->GetPoints().IsEmpty())) { return false; }

Context->StageOutput(OutputPin, Out, Tags->ToSet(), Out != In, bMutable);
Expand Down Expand Up @@ -189,20 +192,21 @@ namespace PCGExData

#pragma region FPointIOCollection

FPointIOCollection::FPointIOCollection(FPCGExContext* InContext): Context(InContext)
FPointIOCollection::FPointIOCollection(FPCGExContext* InContext, const bool bIsTransactional)
: Context(InContext), bTransactional(bIsTransactional)
{
PCGEX_LOG_CTR(FPointIOCollection)
}

FPointIOCollection::FPointIOCollection(FPCGExContext* InContext, const FName InputLabel, const EIOInit InitOut)
: FPointIOCollection(InContext)
FPointIOCollection::FPointIOCollection(FPCGExContext* InContext, const FName InputLabel, const EIOInit InitOut, const bool bIsTransactional)
: FPointIOCollection(InContext, bIsTransactional)
{
TArray<FPCGTaggedData> Sources = Context->InputData.GetInputsByPin(InputLabel);
Initialize(Sources, InitOut);
}

FPointIOCollection::FPointIOCollection(FPCGExContext* InContext, TArray<FPCGTaggedData>& Sources, const EIOInit InitOut)
: FPointIOCollection(InContext)
FPointIOCollection::FPointIOCollection(FPCGExContext* InContext, TArray<FPCGTaggedData>& Sources, const EIOInit InitOut, const bool bIsTransactional)
: FPointIOCollection(InContext, bIsTransactional)
{
Initialize(Sources, InitOut);
}
Expand All @@ -226,9 +230,18 @@ namespace PCGExData
UniqueData.Add(Source.Data->UID, &bIsAlreadyInSet);
if (bIsAlreadyInSet) { continue; } // Dedupe

const UPCGPointData* MutablePointData = PCGExPointIO::GetMutablePointData(Context, Source);
if (!MutablePointData || MutablePointData->GetPoints().Num() == 0) { continue; }
Emplace_GetRef(MutablePointData, InitOut, &Source.Tags);
const UPCGPointData* SourcePointData = PCGExPointIO::GetPointData(Context, Source);
if (!SourcePointData && bTransactional)
{
// Only allowed for execution-time only
// Otherwise find a way to ensure conversion is plugged to the outputs, pin-less
check(InitOut == EIOInit::None)
SourcePointData = PCGExPointIO::ToPointData(Context, Source);
}

if (!SourcePointData || SourcePointData->GetPoints().Num() == 0) { continue; }
const TSharedPtr<FPointIO> NewIO = Emplace_GetRef(SourcePointData, InitOut, &Source.Tags);
NewIO->bTransactional = bTransactional;
}
UniqueData.Empty();
}
Expand Down
18 changes: 9 additions & 9 deletions Source/PCGExtendedToolkit/Private/Graph/PCGExCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,22 @@ namespace PCGExCluster
VtxPoints = &InVtxIO->GetPoints(PCGExData::ESource::In);

bIsMirror = true;
bIsCopyCluster = false;
OriginalCluster = OtherCluster;

NumRawVtx = InVtxIO->GetNum();
NumRawEdges = InEdgesIO->GetNum();

Bounds = OtherCluster->Bounds;
Bounds = OriginalCluster->Bounds;

BoundedEdges = OtherCluster->BoundedEdges;
BoundedEdges = OriginalCluster->BoundedEdges;

if (bCopyNodes)
{
const int32 NumNewNodes = OtherCluster->Nodes->Num();
const int32 NumNewNodes = OriginalCluster->Nodes->Num();

Nodes = MakeShared<TArray<FNode>>();
TArray<FNode>& NewNodes = *Nodes;
TArray<FNode>& SourceNodes = *OtherCluster->Nodes;
TArray<FNode>& SourceNodes = *OriginalCluster->Nodes;

PCGEx::InitArray(NewNodes, NumNewNodes);

Expand All @@ -123,7 +123,7 @@ namespace PCGExCluster
}
else
{
Nodes = OtherCluster->Nodes;
Nodes = OriginalCluster->Nodes;

// Update index lookup
for (const FNode& Node : *Nodes) { NodeIndexLookup->GetMutable(Node.PointIndex) = Node.Index; }
Expand All @@ -133,11 +133,11 @@ namespace PCGExCluster

if (bCopyEdges)
{
const int32 NumNewEdges = OtherCluster->Edges->Num();
const int32 NumNewEdges = OriginalCluster->Edges->Num();

Edges = MakeShared<TArray<FEdge>>();
TArray<FEdge>& NewEdges = *Edges;
TArray<FEdge>& SourceEdges = *OtherCluster->Edges;
TArray<FEdge>& SourceEdges = *OriginalCluster->Edges;

PCGEx::InitArray(NewEdges, NumNewEdges);

Expand All @@ -153,7 +153,7 @@ namespace PCGExCluster
}
else
{
Edges = OtherCluster->Edges;
Edges = OriginalCluster->Edges;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/PCGExtendedToolkit/Private/Graph/PCGExGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ MACRO(EdgeUnionSize, int32, 0, UnionSize)
}

if (!Limits.IsValid(SubGraph)) { SubGraph->Invalidate(this); } // Will invalidate isolated points
else if (!SubGraph->Edges.IsEmpty()) { SubGraphs.Add(SubGraph); }
else if (!SubGraph->Edges.IsEmpty()) { SubGraphs.Add(SubGraph.ToSharedRef()); }
}
}

Expand Down
74 changes: 57 additions & 17 deletions Source/PCGExtendedToolkit/Private/Misc/PCGExAttributesToTags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,36 @@
#define LOCTEXT_NAMESPACE "PCGExAttributesToTagsElement"
#define PCGEX_NAMESPACE AttributesToTags

PCGExData::EIOInit UPCGExAttributesToTagsSettings::GetMainOutputInitMode() const { return bCleanupConsumableAttributes ? PCGExData::EIOInit::Duplicate : PCGExData::EIOInit::Forward; }
PCGExData::EIOInit UPCGExAttributesToTagsSettings::GetMainOutputInitMode() const
{
if (Action == EPCGExAttributeToTagsAction::Attribute) { return PCGExData::EIOInit::None; }
return bCleanupConsumableAttributes ? PCGExData::EIOInit::Duplicate : PCGExData::EIOInit::Forward;
}

TArray<FPCGPinProperties> UPCGExAttributesToTagsSettings::InputPinProperties() const
{
TArray<FPCGPinProperties> PinProperties = Super::InputPinProperties();
if (Resolution != EPCGExAttributeToTagsResolution::Self)
{
PCGEX_PIN_POINTS(FName("Tags Source"), "Source collection(s) to read the tags from.", Required, {})
PCGEX_PIN_ANY(FName("Tags Source"), "Source collection(s) to read the tags from.", Required, {})
}
return PinProperties;
}

TArray<FPCGPinProperties> UPCGExAttributesToTagsSettings::OutputPinProperties() const
{
if (Action == EPCGExAttributeToTagsAction::AddTags)
{
return Super::OutputPinProperties();
}
else
{
TArray<FPCGPinProperties> PinProperties;
PCGEX_PIN_PARAMS(FName("Tags"), "Tags value in the format `AttributeName = AttributeName:AttributeValue`", Required, {})
return PinProperties;
}
}

PCGEX_INITIALIZE_ELEMENT(AttributesToTags)

bool FPCGExAttributesToTagsElement::Boot(FPCGExContext* InContext) const
Expand All @@ -34,7 +52,8 @@ bool FPCGExAttributesToTagsElement::Boot(FPCGExContext* InContext) const
return true;
}

PCGEX_MAKE_SHARED(SourceCollection, PCGExData::FPointIOCollection, InContext, FName("Tags Source"))
// Converting collection
PCGEX_MAKE_SHARED(SourceCollection, PCGExData::FPointIOCollection, InContext, FName("Tags Source"), PCGExData::EIOInit::None, true)

if (SourceCollection->IsEmpty())
{
Expand All @@ -56,7 +75,7 @@ bool FPCGExAttributesToTagsElement::Boot(FPCGExContext* InContext) const
}
else
{
if (SourceCollection->Num() != 1)
if (SourceCollection->Num() != 1 && !Settings->bQuietTooManyCollectionsWarning)
{
PCGE_LOG(Warning, GraphAndLog, FTEXT("More that one collections found in the sources, only the first one will be used."));
}
Expand Down Expand Up @@ -86,7 +105,7 @@ bool FPCGExAttributesToTagsElement::ExecuteInternal(FPCGContext* InContext) cons
{
TRACE_CPUPROFILER_EVENT_SCOPE(FPCGExAttributesToTagsElement::Execute);

PCGEX_CONTEXT(AttributesToTags)
PCGEX_CONTEXT_AND_SETTINGS(AttributesToTags)
PCGEX_EXECUTION_CHECK
PCGEX_ON_INITIAL_EXECUTION
{
Expand All @@ -102,7 +121,14 @@ bool FPCGExAttributesToTagsElement::ExecuteInternal(FPCGContext* InContext) cons

PCGEX_POINTS_BATCH_PROCESSING(PCGEx::State_Done)

Context->MainPoints->StageOutputs();
if (Settings->Action == EPCGExAttributeToTagsAction::AddTags)
{
Context->MainPoints->StageOutputs();
}
else
{
Context->MainBatch->Output();
}

return Context->TryComplete();
}
Expand All @@ -117,13 +143,23 @@ namespace PCGExAttributesToTags

FRandomStream RandomSource(BatchIndex);

for(int i = 0; i < Settings->Attributes.Num(); i++)
for (int i = 0; i < Settings->Attributes.Num(); i++)
{
FPCGAttributePropertyInputSelector Selector = Settings->Attributes[i].CopyAndFixLast(PointDataFacade->Source->GetIn());
Context->AddConsumableAttributeName(Selector.GetName());
}

TSet<FString> OutTags;

if (Settings->Action == EPCGExAttributeToTagsAction::Attribute)
{
OutputSet = Context->ManagedObjects->New<UPCGParamData>();
OutputSet->Metadata->AddEntry();
}

auto Tag = [&](const FPCGExAttributeToTagDetails& InDetails, const int32 Index)
{
if (OutputSet) { InDetails.Tag(Index, OutputSet->Metadata); }
else { InDetails.Tag(Index, PointDataFacade->Source); }
};

if (Settings->Resolution == EPCGExAttributeToTagsResolution::Self)
{
Expand All @@ -137,13 +173,13 @@ namespace PCGExAttributesToTags
switch (Settings->Selection)
{
case EPCGExCollectionEntrySelection::FirstIndex:
Details.Tag(0, OutTags);
Tag(Details, 0);
break;
case EPCGExCollectionEntrySelection::LastIndex:
Details.Tag(PointDataFacade->GetNum() - 1, OutTags);
Tag(Details, PointDataFacade->GetNum() - 1);
break;
case EPCGExCollectionEntrySelection::RandomIndex:
Details.Tag(RandomSource.RandRange(0, PointDataFacade->GetNum() - 1), OutTags);
Tag(Details, RandomSource.RandRange(0, PointDataFacade->GetNum() - 1));
break;
}
}
Expand All @@ -154,21 +190,25 @@ namespace PCGExAttributesToTags
switch (Settings->Selection)
{
case EPCGExCollectionEntrySelection::FirstIndex:
Details.Tag(0, OutTags);
Tag(Details, 0);
break;
case EPCGExCollectionEntrySelection::LastIndex:
Details.Tag(PointDataFacade->GetNum() - 1, OutTags);
Tag(Details, PointDataFacade->GetNum() - 1);
break;
case EPCGExCollectionEntrySelection::RandomIndex:
Details.Tag(RandomSource.RandRange(0, PointDataFacade->GetNum() - 1), OutTags);
Tag(Details, RandomSource.RandRange(0, PointDataFacade->GetNum() - 1));
break;
}
}

PointDataFacade->Source->Tags->Append(OutTags);

return true;
}

void FProcessor::Output()
{
TPointsProcessor<FPCGExAttributesToTagsContext, UPCGExAttributesToTagsSettings>::Output();
if (OutputSet) { Context->StageOutput(FName("Tags"), OutputSet, false); }
}
}

#undef LOCTEXT_NAMESPACE
Expand Down
2 changes: 2 additions & 0 deletions Source/PCGExtendedToolkit/Private/Misc/PCGExGetGUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ PCGExData::EIOInit UPCGExGetGUIDSettings::GetMainOutputInitMode() const { return

PCGEX_INITIALIZE_ELEMENT(GetGUID)

bool UPCGExGetGUIDSettings::GetIsMainTransactional() const { return true; }

bool FPCGExGetGUIDElement::Boot(FPCGExContext* InContext) const
{
if (!FPCGExPointsProcessorElement::Boot(InContext)) { return false; }
Expand Down
14 changes: 11 additions & 3 deletions Source/PCGExtendedToolkit/Private/PCGExPointsProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ TArray<FPCGPinProperties> UPCGExPointsProcessorSettings::InputPinProperties() co

if (!IsInputless())
{
if (GetMainAcceptMultipleData()) { PCGEX_PIN_POINTS(GetMainInputPin(), "The point data to be processed.", Required, {}) }
else { PCGEX_PIN_POINT(GetMainInputPin(), "The point data to be processed.", Required, {}) }
if(!GetIsMainTransactional())
{
if (GetMainAcceptMultipleData()) { PCGEX_PIN_POINTS(GetMainInputPin(), "The point data to be processed.", Required, {}) }
else { PCGEX_PIN_POINT(GetMainInputPin(), "The point data to be processed.", Required, {}) }
}else
{
if (GetMainAcceptMultipleData()) { PCGEX_PIN_ANY(GetMainInputPin(), "The data to be processed.", Required, {}) }
else { PCGEX_PIN_ANY(GetMainInputPin(), "The data to be processed.", Required, {}) }
}

}

if (SupportsPointFilters())
Expand All @@ -52,7 +60,7 @@ TArray<FPCGPinProperties> UPCGExPointsProcessorSettings::InputPinProperties() co
TArray<FPCGPinProperties> UPCGExPointsProcessorSettings::OutputPinProperties() const
{
TArray<FPCGPinProperties> PinProperties;
PCGEX_PIN_POINTS(GetMainOutputPin(), "The processed points.", Required, {})
PCGEX_PIN_POINTS(GetMainOutputPin(), "The processed input.", Required, {})
return PinProperties;
}

Expand Down
1 change: 1 addition & 0 deletions Source/PCGExtendedToolkit/Public/Data/PCGExDataForward.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ struct /*PCGEXTENDEDTOOLKIT_API*/ FPCGExAttributeToTagDetails
bool Init(const FPCGContext* InContext, const TSharedPtr<PCGExData::FFacade>& InSourceFacade);
void Tag(const int32 TagIndex, TSet<FString>& InTags) const;
void Tag(const int32 TagIndex, const TSharedPtr<PCGExData::FPointIO>& PointIO) const;
void Tag(const int32 TagIndex, UPCGMetadata* InMetadata) const;
};
Loading

0 comments on commit 76f87d2

Please sign in to comment.