Пример #1
0
        private void OnGraphicComplete(object sender, GraphicEventArgs e)
        {
            _graphicBuilder.GraphicCancelled -= OnGraphicCancelled;
            _graphicBuilder.GraphicComplete  -= OnGraphicComplete;
            _graphicBuilder = null;

            if (_primitiveGraphic != null)
            {
                bool boundingBoxTooSmall = false;
                _primitiveGraphic.CoordinateSystem = CoordinateSystem.Destination;
                if (_primitiveGraphic.BoundingBox.Width < 50 || _primitiveGraphic.BoundingBox.Height < 50)
                {
                    boundingBoxTooSmall = true;
                }
                _primitiveGraphic.ResetCoordinateSystem();

                if (boundingBoxTooSmall)
                {
                    RemoveDrawShutterGraphic();
                    base.SelectedPresentationImage.Draw();
                }
                else
                {
                    GeometricShutter         shutter         = ConvertToGeometricShutter();
                    GeometricShuttersGraphic shuttersGraphic =
                        GetGeometricShuttersGraphic((IDicomPresentationImage)base.SelectedPresentationImage, true);
                    DrawableUndoableCommand command = new DrawableUndoableCommand(shuttersGraphic);
                    command.Name = SR.CommandDrawShutter;
                    command.Enqueue(new AddGeometricShutterUndoableCommand(shuttersGraphic, shutter));
                    command.Execute();

                    base.ImageViewer.CommandHistory.AddCommand(command);
                }
            }
        }
Пример #2
0
        public static GeometricShuttersGraphic CreateGeometricShuttersGraphic(DisplayShutterMacroIod shutterModule, int imageRows, int imageColumns)
        {
            GeometricShuttersGraphic shuttersGraphic = new GeometricShuttersGraphic(imageRows, imageColumns);

            if ((shutterModule.ShutterShape & ShutterShape.Circular) == ShutterShape.Circular)
            {
                Point?center = shutterModule.CenterOfCircularShutter;
                int?  radius = shutterModule.RadiusOfCircularShutter;
                if (center != null && radius != null)
                {
                    shuttersGraphic.AddDicomShutter(new CircularShutter(center.Value, radius.Value));
                }
            }

            if ((shutterModule.ShutterShape & ShutterShape.Rectangular) == ShutterShape.Rectangular)
            {
                int?left   = shutterModule.ShutterLeftVerticalEdge;
                int?right  = shutterModule.ShutterRightVerticalEdge;
                int?top    = shutterModule.ShutterUpperHorizontalEdge;
                int?bottom = shutterModule.ShutterLowerHorizontalEdge;

                if (left != null && right != null && top != null && bottom != null)
                {
                    shuttersGraphic.AddDicomShutter(new RectangularShutter(left.Value, right.Value, top.Value, bottom.Value));
                }
            }

            if ((shutterModule.ShutterShape & ShutterShape.Polygonal) == ShutterShape.Polygonal)
            {
                Point[] points = shutterModule.VerticesOfThePolygonalShutter;
                shuttersGraphic.AddDicomShutter(new PolygonalShutter(points));
            }

            return(shuttersGraphic);
        }
Пример #3
0
        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 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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        public override bool Stop(IMouseInformation mouseInformation)
        {
            if (!Enabled)
            {
                return(false);
            }

            if (_graphicBuilder != null && _graphicBuilder.Stop(mouseInformation))
            {
                _primitiveGraphic.Draw();
                return(true);
            }

            if (_graphicBuilder == null && _primitiveGraphic != null)
            {
                bool boundingBoxTooSmall = false;
                _primitiveGraphic.CoordinateSystem = CoordinateSystem.Destination;
                if (_primitiveGraphic.BoundingBox.Width < 50 || _primitiveGraphic.BoundingBox.Height < 50)
                {
                    boundingBoxTooSmall = true;
                }
                _primitiveGraphic.ResetCoordinateSystem();

                if (boundingBoxTooSmall)
                {
                    RemoveDrawShutterGraphic();
                    base.SelectedPresentationImage.Draw();
                }
                else
                {
                    GeometricShutter         shutter         = ConvertToGeometricShutter();
                    GeometricShuttersGraphic shuttersGraphic =
                        GetGeometricShuttersGraphic((IDicomPresentationImage)base.SelectedPresentationImage);
                    DrawableUndoableCommand command = new DrawableUndoableCommand(shuttersGraphic);
                    command.Name = SR.CommandDrawShutter;
                    command.Enqueue(new AddGeometricShutterUndoableCommand(shuttersGraphic, shutter));
                    command.Execute();

                    base.ImageViewer.CommandHistory.AddCommand(command);
                }
            }

            return(false);
        }
