Exemplo n.º 1
0
		/// <summary>
		/// Constructs a new linear region of interest.
		/// </summary>
		/// <param name="point1">The first end point of the line.</param>
		/// <param name="point2">The second end point of the line.</param>
		/// <param name="presentationImage">The image containing the source pixel data.</param>
		public LinearRoi(PointF point1, PointF point2, IPresentationImage presentationImage) : base(presentationImage)
		{
			List<PointF> points = new List<PointF>();
			points.Add(point1);
			points.Add(point2);
			_points = points.AsReadOnly();
		}
Exemplo n.º 2
0
		public void Apply(IPresentationImage image)
		{
			var transform = ResetImageOperation.GetSpatialTransform(image);
			if (transform != null)
			{
				transform.Scale = 1.0f;
				transform.TranslationX = 0.0f;
				transform.TranslationY = 0.0f;
				transform.FlipY = false;
				transform.FlipX = false;
				transform.RotationXY = 0;
				transform.ScaleToFit = true;
			}

			var transform3D = ResetImageOperation.GetSpatialTransform3D(image);
			if (transform3D != null)
			{
				transform3D.Scale = 1.0f;
				transform3D.TranslationX = 0.0f;
				transform3D.TranslationY = 0.0f;
				transform3D.TranslationZ = 0.0f;
				transform3D.FlipYZ = false;
				transform3D.FlipXZ = false;
				transform3D.FlipXY = false;
				transform3D.Rotation = null;
			}
		}
		public override string GetAnnotationText(IPresentationImage presentationImage)
		{
			if (presentationImage != null && presentationImage.ParentDisplaySet != null)
			{
				if (presentationImage.ParentDisplaySet.ParentImageSet != null)
				{
					return String.Format(SR.FormatDisplaySetNumberAndCount, presentationImage.ParentDisplaySet.Number,
						presentationImage.ParentDisplaySet.ParentImageSet.DisplaySets.Count);
				}
				else
				{
					// try to find a corresponding display set in the logical workspace with a matching UID, and let display set number reflect that
					// this happens particularly when the image is part of a generated display set derived from a display set based on stored DICOM SOP instances
					var displaySetUid = presentationImage.ParentDisplaySet.Uid ?? string.Empty;
					var sourceDisplaySet = presentationImage.ImageViewer.LogicalWorkspace.ImageSets.SelectMany(s => s.DisplaySets).FirstOrDefault(s => s.Uid == displaySetUid);
					if (sourceDisplaySet != null)
						return string.Format(SR.FormatDisplaySetNumberAndCount, sourceDisplaySet.Number, sourceDisplaySet.ParentImageSet.DisplaySets.Count);

					return presentationImage.ParentDisplaySet.Number.ToString(System.Globalization.CultureInfo.InvariantCulture);
				}
			}
			else
			{
				return "";
			}
		}
		/// <summary>
		/// Initializes a new instance of <see cref="PresentationImageChangedEventArgs"/>.
		/// </summary>
		/// <param name="oldPresentationImage"></param>
		/// <param name="newPresentationImage"></param>
		public PresentationImageChangedEventArgs(
			IPresentationImage oldPresentationImage,
			IPresentationImage newPresentationImage)
		{
			_oldPresentationImage = oldPresentationImage;
			_newPresentationImage = newPresentationImage;
		}
		/// <summary>
		/// Gets the annotation text.
		/// </summary>
		/// <param name="presentationImage">the input presentation image.</param>
		/// <returns>the annotation text.</returns>
		public override string GetAnnotationText(IPresentationImage presentationImage)
		{
			string markerText = "";

			if (presentationImage != null)
			{
				ISpatialTransformProvider associatedTransform = presentationImage as ISpatialTransformProvider;
				IImageSopProvider associatedDicom = presentationImage as IImageSopProvider;

				if (associatedDicom != null && associatedTransform != null)
				{
					var spatialTransform = associatedTransform.SpatialTransform as SpatialTransform;
					if (spatialTransform != null)
					{
						var imageOrientationPatient = associatedDicom.Frame.ImageOrientationPatient;
						var patientOrientation = associatedDicom.Frame.PatientOrientation;

						if (imageOrientationPatient != null && !imageOrientationPatient.IsNull)
							markerText = GetAnnotationTextInternal(spatialTransform, imageOrientationPatient);
						else if (patientOrientation != null && patientOrientation.IsValid)
							markerText = GetAnnotationTextInternal(spatialTransform, patientOrientation);
					}
				}
			}

			return markerText;
		}
Exemplo n.º 6
0
		private static IMemorable GetLayerOpacityManager(IPresentationImage image)
		{
			if (image is FusionPresentationImage)
				return ((FusionPresentationImage) image).LayerOpacityManager;

			return null;
		}
Exemplo n.º 7
0
		private static IMemorable GetTransform(IPresentationImage image)
		{
			if (image is ISpatialTransformProvider)
				return ((ISpatialTransformProvider)image).SpatialTransform;

			return null;
		}
