Skip to content

Commit 943b648

Browse files
authored
Merge pull request #37 from ZEISS-PiWeb/feature/ColorScales
feat: add a color scale property to the volume metadata
2 parents 2be215c + f5c2769 commit 943b648

File tree

2 files changed

+56
-19
lines changed

2 files changed

+56
-19
lines changed

src/PiWeb.Volume/PiWeb.Volume.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
</EmbeddedResource>
5959
</ItemGroup>
6060

61+
<ItemGroup>
62+
<PackageReference Include="Zeiss.PiWeb.ColorScale" Version="1.0.0"/>
63+
</ItemGroup>
64+
6165
<ItemGroup>
6266
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="LICENSE.txt" />
6367
<None Include="..\..\docs\img\logo_128x128.png" Pack="true" PackagePath="logo_128x128.png" />

src/PiWeb.Volume/VolumeMetadata.cs

+52-19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Zeiss.PiWeb.Volume
1818
using System.IO;
1919
using System.Text;
2020
using System.Xml;
21+
using Zeiss.PiWeb.ColorScale;
2122

2223
#endregion
2324

@@ -26,6 +27,24 @@ namespace Zeiss.PiWeb.Volume
2627
/// </summary>
2728
public sealed class VolumeMetadata
2829
{
30+
#region fields
31+
32+
private ushort _SizeX;
33+
private ushort _SizeY;
34+
private ushort _SizeZ;
35+
36+
private double _ResolutionX;
37+
private double _ResolutionY;
38+
private double _ResolutionZ;
39+
40+
private ushort _PositionX;
41+
private ushort _PositionY;
42+
private ushort _PositionZ;
43+
44+
private ColorScale? _ColorScale;
45+
46+
#endregion
47+
2948
#region constructors
3049

3150
private VolumeMetadata()
@@ -57,7 +76,6 @@ public VolumeMetadata(
5776
SizeX = sizeX;
5877
SizeY = sizeY;
5978
SizeZ = sizeZ;
60-
6179
ResolutionX = resolutionX;
6280
ResolutionY = resolutionY;
6381
ResolutionZ = resolutionZ;
@@ -78,53 +96,58 @@ public VolumeMetadata(
7896
/// <summary>
7997
/// The number of Voxels in X-Dimension.
8098
/// </summary>
81-
public ushort PositionX { get; private set; }
99+
public ushort PositionX { get => _PositionX; init => _PositionX = value; }
82100

83101
/// <summary>
84102
/// The number of Voxels in Y-Dimension.
85103
/// </summary>
86-
public ushort PositionY { get; private set; }
104+
public ushort PositionY { get => _PositionY; init => _PositionY = value; }
87105

88106
/// <summary>
89107
/// The number of Voxels in Z-Dimension.
90108
/// </summary>
91-
public ushort PositionZ { get; private set; }
109+
public ushort PositionZ { get => _PositionZ; init => _PositionZ = value; }
92110

93111
/// <summary>
94112
/// The number of Voxels in X-Dimension.
95113
/// </summary>
96-
public ushort SizeX { get; private set; }
114+
public ushort SizeX { get => _SizeX; init => _SizeX = value; }
97115

98116
/// <summary>
99117
/// The number of Voxels in Y-Dimension.
100118
/// </summary>
101-
public ushort SizeY { get; private set; }
119+
public ushort SizeY { get => _SizeY; init => _SizeY = value; }
102120

103121
/// <summary>
104122
/// The number of Voxels in Z-Dimension.
105123
/// </summary>
106-
public ushort SizeZ { get; private set; }
124+
public ushort SizeZ { get => _SizeZ; init => _SizeZ = value; }
107125

108126
/// <summary>
109127
/// The size of a Voxel in X-Dimension (mm).
110128
/// </summary>
111-
public double ResolutionX { get; private set; }
129+
public double ResolutionX { get => _ResolutionX; init => _ResolutionX = value; }
112130

113131
/// <summary>
114132
/// The size of a Voxel in Y-Dimension (mm).
115133
/// </summary>
116-
public double ResolutionY { get; private set; }
134+
public double ResolutionY { get => _ResolutionY; init => _ResolutionY = value; }
117135

118136
/// <summary>
119137
/// The size of a Voxel in Z-Dimension (mm).
120138
/// </summary>
121-
public double ResolutionZ { get; private set; }
139+
public double ResolutionZ { get => _ResolutionZ; init => _ResolutionZ = value; }
122140

123141
/// <summary>
124142
/// Gets or sets the metadata.
125143
/// </summary>
126144
public ICollection<Property> Properties { get; } = new List<Property>();
127145

146+
/// <summary>
147+
/// The color scale that should be used to colorize the grayscale values of the volume.
148+
/// </summary>
149+
public ColorScale? ColorScale { get => _ColorScale; init => _ColorScale = value; }
150+
128151
#endregion
129152

130153
#region methods
@@ -235,6 +258,13 @@ internal void Serialize( Stream stream, bool upgradeVersionNumber = true )
235258
}
236259
}
237260

261+
if( ColorScale is not null )
262+
{
263+
writer.WriteStartElement( "ColorScale" );
264+
ColorScale.Write( writer );
265+
writer.WriteEndElement();
266+
}
267+
238268
writer.WriteEndElement();
239269
writer.WriteEndDocument();
240270
}
@@ -264,36 +294,39 @@ internal static VolumeMetadata Deserialize( Stream stream )
264294
result.FileVersion = new Version( reader.ReadString() );
265295
break;
266296
case "SizeX":
267-
result.SizeX = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
297+
result._SizeX = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
268298
break;
269299
case "SizeY":
270-
result.SizeY = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
300+
result._SizeY = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
271301
break;
272302
case "SizeZ":
273-
result.SizeZ = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
303+
result._SizeZ = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
274304
break;
275305
case "ResolutionX":
276-
result.ResolutionX = double.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
306+
result._ResolutionX = double.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
277307
break;
278308
case "ResolutionY":
279-
result.ResolutionY = double.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
309+
result._ResolutionY = double.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
280310
break;
281311
case "ResolutionZ":
282-
result.ResolutionZ = double.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
312+
result._ResolutionZ = double.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
283313
break;
284314
case "Property":
285315
var property = Property.Deserialize( reader );
286316
if( property is not null )
287317
result.Properties.Add( property );
288318
break;
289319
case "PositionX":
290-
result.PositionX = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
320+
result._PositionX = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
291321
break;
292322
case "PositionY":
293-
result.PositionY = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
323+
result._PositionY = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
294324
break;
295325
case "PositionZ":
296-
result.PositionZ = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
326+
result._PositionZ = ushort.Parse( reader.ReadString(), CultureInfo.InvariantCulture );
327+
break;
328+
case "ColorScale":
329+
result._ColorScale = ColorScale.Read( reader );
297330
break;
298331
}
299332
}

0 commit comments

Comments
 (0)