Пример #7
0
        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.");
            }
        }
		public static GeometricShuttersGraphic CreateGeometricShuttersGraphic(DisplayShutterMacroIod shutterModule, int imageRows, int imageColumns)
		{
			GeometricShuttersGraphic shuttersGraphic = new GeometricShuttersGraphic(imageRows, imageColumns);
			if ((shutterModule.ShutterShape & ShutterShape.Circular) == ShutterShape.Circular)
			{
				Point? center = shutterModule.CenterOfCircularShutter;
				int? radius = shutterModule.RadiusOfCircularShutter;
				if (center != null && radius != null)
					shuttersGraphic.AddDicomShutter(new CircularShutter(center.Value, radius.Value));
			}

			if ((shutterModule.ShutterShape & ShutterShape.Rectangular) == ShutterShape.Rectangular)
			{
				int? left = shutterModule.ShutterLeftVerticalEdge;
				int? right = shutterModule.ShutterRightVerticalEdge;
				int? top = shutterModule.ShutterUpperHorizontalEdge;
				int? bottom = shutterModule.ShutterLowerHorizontalEdge;

				if (left != null && right != null && top != null && bottom != null)
					shuttersGraphic.AddDicomShutter(new RectangularShutter(left.Value, right.Value, top.Value, bottom.Value));
			}

			if ((shutterModule.ShutterShape & ShutterShape.Polygonal) == ShutterShape.Polygonal)
			{
				Point[] points = shutterModule.VerticesOfThePolygonalShutter;
				shuttersGraphic.AddDicomShutter(new PolygonalShutter(points));
			}

			return shuttersGraphic;
		}
        protected void SerializeDisplayShutter(DisplayShutterModuleIod displayShutterModule, DicomPresentationImageCollection <T> images)
        {
            // Doesn't support multiframe or whatever case it is when we get more than one image serialized to one state
            CircularShutter    circular    = null;
            RectangularShutter rectangular = null;
            PolygonalShutter   polygonal   = null;
            int unserializedCount          = 0;

            foreach (T image in images)
            {
                DicomGraphicsPlane dicomGraphics = DicomGraphicsPlane.GetDicomGraphicsPlane(image, false);
                if (dicomGraphics != null)
                {
                    // identify visible geometric shutter if exists
                    GeometricShuttersGraphic geometricShutters = dicomGraphics.Shutters.ActiveShutter as GeometricShuttersGraphic;
                    if (geometricShutters != null)
                    {
                        // we can only save the first of each
                        foreach (GeometricShutter shutter in geometricShutters.CustomShutters)
                        {
                            if (shutter is CircularShutter && circular == null)
                            {
                                circular = (CircularShutter)shutter;
                            }
                            else if (shutter is RectangularShutter && rectangular == null)
                            {
                                rectangular = (RectangularShutter)shutter;
                            }
                            else if (shutter is PolygonalShutter && polygonal == null)
                            {
                                polygonal = (PolygonalShutter)shutter;
                            }
                            else
                            {
                                unserializedCount++;
                            }
                        }
                        foreach (GeometricShutter shutter in geometricShutters.DicomShutters)
                        {
                            if (shutter is CircularShutter && circular == null)
                            {
                                circular = (CircularShutter)shutter;
                            }
                            else if (shutter is RectangularShutter && rectangular == null)
                            {
                                rectangular = (RectangularShutter)shutter;
                            }
                            else if (shutter is PolygonalShutter && polygonal == null)
                            {
                                polygonal = (PolygonalShutter)shutter;
                            }
                            else
                            {
                                unserializedCount++;
                            }
                        }
                    }
                }
            }

            ShutterShape shape = ShutterShape.None;

            if (circular != null)
            {
                shape |= ShutterShape.Circular;

                displayShutterModule.CenterOfCircularShutter = circular.Center;
                displayShutterModule.RadiusOfCircularShutter = circular.Radius;
            }
            if (rectangular != null)
            {
                shape |= ShutterShape.Rectangular;

                Rectangle r = rectangular.Rectangle;
                displayShutterModule.ShutterLeftVerticalEdge    = r.Left;
                displayShutterModule.ShutterRightVerticalEdge   = r.Right;
                displayShutterModule.ShutterUpperHorizontalEdge = r.Top;
                displayShutterModule.ShutterLowerHorizontalEdge = r.Bottom;
            }
            if (polygonal != null)
            {
                shape |= ShutterShape.Polygonal;

                List <Point> vertices = new List <Point>();
                vertices.AddRange(polygonal.Vertices);
                displayShutterModule.VerticesOfThePolygonalShutter = vertices.ToArray();
            }

            if (shape != ShutterShape.None)
            {
                displayShutterModule.ShutterShape             = shape;
                displayShutterModule.ShutterPresentationValue = 0;
            }
            else
            {
                foreach (uint tag in DisplayShutterMacroIod.DefinedTags)
                {
                    displayShutterModule.DicomAttributeProvider[tag] = null;
                }
            }

            if (unserializedCount > 0)
            {
                Platform.Log(LogLevel.Warn, "Attempt to serialize presentation state with an unsupported combination of shutters - some information may be lost.");
            }
        }
 /// <summary>
 /// Constructs a new <see cref="RemoveGeometricShutterUndoableCommand"/>.
 /// </summary>
 /// <param name="parent">The parent <see cref="GeometricShuttersGraphic"/>.</param>
 /// <param name="shutter">The <see cref="GeometricShutter"/> to add to <paramref name="parent"/>.</param>
 public RemoveGeometricShutterUndoableCommand(GeometricShuttersGraphic parent, GeometricShutter shutter)
 {
     _parent  = parent;
     _shutter = shutter;
 }