Exemplo n.º 8
0
		private static IMemorable GetVoiLutManager(IPresentationImage image)
		{
			if (image is IVoiLutProvider)
				return ((IVoiLutProvider)image).VoiLutManager;

			return null;
		}
Exemplo n.º 9
0
Arquivo: Roi.cs Projeto: nhannd/Xian
		/// <summary>
		/// Constructs a new region of interest, specifying an <see cref="IPresentationImage"/> as the source of the pixel data.
		/// </summary>
		/// <param name="presentationImage">The image containing the source pixel data.</param>
		protected Roi(IPresentationImage presentationImage)
		{
			IImageGraphicProvider provider = presentationImage as IImageGraphicProvider;
			if (provider == null)
				return;

			_imageRows = provider.ImageGraphic.Rows;
			_imageColumns = provider.ImageGraphic.Columns;
			_presentationImage = presentationImage;

			_pixelData = provider.ImageGraphic.PixelData;
			if (presentationImage is IModalityLutProvider)
				_modalityLut = ((IModalityLutProvider) presentationImage).ModalityLut;

			if (presentationImage is IImageSopProvider)
			{
				Frame frame = ((IImageSopProvider) presentationImage).Frame;
				_normalizedPixelSpacing = frame.NormalizedPixelSpacing;
				_pixelAspectRatio = frame.PixelAspectRatio;
				_modality = frame.ParentImageSop.Modality;
				_modalityLutUnits = frame.RescaleUnits;
				_subnormalModalityLut = frame.IsSubnormalRescale;
			}
			else
			{
				_normalizedPixelSpacing = new PixelSpacing(0, 0);
				_pixelAspectRatio = new PixelAspectRatio(0, 0);
				_modalityLutUnits = RescaleUnits.None;
				_subnormalModalityLut = false;
			}
		}
Exemplo n.º 10
0
		public static DicomImagePlane FromImage(IPresentationImage sourceImage)
		{
			if (sourceImage == null)
				return null;

			Frame frame = GetFrame(sourceImage);
			SpatialTransform transform = GetSpatialTransform(sourceImage);

			if (transform == null || frame == null)
				return null;

			if (String.IsNullOrEmpty(frame.FrameOfReferenceUid) || String.IsNullOrEmpty(frame.ParentImageSop.StudyInstanceUid))
				return null;

			DicomImagePlane plane;
			if (_referenceCount > 0)
				plane = CreateFromCache(frame);
			else
				plane = CreateFromFrame(frame);

			if (plane != null)
			{
				plane._sourceImage = sourceImage;
				plane._sourceImageTransform = transform;
				plane._sourceFrame = frame;
			}

			return plane;
		}
Exemplo n.º 11
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")));
		}
Exemplo n.º 12
0
		public IMemorable GetOriginator(IPresentationImage image)
		{
			if (image is IVoiLutProvider)
				return ((IVoiLutProvider) image).VoiLutManager;

			return null;
		}
Exemplo n.º 13
0
		public override string GetAnnotationText(IPresentationImage presentationImage)
		{
			if (presentationImage != null && presentationImage.ParentDisplaySet != null)
				return presentationImage.ParentDisplaySet.Description ?? "";
			else
				return "";
		}
