Skip to content

Commit

Permalink
Filter updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebukam committed Sep 8, 2024
1 parent 8072eb2 commit f4b4fef
Show file tree
Hide file tree
Showing 22 changed files with 758 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ namespace PCGExDataBlending
PCGExData::FFacade* InPrimaryFacade,
const PCGExData::ESource SecondarySource,
const bool bInitFirstOperation,
const TSet<FName>* IgnoreAttributeSet)
const TSet<FName>* IgnoreAttributeSet,
const bool bSoftMode)
{
InternalPrepareForData(InPrimaryFacade, InPrimaryFacade, SecondarySource, bInitFirstOperation, IgnoreAttributeSet);
InternalPrepareForData(InPrimaryFacade, InPrimaryFacade, SecondarySource, bInitFirstOperation, IgnoreAttributeSet, bSoftMode);
}

void FMetadataBlender::PrepareForData(
PCGExData::FFacade* InPrimaryFacade,
PCGExData::FFacade* InSecondaryFacade,
const PCGExData::ESource SecondarySource,
const bool bInitFirstOperation,
const TSet<FName>* IgnoreAttributeSet)
const TSet<FName>* IgnoreAttributeSet,
const bool bSoftMode)
{
InternalPrepareForData(InPrimaryFacade, InSecondaryFacade, SecondarySource, bInitFirstOperation, IgnoreAttributeSet);
InternalPrepareForData(InPrimaryFacade, InSecondaryFacade, SecondarySource, bInitFirstOperation, IgnoreAttributeSet, bSoftMode);
}

void FMetadataBlender::PrepareRangeForBlending(
Expand Down Expand Up @@ -143,7 +145,8 @@ namespace PCGExDataBlending
PCGExData::FFacade* InSecondaryFacade,
const PCGExData::ESource SecondarySource,
const bool bInitFirstOperation,
const TSet<FName>* IgnoreAttributeSet)
const TSet<FName>* IgnoreAttributeSet,
const bool bSoftMode)
{
Cleanup();

Expand All @@ -162,7 +165,7 @@ namespace PCGExDataBlending
InSecondaryFacade->Source->CreateKeys(SecondarySource);

PrimaryPoints = &InPrimaryFacade->Source->GetOut()->GetMutablePoints();
SecondaryPoints = const_cast<TArray<FPCGPoint>*>(&InSecondaryFacade->Source->GetData(SecondarySource)->GetPoints());
SecondaryPoints = &InSecondaryFacade->Source->GetData(SecondarySource)->GetPoints();

TArray<PCGEx::FAttributeIdentity> Identities;
PCGEx::FAttributeIdentity::Get(InPrimaryFacade->Source->GetOut()->Metadata, Identities);
Expand Down Expand Up @@ -228,7 +231,8 @@ namespace PCGExDataBlending
if (Op->GetRequiresPreparation()) { OperationsToBePrepared.Add(Op); }
if (Op->GetRequiresFinalization()) { OperationsToBeCompleted.Add(Op); }

Op->PrepareForData(InPrimaryFacade, InSecondaryFacade, SecondarySource);
if (bSoftMode) { Op->SoftPrepareForData(InPrimaryFacade, InSecondaryFacade, SecondarySource); }
else { Op->PrepareForData(InPrimaryFacade, InSecondaryFacade, SecondarySource); }
}

FirstPointOperation.SetNum(PrimaryPoints->Num());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ case EPCGExDataBlendingType::Average: Target##_NAME = PCGExMath::Add(A._ACCESSO
case EPCGExDataBlendingType::Min: Target##_NAME = PCGExMath::Min(A._ACCESSOR, B._ACCESSOR);break;\
case EPCGExDataBlendingType::Max: Target##_NAME = PCGExMath::Max(A._ACCESSOR, B._ACCESSOR);break;\
case EPCGExDataBlendingType::Copy: Target##_NAME = PCGExMath::Copy(A._ACCESSOR, B._ACCESSOR);break;\
case EPCGExDataBlendingType::Sum: Target##_NAME = PCGExMath::Add(A._ACCESSOR, B._ACCESSOR);break;\
case EPCGExDataBlendingType::Add: Target##_NAME = PCGExMath::Add(A._ACCESSOR, B._ACCESSOR);break;\
case EPCGExDataBlendingType::Weight: Target##_NAME = PCGExMath::WeightedAdd(A._ACCESSOR, B._ACCESSOR, Weight);break;\
case EPCGExDataBlendingType::WeightedSum: Target##_NAME = PCGExMath::WeightedAdd(A._ACCESSOR, B._ACCESSOR, Weight);break;\
case EPCGExDataBlendingType::Lerp: Target##_NAME = PCGExMath::Lerp(A._ACCESSOR, B._ACCESSOR, Weight);break;}
case EPCGExDataBlendingType::WeightedAdd: Target##_NAME = PCGExMath::WeightedAdd(A._ACCESSOR, B._ACCESSOR, Weight);break;\
case EPCGExDataBlendingType::Lerp: Target##_NAME = PCGExMath::Lerp(A._ACCESSOR, B._ACCESSOR, Weight);break; \
case EPCGExDataBlendingType::Subtract: Target##_NAME = PCGExMath::Subtract(A._ACCESSOR, B._ACCESSOR);break; }

