public override bool Start(IMouseInformation mouseInformation) { if (!Enabled) { return(false); } base.Start(mouseInformation); if (_graphicBuilder != null) { return(_graphicBuilder.Start(mouseInformation)); } IDicomPresentationImage image = mouseInformation.Tile.PresentationImage as IDicomPresentationImage; if (image == null || GetGeometricShuttersGraphic(image, true) == null) { return(false); } AddDrawShutterGraphic(image); if (_graphicBuilder.Start(mouseInformation)) { _primitiveGraphic.Draw(); return(true); } this.Cancel(); return(false); }
public void Clear() { if (base.SelectedPresentationImage == null) { return; } if (base.SelectedPresentationImage is IDicomPresentationImage) { IDicomPresentationImage dicomImage = (IDicomPresentationImage)base.SelectedPresentationImage; GeometricShuttersGraphic shuttersGraphic = DrawShutterTool.GetGeometricShuttersGraphic(dicomImage); if (shuttersGraphic == null) { return; } DrawableUndoableCommand historyCommand = new DrawableUndoableCommand(shuttersGraphic); foreach (GeometricShutter shutter in shuttersGraphic.CustomShutters) { historyCommand.Enqueue(new RemoveGeometricShutterUndoableCommand(shuttersGraphic, shutter)); } historyCommand.Execute(); historyCommand.Name = SR.CommandClearCustomShutters; base.Context.Viewer.CommandHistory.AddCommand(historyCommand); Visible = false; } }
private void AddDrawShutterGraphic(IDicomPresentationImage image) { switch (_selectedShutterType) { case ShutterType.Polygon: { _primitiveGraphic = new PolylineGraphic(); image.OverlayGraphics.Add(_primitiveGraphic); _graphicBuilder = InteractiveShutterGraphicBuilders.CreatePolygonalShutterBuilder((PolylineGraphic)_primitiveGraphic); break; } case ShutterType.Circle: { _primitiveGraphic = new EllipsePrimitive(); image.OverlayGraphics.Add(_primitiveGraphic); _graphicBuilder = InteractiveShutterGraphicBuilders.CreateCircularShutterBuilder((EllipsePrimitive)_primitiveGraphic); break; } default: { _primitiveGraphic = new RectanglePrimitive(); image.OverlayGraphics.Add(_primitiveGraphic); _graphicBuilder = InteractiveShutterGraphicBuilders.CreateRectangularShutterBuilder((RectanglePrimitive)_primitiveGraphic); break; } } _graphicBuilder.GraphicCancelled += OnGraphicCancelled; _graphicBuilder.GraphicComplete += OnGraphicComplete; }
internal static IDicomGraphicsPlaneShutters GetShuttersGraphic(IDicomPresentationImage image, bool createAsNecessary = false) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, createAsNecessary); if (dicomGraphicsPlane != null) { return(dicomGraphicsPlane.Shutters); } return(null); }
internal static IDicomGraphicsPlaneShutters GetShuttersGraphic(IDicomPresentationImage image) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, false); if (dicomGraphicsPlane != null) { return(dicomGraphicsPlane.Shutters); } return(null); }
internal static GeometricShuttersGraphic GetGeometricShuttersGraphic(IDicomPresentationImage image) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, false); if (dicomGraphicsPlane == null) { return(null); } return(CollectionUtils.SelectFirst(dicomGraphicsPlane.Shutters, delegate(IShutterGraphic shutter) { return shutter is GeometricShuttersGraphic; }) as GeometricShuttersGraphic); }
private static bool HasCustomShutters(IPresentationImage image) { if (image != null && image is IDicomPresentationImage) { IDicomPresentationImage dicomImage = (IDicomPresentationImage)image; GeometricShuttersGraphic shuttersGraphic = DrawShutterTool.GetGeometricShuttersGraphic(dicomImage); if (shuttersGraphic != null) { return(shuttersGraphic.CustomShutters.Count > 0); } } return(false); }
private static IEnumerable<OverlayPlaneGraphic> GetOverlayPlanesGraphic(IDicomPresentationImage image) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, false); if (dicomGraphicsPlane != null) { foreach (ILayer layer in (IEnumerable<ILayer>)dicomGraphicsPlane.Layers) { foreach (OverlayPlaneGraphic overlayGraphic in CollectionUtils.Select(layer.Graphics, delegate(IGraphic graphic) { return graphic is OverlayPlaneGraphic; })) { yield return overlayGraphic; } } } }
private static IEnumerable <OverlayPlaneGraphic> GetOverlayPlanesGraphic(IDicomPresentationImage image) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, false); if (dicomGraphicsPlane != null) { foreach (ILayer layer in (IEnumerable <ILayer>)dicomGraphicsPlane.Layers) { foreach (OverlayPlaneGraphic overlayGraphic in CollectionUtils.Select(layer.Graphics, delegate(IGraphic graphic) { return(graphic is OverlayPlaneGraphic); })) { yield return(overlayGraphic); } } } }
/// <summary> /// Gets the DICOM graphics plane of the specified DICOM presentation image. /// </summary> /// <param name="dicomPresentationImage">The target DICOM presentation image.</param> /// <param name="createIfNecessary">A value indicating if a DICOM graphics plane should be automatically created and associated with the presentation image.</param> /// <returns>The DICOM graphics plane associated with the specified presentation image, or null if one doesn't exist and was not created.</returns> public static DicomGraphicsPlane GetDicomGraphicsPlane(IDicomPresentationImage dicomPresentationImage, bool createIfNecessary) { if (dicomPresentationImage == null) { return(null); } GraphicCollection dicomGraphics = dicomPresentationImage.DicomGraphics; DicomGraphicsPlane dicomGraphicsPlane = dicomGraphics.FirstOrDefault(IsType <DicomGraphicsPlane>) as DicomGraphicsPlane; if (dicomGraphicsPlane == null && createIfNecessary) { dicomGraphics.Add(dicomGraphicsPlane = new DicomGraphicsPlane()); } return(dicomGraphicsPlane); }
internal static GeometricShuttersGraphic GetGeometricShuttersGraphic(IDicomPresentationImage image, bool createAsNecessary = false) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, createAsNecessary); if (dicomGraphicsPlane == null) { return(null); } var geometricShuttersGraphic = (GeometricShuttersGraphic)CollectionUtils.SelectFirst(dicomGraphicsPlane.Shutters, shutter => shutter is GeometricShuttersGraphic); if (createAsNecessary && geometricShuttersGraphic == null) { dicomGraphicsPlane.Shutters.Add(geometricShuttersGraphic = new GeometricShuttersGraphic(image.Frame.Rows, image.Frame.Columns)); dicomGraphicsPlane.Shutters.Activate(geometricShuttersGraphic); } return(geometricShuttersGraphic); }
private void DeserializeInvert(IDicomPresentationImage image) { if (!ShowGrayscaleInverted) { return; } if (!(image.ImageGraphic.PixelData is GrayscalePixelData)) { return; } if (!(image is IVoiLutProvider)) { return; } IVoiLutManager manager = ((IVoiLutProvider)image).VoiLutManager; //Invert can be true by default depending on photometric interpretation, //so we'll just assume the current value is the default and flip it. manager.Invert = !manager.Invert; }
private static void DeserializeHeader(IDicomPresentationImage image) { bool anyFailures = false; DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, true); if (dicomGraphicsPlane == null) { throw new DicomGraphicsDeserializationException("Unknown exception."); } // Check if the image header specifies a bitmap display shutter BitmapDisplayShutterModuleIod bitmapShutterIod = new BitmapDisplayShutterModuleIod(image.ImageSop.DataSource); int bitmapShutterIndex = -1; if (bitmapShutterIod.ShutterShape == ShutterShape.Bitmap) { bitmapShutterIndex = bitmapShutterIod.ShutterOverlayGroupIndex; } if (bitmapShutterIndex < 0 || bitmapShutterIndex > 15) { bitmapShutterIndex = -1; } try { GeometricShuttersGraphic geometricShuttersGraphic = DicomGraphicsFactory.CreateGeometricShuttersGraphic(image.Frame); dicomGraphicsPlane.Shutters.Add(geometricShuttersGraphic); } catch (Exception e) { anyFailures = true; Platform.Log(LogLevel.Warn, e, "An error occurred trying to create geometric shutter graphics from the image header."); } try { List <OverlayPlaneGraphic> overlayPlaneGraphics = DicomGraphicsFactory.CreateOverlayPlaneGraphics(image.Frame); foreach (OverlayPlaneGraphic overlay in overlayPlaneGraphics) { if (bitmapShutterIndex != -1 && overlay.Index == bitmapShutterIndex) { // Someday when we support CIELab colour, we should set presentation value/colour based on client display type if (bitmapShutterIod.ShutterPresentationValue != null) { overlay.GrayPresentationValue = (ushort)bitmapShutterIod.ShutterPresentationValue; } overlay.Color = null; // insert the bitmap shutter into the shutters graphic instead of with the other overlays dicomGraphicsPlane.Shutters.Add(overlay); } else if (overlay.Index >= 0 && overlay.Index < 16) { // otherwise just add the overlay to the default layer for overlays and activate immediately dicomGraphicsPlane.ImageOverlays.Add(overlay); dicomGraphicsPlane.ImageOverlays.ActivateAsLayer(overlay, "OVERLAY"); } else { // otherwise just add the overlay to the default layer for overlays and activate immediately dicomGraphicsPlane.UserOverlays.Add(overlay); dicomGraphicsPlane.UserOverlays.ActivateAsLayer(overlay, "OVERLAY"); } } } catch (Exception e) { anyFailures = true; Platform.Log(LogLevel.Warn, e, "An error occurred trying to create overlay graphics from the image header."); } dicomGraphicsPlane.Shutters.ActivateFirst(); if (anyFailures) { throw new DicomGraphicsDeserializationException("At least one failure occurred in deserializing graphics from the image header."); } }
internal static GeometricShuttersGraphic GetGeometricShuttersGraphic(IDicomPresentationImage image, bool createAsNecessary = false) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, createAsNecessary); if (dicomGraphicsPlane == null) return null; var geometricShuttersGraphic = (GeometricShuttersGraphic) CollectionUtils.SelectFirst(dicomGraphicsPlane.Shutters, shutter => shutter is GeometricShuttersGraphic); if (createAsNecessary && geometricShuttersGraphic == null) { dicomGraphicsPlane.Shutters.Add(geometricShuttersGraphic = new GeometricShuttersGraphic(image.Frame.Rows, image.Frame.Columns)); dicomGraphicsPlane.Shutters.Activate(geometricShuttersGraphic); } return geometricShuttersGraphic; }
/// <summary> /// Gets the DICOM graphics plane of the specified DICOM presentation image, creating the plane if necessary. /// </summary> /// <param name="dicomPresentationImage">The target DICOM presentation image.</param> /// <returns>The DICOM graphics plane associated with the specified presentation image.</returns> public static DicomGraphicsPlane GetDicomGraphicsPlane(IDicomPresentationImage dicomPresentationImage) { return(GetDicomGraphicsPlane(dicomPresentationImage, true)); }
internal static IDicomGraphicsPlaneShutters GetShuttersGraphic(IDicomPresentationImage image) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, false); if (dicomGraphicsPlane != null) return dicomGraphicsPlane.Shutters; return null; }
internal static GeometricShuttersGraphic GetGeometricShuttersGraphic(IDicomPresentationImage image) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, false); if (dicomGraphicsPlane == null) return null; return CollectionUtils.SelectFirst(dicomGraphicsPlane.Shutters, delegate(IShutterGraphic shutter) { return shutter is GeometricShuttersGraphic; }) as GeometricShuttersGraphic; }
internal static IDicomGraphicsPlaneShutters GetShuttersGraphic(IDicomPresentationImage image, bool createAsNecessary = false) { DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, createAsNecessary); if (dicomGraphicsPlane != null) return dicomGraphicsPlane.Shutters; return null; }
private void DeserializeInvert(IDicomPresentationImage image) { if (!ShowGrayscaleInverted) return; if (!(image.ImageGraphic.PixelData is GrayscalePixelData)) return; if (!(image is IVoiLutProvider)) return; IVoiLutManager manager = ((IVoiLutProvider) image).VoiLutManager; //Invert can be true by default depending on photometric interpretation, //so we'll just assume the current value is the default and flip it. manager.Invert = !manager.Invert; }
private static void DeserializeHeader(IDicomPresentationImage image) { bool anyFailures = false; DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, true); if(dicomGraphicsPlane == null) throw new DicomGraphicsDeserializationException("Unknown exception."); // Check if the image header specifies a bitmap display shutter BitmapDisplayShutterModuleIod bitmapShutterIod = new BitmapDisplayShutterModuleIod(image.ImageSop.DataSource); int bitmapShutterIndex = -1; if (bitmapShutterIod.ShutterShape == ShutterShape.Bitmap) bitmapShutterIndex = bitmapShutterIod.ShutterOverlayGroupIndex; if (bitmapShutterIndex < 0 || bitmapShutterIndex > 15) bitmapShutterIndex = -1; try { GeometricShuttersGraphic geometricShuttersGraphic = DicomGraphicsFactory.CreateGeometricShuttersGraphic(image.Frame); dicomGraphicsPlane.Shutters.Add(geometricShuttersGraphic); } catch (Exception e) { anyFailures = true; Platform.Log(LogLevel.Warn, e, "An error occurred trying to create geometric shutter graphics from the image header."); } try { List<OverlayPlaneGraphic> overlayPlaneGraphics = DicomGraphicsFactory.CreateOverlayPlaneGraphics(image.Frame); foreach (OverlayPlaneGraphic overlay in overlayPlaneGraphics) { if (bitmapShutterIndex != -1 && overlay.Index == bitmapShutterIndex) { // Someday when we support CIELab colour, we should set presentation value/colour based on client display type if (bitmapShutterIod.ShutterPresentationValue != null) overlay.GrayPresentationValue = (ushort)bitmapShutterIod.ShutterPresentationValue; overlay.Color = null; // insert the bitmap shutter into the shutters graphic instead of with the other overlays dicomGraphicsPlane.Shutters.Add(overlay); } else if (overlay.Index >= 0 && overlay.Index < 16) { // otherwise just add the overlay to the default layer for overlays and activate immediately dicomGraphicsPlane.ImageOverlays.Add(overlay); dicomGraphicsPlane.ImageOverlays.ActivateAsLayer(overlay, "OVERLAY"); } else { // otherwise just add the overlay to the default layer for overlays and activate immediately dicomGraphicsPlane.UserOverlays.Add(overlay); dicomGraphicsPlane.UserOverlays.ActivateAsLayer(overlay, "OVERLAY"); } } } catch (Exception e) { anyFailures = true; Platform.Log(LogLevel.Warn, e, "An error occurred trying to create overlay graphics from the image header."); } dicomGraphicsPlane.Shutters.ActivateFirst(); if (anyFailures) throw new DicomGraphicsDeserializationException("At least one failure occurred in deserializing graphics from the image header."); }