Exemplo n.º 14
0
		/// <summary>
		/// Adds an <see cref="IPresentationImage"/> to the clipboard.
		/// </summary>
		/// <param name="image"></param>
		/// <remarks>
		/// When called, a copy of the specified <see cref="IPresentationImage"/> is made and stored
		/// in the clipbaord.  This ensures that the <see cref="IPresentationImage"/> is in fact a
		/// snapshot and not a reference that could be changed in unpredictable ways.
		/// Pixel data, however, is not replicated.
		/// </remarks>
		public static void Add(IPresentationImage image)
		{
			Platform.CheckForNullReference(image, "image");

			var clipboard = Default;
			clipboard._items.Add(clipboard.CreatePresentationImageItem(image));
		}
		public override string GetAnnotationText(IPresentationImage presentationImage)
		{
			var imageSopProvider = presentationImage as IImageSopProvider;
			if (imageSopProvider == null)
				return string.Empty;

			var details = imageSopProvider.Frame.NormalizedPixelSpacing.CalibrationDetails;
			switch (imageSopProvider.Frame.NormalizedPixelSpacing.CalibrationType)
			{
				case NormalizedPixelSpacingCalibrationType.None:
					return string.Empty;
				case NormalizedPixelSpacingCalibrationType.Manual:
					return SR.ValueManualCalibration;
				case NormalizedPixelSpacingCalibrationType.CrossSectionalSpacing:
					return SR.ValueActualSpacingCalibration;
				case NormalizedPixelSpacingCalibrationType.Detector:
					return SR.ValueDetectorSpacingCalibration;
				case NormalizedPixelSpacingCalibrationType.Geometry:
					return FormatCalibrationDetails(SR.ValueGeometricCalibration, details);
				case NormalizedPixelSpacingCalibrationType.Fiducial:
					return FormatCalibrationDetails(SR.ValueFiducialCalibration, details);
				case NormalizedPixelSpacingCalibrationType.Magnified:
					return FormatCalibrationDetails(SR.ValueMagnifiedCalibration, details);
				case NormalizedPixelSpacingCalibrationType.Unknown:
				default:
					return FormatCalibrationDetails(SR.ValueUnknownCalibration, details);
			}
		}
		public override string GetAnnotationText(IPresentationImage presentationImage)
		{
			IImageSopProvider provider = presentationImage as IImageSopProvider;
			if (provider == null)
				return "";

            Frame frame = provider.Frame;

            string str;
			
			if (frame.ParentImageSop.ParentSeries != null)
			{
				//TODO: figure out how to do this without the parent series!
				str = String.Format(SR.FormatImageNumberAndCount, frame.ParentImageSop.InstanceNumber, frame.ParentImageSop.ParentSeries.Sops.Count);
			}
			else
			{
				str = frame.ParentImageSop.InstanceNumber.ToString();
			}

            if (frame.ParentImageSop.NumberOfFrames > 1)
            {
                string frameString = String.Format(
					SR.FormatFrameNumberAndCount,
                    frame.FrameNumber,
                    frame.ParentImageSop.NumberOfFrames);

                str += " " + frameString;
            }

            return str;
        }
        public static bool IsImageMarkupPresent(IPresentationImage image)
        {
            IOverlayGraphicsProvider currentOverlayGraphics = image as IOverlayGraphicsProvider;
            if (currentOverlayGraphics != null)
            {
                foreach (IGraphic graphic in currentOverlayGraphics.OverlayGraphics)
                {
                    if (graphic is RoiGraphic)
                        return true;

                    ContextMenuControlGraphic contextMenuControlGraphic = graphic as ContextMenuControlGraphic;
                    if (contextMenuControlGraphic != null && contextMenuControlGraphic.Subject != null)
                    {
                        UserCalloutGraphic userCalloutGraphic = contextMenuControlGraphic.Subject as UserCalloutGraphic;
                        if (userCalloutGraphic != null)
                            return true;

                        InvariantTextPrimitive invariantTextPrimitive = contextMenuControlGraphic.Subject as InvariantTextPrimitive;
                        if (invariantTextPrimitive != null)
                            return true;

                        UserCrosshairCalloutGraphic crosshairGraphic = contextMenuControlGraphic.Subject as UserCrosshairCalloutGraphic;
                        if (crosshairGraphic != null)
                            return true;
                    }
                }
            }
            return false;
        }
Exemplo n.º 18
0
		public static GraphicsVisibilityHelper CreateForOverlayGraphics(IPresentationImage image)
		{
			var provider = image as IOverlayGraphicsProvider;
			if (provider == null)
				return null;

			return new GraphicsVisibilityHelper(provider.OverlayGraphics);
		}
Exemplo n.º 19
0
		protected override void  UpdateVisibility(IPresentationImage image, bool visible)
		{
			if (image is IDicomPresentationImage)
			{
				foreach (OverlayPlaneGraphic overlayGraphic in GetOverlayPlanesGraphic(image as IDicomPresentationImage))
					overlayGraphic.Visible = Checked;
			}
		}
Exemplo n.º 20
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="referenceImage">The 'current' (or reference) <see cref="IPresentationImage"/>.</param>
		/// <param name="operation">The operation to be performed on the current <see cref="IPresentationImage"/> and/or its linked images.</param>
		public ImageOperationApplicator(IPresentationImage referenceImage, IUndoableOperation<IPresentationImage> operation)
		{
			Platform.CheckForNullReference(referenceImage, "referenceImage");
			Platform.CheckForNullReference(operation, "operation");

			_imageEnumerator = new LinkedImageEnumerator(referenceImage);
			_operation = operation;
		}
Exemplo n.º 21
0
		public static DicomImagePlane FromImage(IPresentationImage sourceImage)
		{
			if (sourceImage == null)
				return null;

			Frame frame = GetFrame(sourceImage);
			return FromFrame(frame);
		}
Exemplo n.º 22
0
		public ProtractorRoi(PointF point1, PointF vertex, PointF point2, IPresentationImage presentationImage)
			: base(presentationImage)
		{
			_points = new List<PointF>();
			_points.Add(point1);
			_points.Add(vertex);
			_points.Add(point2);
		}
Exemplo n.º 23
0
		/// <summary>
		/// Determines and returns the initial Voi Lut that should be applied to the input <see cref="IPresentationImage"/>.
		/// </summary>
		/// <param name="presentationImage">The <see cref="IPresentationImage"/> whose intial Lut is to be determined.</param>
		/// <returns>The Voi Lut as an <see cref="IVoiLut"/>.</returns>
		public IVoiLut GetLut(IPresentationImage presentationImage)
		{
			IVoiLut lut = null;
			if (_extensionProvider != null)
				lut = _extensionProvider.GetLut(presentationImage);

			return lut;
		}
Exemplo n.º 24
0
		protected override void UpdateVisibility(IPresentationImage image, bool visible)
		{
			if (image is IAnnotationLayoutProvider)
			{
				foreach (AnnotationBox box in ((IAnnotationLayoutProvider)image).AnnotationLayout.AnnotationBoxes)
					box.Visible = visible;
			}
		}
		public override void Apply(IPresentationImage presentationImage)
		{
            var applicator = AutoVoiLutApplicator.Create(presentationImage);
            if (applicator == null)
				throw new InvalidOperationException("The input presentation image is not supported.");

		    applicator.ApplyNextLut();
		}