PCGEX_FOREACH_BLENDINIT_POINTPROPERTY(PCGEX_BLEND_PROPDECL)
#undef PCGEX_BLEND_PROPDECL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#define LOCTEXT_NAMESPACE "PCGExCompareFilterDefinition"
#define PCGEX_NAMESPACE CompareFilterDefinition

PCGExPointFilter::TFilter* UPCGExSelfCompareFilterFactory::CreateFilter() const
PCGExPointFilter::TFilter* UPCGExNumericSelfCompareFilterFactory::CreateFilter() const
{
return new PCGExPointsFilter::TSelfComparisonFilter(this);
return new PCGExPointsFilter::TNumericSelfComparisonFilter(this);
}

bool PCGExPointsFilter::TSelfComparisonFilter::Init(const FPCGContext* InContext, PCGExData::FFacade* InPointDataFacade)
bool PCGExPointsFilter::TNumericSelfComparisonFilter::Init(const FPCGContext* InContext, PCGExData::FFacade* InPointDataFacade)
{
if (!TFilter::Init(InContext, InPointDataFacade)) { return false; }

Expand All @@ -20,17 +20,16 @@ bool PCGExPointsFilter::TSelfComparisonFilter::Init(const FPCGContext* InContext

if (MaxIndex < 0) { return false; }

OperandA = PointDataFacade->GetScopedBroadcaster<double>(TypedFilterFactory->Config.OperandA);
OperandA = new PCGEx::FLocalSingleFieldGetter();
OperandA->Capture(TypedFilterFactory->Config.OperandA);

if (!OperandA)
if (!OperandA->SoftGrab(PointDataFacade->Source))
{
PCGE_LOG_C(Error, GraphAndLog, InContext, FText::Format(FTEXT("Invalid Operand A attribute: \"{0}\"."), FText::FromName(TypedFilterFactory->Config.OperandA.GetName())));
return false;
}

ComparisonValueGetter = new PCGEx::FLocalSingleFieldGetter();
ComparisonValueGetter->Capture(TypedFilterFactory->Config.OperandA);
ComparisonValueGetter->SoftGrab(PointDataFacade->Source);


if (TypedFilterFactory->Config.CompareAgainst == EPCGExFetchType::Attribute)
{
Expand All @@ -46,10 +45,10 @@ bool PCGExPointsFilter::TSelfComparisonFilter::Init(const FPCGContext* InContext
return true;
}

PCGEX_CREATE_FILTER_FACTORY(SelfCompare)
PCGEX_CREATE_FILTER_FACTORY(NumericSelfCompare)

#if WITH_EDITOR
FString UPCGExSelfCompareFilterProviderSettings::GetDisplayName() const
FString UPCGExNumericSelfCompareFilterProviderSettings::GetDisplayName() const
{
FString DisplayName = Config.OperandA.GetName().ToString() + PCGExCompare::ToString(Config.Comparison);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ bool PCGExPointsFilter::TStringCompareFilter::Init(const FPCGContext* InContext,
{
if (!TFilter::Init(InContext, InPointDataFacade)) { return false; }

OperandA = PointDataFacade->GetScopedReader<FString>(TypedFilterFactory->Config.OperandA);
if (!OperandA)
OperandA = new PCGEx::FLocalToStringGetter();
OperandA->Capture(TypedFilterFactory->Config.OperandA);

if (!OperandA->SoftGrab(PointDataFacade->Source))
{
PCGE_LOG_C(Error, GraphAndLog, InContext, FText::Format(FTEXT("Invalid Operand A attribute: {0}."), FText::FromName(TypedFilterFactory->Config.OperandA)));
return false;
}

if (TypedFilterFactory->Config.CompareAgainst == EPCGExFetchType::Attribute)
{
OperandB = PointDataFacade->GetScopedReader<FString>(TypedFilterFactory->Config.OperandB);
if (!OperandB)
OperandB = new PCGEx::FLocalToStringGetter();
OperandB->Capture(TypedFilterFactory->Config.OperandB);

if (!OperandB->SoftGrab(PointDataFacade->Source))
{
PCGE_LOG_C(Error, GraphAndLog, InContext, FText::Format(FTEXT("Invalid Operand B attribute: {0}."), FText::FromName(TypedFilterFactory->Config.OperandB)));
return false;
Expand All @@ -41,51 +45,7 @@ PCGEX_CREATE_FILTER_FACTORY(StringCompare)
FString UPCGExStringCompareFilterProviderSettings::GetDisplayName() const
{
FString DisplayName = Config.OperandA.ToString();

switch (Config.Comparison)
{
case EPCGExStringComparison::StrictlyEqual:
DisplayName += " == ";
break;
case EPCGExStringComparison::StrictlyNotEqual:
DisplayName += " != ";
break;
case EPCGExStringComparison::LengthStrictlyEqual:
DisplayName += " L == L ";
break;
case EPCGExStringComparison::LengthStrictlyUnequal:
DisplayName += " L != L ";
break;
case EPCGExStringComparison::LengthEqualOrGreater:
DisplayName += " L >= L ";
break;
case EPCGExStringComparison::LengthEqualOrSmaller:
DisplayName += " L <= L ";
break;
case EPCGExStringComparison::StrictlyGreater:
DisplayName += " L > L ";
break;
case EPCGExStringComparison::StrictlySmaller:
DisplayName += " L < L ";
break;
case EPCGExStringComparison::LocaleStrictlyGreater:
DisplayName += " > ";
break;
case EPCGExStringComparison::LocaleStrictlySmaller:
DisplayName += " < ";
break;
case EPCGExStringComparison::Contains:
DisplayName += " contains ";
break;
case EPCGExStringComparison::StartsWith:
DisplayName += " starts with ";
break;
case EPCGExStringComparison::EndsWith:
DisplayName += " ends with ";
break;
default: ;
}

DisplayName += PCGExCompare::ToString(Config.Comparison);
DisplayName += Config.CompareAgainst == EPCGExFetchType::Constant ? Config.OperandBConstant : Config.OperandB.ToString();
return DisplayName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright Timothé Lapetite 2024
// Released under the MIT license https://opensource.org/license/MIT/

#include "Misc/Filters/PCGExStringSelfCompareFilter.h"

#define LOCTEXT_NAMESPACE "PCGExCompareFilterDefinition"
#define PCGEX_NAMESPACE CompareFilterDefinition

PCGExPointFilter::TFilter* UPCGExStringSelfCompareFilterFactory::CreateFilter() const
{
return new PCGExPointsFilter::TStringSelfComparisonFilter(this);
}

bool PCGExPointsFilter::TStringSelfComparisonFilter::Init(const FPCGContext* InContext, PCGExData::FFacade* InPointDataFacade)
{
if (!TFilter::Init(InContext, InPointDataFacade)) { return false; }

bOffset = TypedFilterFactory->Config.IndexMode == EPCGExIndexMode::Offset;
MaxIndex = PointDataFacade->Source->GetNum() - 1;

if (MaxIndex < 0) { return false; }

OperandA = new PCGEx::FLocalToStringGetter();
OperandA->Capture(TypedFilterFactory->Config.OperandA);

if (!OperandA->SoftGrab(PointDataFacade->Source))
{
PCGE_LOG_C(Error, GraphAndLog, InContext, FText::Format(FTEXT("Invalid Operand A attribute: \"{0}\"."), FText::FromName(TypedFilterFactory->Config.OperandA)));
return false;
}

if (TypedFilterFactory->Config.CompareAgainst == EPCGExFetchType::Attribute)
{
Index = PointDataFacade->GetScopedBroadcaster<int32>(TypedFilterFactory->Config.IndexAttribute);

if (!Index)
{
PCGE_LOG_C(Error, GraphAndLog, InContext, FText::Format(FTEXT("Invalid Index attribute: \"{0}\"."), FText::FromName(TypedFilterFactory->Config.IndexAttribute.GetName())));
return false;
}
}

return true;
}

PCGEX_CREATE_FILTER_FACTORY(StringSelfCompare)

#if WITH_EDITOR
FString UPCGExStringSelfCompareFilterProviderSettings::GetDisplayName() const
{
FString DisplayName = Config.OperandA.ToString() + PCGExCompare::ToString(Config.Comparison);

if (Config.IndexMode == EPCGExIndexMode::Pick) { DisplayName += TEXT(" @ "); }
else { DisplayName += TEXT(" i+ "); }

if (Config.CompareAgainst == EPCGExFetchType::Attribute) { DisplayName += Config.IndexAttribute.GetName().ToString(); }
else { DisplayName += FString::Printf(TEXT("%d"), Config.IndexConstant); }

return DisplayName;
}
#endif

#undef LOCTEXT_NAMESPACE
#undef PCGEX_NAMESPACE
Loading

0 comments on commit f4b4fef

Please sign in to comment.