IOLink C# 1.11.0
Loading...
Searching...
No Matches
DiskImageView.cs

This code demonstrates how to create an image view on disk and write/read data to/from it. The code creates a 3D image of size 100x100x100 without allocating any CPU memory, and writes a line of data in each slice. Finally, it then reads and prints the value of the last written sample.

using IOLink;
using System;
using System.Runtime.Intrinsics;
namespace Examples
{
public class DiskImageView
{
static ImageView Generate()
{
VectorXu64 shape = new VectorXu64(100, 100, 100);
DataType dt = DataTypeId.DOUBLE;
// create an image view on disk
double[] lineBuffer = new double[shape[0]];
VectorXu64 lineSize = new VectorXu64(shape[0], 1, 1);
Console.WriteLine("Writing data slice by slice, line by line");
// write data slice by slice, line by line with a
// growing value
double valueInit = 0;
for (ulong i = 0; i < shape[2]; ++i)
{
for (ulong j = 0; j < shape[1]; ++j)
{
RegionXu64 lineRegion = new RegionXu64(new VectorXu64(0, j, i), lineSize);
// fill buffer with the same value
for (ulong k = 0; k < shape[0]; ++k)
{
lineBuffer[k] = valueInit;
}
image.WriteRegion(lineRegion, lineBuffer);
valueInit++;
}
}
Console.WriteLine("Writing completed");
return image;
}
public static void Main(string[] args)
{
var image = Generate();
Console.WriteLine("Reading Last Sample");
byte[] bytearr = new byte[8];
image.Read(new VectorXu64(99, 99, 99), bytearr);
// convert byte array to double
double value = BitConverter.ToDouble(bytearr, 0);
Console.WriteLine("Last Sample Value: " + value);
Console.WriteLine("SUCCESS");
}
}
}
Definition CreateDataFrame.cs:6