Exemplo n.º 26
0
		private ImageItem DoInsertImage(IPresentationImage pImage) {
			IImageSopProvider sop = pImage as IImageSopProvider;
			DicomFile dcf = sop.ImageSop.NativeDicomObject as DicomFile;
			PatientItem patient = _patients.GetById(dcf.DataSet);
			StudyItem study = patient.Studies.GetByUid(dcf.DataSet);
			SeriesItem series = study.Series.GetByUid(dcf.DataSet);
			ImageItem image = series.Images.GetByUid(dcf, pImage);
			return image;
		}
Exemplo n.º 27
0
		public override void SetOverlayVisible(IPresentationImage image, bool visible)
		{
			var annotationLayoutProvider = image as IAnnotationLayoutProvider;
			if (annotationLayoutProvider == null)
				return;

			foreach (AnnotationBox box in annotationLayoutProvider.AnnotationLayout.AnnotationBoxes)
				box.Visible = visible;
		}
Exemplo n.º 28
0
		internal static string BuildMessage(IPresentationImage sourceImage)
		{
			string message = "An error has occurred while attempting to clone an image";
			if (!String.IsNullOrEmpty(sourceImage.Uid))
				message += string.Format(" (uid = {0})", sourceImage.Uid);

			message += ".";
			return message;
		}
Exemplo n.º 29
0
		/// <summary>
		/// Constructs a new polygonal region of interest.
		/// </summary>
		/// <param name="vertices">The ordered vertices defining the polygonal region of interest.</param>
		/// <param name="presentationImage">The image containing the source pixel data.</param>
		public PolygonalRoi(IEnumerable<PointF> vertices, IPresentationImage presentationImage) : base(presentationImage)
		{
			var list = new List<PointF>(vertices);
			if (list.Count < 3) // a valid list of vertices needs 3 items
				throw new ArgumentException("Three vertices are required to define a polygon.", "vertices");

			// vertices should not contain repeated start point
			_polygon = new PolygonF(vertices);
		}
Exemplo n.º 30
0
		public override void SetOverlayVisible(IPresentationImage image, bool visible)
		{
			var dicomPresentationImage = image as IDicomPresentationImage;
			if (dicomPresentationImage == null) return;

			DicomGraphicsPlane dicomGraphicsPlane = DicomGraphicsPlane.GetDicomGraphicsPlane(dicomPresentationImage, true);
			if (dicomGraphicsPlane != null)
				dicomGraphicsPlane.Layers.Enabled = visible;
		}
Exemplo n.º 31
0
        /// <summary>
        /// Constructs a new region of interest, specifying an <see cref="IPresentationImage"/> as the source of the pixel data.
        /// </summary>
        /// <param name="presentationImage">The image containing the source pixel data.</param>
        protected Roi(IPresentationImage presentationImage)
        {
            _presentationImage = presentationImage;

            IImageGraphicProvider provider = presentationImage as IImageGraphicProvider;

            if (provider != null)
            {
                _imageRows    = provider.ImageGraphic.Rows;
                _imageColumns = provider.ImageGraphic.Columns;
                _pixelData    = provider.ImageGraphic.PixelData;
            }

            var modalityLutProvider = presentationImage as IModalityLutProvider;

            if (modalityLutProvider != null)
            {
                _modalityLut = (modalityLutProvider).ModalityLut;
            }

            if (presentationImage is IImageSopProvider)
            {
                Frame frame = ((IImageSopProvider)presentationImage).Frame;
                _normalizedPixelSpacing = frame.NormalizedPixelSpacing;
                _pixelAspectRatio       = frame.PixelAspectRatio;
                _modality             = frame.ParentImageSop.Modality;
                _modalityLutUnits     = frame.RescaleUnits;
                _subnormalModalityLut = frame.IsSubnormalRescale;
            }
            else
            {
                _normalizedPixelSpacing = new PixelSpacing(0, 0);
                _pixelAspectRatio       = new PixelAspectRatio(0, 0);
                _modalityLutUnits       = RescaleUnits.None;
                _subnormalModalityLut   = false;
            }
        }
Exemplo n.º 32
0
        private void AddPinwheelGraphic()
        {
            IPresentationImage selectedImage = base.SelectedPresentationImage;

            if (selectedImage == null)
            {
                return;
            }

            if (!base.IsMprImage(selectedImage))
            {
                return;
            }

            MprDisplaySet displaySet = (MprDisplaySet)selectedImage.ParentDisplaySet;

            if (displaySet.Identifier == MprDisplaySetIdentifier.Oblique)
            {
                return;
            }

            IOverlayGraphicsProvider overlayProvider      = selectedImage as IOverlayGraphicsProvider;
            IImageGraphicProvider    imageGraphicProvider = selectedImage as IImageGraphicProvider;

            if (overlayProvider != null && imageGraphicProvider != null)
            {
                _currentPinwheelGraphic = new PinwheelGraphic();

                int width  = imageGraphicProvider.ImageGraphic.Columns;
                int height = imageGraphicProvider.ImageGraphic.Rows;

                overlayProvider.OverlayGraphics.Add(_currentPinwheelGraphic);
                _currentPinwheelGraphic.CoordinateSystem = CoordinateSystem.Source;
                _currentPinwheelGraphic.Rotation         = GetRotationAngle();
                _currentPinwheelGraphic.Draw();
            }
        }
