Пример #1
0
 protected override void AddShapeToGraphicsPath(GraphicsPath graphicsPath, RectangleF shapeData)
 {
     // we must do the positive rectangle conversion because the GDI GraphicsPath tests will fail on negative rectangles
     graphicsPath.AddRectangle(RectangleUtilities.ConvertToPositiveRectangle(shapeData));
 }
Пример #2
0
 /// <summary>
 /// Called by <see cref="Roi.BoundingBox"/> to compute the tightest bounding box of the region of interest.
 /// </summary>
 /// <remarks>
 /// <para>This method is only called once and the result is cached for future accesses.</para>
 /// <para>
 /// Regions of interest have no notion of coordinate system. All coordinates are inherently
 /// given relative to the image pixel space (i.e. <see cref="CoordinateSystem.Source"/>.)
 /// </para>
 /// </remarks>
 /// <returns>A rectangle defining the bounding box.</returns>
 protected override RectangleF ComputeBounds()
 {
     return(RectangleUtilities.ConvertToPositiveRectangle(_rectangle));
 }
        protected void SerializeDisplayedArea(DisplayedAreaModuleIod displayedAreaModule, DicomPresentationImageCollection <T> images)
        {
            displayedAreaModule.InitializeAttributes();
            List <DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem> displayedAreas = new List <DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem>();

            foreach (T image in images)
            {
                DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem displayedArea = new DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem();
                displayedArea.InitializeAttributes();
                displayedArea.ReferencedImageSequence = new[] { CreateImageSopInstanceReference(image.Frame) };

                ImageGraphic imageGraphic = ((IImageGraphicProvider)image).ImageGraphic;
                Size         imageSize    = new Size(imageGraphic.Columns, imageGraphic.Rows);

                // compute the visible boundaries of the image as a positive rectangle in screen space
                RectangleF visibleBounds = imageGraphic.SpatialTransform.ConvertToDestination(new Rectangle(new Point(0, 0), imageSize));
                visibleBounds = RectangleUtilities.Intersect(visibleBounds, image.ClientRectangle);
                visibleBounds = RectangleUtilities.ConvertToPositiveRectangle(visibleBounds);

                // compute the visible area of the image as a rectangle oriented positively in screen space
                RectangleF visibleImageArea = imageGraphic.SpatialTransform.ConvertToSource(visibleBounds);
                visibleImageArea = RectangleUtilities.RoundInflate(visibleImageArea);

                // compute the pixel addresses of the visible area by intersecting area with actual pixel addresses available
                //Rectangle visiblePixels = Rectangle.Truncate(RectangleUtilities.Intersect(visibleImageArea, new RectangleF(_point1, imageSize)));
                Rectangle visiblePixels = ConvertToPixelAddressRectangle(Rectangle.Truncate(visibleImageArea));
                displayedArea.DisplayedAreaTopLeftHandCorner     = visiblePixels.Location;
                displayedArea.DisplayedAreaBottomRightHandCorner = visiblePixels.Location + visiblePixels.Size;

                ISpatialTransform spatialTransform = image.SpatialTransform;
                switch (_displayAreaSerializationOption)
                {
                case DisplayAreaSerializationOption.SerializeAsMagnification:
                    displayedArea.PresentationSizeMode = DisplayedAreaModuleIod.PresentationSizeMode.Magnify;
                    displayedArea.PresentationPixelMagnificationRatio = spatialTransform.Scale;
                    break;

                case DisplayAreaSerializationOption.SerializeAsTrueSize:
                    displayedArea.PresentationSizeMode     = DisplayedAreaModuleIod.PresentationSizeMode.TrueSize;
                    displayedArea.PresentationPixelSpacing = image.Frame.PixelSpacing;
                    break;

                case DisplayAreaSerializationOption.SerializeAsDisplayedArea:
                default:
                    displayedArea.PresentationSizeMode = DisplayedAreaModuleIod.PresentationSizeMode.ScaleToFit;
                    break;
                }

                PixelAspectRatio pixelAspectRatio = image.Frame.PixelAspectRatio;
                if (pixelAspectRatio == null || pixelAspectRatio.IsNull)
                {
                    pixelAspectRatio = PixelAspectRatio.FromString(image.Frame[DicomTags.PixelAspectRatio].ToString());
                }
                if (pixelAspectRatio == null || pixelAspectRatio.IsNull)
                {
                    pixelAspectRatio = new PixelAspectRatio(1, 1);
                }
                displayedArea.PresentationPixelAspectRatio = pixelAspectRatio;

                displayedAreas.Add(displayedArea);
            }
            displayedAreaModule.DisplayedAreaSelectionSequence = displayedAreas.ToArray();
        }
        protected void DeserializeDisplayedArea(DisplayedAreaModuleIod dispAreaMod, out RectangleF displayedArea, T image)
        {
            ISpatialTransform spatialTransform = image.SpatialTransform;

            foreach (DisplayedAreaModuleIod.DisplayedAreaSelectionSequenceItem item in dispAreaMod.DisplayedAreaSelectionSequence)
            {
                if (item.ReferencedImageSequence[0].ReferencedSopInstanceUid == image.ImageSop.SopInstanceUid)
                {
                    // get the displayed area of the image in source coordinates (stored values do not have sub-pixel accuracy)
                    var displayRect = RectangleF.FromLTRB(item.DisplayedAreaTopLeftHandCorner.X,
                                                          item.DisplayedAreaTopLeftHandCorner.Y,
                                                          item.DisplayedAreaBottomRightHandCorner.X,
                                                          item.DisplayedAreaBottomRightHandCorner.Y);
                    displayRect          = RectangleUtilities.ConvertToPositiveRectangle(displayRect);
                    displayRect.Location = displayRect.Location - new SizeF(1, 1);
                    displayRect.Size     = displayRect.Size + new SizeF(1, 1);

                    var centerDisplay = true;

                    switch (item.PresentationSizeMode)
                    {
                    case DisplayedAreaModuleIod.PresentationSizeMode.Magnify:
                        // displays selected area at specified magnification factor
                        spatialTransform.Scale = (float)item.PresentationPixelMagnificationRatio.GetValueOrDefault(1);
                        break;

                    case DisplayedAreaModuleIod.PresentationSizeMode.TrueSize:
                    // currently no support for determining true size, so default to scale area to fit
                    case DisplayedAreaModuleIod.PresentationSizeMode.ScaleToFit:
                    case DisplayedAreaModuleIod.PresentationSizeMode.None:
                    default:
                        if (spatialTransform is IImageSpatialTransform && displayRect.Location == new PointF(0, 0) && displayRect.Size == new SizeF(image.ImageGraphic.Columns, image.ImageGraphic.Rows))
                        {
                            // if the display rect is the whole image, then take advantage of the built-in scale image to fit functionality
                            IImageSpatialTransform iist = (IImageSpatialTransform)spatialTransform;
                            iist.ScaleToFit = true;
                            centerDisplay   = false;                                   // when ScaleToFit is true, the image will automatically be positioned correctly in the client area
                        }
                        else
                        {
                            var clientArea  = image.ClientRectangle.Size;
                            var displaySize = displayRect.Size;

                            // if image is rotated 90 or 270, transpose width/height
                            if (Math.Abs(Math.Round(Math.Sin(spatialTransform.RotationXY * Math.PI / 180))) > 0)
                            {
                                displaySize = new SizeF(displaySize.Height, displaySize.Width);
                            }

                            // compute the maximum magnification that allows the entire displayRect to be visible
                            spatialTransform.Scale = Math.Min(clientArea.Width / displaySize.Width, clientArea.Height / displaySize.Height);
                        }

                        break;
                    }

                    if (centerDisplay)
                    {
                        // compute translation so that the displayRect is centered in the clientRect
                        var displayCentre = GetRectangleCenter(displayRect);
                        var clientCentre  = spatialTransform.ConvertToSource(GetRectangleCenter(image.ClientRectangle));
                        spatialTransform.TranslationX = clientCentre.X - displayCentre.X;
                        spatialTransform.TranslationY = clientCentre.Y - displayCentre.Y;
                    }

                    displayedArea = displayRect;
                    return;
                }
            }
            displayedArea = new RectangleF(0, 0, image.ImageGraphic.Columns, image.ImageGraphic.Rows);
        }
Пример #5
0
 /// <summary>
 /// Constructs a new rectangular geometric shutter.
 /// </summary>
 /// <param name="rectangle">The rectangle defining the shutter boundary.</param>
 public RectangularShutter(Rectangle rectangle)
 {
     this.Rectangle = RectangleUtilities.ConvertToPositiveRectangle(rectangle);
 }