Exemplo n.º 1
0
        private void LoadVolume(IBackgroundTaskContext context)
        {
            try
            {
                ProgressTask mainTask = new ProgressTask();
                mainTask.AddSubTask("BUILD", 90);
                mainTask.AddSubTask("LAYOUT", 10);

                context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessageInitializingMpr, mainTask.Progress)));

                BackgroundTaskParams @params = (BackgroundTaskParams)context.UserState;
                Volume volume = Volume.Create(@params.Frames,
                                              delegate(int i, int count)
                {
                    if (context.CancelRequested)
                    {
                        throw new BackgroundTaskCancelledException();
                    }
                    if (i == 0)
                    {
                        mainTask["BUILD"].AddSubTask("", count);
                    }
                    mainTask["BUILD"][""].Increment();
                    string message = string.Format(SR.MessageBuildingMprVolumeProgress, mainTask.Progress, i + 1, count, mainTask["BUILD"].Progress);
                    context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, message));
                });

                mainTask["BUILD"].MarkComplete();
                context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessagePerformingMprWorkspaceLayout, mainTask.Progress)));

                //call layout here b/c it could take a while
                @params.SynchronizationContext.Send(delegate
                {
                    _viewer = new MprViewerComponent(volume);
                    _viewer.Layout();
                }, null);

                mainTask["LAYOUT"].MarkComplete();
                context.ReportProgress(new BackgroundTaskProgress(mainTask.IntPercent, string.Format(SR.MessageDone, mainTask.Progress)));

                context.Complete();
            }
            catch (BackgroundTaskCancelledException)
            {
                context.Cancel();
            }
            catch (Exception ex)
            {
                context.Error(ex);
            }
        }
Exemplo n.º 2
0
            private Volume LoadCore(VolumeLoadProgressCallback callback)
            {
                if (_volumeReference != null)
                {
                    return(_volumeReference.Volume);
                }

                lock (_syncRoot)
                {
                    if (_volumeReference != null)
                    {
                        return(_volumeReference.Volume);
                    }

                    Progress = 0;

                    using (var volume = Volume.Create(_frames, (n, total) =>
                    {
                        Progress = Math.Min(100f, 100f * n / total);
                        if (callback != null)
                        {
                            callback.Invoke(this, n, total);
                        }
                    }))
                    {
                        _volumeReference = volume.CreateTransientReference();

                        _largeObjectContainerData.LargeObjectCount = 1;
                        _largeObjectContainerData.BytesHeldCount   = 2 * volume.SizeInVoxels;
                        _largeObjectContainerData.UpdateLastAccessTime();
                        MemoryManager.Add(this);
                    }

                    Progress = 100f;

                    return(_volumeReference.Volume);
                }
            }
        private VolumeData LoadVolume(IBackgroundTaskContext context)
        {
            // wait for synchronized access
            lock (_syncVolumeDataLock)
            {
                // if the data is now available, return it immediately
                // (i.e. we were blocked because we were already reading the data)
                if (_volume != null)
                {
                    return(_volume);
                }

                // load the volume data
                if (context == null)
                {
                    _volume = VolumeData.Create(_frames);
                }
                else
                {
                    _volume = VolumeData.Create(_frames, (n, count) => context.ReportProgress(new BackgroundTaskProgress(n, count, SR.MessageFusionInProgress)));
                }

                // update our stats
                _largeObjectData.BytesHeldCount   = 2 * _volume.SizeInVoxels;
                _largeObjectData.LargeObjectCount = 1;
                _largeObjectData.UpdateLastAccessTime();

                // regenerating the volume data is easy when the source frames are already in memory!
                _largeObjectData.RegenerationCost = RegenerationCost.Low;

                // register with memory manager
                MemoryManager.Add(this);

                return(_volume);
            }
        }