Skip to content

Commit 0a0d425

Browse files
committed
Added Cell Hash artifact
1 parent 58aa817 commit 0a0d425

File tree

8 files changed

+59
-19
lines changed

8 files changed

+59
-19
lines changed

Source/PCGExtendedToolkit/Private/Data/PCGExDataHelpers.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,25 @@ namespace PCGExDataHelpers
4949
Attribute->SetDefaultValue(Value);
5050
}
5151

52+
template <typename T>
53+
void SetDataValue(UPCGData* InData, FName Name, const T Value)
54+
{
55+
FPCGAttributeIdentifier Identifier = FPCGAttributeIdentifier(Name, EPCGMetadataDomainFlag::Data);
56+
SetDataValue<T>(InData->Metadata->FindOrCreateAttribute<T>(Identifier, Value, true, true), Value);
57+
}
58+
59+
template <typename T>
60+
void SetDataValue(UPCGData* InData, FPCGAttributeIdentifier Identifier, const T Value)
61+
{
62+
SetDataValue<T>(InData, Identifier.Name, Value);
63+
}
64+
5265
#define PCGEX_TPL(_TYPE, _NAME, ...) \
5366
template PCGEXTENDEDTOOLKIT_API _TYPE ReadDataValue<_TYPE>(const FPCGMetadataAttribute<_TYPE>* Attribute); \
5467
template PCGEXTENDEDTOOLKIT_API _TYPE ReadDataValue<_TYPE>(const FPCGMetadataAttributeBase* Attribute, _TYPE Fallback); \
55-
template PCGEXTENDEDTOOLKIT_API void SetDataValue<_TYPE>(FPCGMetadataAttribute<_TYPE>* Attribute, const _TYPE Value);
68+
template PCGEXTENDEDTOOLKIT_API void SetDataValue<_TYPE>(FPCGMetadataAttribute<_TYPE>* Attribute, const _TYPE Value); \
69+
template PCGEXTENDEDTOOLKIT_API void SetDataValue<_TYPE>(UPCGData* InData, FName Name, const _TYPE Value); \
70+
template PCGEXTENDEDTOOLKIT_API void SetDataValue<_TYPE>(UPCGData* InData, FPCGAttributeIdentifier Identifier, const _TYPE Value);
5671
PCGEX_FOREACH_SUPPORTEDTYPES(PCGEX_TPL)
5772
#undef PCGEX_TPL
5873

