Exemplo n.º 1
0
        /// <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);
        }
 public UserOverlaysCollection(DicomGraphicsPlane owner)
 {
     _owner    = owner;
     _overlays = new List <OverlayPlaneGraphic>();
 }
Exemplo n.º 3
0
 public OverlaysCollection(DicomGraphicsPlane owner)
 {
     _owner    = owner;
     _overlays = new OverlayPlaneGraphic[16];
 }
        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.");
            }
        }