Skip to content

Commit cb62313

Browse files
committed
Use texture source as payload identity carrier
1 parent ed4272e commit cb62313

11 files changed

Lines changed: 118 additions & 129 deletions

src/PlateauResoniteLink/Application/Importing/CityGmlAppearanceStore.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,11 @@ private void ApplyGeoreferencedTexture(XElement textureElement)
191191
texturePayload = new EncodedImageTexturePayload(
192192
null,
193193
null,
194-
"sRGB",
195194
TextureImportSourceFactory.CreateDatasetEncodedImage(
196195
datasetSource,
197196
resolvedTexturePath,
198197
"sRGB",
199-
$"dataset:{resolvedTexturePath}"),
200-
$"dataset:{resolvedTexturePath}");
198+
$"dataset:{resolvedTexturePath}"));
201199
texturePayloadsByResolvedPath[resolvedTexturePath] = texturePayload;
202200
}
203201

src/PlateauResoniteLink/Application/Importing/MaterialGroupingPolicy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal static MaterialGroupingKey CreateKey(
3333

3434
return new MaterialGroupingKey(
3535
material.MaterialType,
36-
material.TexturePayload?.Identity,
36+
material.TexturePayload?.Source.Identity,
3737
material.TextureSourceKind,
3838
material.Projection,
3939
depthOffset,

src/PlateauResoniteLink/Application/Importing/SceneImportContractTypes.cs

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,13 @@ public sealed record MeshSubmesh(
9898

9999
public abstract record TexturePayload
100100
{
101-
private protected TexturePayload(
102-
string? colorProfile,
103-
string identity,
104-
ITextureImportSource source)
101+
private protected TexturePayload(ITextureImportSource source)
105102
{
106-
if (string.IsNullOrWhiteSpace(identity))
107-
{
108-
throw new ArgumentException("Texture payload identity must be provided.", nameof(identity));
109-
}
110-
111-
ColorProfile = colorProfile;
112-
Identity = identity;
113-
Source = source ?? throw new ArgumentNullException(nameof(source));
114-
}
115-
116-
public string? ColorProfile { get; }
103+
ArgumentNullException.ThrowIfNull(source);
104+
ArgumentException.ThrowIfNullOrWhiteSpace(source.Identity);
117105

118-
public string Identity { get; }
106+
Source = source;
107+
}
119108

120109
public ITextureImportSource Source { get; }
121110
}
@@ -142,8 +131,8 @@ private RawRgba32TexturePayload(
142131
int height,
143132
string? colorProfile,
144133
byte[] binaryPayload,
145-
(string Identity, ITextureImportSource Source) source)
146-
: base(colorProfile, source.Identity, source.Source)
134+
ITextureImportSource source)
135+
: base(source)
147136
{
148137
ArgumentNullException.ThrowIfNull(binaryPayload);
149138
Width = width;
@@ -157,7 +146,7 @@ private RawRgba32TexturePayload(
157146

158147
public ImmutableArray<byte> BinaryPayload { get; }
159148

160-
private static (string Identity, ITextureImportSource Source) CreateSource(
149+
private static ITextureImportSource CreateSource(
161150
int width,
162151
int height,
163152
string? colorProfile,
@@ -166,14 +155,12 @@ private static (string Identity, ITextureImportSource Source) CreateSource(
166155
{
167156
ArgumentNullException.ThrowIfNull(binaryPayload);
168157
string effectiveIdentity = identity ?? Guid.NewGuid().ToString("N");
169-
return (
170-
effectiveIdentity,
171-
TextureImportSourceFactory.CreateInMemoryRaw(
172-
width,
173-
height,
174-
colorProfile,
175-
binaryPayload,
176-
effectiveIdentity));
158+
return TextureImportSourceFactory.CreateInMemoryRaw(
159+
width,
160+
height,
161+
colorProfile,
162+
binaryPayload,
163+
effectiveIdentity);
177164
}
178165
}
179166

@@ -182,19 +169,8 @@ public sealed record EncodedImageTexturePayload : TexturePayload
182169
public EncodedImageTexturePayload(
183170
int? width,
184171
int? height,
185-
string? colorProfile,
186-
ITextureImportSource source,
187-
string? identity = null)
188-
: this(width, height, colorProfile, CreateSource(source, identity))
189-
{
190-
}
191-
192-
private EncodedImageTexturePayload(
193-
int? width,
194-
int? height,
195-
string? colorProfile,
196-
(string Identity, ITextureImportSource Source) source)
197-
: base(colorProfile, source.Identity, source.Source)
172+
ITextureImportSource source)
173+
: base(source)
198174
{
199175
Width = width;
200176
Height = height;
@@ -203,14 +179,6 @@ private EncodedImageTexturePayload(
203179
public int? Width { get; }
204180

205181
public int? Height { get; }
206-
207-
private static (string Identity, ITextureImportSource Source) CreateSource(
208-
ITextureImportSource source,
209-
string? identity)
210-
{
211-
ArgumentNullException.ThrowIfNull(source);
212-
return (identity ?? source.Identity, source);
213-
}
214182
}
215183

216184
public enum TextureSourceKind

src/PlateauResoniteLink/Targets/Resonite/ResoniteTexturePayload.cs

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,15 @@ namespace PlateauResoniteLink.Targets.Resonite;
77

88
public abstract class ResoniteTexturePayload
99
{
10-
private protected ResoniteTexturePayload(
11-
string? colorProfile,
12-
string identity,
13-
ITextureImportSource source)
10+
private protected ResoniteTexturePayload(ITextureImportSource source)
1411
{
15-
if (string.IsNullOrWhiteSpace(identity))
12+
Source = source ?? throw new ArgumentNullException(nameof(source));
13+
if (string.IsNullOrWhiteSpace(Source.Identity))
1614
{
17-
throw new ArgumentException("Resonite texture payload identity must be provided.", nameof(identity));
15+
throw new ArgumentException("Texture source identity must be non-empty.", nameof(source));
1816
}
19-
20-
ColorProfile = colorProfile;
21-
Identity = identity;
22-
Source = source ?? throw new ArgumentNullException(nameof(source));
2317
}
2418

25-
public string? ColorProfile { get; }
26-
27-
public string Identity { get; }
28-
2919
public ITextureImportSource Source { get; }
3020
}
3121

@@ -51,8 +41,8 @@ private RawRgba32ResoniteTexturePayload(
5141
int height,
5242
string? colorProfile,
5343
byte[] binaryPayload,
54-
(string Identity, ITextureImportSource Source) source)
55-
: base(colorProfile, source.Identity, source.Source)
44+
ITextureImportSource source)
45+
: base(source)
5646
{
5747
ArgumentNullException.ThrowIfNull(binaryPayload);
5848
Width = width;
@@ -66,7 +56,7 @@ private RawRgba32ResoniteTexturePayload(
6656

6757
public ImmutableArray<byte> BinaryPayload { get; }
6858

69-
private static (string Identity, ITextureImportSource Source) CreateSource(
59+
private static ITextureImportSource CreateSource(
7060
int width,
7161
int height,
7262
string? colorProfile,
@@ -75,14 +65,12 @@ private static (string Identity, ITextureImportSource Source) CreateSource(
7565
{
7666
ArgumentNullException.ThrowIfNull(binaryPayload);
7767
string effectiveIdentity = identity ?? Guid.NewGuid().ToString("N");
78-
return (
79-
effectiveIdentity,
80-
TextureImportSourceFactory.CreateInMemoryRaw(
81-
width,
82-
height,
83-
colorProfile,
84-
binaryPayload,
85-
effectiveIdentity));
68+
return TextureImportSourceFactory.CreateInMemoryRaw(
69+
width,
70+
height,
71+
colorProfile,
72+
binaryPayload,
73+
effectiveIdentity);
8674
}
8775
}
8876

@@ -91,19 +79,8 @@ public sealed class EncodedImageResoniteTexturePayload : ResoniteTexturePayload
9179
public EncodedImageResoniteTexturePayload(
9280
int? width,
9381
int? height,
94-
string? colorProfile,
95-
ITextureImportSource source,
96-
string? identity = null)
97-
: this(width, height, colorProfile, CreateSource(source, identity))
98-
{
99-
}
100-
101-
private EncodedImageResoniteTexturePayload(
102-
int? width,
103-
int? height,
104-
string? colorProfile,
105-
(string Identity, ITextureImportSource Source) source)
106-
: base(colorProfile, source.Identity, source.Source)
82+
ITextureImportSource source)
83+
: base(source)
10784
{
10885
Width = width;
10986
Height = height;
@@ -112,12 +89,4 @@ private EncodedImageResoniteTexturePayload(
11289
public int? Width { get; }
11390

11491
public int? Height { get; }
115-
116-
private static (string Identity, ITextureImportSource Source) CreateSource(
117-
ITextureImportSource source,
118-
string? identity)
119-
{
120-
ArgumentNullException.ThrowIfNull(source);
121-
return (identity ?? source.Identity, source);
122-
}
12392
}

src/PlateauResoniteLink/Targets/Resonite/SceneImportContractMapper.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,13 @@ private static ResoniteTexturePayload ToInternal(TexturePayload payload)
144144
RawRgba32TexturePayload raw => new RawRgba32ResoniteTexturePayload(
145145
raw.Width,
146146
raw.Height,
147-
raw.ColorProfile,
147+
raw.Source.ColorProfile,
148148
raw.BinaryPayload.AsSpan().ToArray(),
149-
raw.Identity),
149+
raw.Source.Identity),
150150
EncodedImageTexturePayload encoded => new EncodedImageResoniteTexturePayload(
151151
encoded.Width,
152152
encoded.Height,
153-
encoded.ColorProfile,
154-
encoded.Source,
155-
encoded.Identity),
153+
encoded.Source),
156154
_ => throw new ArgumentOutOfRangeException(nameof(payload), payload.GetType(), "Unsupported texture payload type."),
157155
};
158156
}

tests/PlateauResoniteLink.Tests/Application/TexturePayloadTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
using PlateauResoniteLink.Application.Importing;
24

35
namespace PlateauResoniteLink.Tests.Application;
@@ -14,4 +16,31 @@ public void ConstructorCopiesBinaryPayloadBytes()
1416

1517
Assert.Equal<byte>([1, 2, 3, 4], payload.BinaryPayload);
1618
}
19+
20+
[Fact]
21+
public void ConstructorCarriesIdentityAndColorProfileOnSourceOnly()
22+
{
23+
RawRgba32TexturePayload payload = new(1, 1, "sRGB", [1, 2, 3, 4], "dataset:texture");
24+
25+
Assert.Equal("dataset:texture", payload.Source.Identity);
26+
Assert.Equal("sRGB", payload.Source.ColorProfile);
27+
}
28+
29+
[Fact]
30+
public void ConstructorRejectsTextureSourceWithoutIdentity()
31+
{
32+
Assert.Throws<ArgumentException>(
33+
() => new EncodedImageTexturePayload(null, null, new BlankIdentityTextureImportSource()));
34+
}
35+
36+
private sealed class BlankIdentityTextureImportSource : ITextureImportSource
37+
{
38+
public string Identity => " ";
39+
40+
public string Description => "blank";
41+
42+
public string? ColorProfile => null;
43+
44+
public long? EstimatedByteLength => null;
45+
}
1746
}

tests/PlateauResoniteLink.Tests/Profiles/LocalCityGmlObjectProjectionTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,10 +2071,10 @@ public void ProjectCityObjectCullsBottomBandBuildingSurfacesBySemanticOrDownward
20712071
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));
20722072

