| 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
ImageView image = ImageViewFactory.CreateOnDisk(shape, dt);
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");
}
}
}
IOLink.DataType
Stores information about a data type.
Definition DataType.cs:24
IOLink.ImageViewFactory
This factory is aimed at creating dataset views.
Definition ImageViewFactory.cs:21
IOLink.ImageViewFactory.CreateOnDisk
static ImageView CreateOnDisk(string dirPath, VectorXu64 shape, DataType type, ImageProperties properties, MetadataNode metadata)
Create an image with the data stored into a temporary file (in given folder) on disk in raw.
Definition ImageViewFactory.cs:143
IOLink.ImageView
Interface representing an N dimensional image.
Definition ImageView.cs:30
IOLink.ImageView.WriteRegion
unsafe void WriteRegion(RegionXu64 region, byte[] src)
Write a input buffer into a given region of the image.
Definition ImageView.cs:387
IOLink.RegionXu64
A Region using dynamic vectors.
Definition RegionXu64.cs:14
IOLink.VectorXu64
A dynamically sized arithmetic vector.
Definition VectorXu64.cs:14
Examples
Definition CreateDataFrame.cs:6
IOLink
Definition AccessCapabilities.cs:11
IOLink.DataTypeId
DataTypeId
A collection of built-in data types.
Definition DataTypeId.cs:15