private static void UpdateVisibility(IDisplaySet displaySet, ShowHideOption option) { if (displaySet == null) { return; } //Have to update all images each time so that even ones that haven't been drawn are correct. //That way, even ones that are exported to the clipboard look right. switch (option) { case ShowHideOption.HideUnimportant: foreach (var image in displaySet.PresentationImages) { image.GetOverlays().HideUnimportant(false); } break; case ShowHideOption.ShowSelected: foreach (var image in displaySet.PresentationImages) { image.GetOverlays().ShowSelected(false); } break; case ShowHideOption.HideAll: foreach (var image in displaySet.PresentationImages) { image.GetOverlays().HideAll(false); } break; } }
private void SetActiveViewer(IImageViewer viewer) { if (_activeViewer != null) { _activeViewer.EventBroker.ImageBoxSelected -= OnImageBoxSelected; _activeViewer.EventBroker.DisplaySetSelected -= OnDisplaySetSelected; } _activeViewer = viewer; IDisplaySet displaySet = null; if (_activeViewer != null) { _activeViewer.EventBroker.ImageBoxSelected += OnImageBoxSelected; _activeViewer.EventBroker.DisplaySetSelected += OnDisplaySetSelected; if (_activeViewer.SelectedImageBox != null) { displaySet = _activeViewer.SelectedImageBox.DisplaySet; } } CurrentDisplaySet = displaySet; }
private IDisplaySet GetSourceDisplaySet() { IImageBox imageBox = base.Context.Viewer.SelectedImageBox; if (imageBox == null) { return(null); } IDisplaySet currentDisplaySet = imageBox.DisplaySet; if (currentDisplaySet == null) { return(null); } if (currentDisplaySet.ParentImageSet == null) { // if the display set doesn't have a parent image set, fall back to using the logical workspace and the UID fo the display set // this situation usually arises from dynamically generated alternate views of a display set which is part of an image set return(currentDisplaySet.ImageViewer != null?currentDisplaySet.ImageViewer.LogicalWorkspace.ImageSets.SelectMany(ims => ims.DisplaySets).FirstOrDefault(ds => ds.Uid == currentDisplaySet.Uid) : null); } return(CollectionUtils.SelectFirst(currentDisplaySet.ParentImageSet.DisplaySets, displaySet => displaySet.Uid == currentDisplaySet.Uid)); }
public IEnumerable<IPresentationImage> GetImages(IDisplaySet displaySet) { if (_useInstanceNumbers) { foreach (IPresentationImage image in displaySet.PresentationImages) { if (image is IImageSopProvider) { IImageSopProvider provider = (IImageSopProvider)image; int maxValue = _endValue - _startValue; int testValue = provider.ImageSop.InstanceNumber - _startValue; if (testValue >= 0 && testValue <= maxValue && (0 == testValue % _selectionInterval)) yield return image; } } } else { //selection indices are 1-based. for (int i = _startValue - 1; i < _endValue && i < displaySet.PresentationImages.Count; i += _selectionInterval) yield return displaySet.PresentationImages[i]; } }
public VolumePresentationImage(IDisplaySet displaySet) : base(1, 1, 1) { _displaySet = displaySet; ValidateSliceData(); }
private void OnImageViewerImageBoxDrawing(object sender, ImageBoxDrawingEventArgs e) { IImageBox imageBox = this.SliceImageBox; IDisplaySet containingDisplaySet = null; if (_resliceGraphic.ParentPresentationImage != null) { containingDisplaySet = _resliceGraphic.ParentPresentationImage.ParentDisplaySet; } if (containingDisplaySet != null && containingDisplaySet.ImageBox == e.ImageBox) { // translocate the graphic if the user is stacking through the display set that the graphic sits in // do not add this command to history - the stack command generates the actual action command if (_lastTopLeftPresentationImageIndex != e.ImageBox.TopLeftPresentationImageIndex) { _lastTopLeftPresentationImageIndex = e.ImageBox.TopLeftPresentationImageIndex; TranslocateGraphic(_resliceGraphic, e.ImageBox.TopLeftPresentationImage); } } else if (imageBox != null && imageBox == e.ImageBox) { // we're stacking on the set we control, so make sure the colourised display set name is replicated IPresentationImage firstReslicedImage = imageBox.TopLeftPresentationImage; ColorizeDisplaySetDescription(firstReslicedImage, this.NormalColor); // and realign the slice line with the stacked position if (_resliceGraphic.ParentPresentationImage != null && _resliceGraphic.ParentPresentationImage != firstReslicedImage) { _resliceGraphic.SetLine(imageBox.TopLeftPresentationImage, _resliceGraphic.ParentPresentationImage); _resliceGraphic.Draw(); } } }
/// <summary> /// Initializes a new instance of <see cref="DisplaySetChangedEventArgs"/>. /// </summary> public DisplaySetChangedEventArgs( IDisplaySet oldDisplaySet, IDisplaySet newDisplaySet) { _oldDisplaySet = oldDisplaySet; _newDisplaySet = newDisplaySet; }
/// <summary> /// Initializes a new instance of <see cref="DisplaySetChangingEventArgs"/>. /// </summary> public DisplaySetChangingEventArgs( IDisplaySet currentDisplaySet, IDisplaySet newDisplaySet) { _currentDisplaySet = currentDisplaySet; _newDisplaySet = newDisplaySet; }
public IEnumerable <IPresentationImage> GetImages(IDisplaySet displaySet) { if (_useInstanceNumbers) { foreach (IPresentationImage image in displaySet.PresentationImages) { if (image is IImageSopProvider) { IImageSopProvider provider = (IImageSopProvider)image; int maxValue = _endValue - _startValue; int testValue = provider.ImageSop.InstanceNumber - _startValue; if (testValue >= 0 && testValue <= maxValue && (0 == testValue % _selectionInterval)) { yield return(image); } } } } else { //selection indices are 1-based. for (int i = _startValue - 1; i < _endValue && i < displaySet.PresentationImages.Count; i += _selectionInterval) { yield return(displaySet.PresentationImages[i]); } } }
internal ThumbnailGalleryItem(ThumbnailGalleryItemFactory factory, IDisplaySet displaySet, NameAndDescriptionFormat nameAndDescriptionFormat, bool suppressLoadingThumbnails) : base(displaySet) { _factory = factory; _suppressLoadingImage = suppressLoadingThumbnails; switch (nameAndDescriptionFormat) { case NameAndDescriptionFormat.NameAndDescription: Name = GetDisplaySetName(displaySet); Description = GetDisplaySetDescription(displaySet); break; case NameAndDescriptionFormat.NoDescription: Name = GetDisplaySetName(displaySet); break; case NameAndDescriptionFormat.VerboseNameNoDescription: Name = GetDisplaySetDescription(displaySet); break; case NameAndDescriptionFormat.VerboseNameAndDescription: Name = Description = GetDisplaySetDescription(displaySet); break; } }
public Bitmap CreateStackIcon(IDisplaySet displaySet) { Platform.CheckForNullReference(displaySet, "displaySet"); IPresentationImage image = GetMiddlePresentationImage(displaySet); return(GetStackIcon(delegate(int width, int height) { return image.DrawToBitmap(width, height); })); }
private static string GetDisplaySetDirectoryPrefix(IDisplaySet displaySet) { string prefix = "DisplaySet"; if (displaySet.PresentationImages.Count > 0 && displaySet.PresentationImages[0] is IImageSopProvider) { IImageSopProvider provider = (IImageSopProvider)displaySet.PresentationImages[0]; string seriesDescription = (provider.ImageSop.SeriesDescription ?? "").Trim(); if (!String.IsNullOrEmpty(seriesDescription)) { prefix = seriesDescription; if (prefix.Length > 16) prefix = prefix.Remove(16); } else { string modality = (provider.ImageSop.Modality ?? "").Trim(); if (!String.IsNullOrEmpty(modality)) { prefix = String.Format("{0}{1}", modality, provider.ImageSop.SeriesNumber); if (provider.ImageSop.NumberOfFrames > 1) prefix = String.Format("{0}.{1}", prefix, provider.ImageSop.InstanceNumber); } } } //This method returns a number of characters, including :\/*? foreach (char invalidChar in Path.GetInvalidFileNameChars()) prefix = prefix.Replace(invalidChar, ' '); //replace invalid characters with spaces. return prefix.Trim(); }
public void CreateVolume() { if (this.ImageViewer == null) { return; } if (this.ImageViewer.SelectedImageBox == null) { return; } IDisplaySet selectedDisplaySet = this.ImageViewer.SelectedImageBox.DisplaySet; VolumePresentationImage image = new VolumePresentationImage(selectedDisplaySet); AddTissueLayers(image); IDisplaySet displaySet = new DisplaySet(String.Format("{0} (3D)", selectedDisplaySet.Name), String.Format("VTK.{0}", Guid.NewGuid().ToString())); displaySet.PresentationImages.Add(image); this.ImageViewer.LogicalWorkspace.ImageSets[0].DisplaySets.Add(displaySet); IImageBox imageBox = this.ImageViewer.SelectedImageBox; imageBox.DisplaySet = displaySet; imageBox.Draw(); imageBox[0, 0].Select(); NotifyAllPropertiesChanged(); }
internal void RemoveCopy(IDisplaySet copy) { if (_displaySetCopies != null) { _displaySetCopies.Remove(copy); } }
internal ThumbnailGalleryItem(ThumbnailGalleryItemFactory factory, IDisplaySet displaySet, NameAndDescriptionFormat nameAndDescriptionFormat) : base(displaySet) { _factory = factory; switch (nameAndDescriptionFormat) { case NameAndDescriptionFormat.NameAndDescription: Name = GetDisplaySetName(displaySet); Description = GetDisplaySetDescription(displaySet); break; case NameAndDescriptionFormat.NoDescription: Name = GetDisplaySetName(displaySet); break; case NameAndDescriptionFormat.VerboseNameNoDescription: Name = GetDisplaySetDescription(displaySet); break; case NameAndDescriptionFormat.VerboseNameAndDescription: Name = Description = GetDisplaySetDescription(displaySet); break; } }
private bool IsKeyImageDisplaySet(IDisplaySet displaySet) { if (displaySet == null || displaySet.PresentationImages.Count == 0) { return(false); } var descriptor = displaySet.Descriptor as IDicomDisplaySetDescriptor; if (descriptor == null) { return(false); } const string koModality = "KO"; if (descriptor.SourceSeries != null && descriptor.SourceSeries.Modality == koModality) { return(true); } var allImagesDescriptor = descriptor as ModalityDisplaySetDescriptor; return(allImagesDescriptor != null && allImagesDescriptor.Modality == koModality); }
public ImageBoxMemento( IDisplaySet displaySet, bool displaySetLocked, object displaySetMemento, int rows, int columns, int topLeftPresentationImageIndex, RectangleF normalizedRectangle, int indexOfSelectedTile) { // displaySet can be null, as that would correspond to an // empty imageBox Platform.CheckNonNegative(rows, "rows"); Platform.CheckNonNegative(columns, "columns"); Platform.CheckNonNegative(_topLeftPresentationImageIndex, "_topLeftPresentationImageIndex"); _displaySet = displaySet; _displaySetLocked = displaySetLocked; _displaySetMemento = displaySetMemento; _rows = rows; _columns = columns; _topLeftPresentationImageIndex = topLeftPresentationImageIndex; _normalizedRectangle = normalizedRectangle; _indexOfSelectedTile = indexOfSelectedTile; }
public static IPresentationImage PresentationImageFromPositionOrientation( double[] imagePositionPatientValues, double[] imageOrientationPatientValues, IDisplaySet displaySet, string frameOfReferenceUid) { Platform.CheckForNullReference(displaySet, "displaySet"); if (imagePositionPatientValues != null && imagePositionPatientValues.Length > 2 && imageOrientationPatientValues != null && imageOrientationPatientValues.Length > 5) { var imagePositionPatient = new ImagePositionPatient( imagePositionPatientValues[0], imagePositionPatientValues[1], imagePositionPatientValues[2]); var imageOrientationPatient = new ImageOrientationPatient( imageOrientationPatientValues[0], imageOrientationPatientValues[1], imageOrientationPatientValues[2], imageOrientationPatientValues[3], imageOrientationPatientValues[4], imageOrientationPatientValues[5]); return(PresentationImageFromPositionOrientation( imagePositionPatient, imageOrientationPatient, displaySet, frameOfReferenceUid)); } return(null); }
/// <summary> /// Compares two <see cref="IDisplaySet"/>s. /// </summary> public override int Compare(IDisplaySet x, IDisplaySet y) { if (x.PresentationImages.Count == 0 || y.PresentationImages.Count == 0) { return(0); } IImageSopProvider provider1 = x.PresentationImages[0] as IImageSopProvider; IImageSopProvider provider2 = y.PresentationImages[0] as IImageSopProvider; if (provider1 == null) { if (provider2 == null) { return(0); // x == y } else { return(-ReturnValue); // x > y (because we want it at the end for non-reverse sorting) } } else { if (provider2 == null) { return(ReturnValue); // x < y (because we want it at the end for non-reverse sorting) } } return(Compare(provider1.ImageSop, provider2.ImageSop)); }
/// <summary> /// Adds an <see cref="IDisplaySet"/> to the clipboard. /// </summary> /// <param name="displaySet"></param> /// <param name="selectionStrategy"></param> /// <remarks> /// When called, a copy of the specified <see cref="IPresentationImage"/>s /// (as determined by the <paramref name="selectionStrategy"/>) is made and stored /// in the clipbaord. This ensures that the <see cref="IPresentationImage"/> is in fact a /// snapshot and not a reference that could be changed in unpredictable ways. /// Pixel data, however, is not replicated. /// </remarks> public static void Add(IDisplaySet displaySet, IImageSelectionStrategy selectionStrategy) { Platform.CheckForNullReference(displaySet, "displaySet"); Platform.CheckForNullReference(selectionStrategy, "selectionStrategy"); Items.Add(ClipboardComponent.CreateDisplaySetItem(displaySet, selectionStrategy)); }
private void SynchronizeNewDisplaySet(IDisplaySet newDisplaySet) { if (!SynchronizeActive || newDisplaySet == null) { return; } IImageBox changedImageBox = newDisplaySet.ImageBox; IImageBox selectedImageBox = this.Context.Viewer.SelectedImageBox; if (selectedImageBox == null || selectedImageBox == changedImageBox) { // if there is no selected image box or the new one is selected, try // to sync it up with the other ones. // Do a reverse synchronization; sync the newly selected one with all the others. foreach (IImageBox imageBox in GetTargetImageBoxes(changedImageBox)) { if (imageBox != selectedImageBox) { SynchronizeImageBox(imageBox, changedImageBox); } } } else { SynchronizeImageBox(selectedImageBox, changedImageBox); } }
protected virtual void UpdateVisibility(IDisplaySet displaySet, bool visible) { foreach (var image in displaySet.PresentationImages) { UpdateVisibility(image, visible); } }
public void TestSeriesSplittingMREcho() { const int numberOfSeries = 5; const int instancesPerSeries = 10; List <TestDataSource> dataSources = CreateMRStudyDataSources(numberOfSeries, instancesPerSeries, "1.2.3"); StudyTree studyTree = CreateStudyTree(ConvertToSops(dataSources)); MREchoDisplaySetFactory factory = new MREchoDisplaySetFactory(); factory.SetStudyTree(studyTree); List <IDisplaySet> allDisplaySets = new List <IDisplaySet>(); try { Patient patient = studyTree.Patients[0]; Study study = patient.Studies[0]; Assert.AreEqual(numberOfSeries, study.Series.Count, "There should be exactly {0} series", numberOfSeries); Series series2 = study.Series[1]; Series series3 = study.Series[2]; MakeEchoSeries(series2); MakeEchoSeries(series3); foreach (Series series in study.Series) { Assert.AreEqual(instancesPerSeries, series.Sops.Count, "There should be exactly {0} sops", instancesPerSeries); List <IDisplaySet> displaySets = factory.CreateDisplaySets(series); allDisplaySets.AddRange(displaySets); if (series == series2 || series == series3) { IDisplaySet displaySet = displaySets[0]; Assert.AreEqual(2, displaySets.Count, "There should be exactly 2 display sets"); Assert.AreEqual(series.Sops.Count / 2, displaySet.PresentationImages.Count, "#presentation images should be #Sops/2"); Assert.AreNotEqual(series.SeriesInstanceUid, displaySet.Descriptor.Uid, "Series UID and Display Set UID don't match"); Assert.AreEqual(typeof(MREchoDisplaySetDescriptor), displaySet.Descriptor.GetType(), "Wrong display set descriptor type"); Assert.IsTrue(displaySet.Name.Contains("Echo"), "Display Set name not correct"); ValidateEchoDisplaySet(displaySets[0], 1); ValidateEchoDisplaySet(displaySets[1], 2); } else { Assert.AreEqual(0, displaySets.Count, "There should be no display sets"); } } } finally { foreach (IDisplaySet displaySet in allDisplaySets) { displaySet.Dispose(); } studyTree.Dispose(); } }
protected override void OnPresentationImageSelected(object sender, PresentationImageSelectedEventArgs e) { base.OnPresentationImageSelected(sender, e); IPresentationImage selectedPresentationImage = base.SelectedPresentationImage; IDisplaySet set = (selectedPresentationImage != null) ? selectedPresentationImage.ParentDisplaySet : null; base.Enabled = set != null; }
private static IPresentationImage GetMiddlePresentationImage(IDisplaySet displaySet) { if (displaySet.PresentationImages.Count == 0) { throw new ArgumentException("The display set must contain at least one image."); } return(displaySet.PresentationImages[(displaySet.PresentationImages.Count - 1) / 2]); }
/// <summary> /// Adds an <see cref="IDisplaySet"/> to the clipboard. /// </summary> /// <param name="displaySet"></param> /// <remarks> /// When called, a copy of the specified <see cref="IDisplaySet"/> is made and stored /// in the clipbaord. This ensures that the <see cref="IDisplaySet"/> is in fact a /// snapshot and not a reference that could be changed in unpredictable ways. /// Pixel data, however, is not replicated. /// </remarks> public static void Add(IDisplaySet displaySet) { Platform.CheckForNullReference(displaySet, "displaySet"); var clipboard = Default; clipboard._items.Add(clipboard.CreateDisplaySetItem(displaySet)); }
protected virtual IArgumentHintResolver BuildArgumentHints(IDisplaySet displaySet) { if (displaySet == null) { return(new ArgumentHintResolver()); } return(BuildArgumentHints(displaySet.PresentationImages)); }
internal static string BuildMessage(IDisplaySet sourceDisplaySet) { string message = "An error has occurred while attempting to clone a display set"; if (!String.IsNullOrEmpty(sourceDisplaySet.Name)) message += string.Format(" (name = {0})", sourceDisplaySet.Name); message += "."; return message; }
/// <summary> /// Adds an <see cref="IDisplaySet"/> to the clipboard. /// </summary> /// <param name="displaySet"></param> /// <param name="selectionStrategy"></param> /// <remarks> /// When called, a copy of the specified <see cref="IPresentationImage"/>s /// (as determined by the <paramref name="selectionStrategy"/>) is made and stored /// in the clipbaord. This ensures that the <see cref="IPresentationImage"/> is in fact a /// snapshot and not a reference that could be changed in unpredictable ways. /// Pixel data, however, is not replicated. /// </remarks> public static void Add(IDisplaySet displaySet, IImageSelectionStrategy selectionStrategy) { Platform.CheckForNullReference(displaySet, "displaySet"); Platform.CheckForNullReference(selectionStrategy, "selectionStrategy"); var clipboard = Default; clipboard._items.Add(clipboard.CreateDisplaySetItem(displaySet, selectionStrategy)); }
private IEnumerable <IPresentationImage> GetAllLinkedImages(IDisplaySet displaySet) { foreach (IPresentationImage image in displaySet.LinkedPresentationImages) { if (image != _referenceImage) { yield return(image); } } }
private static int Enqueue(ICollection <IPresentationImage> queue, IDisplaySet dSet) { int count = 0; foreach (IPresentationImage pImage in dSet.PresentationImages) { count += Enqueue(queue, pImage); } return(count); }
public static void Create(IDesktopWindow desktopWindow, IImageViewer viewer) { IDisplaySet selectedDisplaySet = viewer.SelectedImageBox.DisplaySet; string name = String.Format("{0} - Dynamic TE", selectedDisplaySet.Name); IDisplaySet t2DisplaySet = new DisplaySet(name, ""); double currentSliceLocation = 0.0; BackgroundTask task = new BackgroundTask( delegate(IBackgroundTaskContext context) { int i = 0; foreach (IPresentationImage image in selectedDisplaySet.PresentationImages) { IImageSopProvider imageSopProvider = image as IImageSopProvider; if (imageSopProvider == null) { continue; } ImageSop imageSop = imageSopProvider.ImageSop; Frame frame = imageSopProvider.Frame; if (frame.SliceLocation != currentSliceLocation) { currentSliceLocation = frame.SliceLocation; try { DynamicTePresentationImage t2Image = CreateT2Image(imageSop, frame); t2DisplaySet.PresentationImages.Add(t2Image); } catch (Exception e) { Platform.Log(LogLevel.Error, e); desktopWindow.ShowMessageBox("Unable to create T2 series. Please check the log for details.", MessageBoxActions.Ok); break; } } string message = String.Format("Processing {0} of {1} images", i, selectedDisplaySet.PresentationImages.Count); i++; BackgroundTaskProgress progress = new BackgroundTaskProgress(i, selectedDisplaySet.PresentationImages.Count, message); context.ReportProgress(progress); } }, false); ProgressDialog.Show(task, desktopWindow, true, ProgressBarStyle.Blocks); viewer.LogicalWorkspace.ImageSets[0].DisplaySets.Add(t2DisplaySet); }
private void CreateObjects() { _viewer = new ImageViewerComponent(); _imageBox = new ImageBox(); _tile1 = new Tile(); _tile2 = new Tile(); _imageSet = new ImageSet(); _displaySet = new DisplaySet(); _image1 = new TestPresentationImage(); _image2 = new TestPresentationImage(); }
public IEnumerable<ImageFileNamePair> GetImagesAndFileNames(IDisplaySet displaySet, string fileExtension) { string displaySetDirectory = GetDisplaySetDirectory(displaySet, _baseDirectory); Directory.CreateDirectory(displaySetDirectory); int numberOfZeroes = displaySet.PresentationImages.Count.ToString().Length; int startNumber = 1; foreach(IPresentationImage image in displaySet.PresentationImages) { string filePath = GetImageFileName(displaySetDirectory, "Image", fileExtension, numberOfZeroes, ref startNumber); yield return new ImageFileNamePair(image, filePath); } }
public static Volume Create(IDisplaySet displaySet, CreateVolumeProgressCallback callback) { Platform.CheckForNullReference(displaySet, "displaySet"); List<Frame> frames = new List<Frame>(); foreach (IPresentationImage image in displaySet.PresentationImages) { IImageSopProvider imageSopProvider = image as IImageSopProvider; if (imageSopProvider == null) throw new ArgumentException("Images must be valid IImageSopProviders."); frames.Add(imageSopProvider.Frame); } return Create(frames, callback); }
/// <summary> /// Compares two <see cref="IDisplaySet"/>s. /// </summary> public override int Compare(IDisplaySet x, IDisplaySet y) { DisplaySet displaySet1 = x as DisplaySet; DisplaySet displaySet2 = y as DisplaySet; if (ReferenceEquals(displaySet1, displaySet2)) return 0; //same object or both are null //at this point, at least one of x or y is non-null and they are not the same object if (displaySet1 == null) return -ReturnValue; // x > y (because we want x at the end for non-reverse sorting) if (displaySet2 == null) return ReturnValue; // x < y (because we want y at the end for non-reverse sorting) return base.Compare(GetCompareValues(displaySet1), GetCompareValues(displaySet2)); }
public TestTree() { _viewer = new ImageViewerComponent(); _imageBox1 = new ImageBox(); _imageBox2 = new ImageBox(); _tile1 = new Tile(); _tile2 = new Tile(); _tile3 = new Tile(); _tile4 = new Tile(); _imageSet1 = new ImageSet(); _displaySet1 = new DisplaySet(); _displaySet2 = new DisplaySet(); _image1 = new TestPresentationImage(); _image2 = new TestPresentationImage(); _image3 = new TestPresentationImage(); _image4 = new TestPresentationImage(); _viewer.PhysicalWorkspace.ImageBoxes.Add(_imageBox1); _viewer.PhysicalWorkspace.ImageBoxes.Add(_imageBox2); _imageBox1.Tiles.Add(_tile1); _imageBox1.Tiles.Add(_tile2); _imageBox2.Tiles.Add(_tile3); _imageBox2.Tiles.Add(_tile4); _viewer.LogicalWorkspace.ImageSets.Add(_imageSet1); _imageSet1.DisplaySets.Add(_displaySet1); _imageSet1.DisplaySets.Add(_displaySet2); _displaySet1.PresentationImages.Add(_image1); _displaySet1.PresentationImages.Add(_image2); _displaySet2.PresentationImages.Add(_image3); _displaySet2.PresentationImages.Add(_image4); _imageBox1.DisplaySet = _displaySet1; _imageBox2.DisplaySet = _displaySet2; }
private static ModalityOverlayStates GetDefaultOverlayStates(IDisplaySet displaySet) { if (displaySet == null) return GetDefaultOverlayStates(); var data = GetDefaultOverlayStates(displaySet.ImageViewer); if (data != null) return data; //Cache all the per-modality defaults in the display set so it can be looked up fast for its images. data = displaySet.ExtensionData[typeof (Key)] as ModalityOverlayStates; if (data == null) { data = GetDefaultOverlayStates(); displaySet.ExtensionData[typeof (Key)] = data; } return data; }
internal static void AssignDisplaySetToImageBox(IImageBox imageBox, IDisplaySet displaySet) { MemorableUndoableCommand memorableCommand = new MemorableUndoableCommand(imageBox); memorableCommand.BeginState = imageBox.CreateMemento(); // always create a 'fresh copy' to show in the image box. We never want to show // the 'originals' (e.g. the ones in IImageSet.DisplaySets) because we want them // to remain clean and unaltered - consider them to be templates for what actually // gets shown. imageBox.DisplaySet = displaySet.CreateFreshCopy(); imageBox.Draw(); //this.ImageViewer.SelectedImageBox[0, 0].Select(); memorableCommand.EndState = imageBox.CreateMemento(); DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(imageBox); historyCommand.Enqueue(memorableCommand); imageBox.ImageViewer.CommandHistory.AddCommand(historyCommand); }
public static Bitmap CreateDisplaySetIcon(IDisplaySet displaySet, Rectangle displayedClientRectangle) { Bitmap bmp = new Bitmap(_iconWidth, _iconHeight); int numImages = 3; float aspectRatio = _iconHeight / (float)_iconWidth; int offsetX = 10; int offsetY = (int)(aspectRatio * offsetX); int subIconWidth = _iconWidth - ((numImages - 1) * offsetX); int subIconHeight = (int)(aspectRatio * subIconWidth); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp); int dimension = Math.Max(displayedClientRectangle.Width, displayedClientRectangle.Height); IPresentationImage image = GetMiddlePresentationImage(displaySet); // rendered twice to rasterize the invariant text first and then downsample to icon size Bitmap img = DrawToIcon(image, dimension, (int)(dimension * aspectRatio)); Bitmap iconBmp = new Bitmap(img, subIconWidth, subIconHeight); img.Dispose(); Pen pen = new Pen(Color.DarkGray); g.Clear(Color.Black); for (int i = 0; i < numImages; i++) { int x = offsetX * ((numImages - 1) - i); int y = offsetY * i; g.DrawImage(iconBmp, new Point(x, y)); g.DrawRectangle(pen, x, y, subIconWidth - 1, subIconHeight - 1); } pen.Dispose(); iconBmp.Dispose(); g.Dispose(); return bmp; }
private void ValidateEchoDisplaySet(IDisplaySet displaySet, int echoNumber) { string seriesInstanceUid = null; foreach (IPresentationImage presentationImage in displaySet.PresentationImages) { ImageSop sop = ((IImageSopProvider)presentationImage).ImageSop; seriesInstanceUid = sop.SeriesInstanceUid; Assert.AreEqual(echoNumber, sop[DicomTags.EchoNumbers].GetUInt32(0, 0), "Echo number must be {0} for each image in the series", echoNumber); } Assert.IsNotNull(seriesInstanceUid); Assert.AreEqual(String.Format("{0}:Echo{1}", seriesInstanceUid, echoNumber), displaySet.Uid); }
private void ExportDisplaySet(IDisplaySet displaySet, ExportImageParams exportParams) { foreach (ImageFileNamePair pair in _fileNamingStrategy.GetImagesAndFileNames(displaySet, FileExtension)) { if (IsAsynchronous && _taskContext.CancelRequested) break; IPresentationImage image = GetImageForExport(pair.Image); SelectedImageExporter.Export(image, pair.FileName, exportParams); ReportProgress(pair.FileName, ++_progress); } }
internal static void AssignDisplaySetToImageBox(IImageViewer viewer, IDisplaySet displaySet) { AssignDisplaySetToImageBox(viewer.SelectedImageBox, displaySet); }
public VolumePresentationImage(IDisplaySet displaySet) { _displaySet = displaySet; ValidateSliceData(); }
private static int Enqueue(ICollection<IPresentationImage> queue, IDisplaySet dSet) { int count = 0; foreach (IPresentationImage pImage in dSet.PresentationImages) { count += Enqueue(queue, pImage); } return count; }
public IEnumerable<IPresentationImage> GetImages(IDisplaySet displaySet) { List<IPresentationImage> images = new List<IPresentationImage>(); if (_useInstanceNumbers) { foreach (IPresentationImage image in displaySet.PresentationImages) { if (!images.Contains(image)) { if (image is IImageSopProvider) { int instanceNumber = ((IImageSopProvider)image).ImageSop.InstanceNumber; foreach (Range range in _ranges) { if (instanceNumber >= range.Start && instanceNumber <= range.End) images.Add(image); } } } } } else { foreach (Range range in _ranges) { for (int j = range.Start - 1; j <= range.End - 1; ++j) { if (j >= displaySet.PresentationImages.Count) break; if (!images.Contains(displaySet.PresentationImages[j])) images.Add(displaySet.PresentationImages[j]); } } } return images; }
/// <summary> /// Adds an <see cref="IDisplaySet"/> to the clipboard. /// </summary> /// <param name="displaySet"></param> /// <remarks> /// When called, a copy of the specified <see cref="IDisplaySet"/> is made and stored /// in the clipbaord. This ensures that the <see cref="IDisplaySet"/> is in fact a /// snapshot and not a reference that could be changed in unpredictable ways. /// Pixel data, however, is not replicated. /// </remarks> public static void Add(IDisplaySet displaySet) { Platform.CheckForNullReference(displaySet, "displaySet"); Items.Add(ClipboardComponent.CreateDisplaySetItem(displaySet)); }
private static string GetDisplaySetDirectory(IDisplaySet displaySet, string baseDirectory) { string prefix = GetDisplaySetDirectoryPrefix(displaySet); int i = 0; string directory = prefix; while (true) { string path = String.Format("{0}\\{1}", baseDirectory, directory); if (!Directory.Exists(path)) return path; directory = string.Format("{0}{1}", prefix, ++i); } }
public DisplaySetMemento(IDisplaySet displaySet) { Comparer = displaySet.PresentationImages.SortComparer; }
/// <summary> /// Validates the specified display set as suitable source data for <see cref="Volume"/>. /// </summary> /// <param name="displaySet">The display set to validate.</param> /// <exception cref="ArgumentNullException">Thrown if the parameter was NULL.</exception> /// <exception cref="CreateVolumeException">Thrown if the specified source data is not suitable for creating a <see cref="Volume"/>.</exception> public static void Validate(IDisplaySet displaySet) { Platform.CheckForNullReference(displaySet, "displaySet"); Validate(displaySet.PresentationImages.Cast<IImageSopProvider>().Select(i => i.Frame)); }
internal DisplaySetCloningException(IDisplaySet sourceDisplaySet, Exception innerException) : base(BuildMessage(sourceDisplaySet), innerException) { }
private void UpdateEnabled(IDisplaySet selectedDisplaySet) { base.Enabled = selectedDisplaySet != null && selectedDisplaySet.PresentationImages.Count > 1; }
private static IEnumerable<Frame> FilterSourceFrames(IDisplaySet displaySet, IPresentationImage currentImage) { // this method tries to filter the source display set based on the currently selected image before passing it to MPR // we need this because sometimes MPR-able content is found in a series concatenated with other frames (e.g. 3-plane loc) if (currentImage is IImageSopProvider) { Frame currentFrame = ((IImageSopProvider) currentImage).Frame; string studyInstanceUid = currentFrame.StudyInstanceUid; string seriesInstanceUid = currentFrame.SeriesInstanceUid; string frameOfReferenceUid = currentFrame.FrameOfReferenceUid; ImageOrientationPatient imageOrientationPatient = currentFrame.ImageOrientationPatient; // if the current frame is missing any of the matching parameters, then it is always an error if (string.IsNullOrEmpty(studyInstanceUid) || string.IsNullOrEmpty(seriesInstanceUid)) throw new NullSourceSeriesException(); if (string.IsNullOrEmpty(frameOfReferenceUid)) throw new NullFrameOfReferenceException(); if (imageOrientationPatient == null || imageOrientationPatient.IsNull) { if (currentFrame.ParentImageSop.NumberOfFrames > 1) throw new UnsupportedMultiFrameSourceImagesException(new NullImageOrientationException()); throw new NullImageOrientationException(); } // if the current frame is not a supported pixel format, then it is always an error if (currentFrame.BitsAllocated != 16) throw new UnsupportedPixelFormatSourceImagesException(); // perform a very basic filtering of the selected display set based on the currently selected image var filteredFrames = new List<Frame>(); foreach (IPresentationImage image in displaySet.PresentationImages) { if (image == currentImage) { filteredFrames.Add(currentFrame); } else if (image is IImageSopProvider) { Frame frame = ((IImageSopProvider) image).Frame; if (frame.StudyInstanceUid == studyInstanceUid && frame.SeriesInstanceUid == seriesInstanceUid && frame.FrameOfReferenceUid == frameOfReferenceUid && !frame.ImageOrientationPatient.IsNull && frame.ImageOrientationPatient.EqualsWithinTolerance(imageOrientationPatient, .01f)) filteredFrames.Add(frame); } } // if we found at least 3 frames matching the current image, then return those to MPR if (filteredFrames.Count > 3) return filteredFrames; // JY: #6164 - Error message not accurate for MPR with no location information // if we don't find 3 matching frames, then MPR fails on the minimum frames error // which masks the fact that there *were* enough frames, just not enough frames matching some aspect filter criteria // we don't know what was the specific failed criterion, so we'll just pass all frames unfiltered // this lets MPR decide what's wrong with the display set here and throw the correct exception return CollectionUtils.Map<IPresentationImage, Frame>(displaySet.PresentationImages, img => img is IImageSopProvider ? ((IImageSopProvider) img).Frame : null); } else { throw new UnsupportedSourceImagesException(); } }
private static IPresentationImage GetMiddlePresentationImage(IDisplaySet displaySet) { if (displaySet.PresentationImages.Count == 0) throw new ArgumentException("The display set must contain at least one image."); if (displaySet.PresentationImages.Count <= 2) return displaySet.PresentationImages[0]; return displaySet.PresentationImages[displaySet.PresentationImages.Count/2]; }