コード例 #1
0
        private void CalculateReferenceDisplayValues()
        {
            IImageSpatialTransform transform = GetImageTransform(ReferenceImage);
            Frame frame = GetFrame(ReferenceImage);

            //calculate the width (in mm) of the portion of the image that is visible on the display,
            //as well as the display rectangle it occupies.

            RectangleF sourceRectangle = new RectangleF(0, 0, frame.Columns, frame.Rows);

            _referenceDisplayRectangle = transform.ConvertToDestination(sourceRectangle);
            _referenceDisplayRectangle = RectangleUtilities.Intersect(_referenceDisplayRectangle, ReferenceImage.ClientRectangle);

            _referenceDisplayedWidth = GetDisplayedWidth(ReferenceImage, _referenceDisplayRectangle);
        }
コード例 #2
0
        private static Bitmap DrawCompleteImageToBitmap(IPresentationImage image, float scale, float dpi)
        {
            IImageSpatialTransform transform = (IImageSpatialTransform)((ISpatialTransformProvider)image).SpatialTransform;
            object restoreMemento            = transform.CreateMemento();

            try
            {
                Rectangle imageRectangle = new Rectangle(new Point(0, 0), image.SceneSize);

                transform.Initialize();
                transform.ScaleToFit = false;
                transform.Scale      = scale;
                RectangleF displayRectangle = transform.ConvertToDestination(imageRectangle);
                int        width            = (int)Math.Round(displayRectangle.Width);
                int        height           = (int)Math.Round(displayRectangle.Height);

                transform.ScaleToFit = true;
                return(ImageDrawToBitmap(image, width, height, dpi));
            }
            finally
            {
                transform.SetMemento(restoreMemento);
            }
        }
コード例 #3
0
        public override string GetAnnotationText(IPresentationImage presentationImage)
        {
            if (presentationImage == null)
            {
                return(String.Empty);
            }

            IImageSopProvider imageSopProvider = presentationImage as IImageSopProvider;

            if (imageSopProvider == null)
            {
                return(String.Empty);
            }

            ISpatialTransformProvider spatialTransformProvider = presentationImage as ISpatialTransformProvider;

            if (spatialTransformProvider == null)
            {
                return(String.Empty);
            }

            // 2D DFOV value doesn't make a lot of sense when the "image" is 3D, so we're blanking it out until we define what DFOV means in this context
            if (presentationImage is ISpatialTransform3DProvider)
            {
                return(String.Empty);
            }

            IImageSpatialTransform transform = spatialTransformProvider.SpatialTransform as IImageSpatialTransform;

            if (transform == null)
            {
                return(String.Empty);
            }

            if (transform.RotationXY % 90 != 0)
            {
                return(SR.ValueNotApplicable);
            }

            Frame        frame = imageSopProvider.Frame;
            PixelSpacing normalizedPixelSpacing = frame.NormalizedPixelSpacing;

            if (normalizedPixelSpacing.IsNull)
            {
                return(String.Empty);
            }

            RectangleF sourceRectangle      = new RectangleF(0, 0, frame.Columns, frame.Rows);
            RectangleF destinationRectangle = transform.ConvertToDestination(sourceRectangle);

            destinationRectangle = RectangleUtilities.Intersect(destinationRectangle, presentationImage.ClientRectangle);

            //Convert the displayed width and height to source dimensions
            SizeF widthInSource  = transform.ConvertToSource(new SizeF(destinationRectangle.Width, 0));
            SizeF heightInSource = transform.ConvertToSource(new SizeF(0, destinationRectangle.Height));

            //The displayed FOV is given by the magnitude of each line in source coordinates, but
            //for each of the 2 lines, one of x or y will be zero, so we can optimize.

            float x1 = Math.Abs(widthInSource.Width);
            float y1 = Math.Abs(widthInSource.Height);
            float x2 = Math.Abs(heightInSource.Width);
            float y2 = Math.Abs(heightInSource.Height);

            double displayedFieldOfViewX, displayedFieldOfViewY;

            if (x1 > y1)             //the image is not rotated
            {
                displayedFieldOfViewX = x1 * normalizedPixelSpacing.Column / 10;
                displayedFieldOfViewY = y2 * normalizedPixelSpacing.Row / 10;
            }
            else             //the image is rotated by 90 or 270 degrees
            {
                displayedFieldOfViewX = x2 * normalizedPixelSpacing.Column / 10;
                displayedFieldOfViewY = y1 * normalizedPixelSpacing.Row / 10;
            }

            return(String.Format(SR.FormatCentimeters, String.Format(SR.Format2Dimensions, displayedFieldOfViewX.ToString("F1"), displayedFieldOfViewY.ToString("F1"))));
        }