Exemplo n.º 1
0
    /// <summary>
    /// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the texture.</typeparam>
    /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
    /// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
    /// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
    /// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
    /// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
    /// <param name="width">The width of the memory area to copy.</param>
    /// <param name="height">The height of the memory area to copy.</param>
    /// <param name="depth">The depth of the memory area to copy.</param>
    public static void CopyTo <T>(this Texture3D <T> source, Span <T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
        where T : unmanaged
    {
        Guard.IsNotNull(source);

        source.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, sourceOffsetX, sourceOffsetY, sourceOffsetZ, width, height, depth);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the texture.</typeparam>
    /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
    /// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
    public static void CopyTo <T>(this Texture3D <T> source, Span <T> destination)
        where T : unmanaged
    {
        Guard.IsNotNull(source);

        source.CopyTo(destination, 0, 0, 0, source.Width, source.Height, source.Depth);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the texture.</typeparam>
    /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
    /// <param name="destination">The input array to write data to.</param>
    /// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
    /// <param name="x">The horizontal range of items to copy.</param>
    /// <param name="y">The vertical range of items to copy.</param>
    /// <param name="z">The depthwise range of items to copy.</param>
    public static void CopyTo <T>(this Texture3D <T> source, T[] destination, int destinationOffset, Range x, Range y, Range z)
        where T : unmanaged
    {
        Guard.IsNotNull(source);
        Guard.IsNotNull(destination);

        source.CopyTo(destination.AsSpan(destinationOffset), x, y, z);
    }
    /// <summary>
    /// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the texture.</typeparam>
    /// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
    /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
    public static void CopyFrom <T>(this ReadBackTexture3D <T> destination, Texture3D <T> source)
        where T : unmanaged
    {
        Guard.IsNotNull(destination);
        Guard.IsNotNull(source);

        source.CopyTo(destination, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
    }
Exemplo n.º 5
0
    /// <summary>
    /// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the texture.</typeparam>
    /// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
    /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
    /// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
    /// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
    /// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
    /// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
    /// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
    /// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
    /// <param name="width">The width of the memory area to copy.</param>
    /// <param name="height">The height of the memory area to copy.</param>
    /// <param name="depth">The depth of the memory area to copy.</param>
    public static void CopyFrom <T>(this Texture3D <T> destination, Texture3D <T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
        where T : unmanaged
    {
        Guard.IsNotNull(destination);
        Guard.IsNotNull(source);

        source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
    }
Exemplo n.º 6
0
    /// <summary>
    /// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the texture.</typeparam>
    /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
    /// <param name="destination">The input array to write data to.</param>
    /// <param name="destinationOffset">The starting offset within <paramref name="destination"/> to write data to.</param>
    public static void CopyTo <T>(this Texture3D <T> source, T[] destination, int destinationOffset)
        where T : unmanaged
    {
        Guard.IsNotNull(source);
        Guard.IsNotNull(destination);

        source.CopyTo(destination.AsSpan(destinationOffset), 0, 0, 0, source.Width, source.Height, source.Depth);
    }
        public static T[,,] ToArray <T>(this Texture3D <T> texture)
        where T : unmanaged
        {
            T[,,] data = new T[texture.Depth, texture.Height, texture.Width];

            texture.CopyTo(data);

            return(data);
        }
        /// <summary>
        /// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
        /// </summary>
        /// <typeparam name="T">The type of items stored on the texture.</typeparam>
        /// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
        /// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
        /// <param name="x">The horizontal range in the source texture.</param>
        /// <param name="y">The vertical range in the source texture.</param>
        /// <param name="z">The depthwise range in the source texture.</param>
        public static void CopyTo <T>(this Texture3D <T> texture, Span <T> destination, Range x, Range y, Range z)
            where T : unmanaged
        {
            var(offsetX, width)  = x.GetOffsetAndLength(texture.Width);
            var(offsetY, height) = y.GetOffsetAndLength(texture.Height);
            var(offsetZ, depth)  = z.GetOffsetAndLength(texture.Depth);

            texture.CopyTo(destination, offsetX, offsetY, offsetZ, width, height, depth);
        }
        /// <summary>
        /// Reads the contents of the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
        /// </summary>
        /// <typeparam name="T">The type of items stored on the texture.</typeparam>
        /// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
        /// <param name="destination">The input array to write data to.</param>
        /// <remarks>
        /// The input 3D array needs to have each 2D plane stacked on the depth axis. That is, the expected
        /// layout of the input array has to be of shape [depth, height, width].
        /// </remarks>
        public static void CopyTo <T>(this Texture3D <T> texture, T[,,] destination)
            where T : unmanaged
        {
            Guard.IsEqualTo(destination.GetLength(0), texture.Depth, nameof(destination));
            Guard.IsEqualTo(destination.GetLength(1), texture.Height, nameof(destination));
            Guard.IsEqualTo(destination.GetLength(2), texture.Width, nameof(destination));

            texture.CopyTo(ref destination[0, 0, 0], destination.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
        }
Exemplo n.º 10
0
    /// <summary>
    /// Initializes a new instance of the <see cref="Texture3DDebugView{T}"/> class with the specified parameters.
    /// </summary>
    /// <param name="texture">The input <see cref="Texture3D{T}"/> instance with the items to display.</param>
    public Texture3DDebugView(Texture3D <T>?texture)
    {
        if (texture is not null)
        {
            T[,,] items = new T[texture.Depth, texture.Height, texture.Width];

            texture.CopyTo(ref items[0, 0, 0], items.Length, 0, 0, 0, texture.Width, texture.Height, texture.Depth);

            Items = items;
        }
    }
Exemplo n.º 11
0
    /// <summary>
    /// Reads the contents of the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the texture.</typeparam>
    /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
    /// <param name="destination">The input array to write data to.</param>
    /// <remarks>
    /// The input 3D array needs to have each 2D plane stacked on the depth axis. That is, the expected
    /// layout of the input array has to be of shape [depth, height, width].
    /// </remarks>
    public static void CopyTo <T>(this Texture3D <T> source, T[,,] destination)
        where T : unmanaged
    {
        Guard.IsNotNull(source);
        Guard.IsNotNull(destination);
        Guard.IsEqualTo(destination.GetLength(0), source.Depth, nameof(destination));
        Guard.IsEqualTo(destination.GetLength(1), source.Height, nameof(destination));
        Guard.IsEqualTo(destination.GetLength(2), source.Width, nameof(destination));

        source.CopyTo(ref destination[0, 0, 0], destination.Length, 0, 0, 0, source.Width, source.Height, source.Depth);
    }
Exemplo n.º 12
0
    /// <summary>
    /// Reads the contents of the current <see cref="Texture3D{T}"/> instance and returns an array.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the texture.</typeparam>
    /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
    /// <returns>A <typeparamref name="T"/> array with the contents of the current buffer.</returns>
    /// <remarks>
    /// The returned array will be using the same memory layout as the texture, that is, each 2D plane
    /// in the 3D volume represented by the texture is contiguous in memory, and planes are stacked in
    /// the depth dimension. This means that the resulting 3D array will have a size of [D, H, W].
    /// </remarks>
    public static T[,,] ToArray <T>(this Texture3D <T> source)
    where T : unmanaged
    {
        Guard.IsNotNull(source);

        T[,,] data = new T[source.Depth, source.Height, source.Width];

        source.CopyTo(data);

        return(data);
    }
Exemplo n.º 13
0
    /// <summary>
    /// Reads the contents of the current <see cref="Texture3D{T}"/> instance and returns an array.
    /// </summary>
    /// <typeparam name="T">The type of items stored on the texture.</typeparam>
    /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
    /// <param name="x">The horizontal offset in the source texture.</param>
    /// <param name="y">The vertical offset in the source texture.</param>
    /// <param name="z">The depthwise offset in the source texture.</param>
    /// <param name="width">The width of the memory area to copy.</param>
    /// <param name="height">The height of the memory area to copy.</param>
    /// <param name="depth">The depth of the memory area to copy.</param>
    /// <returns>A <typeparamref name="T"/> array with the contents of the current texture.</returns>
    public static unsafe T[,,] ToArray <T>(this Texture3D <T> source, int x, int y, int z, int width, int height, int depth)
    where T : unmanaged
    {
        Guard.IsGreaterThanOrEqualTo(width, 0, nameof(width));
        Guard.IsGreaterThanOrEqualTo(height, 0, nameof(height));
        Guard.IsGreaterThanOrEqualTo(depth, 0, nameof(depth));

        T[,,] data = new T[depth, height, width];

        fixed(T *p = data)
        {
            source.CopyTo(new Span <T>(p, width * height * depth), x, y, z, width, height, depth);
        }

        return(data);
    }
Exemplo n.º 14
0
    /// <summary>
    /// Creates a new <see cref="Image{TPixel}"/> instance with the specified texture data.
    /// </summary>
    /// <typeparam name="TFrom">The input pixel format used in the texture.</typeparam>
    /// <typeparam name="TTo">The target pixel format for the returned image.</typeparam>
    /// <param name="texture">The source <see cref="Texture3D{T}"/> instance to read data from.</param>
    /// <param name="depth">The depth layer to read the image from.</param>
    /// <returns>An image with the data from the input texture at a specified depth layer.</returns>
    public static unsafe Image <TTo> ToImage <TFrom, TTo>(this Texture3D <TFrom> texture, int depth)
        where TFrom : unmanaged
        where TTo : unmanaged, IPixel <TTo>
    {
        Guard.IsEqualTo(sizeof(TTo), sizeof(TFrom), nameof(TTo));

        Image <TTo> image = new(texture.Width, texture.Height);

        Assert.IsTrue(image.DangerousTryGetSinglePixelMemory(out Memory <TTo> memory));

        Span <TFrom> pixels = MemoryMarshal.Cast <TTo, TFrom>(memory.Span);

        texture.CopyTo(pixels, 0, 0, depth, texture.Width, texture.Height, 1);

        return(image);
    }
 /// <summary>
 /// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
 /// <param name="destination">The input array to write data to.</param>
 /// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
 public static void CopyTo <T>(this Texture3D <T> texture, T[] destination, int offset)
     where T : unmanaged
 {
     texture.CopyTo(destination.AsSpan(offset), 0, 0, 0, texture.Width, texture.Height, texture.Depth);
 }
 /// <summary>
 /// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Span{T}"/>.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
 /// <param name="destination">The input <see cref="Span{T}"/> to write data to.</param>
 /// <param name="x">The horizontal offset in the source texture.</param>
 /// <param name="y">The vertical offset in the source texture.</param>
 /// <param name="z">The depthwise offset in the source texture.</param>
 /// <param name="width">The width of the memory area to copy.</param>
 /// <param name="height">The height of the memory area to copy.</param>
 /// <param name="depth">The depth of the memory area to copy.</param>
 public static void CopyTo <T>(this Texture3D <T> texture, Span <T> destination, int x, int y, int z, int width, int height, int depth)
     where T : unmanaged
 {
     texture.CopyTo(ref MemoryMarshal.GetReference(destination), destination.Length, x, y, z, width, height, depth);
 }
 /// <summary>
 /// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
 /// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
 public static void CopyTo <T>(this Texture3D <T> texture, ReadBackTexture3D <T> destination)
     where T : unmanaged
 {
     texture.CopyTo(destination, 0, 0, 0, 0, 0, 0, texture.Width, texture.Height, texture.Depth);
 }
 /// <summary>
 /// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
 /// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
 /// <param name="x">The horizontal offset in the source texture.</param>
 /// <param name="y">The vertical offset in the source texture.</param>
 /// <param name="z">The depthwise offset in the source texture.</param>
 /// <param name="width">The width of the memory area to copy.</param>
 /// <param name="height">The height of the memory area to copy.</param>
 /// <param name="depth">The depth of the memory area to copy.</param>
 public static void CopyTo <T>(this Texture3D <T> texture, ReadBackTexture3D <T> destination, int x, int y, int z, int width, int height, int depth)
     where T : unmanaged
 {
     texture.CopyTo(destination, 0, 0, 0, x, y, z, width, height, depth);
 }
 /// <summary>
 /// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
 /// <param name="destination">The input array to write data to.</param>
 /// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
 /// <param name="x">The horizontal offset in the source texture.</param>
 /// <param name="y">The vertical offset in the source texture.</param>
 /// <param name="z">The depthwise offset in the source texture.</param>
 /// <param name="width">The width of the memory area to copy.</param>
 /// <param name="height">The height of the memory area to copy.</param>
 /// <param name="depth">The depth of the memory area to copy.</param>
 public static void CopyTo <T>(this Texture3D <T> texture, T[] destination, int offset, int x, int y, int z, int width, int height, int depth)
     where T : unmanaged
 {
     texture.CopyTo(destination.AsSpan(offset), x, y, z, width, height, depth);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
 /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
 public static void CopyFrom <T>(this Texture3D <T> destination, Texture3D <T> source)
     where T : unmanaged
 {
     source.CopyTo(destination, 0, 0, 0, 0, 0, 0, source.Width, source.Height, source.Depth);
 }
 /// <summary>
 /// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="ReadBackTexture3D{T}"/> instance.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="destination">The target <see cref="ReadBackTexture3D{T}"/> instance to write data to.</param>
 /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
 /// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
 /// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
 /// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
 /// <param name="destinationOffsetX">The horizontal offset in the destination texture.</param>
 /// <param name="destinationOffsetY">The vertical offset in the destination texture.</param>
 /// <param name="destinationOffsetZ">The depthwise offset in the destination texture.</param>
 /// <param name="width">The width of the memory area to copy.</param>
 /// <param name="height">The height of the memory area to copy.</param>
 /// <param name="depth">The depth of the memory area to copy.</param>
 public static void CopyFrom <T>(this ReadBackTexture3D <T> destination, Texture3D <T> source, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int destinationOffsetX, int destinationOffsetY, int destinationOffsetZ, int width, int height, int depth)
     where T : unmanaged
 {
     source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, destinationOffsetX, destinationOffsetY, destinationOffsetZ, width, height, depth);
 }
 /// <summary>
 /// Reads the contents of the specified range from the current <see cref="Texture3D{T}"/> instance and writes them into a target array.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="texture">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
 /// <param name="destination">The input array to write data to.</param>
 /// <param name="offset">The starting offset within <paramref name="destination"/> to write data to.</param>
 /// <param name="x">The horizontal range of items to copy.</param>
 /// <param name="y">The vertical range of items to copy.</param>
 /// <param name="z">The depthwise range of items to copy.</param>
 public static void CopyTo <T>(this Texture3D <T> texture, T[] destination, int offset, Range x, Range y, Range z)
     where T : unmanaged
 {
     texture.CopyTo(destination.AsSpan(offset), x, y, z);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Reads the contents of a <see cref="Texture3D{T}"/> instance and writes them into a target <see cref="Texture3D{T}"/> instance.
 /// </summary>
 /// <typeparam name="T">The type of items stored on the texture.</typeparam>
 /// <param name="source">The input <see cref="Texture3D{T}"/> instance to read data from.</param>
 /// <param name="destination">The target <see cref="Texture3D{T}"/> instance to write data to.</param>
 /// <param name="sourceOffsetX">The horizontal offset in the source texture.</param>
 /// <param name="sourceOffsetY">The vertical offset in the source texture.</param>
 /// <param name="sourceOffsetZ">The depthwise offset in the source texture.</param>
 /// <param name="width">The width of the memory area to copy.</param>
 /// <param name="height">The height of the memory area to copy.</param>
 /// <param name="depth">The depth of the memory area to copy.</param>
 public static void CopyTo <T>(this Texture3D <T> source, Texture3D <T> destination, int sourceOffsetX, int sourceOffsetY, int sourceOffsetZ, int width, int height, int depth)
     where T : unmanaged
 {
     source.CopyTo(destination, sourceOffsetX, sourceOffsetY, sourceOffsetZ, 0, 0, 0, width, height, depth);
 }