Exemplo n.º 33
0
        /// <summary>
        /// Computes the closest image in a display set to the specified position in patient coordinates.
        /// </summary>
        private static IPresentationImage GetClosestSlice(Vector3D positionPatient, IDisplaySet displaySet)
        {
            float closestDistance           = float.MaxValue;
            IPresentationImage closestImage = null;

            foreach (IPresentationImage image in displaySet.PresentationImages)
            {
                if (image is IImageSopProvider)
                {
                    Frame    frame = (image as IImageSopProvider).Frame;
                    Vector3D positionCenterOfImage = frame.ImagePlaneHelper.ConvertToPatient(new PointF((frame.Columns - 1) / 2F, (frame.Rows - 1) / 2F));
                    Vector3D distanceVector        = positionCenterOfImage - positionPatient;
                    float    distance = distanceVector.Magnitude;

                    if (distance <= closestDistance)
                    {
                        closestDistance = distance;
                        closestImage    = image;
                    }
                }
            }

            return(closestImage);
        }
Exemplo n.º 34
0
        /// <summary>
        /// Moves the graphic from where ever it is to the target image.
        /// </summary>
        private static void TranslocateGraphic(IGraphic graphic, IPresentationImage targetImage)
        {
            IPresentationImage oldImage = graphic.ParentPresentationImage;

            if (oldImage != targetImage)
            {
                IApplicationGraphicsProvider imageOnUnexecute = oldImage as IApplicationGraphicsProvider;
                if (imageOnUnexecute != null)
                {
                    imageOnUnexecute.ApplicationGraphics.Remove(graphic);
                }

                IApplicationGraphicsProvider imageOnExecute = targetImage as IApplicationGraphicsProvider;
                if (imageOnExecute != null)
                {
                    imageOnExecute.ApplicationGraphics.Add(graphic);
                }

                if (oldImage != null)
                {
                    oldImage.Draw();
                }
            }
        }
Exemplo n.º 35
0
        /// <summary>
        /// Draws the Text Overlay.
        /// </summary>
        protected void DrawTextOverlay(IPresentationImage presentationImage)
        {
#if DEBUG
            CodeClock clock = new CodeClock();
            clock.Start();
#endif
            var layoutProvider = presentationImage as IAnnotationLayoutProvider;
            if (layoutProvider == null)
            {
                return;
            }

            var layout = layoutProvider.AnnotationLayout;
            if (layout == null || !layout.Visible)
            {
                return;
            }

            foreach (AnnotationBox annotationBox in layout.AnnotationBoxes)
            {
                if (!annotationBox.Visible)
                {
                    continue;
                }

                string annotationText = annotationBox.GetAnnotationText(presentationImage);
                if (!String.IsNullOrEmpty(annotationText))
                {
                    DrawAnnotationBox(annotationText, annotationBox);
                }
            }
#if DEBUG
            clock.Stop();
            PerformanceReportBroker.PublishReport(_rendererTypeId, "DrawTextOverlay", clock.Seconds);
#endif
        }
            public RenderImageHelper(IPresentationImage image)
            {
                _image = image;

                var annotationLayoutProvider = image as IAnnotationLayoutProvider;

                if (annotationLayoutProvider != null)
                {
                    _annotationLayoutVisible = annotationLayoutProvider.AnnotationLayout.Visible;
                    annotationLayoutProvider.AnnotationLayout.Visible = false;
                }

                var overlayGraphicsProvider = image as IOverlayGraphicsProvider;

                if (overlayGraphicsProvider != null)
                {
                    _overlayGraphicsVisible = overlayGraphicsProvider.OverlayGraphics.Visible;
                    overlayGraphicsProvider.OverlayGraphics.Visible = true;
                }

                var applicationGraphicsProvider = image as IApplicationGraphicsProvider;

                if (applicationGraphicsProvider != null)
                {
                    _applicationGraphicsVisible = applicationGraphicsProvider.ApplicationGraphics.Visible;
                    applicationGraphicsProvider.ApplicationGraphics.Visible = false;
                }

                var dicomPresentationImage = image as IDicomPresentationImage;

                if (dicomPresentationImage != null)
                {
                    _dicomGraphicsVisible = dicomPresentationImage.DicomGraphics.Visible;
                    dicomPresentationImage.DicomGraphics.Visible = false;
                }
            }