Source/PCGExtendedToolkit/Private/Data/PCGExUnionData.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace PCGExData
1515
int32 IUnionData::ComputeWeights(
1616
const TArray<const UPCGBasePointData*>& Sources, const TSharedPtr<PCGEx::FIndexLookup>& IdxLookup, const FPoint& Target,
1717
const TSharedPtr<PCGExDetails::FDistances>& InDistanceDetails, TArray<FWeightedPoint>& OutWeightedPoints) const
18-
{
18+
{
1919
const int32 NumElements = Elements.Num();
2020
OutWeightedPoints.Reset(NumElements);
2121

@@ -63,14 +63,14 @@ namespace PCGExData
6363
void IUnionData::Add_Unsafe(const FElement& Point)
6464
{
6565
IOSet.Add(Point.IO);
66-
Elements.Add(FElement(Point.Index == -1 ? 0 : Point.Index, Point.IO));
66+
Elements.Emplace(Point.Index == -1 ? 0 : Point.Index, Point.IO);
6767
}
6868

6969
void IUnionData::Add(const FElement& Point)
7070
{
7171
FWriteScopeLock WriteScopeLock(UnionLock);
7272
IOSet.Add(Point.IO);
73-
Elements.Add(FElement(Point.Index == -1 ? 0 : Point.Index, Point.IO));
73+
Elements.Emplace(Point.Index == -1 ? 0 : Point.Index, Point.IO);
7474
}
7575

7676

Source/PCGExtendedToolkit/Private/Details/PCGExDetailsSettings.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Data/PCGExData.h"
1111
#include "Data/PCGExDataHelpers.h"
1212
#include "Data/PCGExPointIO.h"
13+
#include "Data/PCGExValueHash.h"
1314

1415
namespace PCGExDetails
1516
{
@@ -40,7 +41,10 @@ namespace PCGExDetails
4041

4142
template <typename T>
4243
T TSettingValueBuffer<T>::Max() { return Buffer->Max; }
43-
44+
45+
template <typename T>
46+
uint32 TSettingValueBuffer<T>::ReadValueHash(const int32 Index){ return Buffer->ReadValueHash(Index); }
47+
4448
template <typename T>
4549
bool TSettingValueSelector<T>::Init(const TSharedPtr<PCGExData::FFacade>& InDataFacade, const bool bSupportScoped, const bool bCaptureMinMax)
4650
{
@@ -68,9 +72,15 @@ namespace PCGExDetails
6872
template <typename T>
6973
T TSettingValueSelector<T>::Max() { return Buffer->Max; }
7074

75+
template <typename T>
76+
uint32 TSettingValueSelector<T>::ReadValueHash(const int32 Index){ return Buffer->ReadValueHash(Index); }
77+
7178
template <typename T>
7279
bool TSettingValueConstant<T>::Init(const TSharedPtr<PCGExData::FFacade>& InDataFacade, const bool bSupportScoped, const bool bCaptureMinMax) { return true; }
7380

81+
template <typename T>
82+
uint32 TSettingValueConstant<T>::ReadValueHash(const int32 Index) { return PCGExBlend::ValueHash(Constant); }
83+
7484
template <typename T>
7585
bool TSettingValueSelectorConstant<T>::Init(const TSharedPtr<PCGExData::FFacade>& InDataFacade, const bool bSupportScoped, const bool bCaptureMinMax)
7686
{

Source/PCGExtendedToolkit/Private/Paths/PCGExPaths.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ namespace PCGExPaths
8989

9090
void SetClosedLoop(UPCGData* InData, const bool bIsClosedLoop)
9191
{
92-
FPCGMetadataAttribute<bool>* Attr = PCGEx::TryGetMutableAttribute<bool>(InData, ClosedLoopIdentifier);
93-
if (!Attr) { Attr = InData->Metadata->CreateAttribute<bool>(ClosedLoopIdentifier, bIsClosedLoop, true, true); }
94-
PCGExDataHelpers::SetDataValue(Attr, bIsClosedLoop);
92+
PCGExDataHelpers::SetDataValue(InData, ClosedLoopIdentifier, bIsClosedLoop);
9593
}
9694

9795
void SetClosedLoop(const TSharedPtr<PCGExData::FPointIO>& InData, const bool bIsClosedLoop)

Source/PCGExtendedToolkit/Private/Topology/PCGExTopology.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "PCGExContext.h"
77
#include "Data/PCGExData.h"
8+
#include "Data/PCGExDataHelpers.h"
89
#include "Data/PCGExDataTag.h"
910
#include "Data/PCGExPointElements.h"
1011
#include "Data/PCGExPointIO.h"
@@ -471,7 +472,7 @@ namespace PCGExTopology
471472
}
472473

473474
const PCGExGraph::FEdge* E = InCluster->GetEdge(Link.Edge);
474-
475+
475476
// choose a deterministic right-hand frame
476477
Link.Node = InCluster->GetGuidedHalfEdge(Link.Edge, SeedPosition, UpVector)->Index;
477478
return BuildFromCluster(Link, InCluster, ProjectedPositions);
@@ -491,7 +492,7 @@ namespace PCGExTopology
491492

492493
bool FPCGExCellArtifactsDetails::WriteAny() const
493494
{
494-
return bWriteVtxId || bFlagTerminalPoint || bWriteNumRepeat;
495+
return bWriteCellHash || bWriteVtxId || bFlagTerminalPoint || bWriteNumRepeat;
495496
}
496497

497498
bool FPCGExCellArtifactsDetails::Init(FPCGExContext* InContext)
@@ -550,17 +551,13 @@ void FPCGExCellArtifactsDetails::Process(
550551
for (int i = 0; i < NumNodes; i++)
551552
{
552553
int32 NodeIdx = InCell->Nodes[i];
553-
int32 Count = NumRepeats.FindOrAdd(NodeIdx, 0);
554-
NumRepeats.Add(NodeIdx, Count + 1);
554+
NumRepeats.Add(NodeIdx, NumRepeats.FindOrAdd(NodeIdx, 0) + 1);
555555
}
556556
}
557557

558-
for (int i = 0; i < NumNodes; i++)
559-
{
560-
int32 NodeIdx = InCell->Nodes[i];
561-
if (TerminalBuffer) { TerminalBuffer->SetValue(i, InCluster->GetNode(NodeIdx)->IsLeaf()); }
562-
if (RepeatBuffer) { RepeatBuffer->SetValue(i, NumRepeats[NodeIdx] - 1); }
563-
}
558+
if (bWriteCellHash) { PCGExDataHelpers::SetDataValue(InDataFacade->GetOut(), CellHashAttributeName, static_cast<int64>(InCell->GetCellHash())); }
559+
if (TerminalBuffer) { for (int i = 0; i < NumNodes; i++) { TerminalBuffer->SetValue(i, InCluster->GetNode(InCell->Nodes[i])->IsLeaf()); } }
560+
if (RepeatBuffer) { for (int i = 0; i < NumNodes; i++) { RepeatBuffer->SetValue(i, NumRepeats[InCell->Nodes[i]] - 1); } }
564561

565562
const TSharedPtr<PCGExData::TBuffer<int32>> VtxIDBuffer = bWriteVtxId ? InDataFacade->GetWritable(VtxIdAttributeName, 0, true, PCGExData::EBufferInit::New) : nullptr;
566563
if (VtxIDBuffer)

Source/PCGExtendedToolkit/Public/Data/PCGExDataHelpers.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,19 @@ namespace PCGExDataHelpers
3636

3737
template <typename T>
3838
void SetDataValue(FPCGMetadataAttribute<T>* Attribute, const T Value);
39+
40+
template <typename T>
41+
void SetDataValue(UPCGData* InData, FName Name, const T Value);
42+
43+
template <typename T>
44+
void SetDataValue(UPCGData* InData, FPCGAttributeIdentifier Identifier, const T Value);
3945

4046
#define PCGEX_TPL(_TYPE, _NAME, ...) \
4147
extern template _TYPE ReadDataValue<_TYPE>(const FPCGMetadataAttribute<_TYPE>* Attribute); \
4248
extern template _TYPE ReadDataValue<_TYPE>(const FPCGMetadataAttributeBase* Attribute, _TYPE Fallback); \
43-
extern template void SetDataValue<_TYPE>(FPCGMetadataAttribute<_TYPE>* Attribute, const _TYPE Value);
49+
extern template void SetDataValue<_TYPE>(FPCGMetadataAttribute<_TYPE>* Attribute, const _TYPE Value); \
50+
extern template void SetDataValue<_TYPE>(UPCGData* InData, FName Name, const _TYPE Value); \
51+
extern template void SetDataValue<_TYPE>(UPCGData* InData, FPCGAttributeIdentifier Identifier, const _TYPE Value);
4452
PCGEX_FOREACH_SUPPORTEDTYPES(PCGEX_TPL)
4553
#undef PCGEX_TPL
4654

Source/PCGExtendedToolkit/Public/Details/PCGExDetailsSettings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace PCGExDetails
4040
FORCEINLINE virtual T Read(const int32 Index) = 0;
4141
FORCEINLINE virtual T Min() = 0;
4242
FORCEINLINE virtual T Max() = 0;
43+
FORCEINLINE virtual uint32 ReadValueHash(const int32 Index) = 0;
4344
};
4445

4546
template <typename T>
@@ -60,6 +61,7 @@ namespace PCGExDetails
6061
virtual T Read(const int32 Index) override;
6162
virtual T Min() override;
6263
virtual T Max() override;
64+
virtual uint32 ReadValueHash(const int32 Index) override;
6365
};
6466

6567
template <typename T>
@@ -80,6 +82,7 @@ namespace PCGExDetails
8082
virtual T Read(const int32 Index) override;
8183
virtual T Min() override;
8284
virtual T Max() override;
85+
virtual uint32 ReadValueHash(const int32 Index) override;
8386
};
8487

8588
template <typename T>
@@ -102,6 +105,7 @@ namespace PCGExDetails
102105
FORCEINLINE virtual T Read(const int32 Index) override { return Constant; }
103106
FORCEINLINE virtual T Min() override { return Constant; }
104107
FORCEINLINE virtual T Max() override { return Constant; }
108+
virtual uint32 ReadValueHash(const int32 Index) override;
105109
};
106110

107111
template <typename T>

Source/PCGExtendedToolkit/Public/Topology/PCGExTopology.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,14 @@ struct PCGEXTENDEDTOOLKIT_API FPCGExCellArtifactsDetails
551551
{
552552
}
553553

554+
/** */
555+
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings, meta = (PCG_Overridable, InlineEditConditionToggle))
556+
bool bWriteCellHash = false;
557+
558+
/** Write cell unique hash as a @Data attribute */
559+
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings, meta = (PCG_Overridable, DisplayName = "Cell Hash", EditCondition="bWriteCellHash"))
560+
FName CellHashAttributeName = FName("CellHash");
561+
554562
/** */
555563
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Settings, meta = (PCG_Overridable, InlineEditConditionToggle))
556564
bool bWriteVtxId = false;

0 commit comments

Comments
 (0)