public AsyncVolumeSliceSopFrameData(int frameNumber, AsyncVolumeSliceSopDataSource parent) : base(frameNumber, parent) { if (Parent.Slice.VolumeReference is ICachedVolumeReference) { _cachedVolumeReference = (ICachedVolumeReference)Parent.Slice.VolumeReference.Clone(); } }
protected override void Dispose(bool disposing) { if (disposing && _cachedVolumeReference != null) { _cachedVolumeReference.Dispose(); _cachedVolumeReference = null; } base.Dispose(disposing); }
protected override void AsyncCreateNormalizedPixelData(Action <byte[], Exception> onComplete) { // only ICachedVolumeReference provides for dynamic loading of the volume - a standard IVolumeReference is a hard reference to a loaded volume if (_cachedVolumeReference == null) { onComplete.Invoke(Parent.Slice.GetPixelData(), null); } else if (_asyncVolumeLoaderReference == null) { var volume = _asyncVolumeLoaderReference = (ICachedVolumeReference)_cachedVolumeReference.Clone(); volume.Lock(); if (!volume.IsLoaded) { volume.ProgressChanged += (s, e) => UpdateProgress((int)volume.Progress, null); InitializeProgress((int)volume.Progress); var task = volume.LoadAsync(); if (task == null) { var pixelData = Parent.Slice.GetPixelData(); onComplete.Invoke(pixelData, null); return; } task.ContinueWith(t => { try { if (t.IsFaulted && t.Exception != null) { onComplete.Invoke(null, t.Exception.Flatten().InnerExceptions.FirstOrDefault()); } else { var pixelData = Parent.Slice.GetPixelData(); UpdateProgress(100, pixelData); onComplete.Invoke(pixelData, null); } } catch (Exception ex) { onComplete.Invoke(null, ex); } finally { volume.Unlock(); volume.Dispose(); _asyncVolumeLoaderReference = null; } }); } } }
protected override void AsyncCreateNormalizedPixelData(Action<byte[], Exception> onComplete) { // only ICachedVolumeReference provides for dynamic loading of the volume - a standard IVolumeReference is a hard reference to a loaded volume if (_cachedVolumeReference == null) { onComplete.Invoke(Parent.Slice.GetPixelData(), null); } else if (_asyncVolumeLoaderReference == null) { var volume = _asyncVolumeLoaderReference = (ICachedVolumeReference) _cachedVolumeReference.Clone(); volume.Lock(); if (!volume.IsLoaded) { volume.ProgressChanged += (s, e) => UpdateProgress((int) volume.Progress, null); InitializeProgress((int) volume.Progress); var task = volume.LoadAsync(); if (task == null) { var pixelData = Parent.Slice.GetPixelData(); onComplete.Invoke(pixelData, null); return; } task.ContinueWith(t => { try { if (t.IsFaulted && t.Exception != null) { onComplete.Invoke(null, t.Exception.Flatten().InnerExceptions.FirstOrDefault()); } else { var pixelData = Parent.Slice.GetPixelData(); UpdateProgress(100, pixelData); onComplete.Invoke(pixelData, null); } } catch (Exception ex) { onComplete.Invoke(null, ex); } finally { volume.Unlock(); volume.Dispose(); _asyncVolumeLoaderReference = null; } }); } } }
public AsyncVolumeSliceSopFrameData(int frameNumber, AsyncVolumeSliceSopDataSource parent) : base(frameNumber, parent) { if (Parent.Slice.VolumeReference is ICachedVolumeReference) { _cachedVolumeReference = (ICachedVolumeReference) Parent.Slice.VolumeReference.Clone(); } }