Skip to content

Commit

Permalink
Merge Poser2DDataSetReplicator and Poser3DDataSetReplicator weights r…
Browse files Browse the repository at this point in the history
…eplication code
  • Loading branch information
Neakita committed Sep 6, 2024
1 parent 3fa865f commit 96b6f07
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Collections.Immutable;
using SightKeeper.Data.Binary.Model.DataSets.Assets;
using SightKeeper.Data.Binary.Model.DataSets.Weights;
using SightKeeper.Data.Binary.Services;
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Model.DataSets.Assets;
using SightKeeper.Domain.Model.DataSets.Poser2D;
using SightKeeper.Domain.Model.DataSets.Screenshots;
using SightKeeper.Domain.Model.DataSets.Weights;

namespace SightKeeper.Data.Binary.Replication.DataSets;

internal sealed class Poser2DDataSetReplicator : PoserDataSetReplicator
internal sealed class Poser2DDataSetReplicator : PoserDataSetReplicator<Poser2DTag, KeyPointTag2D>
{
public Poser2DDataSetReplicator(FileSystemScreenshotsDataAccess screenshotsDataAccess) : base(screenshotsDataAccess)
{
Expand Down Expand Up @@ -42,28 +40,4 @@ protected override void ReplicateAsset(AssetsLibrary library, PackableAsset pack
packedItem.NumericProperties);
}
}

protected override void ReplicateWeights(WeightsLibrary library, PackableWeights weights, TagGetter getTag)
{
var typedLibrary = (WeightsLibrary<Poser2DTag, KeyPointTag2D>)library;
var typedWeights = (PackablePoserWeights)weights;
var tags = GetTags(typedWeights, getTag);
typedLibrary.CreateWeights(weights.CreationDate, weights.ModelSize, weights.Metrics, weights.Resolution, tags);
}

private static IEnumerable<(Poser2DTag, IEnumerable<KeyPointTag2D>)> GetTags(PackablePoserWeights weights, TagGetter getTag)
{
foreach (var (tagId, keyPointTagIds) in weights.Tags)
{
var tag = (Poser2DTag)getTag(tagId);
var keyPointTags = GetKeyPointTags(tagId, keyPointTagIds, getTag);
yield return (tag, keyPointTags);
}
}

private static IEnumerable<KeyPointTag2D> GetKeyPointTags(byte tagId, IEnumerable<byte> keyPointTagIds, TagGetter getTag)
{
foreach (var keyPointTagId in keyPointTagIds)
yield return (KeyPointTag2D)getTag(tagId, keyPointTagId);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Collections.Immutable;
using SightKeeper.Data.Binary.Model.DataSets.Assets;
using SightKeeper.Data.Binary.Model.DataSets.Weights;
using SightKeeper.Data.Binary.Services;
using SightKeeper.Domain.Model;
using SightKeeper.Domain.Model.DataSets.Assets;
using SightKeeper.Domain.Model.DataSets.Poser3D;
using SightKeeper.Domain.Model.DataSets.Screenshots;
using SightKeeper.Domain.Model.DataSets.Weights;

namespace SightKeeper.Data.Binary.Replication.DataSets;

internal sealed class Poser3DDataSetReplicator : PoserDataSetReplicator
internal sealed class Poser3DDataSetReplicator : PoserDataSetReplicator<Poser3DTag, KeyPointTag3D>
{
public Poser3DDataSetReplicator(FileSystemScreenshotsDataAccess screenshotsDataAccess) : base(screenshotsDataAccess)
{
Expand Down Expand Up @@ -44,28 +42,4 @@ protected override void ReplicateAsset(AssetsLibrary library, PackableAsset pack
packedItem.BooleanProperties);
}
}

protected override void ReplicateWeights(WeightsLibrary library, PackableWeights weights, TagGetter getTag)
{
var typedLibrary = (WeightsLibrary<Poser3DTag, KeyPointTag3D>)library;
var typedWeights = (PackablePoserWeights)weights;
var tags = GetTags(typedWeights, getTag);
typedLibrary.CreateWeights(weights.CreationDate, weights.ModelSize, weights.Metrics, weights.Resolution, tags);
}

private static IEnumerable<(Poser3DTag, IEnumerable<KeyPointTag3D>)> GetTags(PackablePoserWeights weights, TagGetter getTag)
{
foreach (var (tagId, keyPointTagIds) in weights.Tags)
{
var tag = (Poser3DTag)getTag(tagId);
var keyPointTags = GetKeyPointTags(tagId, keyPointTagIds, getTag);
yield return (tag, keyPointTags);
}
}

private static IEnumerable<KeyPointTag3D> GetKeyPointTags(byte tagId, IEnumerable<byte> keyPointTagIds, TagGetter getTag)
{
foreach (var keyPointTagId in keyPointTagIds)
yield return (KeyPointTag3D)getTag(tagId, keyPointTagId);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System.Collections.Immutable;
using SightKeeper.Data.Binary.Model.DataSets.Tags;
using SightKeeper.Data.Binary.Model.DataSets.Weights;
using SightKeeper.Data.Binary.Services;
using SightKeeper.Domain.Model.DataSets.Poser;
using SightKeeper.Domain.Model.DataSets.Tags;
using SightKeeper.Domain.Model.DataSets.Weights;

namespace SightKeeper.Data.Binary.Replication.DataSets;

internal abstract class PoserDataSetReplicator : DataSetReplicator
internal abstract class PoserDataSetReplicator<TTag, TKeyPointTag> : DataSetReplicator
where TTag : PoserTag
where TKeyPointTag : KeyPointTag<TTag>
{
protected PoserDataSetReplicator(FileSystemScreenshotsDataAccess screenshotsDataAccess) : base(screenshotsDataAccess)
{
Expand All @@ -24,4 +28,28 @@ protected override PoserTag ReplicateTag(TagsLibrary library, PackableTag packed
}
return tag;
}

protected sealed override void ReplicateWeights(WeightsLibrary library, PackableWeights weights, TagGetter getTag)
{
var typedLibrary = (WeightsLibrary<TTag, TKeyPointTag>)library;
var typedWeights = (PackablePoserWeights)weights;
var tags = GetTags(typedWeights, getTag);
typedLibrary.CreateWeights(weights.CreationDate, weights.ModelSize, weights.Metrics, weights.Resolution, tags);
}

private static IEnumerable<(TTag, IEnumerable<TKeyPointTag>)> GetTags(PackablePoserWeights weights, TagGetter getTag)
{
foreach (var (tagId, keyPointTagIds) in weights.Tags)
{
var tag = (TTag)getTag(tagId);
var keyPointTags = GetKeyPointTags(tagId, keyPointTagIds, getTag);
yield return (tag, keyPointTags);
}
}

private static IEnumerable<TKeyPointTag> GetKeyPointTags(byte tagId, IEnumerable<byte> keyPointTagIds, TagGetter getTag)
{
foreach (var keyPointTagId in keyPointTagIds)
yield return (TKeyPointTag)getTag(tagId, keyPointTagId);
}
}

0 comments on commit 96b6f07

Please sign in to comment.