protected void DeserializeDisplayShutter(DisplayShutterModuleIod displayShutterModule, T image)
        {
            ShutterShape shape = displayShutterModule.ShutterShape;

            if (shape != ShutterShape.Bitmap && shape != ShutterShape.None)
            {
                IShutterGraphic shutter = DicomGraphicsFactory.CreateGeometricShuttersGraphic(displayShutterModule, image.Frame.Rows, image.Frame.Columns);
                // Some day, we will properly deserialize CIELab colours - until then, leave PresentationColor default black

                DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, true);
                dicomGraphicsPlane.Shutters.Add(shutter);
                dicomGraphicsPlane.Shutters.Activate(shutter);
            }
        }
        protected void DeserializeGraphicAnnotation(GraphicAnnotationModuleIod module, RectangleF displayedArea, T image)
        {
            DicomGraphicsPlane graphic = DicomGraphicsPlane.GetDicomGraphicsPlane(image, true);

            var sqItems = module.GraphicAnnotationSequence;

            if (sqItems != null)
            {
                foreach (var annotation in sqItems.Select(sqItem =>
                                                          new
                {
                    LayerId = sqItem.GraphicLayer ?? string.Empty,
                    Graphic = DicomGraphicsFactory.CreateGraphicAnnotation(image.Frame, sqItem, displayedArea, DeserializeInteractiveAnnotations)
                }).Where(g => g.Graphic != null))
                {
                    graphic.Layers[annotation.LayerId].Graphics.Add(annotation.Graphic);
                }
            }
        }
        protected void DeserializeOverlayPlane(OverlayPlaneModuleIod overlayPlaneModule, T image)
        {
            DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, true);

            foreach (OverlayPlaneGraphic overlay in DicomGraphicsFactory.CreateOverlayPlaneGraphics(image.Frame, overlayPlaneModule))
            {
                // the results are a mix of overlays from the image itself and the presentation state
                if (overlay.Source == OverlayPlaneSource.Image)
                {
                    dicomGraphicsPlane.ImageOverlays.Add(overlay);
                }
                else
                {
                    dicomGraphicsPlane.PresentationOverlays.Add(overlay);
                }

                // the above lines will automatically add the overlays to the inactive layer
            }
            _overlayPlanesDeserialized = true;
        }
        protected void DeserializeGraphicAnnotation(GraphicAnnotationModuleIod module, RectangleF displayedArea, T image)
        {
            DicomGraphicsPlane graphic = DicomGraphicsPlane.GetDicomGraphicsPlane(image, true);

            var sqItems = module.GraphicAnnotationSequence;

            if (sqItems != null)
            {
                var interactiveAnnotations   = DeserializeOptions.HasFlag(DicomSoftcopyPresentationStateDeserializeOptions.InteractiveAnnotations);
                var ignoreImageRelationships = DeserializeIgnoreImageRelationship;
                foreach (var annotation in sqItems.Select(sqItem =>
                                                          new
                {
                    LayerId = sqItem.GraphicLayer ?? string.Empty,
                    Graphic = DicomGraphicsFactory.CreateGraphicAnnotation(image.Frame, sqItem, displayedArea, interactiveAnnotations, ignoreImageRelationships)
                }).Where(g => g.Graphic != null))
                {
                    graphic.Layers[annotation.LayerId].Graphics.Add(annotation.Graphic);
                }
            }
        }
예제 #5
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.");
            }
        }