/// <summary>
        /// Deserializes the specified bitmap display shutter module.
        /// </summary>
        /// <remarks>
        /// This method must be called after <see cref="DeserializeOverlayPlane">the overlay planes have been deserialized</see>.
        /// </remarks>
        /// <param name="bitmapDisplayShutterModule"></param>
        /// <param name="image"></param>
        protected void DeserializeBitmapDisplayShutter(BitmapDisplayShutterModuleIod bitmapDisplayShutterModule, T image)
        {
            if (!_overlayPlanesDeserialized)
            {
                throw new InvalidOperationException("Overlay planes must be deserialized first.");
            }

            if (bitmapDisplayShutterModule.ShutterShape == ShutterShape.Bitmap)
            {
                DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(image, true);
                int overlayIndex = bitmapDisplayShutterModule.ShutterOverlayGroupIndex;
                if (overlayIndex >= 0 && overlayIndex < 16)
                {
                    IShutterGraphic shutter = null;
                    if (dicomGraphicsPlane.PresentationOverlays.Contains(overlayIndex))
                    {
                        shutter = dicomGraphicsPlane.PresentationOverlays[overlayIndex];
                        dicomGraphicsPlane.PresentationOverlays.ActivateAsShutter(overlayIndex);
                        dicomGraphicsPlane.ImageOverlays.Deactivate(overlayIndex);
                    }
                    else if (dicomGraphicsPlane.ImageOverlays.Contains(overlayIndex))
                    {
                        shutter = dicomGraphicsPlane.ImageOverlays[overlayIndex];
                        dicomGraphicsPlane.ImageOverlays.ActivateAsShutter(overlayIndex);
                    }

                    // Some day, we will properly deserialize CIELab colours - until then, handle only a specified presentation value
                    if (shutter != null)
                    {
                        shutter.PresentationColor = Color.Empty;
                        shutter.PresentationValue = bitmapDisplayShutterModule.ShutterPresentationValue ?? 0;
                    }
                }
            }
        }
 protected void SerializeBitmapDisplayShutter(BitmapDisplayShutterModuleIod bitmapDisplayShutterModule, IOverlayMapping overlayMapping, DicomPresentationImageCollection <T> images)
 {
     // Doesn't support multiframe or whatever case it is when we get more than one image serialized to one state
     for (int n = 0; n < 16; n++)
     {
         OverlayPlaneGraphic overlay = overlayMapping[n];
         if (overlay != null)
         {
             if (overlay.ParentGraphic is IDicomGraphicsPlaneShutters)
             {
                 bitmapDisplayShutterModule.ShutterShape                        = ShutterShape.Bitmap;
                 bitmapDisplayShutterModule.ShutterOverlayGroupIndex            = n;
                 bitmapDisplayShutterModule.ShutterPresentationValue            = overlay.GrayPresentationValue;
                 bitmapDisplayShutterModule.ShutterPresentationColorCielabValue = null;
                 break;                         // there can only be one
             }
         }
     }
 }
Ejemplo n.º 3
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.");
            }
        }