/// <summary>
        /// Extracts the specified definition.
        /// </summary>
        /// <param name="definition">The definition.</param>
        /// <param name="volumeMetadata">The volume metadata.</param>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        internal static VolumeSliceRange Extract(VolumeSliceRangeDefinition definition, VolumeMetadata volumeMetadata, byte[][] data)
        {
            var slices = new List <VolumeSlice>();

            for (var i = definition.First; i <= definition.Last; i++)
            {
                slices.Add(VolumeSlice.Extract(definition.Direction, i, volumeMetadata, data));
            }

            return(new VolumeSliceRange(definition, slices));
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether the specified range is present in the collection
        /// </summary>
        /// <param name="range">Slice range</param>
        /// <returns></returns>
        public bool Contains(VolumeSliceRangeDefinition range)
        {
            var set = GetSlices(range.Direction);

            for (var i = range.First; i <= range.Last; i++)
            {
                if (!set.ContainsKey(i))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Returns the specified slice range
        /// </summary>
        /// <param name="definition"></param>
        /// <exception cref="ArgumentOutOfRangeException">The collection is missing one or more of the requested slices.</exception>
        /// <returns></returns>
        public VolumeSliceRange GetSliceRange(VolumeSliceRangeDefinition definition)
        {
            var slices = new List <VolumeSlice>();
            var set    = GetSlices(definition.Direction);

            for (ushort s = definition.First; s <= definition.Last; s++)
            {
                if (set.TryGetValue(s, out var data))
                {
                    slices.Add(data);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(nameof(definition));
                }
            }

            return(new VolumeSliceRange(definition, slices));
        }
Beispiel #4
0
        /// <inheritdoc />
        /// <exception cref="NotSupportedException">The volume has no compressed data</exception>
        public override VolumeSliceRange GetSliceRange(VolumeSliceRangeDefinition range, IProgress <VolumeSliceDefinition> progress = null, CancellationToken ct = default(CancellationToken))
        {
            if (_CompressedData[range.Direction] != null)
            {
                using (var input = new MemoryStream(_CompressedData[range.Direction], false))
                {
                    var inputWrapper = new StreamWrapper(input);
                    var rangeReader  = new VolumeSliceRangeCollector(Metadata, range.Direction, new[] { range }, progress, ct);

                    var error = ( VolumeError )DecompressSlices(inputWrapper.Interop, rangeReader.Interop, range.First, ( ushort )(range.Last - range.First + 1));
                    if (error != VolumeError.Success)
                    {
                        throw new VolumeException(error, Resources.FormatResource <Volume>("Decompression_ErrorText", error));
                    }

                    return(rangeReader.GetSliceRange(range));
                }
            }

            if (_CompressedData[Direction.Z] == null)
            {
                throw new NotSupportedException(Resources.GetResource <Volume>("CompressedDataMissing_ErrorText"));
            }

            using (var input = new MemoryStream(_CompressedData[Direction.Z], false))
            {
                var inputWrapper = new StreamWrapper(input);
                var rangeReader  = new VolumeSliceRangeCollector(Metadata, Direction.Z, new[] { range }, progress, ct);

                var error = ( VolumeError )DecompressVolume(inputWrapper.Interop, rangeReader.Interop);
                if (error != VolumeError.Success)
                {
                    throw new VolumeException(error, Resources.FormatResource <Volume>("Decompression_ErrorText", error));
                }

                return(rangeReader.GetSliceRange(range));
            }
        }
Beispiel #5
0
 /// <summary>
 /// Gets the specified slice range. This is usually a lot faster than extracting single slices and consumes less memory than a full decompression.
 /// </summary>
 /// <param name="range">The requested slice range.</param>
 /// <param name="progress">A progress indicator, which reports the current slice number.</param>
 /// <param name="ct"></param>
 /// <returns></returns>
 /// <exception cref="VolumeException">Error during decoding</exception>
 public abstract VolumeSliceRange GetSliceRange(VolumeSliceRangeDefinition range, IProgress <VolumeSliceDefinition> progress = null, CancellationToken ct = default(CancellationToken));
 /// <summary>
 /// Initializes a new instance of the <see cref="VolumeSliceRange"/> class.
 /// </summary>
 /// <param name="definition">The definition.</param>
 /// <param name="slices">The slices.</param>
 internal VolumeSliceRange(VolumeSliceRangeDefinition definition, IEnumerable <VolumeSlice> slices)
 {
     Definition = definition;
     _Slices    = new List <VolumeSlice>(slices);
 }
 /// <inheritdoc />
 public override VolumeSliceRange GetSliceRange(VolumeSliceRangeDefinition range, IProgress <VolumeSliceDefinition> progress = null, CancellationToken ct = default(CancellationToken))
 {
     return(VolumeSliceRange.Extract(range, Metadata, Data));
 }