This code demonstrates how to generate a grayscale sphere in a 3D volume. All voxels inside the sphere have value = 255, and others are 0.
using System;
using System.Numerics;
using System.Runtime.Intrinsics;
{
public class GrayscaleSphere
{
{
{
throw new ApplicationException("Shape must have 3 dimensions");
}
ulong radius = Math.Min(center[0], center[1]);
radius = Math.Min(radius, center[2]);
Byte[] filledVoxel = new Byte[] { 255 };
Byte[] emptyVoxel = new Byte[] { 0 };
for (ulong z = 0; z < shape[2]; z++)
{
for (ulong y = 0; y < shape[1]; y++)
{
for (ulong x = 0; x < shape[0]; x++)
{
double distanceFromCenter = distance.
Length();
if (distanceFromCenter < (double)radius)
{
image.
Write(voxelPos, filledVoxel);
}
else
{
image.
Write(voxelPos, emptyVoxel);
}
}
}
}
return image;
}
public static void Main(string[] args)
{
var image = Generate(
new VectorXu64(100, 100, 100));
Console.WriteLine("Generated image: " + image.ToString());
Console.WriteLine("SUCCESS");
}
}
}
Stores information about a data type.
Definition DataType.cs:24
Enum for the image type (see ImageType)
Definition ImageTypeId.cs:20
This factory is aimed at creating dataset views.
Definition ImageViewFactory.cs:21
static ImageView Allocate(VectorXu64 shape, DataType type, ImageProperties properties, MetadataNode metadata)
Creates a memory image with the given shape and type.
Definition ImageViewFactory.cs:86
Interface representing an N dimensional image.
Definition ImageView.cs:30
unsafe void Write(VectorXu64 index, byte[] src)
Write value from a buffer at the given index.
Definition ImageView.cs:373
A dynamically sized arithmetic vector.
Definition VectorXi64.cs:14
double Length()
Returns the vector's norm.
Definition VectorXi64.cs:210
A dynamically sized arithmetic vector.
Definition VectorXu64.cs:14
uint Size()
Returns the size of the vector, which also correspond to vector number of dimension.
Definition VectorXu64.cs:181
Definition CreateDataFrame.cs:6
Definition AccessCapabilities.cs:11
ImageInterpretation
Interpretation of an Image.
Definition ImageInterpretation.cs:15
DataTypeId
A collection of built-in data types.
Definition DataTypeId.cs:15