Exemplo n.º 37
0
        public void Delete()
        {
            IGraphic graphic = base.Context.Graphic;

            if (graphic == null)
            {
                return;
            }

            IPresentationImage image = graphic.ParentPresentationImage;

            if (image == null)
            {
                return;
            }

            DrawableUndoableCommand command = new DrawableUndoableCommand(graphic.ParentPresentationImage);

            command.Enqueue(new RemoveGraphicUndoableCommand(graphic));

            command.Execute();
            command.Name = SR.CommandDeleteAnnotation;
            image.ImageViewer.CommandHistory.AddCommand(command);
        }
Exemplo n.º 38
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);
            }
        }
Exemplo n.º 39
0
        public static bool UpdateKeyImage(this IPresentationImage image, KeyImageInformation context)
        {
            if (context != null)
            {
                var presentationStateUid = GetPresentationStateSopInstanceUid(image);

                var clipboardItems = context.Items;
                var result         = clipboardItems.Where(IsSerialized).Select((k, i) => new { k.Item, Index = i, MetaData = k.ExtensionData.GetOrCreate <KeyImageItemMetaData>() }).FirstOrDefault(c => GetPresentationStateSopInstanceUid((c.Item as IPresentationImage)) == presentationStateUid);
                if (result != null)
                {
                    var keyImageItem = context.CreateKeyImageItem(image, hasChanges: true);

                    var metadata = ((IClipboardItem)keyImageItem).ExtensionData.GetOrCreate <KeyImageItemMetaData>();
                    metadata.Changes          = true;
                    metadata.Guid             = result.MetaData.Guid;
                    metadata.KoSopInstanceUid = result.MetaData.KoSopInstanceUid;
                    metadata.OriginalItem     = result.MetaData.OriginalItem ?? clipboardItems[result.Index];

                    clipboardItems[result.Index] = keyImageItem;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 40
0
        /// <summary>
        /// Gets the text to be rendered into the area defined by <see cref="NormalizedRectangle"/> for the input <paramref name="presentationImage"/>.
        /// </summary>
        /// <param name="presentationImage">The presentation image.</param>
        public string GetAnnotationText(IPresentationImage presentationImage)
        {
            if (_annotationItem == null)
            {
                return(string.Empty);
            }

            string annotationText  = _annotationItem.GetAnnotationText(presentationImage);
            string annotationLabel = _annotationItem.GetLabel();

            if (string.IsNullOrEmpty(annotationText))
            {
                if (this.ConfigurationOptions.ShowLabelIfValueEmpty)
                {
                    annotationText = string.Format(SR.FormatAnnotationItem, annotationLabel, SR.ValueNil);
                }
            }
            else if (this.ConfigurationOptions.ShowLabel)
            {
                annotationText = string.Format(SR.FormatAnnotationItem, annotationLabel, annotationText);
            }

            return(annotationText);
        }
        protected static Bitmap DrawToBitmap(IPresentationImage presentationImage)
        {
            var imageGraphicProvider     = (IImageGraphicProvider)presentationImage;
            var annotationLayoutProvider = presentationImage as IAnnotationLayoutProvider;
            var annotationLayoutVisible  = true;

            if (annotationLayoutProvider != null)
            {
                annotationLayoutVisible = annotationLayoutProvider.AnnotationLayout.Visible;
                annotationLayoutProvider.AnnotationLayout.Visible = false;
            }

            try
            {
                return(presentationImage.DrawToBitmap(imageGraphicProvider.ImageGraphic.Columns, imageGraphicProvider.ImageGraphic.Rows));
            }
            finally
            {
                if (annotationLayoutProvider != null)
                {
                    annotationLayoutProvider.AnnotationLayout.Visible = annotationLayoutVisible;
                }
            }
        }
        // Populates given IPresentationImage with graphics from the given annotation
        internal bool ReadGraphicsFromAnnotation(IAimDocumentInstance annotationDoc, IPresentationImage presentationImage)
        {
            if (annotationDoc == null)
            {
                return(false);
            }

            Platform.CheckForNullReference(presentationImage, "presentationImage");

            var isRead = false;

            switch (annotationDoc.AimVersion)
            {
            case AimVersion.AimVersion3:
                var aim3AnnotationDoc = (Aim3.Aim3DocumentInstance)annotationDoc;
                foreach (var annotation in aim3AnnotationDoc.AimAnnotations.OfType <Aim3.Aim3AnnotationInstance>())
                {
                    isRead |= Aim3.AimNativeConverter.ReadGraphicsFromAnnotation(annotation, presentationImage);
                }
                break;

            case AimVersion.AimVersion4:
                var aim4AnnotationDoc = (Aim4.Aim4DocumentInstance)annotationDoc;
                foreach (var annotation in aim4AnnotationDoc.AimAnnotations.OfType <Aim4.Aim4AnnotationInstance>())
                {
                    isRead |= Aim4.AimNativeConverter.ReadGraphicsFromAnnotation(annotation, presentationImage);
                }
                break;

            default:
                Debug.Assert(false, "AimManager.ReadGraphicsFromAnnotation: Unexpected AIM version");
                break;
            }

            return(isRead);
        }
Exemplo n.º 43
0
        public static AutoVoiLutSelector CreateFrom(IPresentationImage image)
        {
            var applicator = AutoVoiLutApplicator.Create(image);

            if (applicator == null)
            {
                return(null);
            }

            var autoLut = applicator.GetAppliedLut();

            if (autoLut == null)
            {
                return(null);
            }

            return(!autoLut.IsHeader ? null
                       : new AutoVoiLutSelector
            {
                IsData = autoLut.IsData,
                LutExplanation = autoLut.Explanation,
                LutIndex = autoLut.Index
            });
        }
Exemplo n.º 44
0
        public static Bitmap CreatePresentationImageIcon(IPresentationImage image, RectangleF destRange, double tileRatio)
        {
            if (destRange == RectangleF.Empty)
            {
                return(null);
            }
            ISpatialTransformProvider provider = image as ISpatialTransformProvider;

            if (provider == null)
            {
                throw new Exception(SR.ConvertTransformProviderFailed);
            }
            ImageSpatialTransform spatialTransform = provider.SpatialTransform as ImageSpatialTransform;
            object memento = spatialTransform.CreateMemento();

            spatialTransform.MoveTo(destRange);
            Size   destSize = new Size(Convert.ToInt32(destRange.Width), Convert.ToInt32(destRange.Height));
            Bitmap original = DrawToFilmSizeBitmap(destSize, image, tileRatio, true);
            Bitmap bitmap2  = new Bitmap(original, _iconWidth, (int)(_iconWidth * tileRatio));

            original.Dispose();
            spatialTransform.SetMemento(memento);
            return(bitmap2);
        }
Exemplo n.º 45
0
        public TileMemento(IPresentationImage image)
        {
            // image can be null if the Tile is empty, so we don't check for null

            _presentationImage = image;
        }
Exemplo n.º 46
0
 public static bool CanCreate(IPresentationImage image)
 {
     return(Grayscale.CanCreateFrom(image) || Color.CanCreateFrom(image) || Other.CanCreateFrom(image));
 }
Exemplo n.º 47
0
 /// <summary>
 /// Called when the value of the <see cref="ParentPresentationImage"/> property changes.
 /// </summary>
 /// <param name="oldParentPresentationImage">A reference to the old parent presentation image.</param>
 /// <param name="newParentPresentationImage">A reference to the new parent presentation image.</param>
 protected virtual void OnParentPresentationImageChanged(IPresentationImage oldParentPresentationImage, IPresentationImage newParentPresentationImage)
 {
 }
Exemplo n.º 48
0
        internal ImageDrawingEventArgs(IPresentationImage presentationImage)
        {
            Platform.CheckForNullReference(presentationImage, "presentationImage");

            _presentationImage = presentationImage;
        }
Exemplo n.º 49
0
 void IUndoableOperation <IPresentationImage> .Apply(IPresentationImage image)
 {
 }
Exemplo n.º 50
0
 bool IUndoableOperation <IPresentationImage> .AppliesTo(IPresentationImage image)
 {
     return(image is IDynamicTeProvider);
 }
Exemplo n.º 51
0
 /// <summary>
 /// Initializes a new instance of <see cref="BasicPatientPresentation"/>.
 /// </summary>
 /// <param name="owner">The owner image.</param>
 public BasicPatientPresentation(IPresentationImage owner)
 {
     _owner = owner;
 }
Exemplo n.º 52
0
 protected virtual bool CanStart(IPresentationImage image)
 {
     return(image != null && image is IOverlayGraphicsProvider);
 }
Exemplo n.º 53
0
        public ImageItem InsertImage(IPresentationImage image)
        {
            ImageItem node = DoInsertImage(image);

            return(node);
        }
Exemplo n.º 54
0
        public void TestCloningShowAnglesToolCompositeGraphicLineSelection()
        {
            MockShowAnglesTool mockOwnerTool = new MockShowAnglesTool();

            using (MockPresentationImage image = new MockPresentationImage(100, 100))
            {
                ShowAnglesTool.ShowAnglesToolCompositeGraphic composite = new ShowAnglesTool.ShowAnglesToolCompositeGraphic(mockOwnerTool);
                image.OverlayGraphics.Add(composite);

                using (IPresentationImage clone = image.Clone())
                {
                    var cloneComposite = FindShowAnglesToolComposite(clone);
                    Assert.IsNotNull(cloneComposite, "ShowAnglesToolCompositeGraphic should be cloneable.");
                }

                PolylineGraphic line1 = new PolylineGraphic();
                line1.Points.Add(new PointF(0, 0));
                line1.Points.Add(new PointF(10, 10));
                VerticesControlGraphic control1 = new VerticesControlGraphic(line1);
                image.OverlayGraphics.Add(control1);
                composite.Select(control1);
                composite.OnDrawing();

                using (IPresentationImage clone = image.Clone())
                {
                    var cloneComposite = FindShowAnglesToolComposite(clone);

                    cloneComposite.CoordinateSystem = line1.CoordinateSystem;
                    try
                    {
                        Assert.IsNotNull(cloneComposite.SelectedLine, "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection.");
                        Assert.AreEqual(line1.Points[0], cloneComposite.SelectedLine.Points[0], "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (X).");
                        Assert.AreEqual(line1.Points[1], cloneComposite.SelectedLine.Points[1], "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (Y).");
                    }
                    finally
                    {
                        cloneComposite.ResetCoordinateSystem();
                    }
                }

                PolylineGraphic line2 = new PolylineGraphic();
                line2.Points.Add(new PointF(0, 10));
                line2.Points.Add(new PointF(10, 0));
                VerticesControlGraphic control2 = new VerticesControlGraphic(line2);
                image.OverlayGraphics.Add(control2);
                composite.Select(control2);
                composite.OnDrawing();

                using (IPresentationImage clone = image.Clone())
                {
                    var cloneComposite = FindShowAnglesToolComposite(clone);

                    cloneComposite.CoordinateSystem = line2.CoordinateSystem;
                    try
                    {
                        Assert.IsNotNull(cloneComposite.SelectedLine, "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (2).");
                        Assert.AreEqual(line2.Points[0], cloneComposite.SelectedLine.Points[0], "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (X2).");
                        Assert.AreEqual(line2.Points[1], cloneComposite.SelectedLine.Points[1], "Cloned ShowAnglesToolCompositeGraphic should retain line graphic selection (Y2).");
                    }
                    finally
                    {
                        cloneComposite.ResetCoordinateSystem();
                    }
                }
            }
        }
Exemplo n.º 55
0
        private static ShowAnglesTool.ShowAnglesToolCompositeGraphic FindShowAnglesToolComposite(IPresentationImage image)
        {
            IOverlayGraphicsProvider imageOverlayGraphics = (IOverlayGraphicsProvider)image;
            IGraphic graphic = imageOverlayGraphics.OverlayGraphics.FirstOrDefault(IsOfType <ShowAnglesTool.ShowAnglesToolCompositeGraphic>);

            if (graphic is CompositeGraphic)
            {
                ((CompositeGraphic)graphic).OnDrawing();
            }
            return((ShowAnglesTool.ShowAnglesToolCompositeGraphic)graphic);
        }
        private void Refresh(bool force)
        {
            lock (_syncLock)
            {
                if (_imageBox.DisplaySet == null || _imageBox.DisplaySet.PresentationImages.Count == 0)
                {
                    _frames.Clear();
                    return;
                }

                if (!force && _currentIndex == _imageBox.TopLeftPresentationImageIndex)
                {
                    return;
                }

                _frames.Clear();

                _currentIndex = _imageBox.TopLeftPresentationImageIndex;
                int numberOfImages = _imageBox.DisplaySet.PresentationImages.Count;
                int lastImageIndex = numberOfImages - 1;

                int selectionWindow;
                if (_window >= 0)
                {
                    selectionWindow = 2 * _window + 1;
                }
                else
                {
                    //not terribly efficient, but by default will end up including all images.
                    selectionWindow = 2 * numberOfImages + 1;
                }

                int offsetFromCurrent = 0;
                for (int i = 0; i < selectionWindow; ++i)
                {
                    int index = _currentIndex + offsetFromCurrent;

                    if (index >= 0 && index <= lastImageIndex)
                    {
                        IPresentationImage image = _imageBox.DisplaySet.PresentationImages[index];
                        if (image is IImageSopProvider)
                        {
                            Frame frame = ((IImageSopProvider)image).Frame;
                            if (_canFetchFrame(frame))
                            {
                                _frames.Enqueue(frame);
                            }
                        }
                    }

                    if (offsetFromCurrent == 0)
                    {
                        ++offsetFromCurrent;
                    }
                    else if (offsetFromCurrent > 0)
                    {
                        offsetFromCurrent = -offsetFromCurrent;
                    }
                    else
                    {
                        offsetFromCurrent = -offsetFromCurrent + 1;
                    }
                }

                string message = String.Format("Current: {0}, Window: {1}, Queue: {2}", _currentIndex, selectionWindow, _frames.Count);
                Trace.WriteLine(message);
            }

            //trigger another round of retrievals.
            _notifyChanged();
        }
Exemplo n.º 57
0
 /// <summary>
 /// Creates a copy of this <see cref="Roi"/> using the same region of interest shape but using a different image as the source pixel data.
 /// </summary>
 /// <param name="presentationImage">The image upon which to copy this region of interest.</param>
 /// <returns>A new <see cref="Roi"/> of the same type and shape as the current region of interest.</returns>
 public override Roi CopyTo(IPresentationImage presentationImage)
 {
     return(new EllipticalRoi(_bounds, presentationImage));
 }
 public override bool AppliesTo(IPresentationImage presentationImage)
 {
     return(AutoVoiLutApplicator.CanCreate(presentationImage));
 }
Exemplo n.º 59
0
 internal PresentationImageSelectedEventArgs(
     IPresentationImage selectedPresentationImage)
 {
     Platform.CheckForNullReference(selectedPresentationImage, "selectedPresentationImage");
     _selectedPresentationImage = selectedPresentationImage;
 }
Exemplo n.º 60
0
        private void Invert(IPresentationImage image)
        {
            IVoiLutManager manager = (IVoiLutManager)_operation.GetOriginator(image);

            manager.Invert = !manager.Invert;
        }