20732073
Assert.Equal(3, projected.Materials.Count);
2074-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "ground");
2075-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "ground-reversed");
2076-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "outer-floor");
2077-
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "high-outer-floor");
2074+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "ground");
2075+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "ground-reversed");
2076+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "outer-floor");
2077+
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "high-outer-floor");
20782078
}
20792079

20802080
[Fact]
@@ -2111,7 +2111,7 @@ public void ProjectCityObjectKeepsNonBuildingDownwardHorizontalGroundSurface()
21112111
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));
21122112

21132113
Assert.Single(projected.Materials);
2114-
Assert.Equal("tran-ground", projected.Materials[0].TexturePayload?.Identity);
2114+
Assert.Equal("tran-ground", projected.Materials[0].TexturePayload?.Source.Identity);
21152115
Assert.NotEmpty(projected.Mesh.Vertices);
21162116
}
21172117

@@ -2169,10 +2169,10 @@ public void ProjectCityObjectCullsBuildingLod1UnknownBottomBandSurfaces()
21692169
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));
21702170

21712171
Assert.Equal(2, projected.Materials.Count);
2172-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-bottom");
2173-
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-bottom-reversed");
2174-
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-roof");
2175-
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "lod1-wall");
2172+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-bottom");
2173+
Assert.DoesNotContain(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-bottom-reversed");
2174+
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-roof");
2175+
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "lod1-wall");
21762176
}
21772177

21782178
[Fact]
@@ -2244,7 +2244,7 @@ public void ProjectCityObjectKeepsSingleDownwardHorizontalBuildingSurfaceWhenNoH
22442244
materialResolver: new DefaultMaterialResolver(CommonMaterialCatalog.Create()));
22452245

22462246
Assert.Single(projected.Materials);
2247-
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Identity == "only-surface");
2247+
Assert.Contains(projected.Materials, static material => material.TexturePayload?.Source.Identity == "only-surface");
22482248
}
22492249

22502250
[Fact]
@@ -2379,7 +2379,7 @@ await service.ExecuteAsync(
23792379
Assert.NotNull(explicitMaterial.TexturePayload);
23802380
Assert.Contains(
23812381
"udx/dem/53394525/appearance/mixed_surface.png",
2382-
explicitMaterial.TexturePayload!.Identity,
2382+
explicitMaterial.TexturePayload!.Source.Identity,
23832383
StringComparison.Ordinal);
23842384
}
23852385

0 commit comments

Comments
 (0)