private SizeF[] GetImageEdgeVectors()
        {
            var imageEdgeVectors = new SizeF[4];

            for (int i = 0; i < 4; ++i)
            {
                imageEdgeVectors[i] = _imageTransform.ConvertToDestination(_edgeVectors[i]);
            }
            return(imageEdgeVectors);
        }
		/// <summary>
		/// Performs validation on the specified <see cref="ISpatialTransform"/>.
		/// </summary>
		/// <param name="transform"></param>
		/// <remarks>
		/// At present, validation amounts to ensuring that rotations are
		/// only in increments of 90 degrees.
		/// </remarks>
		public override void Validate(ISpatialTransform transform)
		{
			PointF xVector = new PointF(100, 0);
			SizeF xVectorTransformed = transform.ConvertToDestination(new SizeF(xVector));

			//figure out where the source x-axis went in destination
			int rotation = (int) Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector));
			if (rotation < 0)
				rotation += 360;

			if ((rotation % 90) != 0)
				throw new ArgumentException("Images can only be rotated by multiples of 90 degrees.");
		}
        /// <summary>
        /// Called by GetAnnotationText (and also by Unit Test code).  Making this function internal simply makes it easier
        /// to write unit tests for this class (don't have to implement a fake PresentationImage).
        /// </summary>
        /// <param name="imageTransform">the image transform</param>
        /// <param name="patientOrientation">the image orientation patient (direction cosines)</param>
        /// <returns></returns>
        internal string GetAnnotationTextInternal(ISpatialTransform imageTransform, PatientOrientation patientOrientation)
        {
            SizeF[] imageEdgeVectors = new SizeF[4];
            for (int i = 0; i < 4; ++i)
            {
                imageEdgeVectors[i] = imageTransform.ConvertToDestination(_edgeVectors[i]);
            }

            //find out which source image edge got transformed to coincide with this viewport edge.
            ImageEdge transformedEdge = GetTransformedEdge(imageEdgeVectors);

            //get the marker for the appropriate (source) image edge.
            return(GetMarker(transformedEdge, patientOrientation));
        }
        /// <summary>
        /// Performs validation on the specified <see cref="ISpatialTransform"/>.
        /// </summary>
        /// <param name="transform"></param>
        /// <remarks>
        /// At present, validation amounts to ensuring that rotations are
        /// only in increments of 90 degrees.
        /// </remarks>
        public override void Validate(ISpatialTransform transform)
        {
            PointF xVector            = new PointF(100, 0);
            SizeF  xVectorTransformed = transform.ConvertToDestination(new SizeF(xVector));

            //figure out where the source x-axis went in destination
            int rotation = (int)Math.Round(Vector.SubtendedAngle(xVectorTransformed.ToPointF(), PointF.Empty, xVector));

            if (rotation < 0)
            {
                rotation += 360;
            }

            if ((rotation % 90) != 0)
            {
                throw new ArgumentException("Images can only be rotated by multiples of 90 degrees.");
            }
        }
示例#5
0
        private void Probe(Point sourcePointRounded, bool showPixelValue, bool showVoiValue)
        {
            string probeString;
            string pixelValueString  = String.Format(SR.FormatProbeInfo, SR.LabelRawPixel, SR.LabelNotApplicable);
            string modalityLutString = String.Format(SR.FormatProbeInfo, SR.LabelModalityLut, SR.LabelNotApplicable);
            string voiLutString      = String.Format(SR.FormatProbeInfo, SR.LabelVOILut, SR.LabelNotApplicable);

            try
            {
                var displayString = new StringBuilder();

                if (_selectedImageGraphic != null && _selectedImageGraphic.BoundingBox.Contains(sourcePointRounded))
                {
                    if (_selectedImageGraphic is ILutPipelineProvider)
                    {
                        var luts       = _selectedImageGraphic as ILutPipelineProvider;
                        var pixelValue = _selectedImageGraphic.PixelData.GetPixel(sourcePointRounded.X, sourcePointRounded.Y);

                        GetPixelValue(luts, pixelValue, ref pixelValueString);
                        GetModalityLutValue(luts, pixelValue, ref modalityLutString);
                        GetVoiLutValue(luts, pixelValue, ref voiLutString);

                        // the modality LUT value is always shown
                        displayString.AppendLine(modalityLutString);

                        if (showPixelValue)
                        {
                            displayString.AppendLine(pixelValueString);
                        }
                        if (showVoiValue)
                        {
                            displayString.AppendLine(voiLutString);
                        }
                    }
                    else if (_selectedImageGraphic is ColorImageGraphic)
                    {
                        ColorImageGraphic image        = _selectedImageGraphic as ColorImageGraphic;
                        Color             color        = image.PixelData.GetPixelAsColor(sourcePointRounded.X, sourcePointRounded.Y);
                        string            rgbFormatted = String.Format(SR.FormatRGB, color.R, color.G, color.B);
                        pixelValueString = String.Format(SR.FormatProbeInfo, SR.LabelRGBPixel, rgbFormatted);
                        displayString.AppendLine(pixelValueString);
                    }
                }

                // show the coordinates last, cause it's probably the least interesting information
                var coordinateString = String.Format(SR.FormatProbeInfo, SR.LabelLocation, string.Format(SR.FormatCoordinates, sourcePointRounded.X, sourcePointRounded.Y));
                displayString.AppendLine(coordinateString);

                var patientPoint = _selectedCoordinateMapping != null && _selectedCoordinateMapping.IsValid
                                                        ? _selectedCoordinateMapping.ConvertToPatient(sourcePointRounded)
                                                        : _selectedFrame.ImagePlaneHelper.ConvertToPatient(sourcePointRounded);
                if (patientPoint != null)
                {
                    var patientString = String.Format(SR.FormatProbeInfo, SR.LabelPatientLocation, string.Format(SR.FormatCoordinates3D, patientPoint.X.ToString("f3"), patientPoint.Y.ToString("f3"), patientPoint.Z.ToString("f3")));
                    displayString.AppendLine(patientString);
                }

                probeString = displayString.ToString().Trim();
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e);
                probeString = SR.MessageProbeToolError;
            }

            var destinationPoint = Point.Round(_selectedSpatialTransform.ConvertToDestination(sourcePointRounded));

            _selectedTile.InformationBox.Update(probeString, destinationPoint);
        }
		/// <summary>
		/// Called by GetAnnotationText (and also by Unit Test code).  Making this function internal simply makes it easier
		/// to write unit tests for this class (don't have to implement a fake PresentationImage).
		/// </summary>
		/// <param name="imageTransform">the image transform</param>
		/// <param name="patientOrientation">the image orientation patient (direction cosines)</param>
		/// <returns></returns>
		internal string GetAnnotationTextInternal(ISpatialTransform imageTransform, PatientOrientation patientOrientation)
		{
			SizeF[] imageEdgeVectors = new SizeF[4];
			for (int i = 0; i < 4; ++i)
				imageEdgeVectors[i] = imageTransform.ConvertToDestination(_edgeVectors[i]);

			//find out which source image edge got transformed to coincide with this viewport edge.
			ImageEdge transformedEdge = GetTransformedEdge(imageEdgeVectors);

			//get the marker for the appropriate (source) image edge.
			return GetMarker(transformedEdge, patientOrientation);
		}