private static Plane FromDicomImagePlane(DicomImagePlane plane)
			{
				string frameOfReferenceUid = plane.FrameOfReferenceUid;
				string studyInstanceUid = plane.StudyInstanceUid;
				Vector3D normal = plane.Normal;

				return new Plane(studyInstanceUid, frameOfReferenceUid, normal);
			}
Exemplo n.º 2
0
        public bool IsInSameFrameOfReference(DicomImagePlane other)
        {
            Frame otherFrame = other._sourceFrame;

            if (_sourceFrame.ParentImageSop.StudyInstanceUid != otherFrame.ParentImageSop.StudyInstanceUid)
            {
                return(false);
            }

            return(_sourceFrame.FrameOfReferenceUid == otherFrame.FrameOfReferenceUid);
        }
Exemplo n.º 3
0
 private IEnumerable <DicomImagePlane> GetTargetImagePlanes(IImageBox imageBox)
 {
     for (int i = imageBox.DisplaySet.PresentationImages.Count - 1; i >= 0; --i)
     {
         DicomImagePlane targetImagePlane = DicomImagePlane.FromImage(imageBox.DisplaySet.PresentationImages[i]);
         if (targetImagePlane != null && _referencePlane.IsInSameFrameOfReference(targetImagePlane))
         {
             yield return(targetImagePlane);
         }
     }
 }
        protected override void Dispose(bool disposing)
        {
            base.ImageViewer.EventBroker.ImageDrawing     -= OnImageDrawing;
            Context.Viewer.EventBroker.ImageBoxSelected   -= OnImageBoxSelected;
            Context.Viewer.EventBroker.DisplaySetSelected -= OnDisplaySetSelected;

            _coordinator.Release();
            _coordinator = null;
            _currentReferenceImagePlane = null;

            base.Dispose(disposing);
        }
        public void Release()
        {
            DicomImagePlane.ReleaseCache();

            --_referenceCount;
            if (_referenceCount <= 0)
            {
                _viewer.EventBroker.PresentationImageSelected -= OnPresentationImageSelected;
                _viewer.EventBroker.TileSelected -= OnTileSelected;

                Coordinators.Remove(_viewer);
            }
        }
Exemplo n.º 6
0
 private static IEnumerable <DicomImagePlane> GetAllImagePlanes(IImageBox imageBox)
 {
     if (imageBox.DisplaySet != null)
     {
         for (int index = imageBox.DisplaySet.PresentationImages.Count - 1; index >= 0; --index)
         {
             DicomImagePlane targetPlane = DicomImagePlane.FromImage(imageBox.DisplaySet.PresentationImages[index]);
             if (targetPlane != null)
             {
                 yield return(targetPlane);
             }
         }
     }
 }
Exemplo n.º 7
0
        public void Release()
        {
            DicomImagePlane.ReleaseCache();

            if (_referenceCount > 0)
            {
                --_referenceCount;
            }

            if (_referenceCount <= 0)
            {
                _viewer.EventBroker.PresentationImageSelected -= OnPresentationImageSelected;
                _viewer.EventBroker.TileSelected -= OnTileSelected;
            }
        }
Exemplo n.º 8
0
 private IEnumerable <DicomImagePlane> GetPlanesParallelToReferencePlane()
 {
     foreach (IPresentationImage image in CurrentReferenceImage.ParentDisplaySet.PresentationImages.Where(i => !(i is BasicPresentationImage3D)))
     {
         DicomImagePlane plane = DicomImagePlane.FromImage(image);
         if (plane != null)
         {
             if (_currentReferenceImagePlane.IsInSameFrameOfReference(plane) &&
                 _currentReferenceImagePlane.IsParallelTo(plane, _oneDegreeInRadians))
             {
                 yield return(plane);
             }
         }
     }
 }
            public void Calibrate(DicomImagePlane referenceImagePlane, DicomImagePlane targetImagePlane)
            {
                if (!referenceImagePlane.IsInSameFrameOfReference(targetImagePlane) && referenceImagePlane.IsParallelTo(targetImagePlane, _angleTolerance))
                {
                    Plane referencePlane = FromDicomImagePlane(referenceImagePlane);
                    Plane targetPlane    = FromDicomImagePlane(targetImagePlane);

                    Dictionary <Plane, Vector3D> referenceOffsets = GetOffsetDictionary(referencePlane);
                    Dictionary <Plane, Vector3D> targetOffsets    = GetOffsetDictionary(targetPlane);

                    Vector3D offset = targetImagePlane.PositionPatientCenterOfImage - referenceImagePlane.PositionPatientCenterOfImage;

                    referenceOffsets[targetPlane] = offset;
                    targetOffsets[referencePlane] = -offset;
                }
            }
Exemplo n.º 10
0
        private void SetCurrentReferencePlane()
        {
            if (CurrentReferenceImage == this.SelectedPresentationImage)
            {
                return;
            }

            _currentReferenceImagePlane = DicomImagePlane.FromImage(this.SelectedPresentationImage);
            if (_currentReferenceImagePlane == null)
            {
                return;
            }

            ReferenceLineCompositeGraphic referenceLineCompositeGraphic =
                _coordinator.GetReferenceLineCompositeGraphic(CurrentReferenceImage);
        }
Exemplo n.º 11
0
        private void RefreshReferenceLines(IPresentationImage targetImage)
        {
            try
            {
                DicomImagePlane targetImagePlane = DicomImagePlane.FromImage(targetImage);
                if (targetImagePlane == null)
                {
                    return;
                }

                ReferenceLineCompositeGraphic referenceLineCompositeGraphic = _coordinator.GetReferenceLineCompositeGraphic(targetImage);
                if (referenceLineCompositeGraphic == null)
                {
                    return;
                }
                //bool showReferenceLines = this.Active && _currentReferenceImagePlane != null &&
                //    _currentReferenceImagePlane.IsInSameFrameOfReference(targetImagePlane);

                bool showReferenceLines = targetImage.ParentDisplaySet.ImageBox.ShowReferenceLine;
                if (!showReferenceLines)
                {
                    referenceLineCompositeGraphic.HideAllReferenceLines();
                    return;
                }

                int i = 0;

                foreach (ReferenceLine referenceLine in GetAllReferenceLines(targetImagePlane))
                {
                    ReferenceLineGraphic referenceLineGraphic = referenceLineCompositeGraphic[i++];
                    referenceLineGraphic.Point1  = referenceLine.StartPoint;
                    referenceLineGraphic.Point2  = referenceLine.EndPoint;
                    referenceLineGraphic.Text    = referenceLine.Label;
                    referenceLineGraphic.Visible = true;
                }
                // make any that aren't valid invisible.

                for (int j = i; j < referenceLineCompositeGraphic.Graphics.Count; ++j)
                {
                    referenceLineCompositeGraphic[j].Visible = false;
                }
            }
            catch (Exception ex)
            {
                Platform.Log(LogLevel.Error, ex.ToString());
            }
        }
Exemplo n.º 12
0
        private void SynchronizeImageBox(IImageBox referenceImageBox, IImageBox targetImageBox)
        {
            if (referenceImageBox.TopLeftPresentationImage == null)
            {
                return;
            }

            if (targetImageBox.TopLeftPresentationImage == null)
            {
                return;
            }

            DicomImagePlane referenceImagePlane = DicomImagePlane.FromImage(referenceImageBox.TopLeftPresentationImage);

            if (referenceImagePlane == null)
            {
                return;
            }

            IEnumerable <DicomImagePlane> targetImagePlanes = GetAllImagePlanes(targetImageBox);
            DicomImagePlane targetImagePlane = GetClosestParallelImagePlane(referenceImagePlane, targetImagePlanes);

            if (targetImagePlane == null)
            {
                return;
            }
            // Original
            int lastIndex = targetImageBox.TopLeftPresentationImageIndex;

            targetImageBox.TopLeftPresentationImage = targetImagePlane.SourceImage;

            if (lastIndex != targetImageBox.TopLeftPresentationImageIndex)
            {
                if (!_imageBoxesToDraw.Contains(targetImageBox))
                {
                    _imageBoxesToDraw.Add(targetImageBox);
                }
            }

            //if (GlobalData.direct > 0)
            //    targetImageBox.TopLeftPresentationImageIndex = lastIndex + 1;
            //else if (GlobalData.direct < 0)
            //    targetImageBox.TopLeftPresentationImageIndex = lastIndex - 1;

            //if (!_imageBoxesToDraw.Contains(targetImageBox))
            //    _imageBoxesToDraw.Add(targetImageBox);
        }
        public static SynchronizationToolCoordinator Get(IImageViewer viewer)
        {
            if (!Coordinators.ContainsKey(viewer))
            {
                SynchronizationToolCoordinator coordinator = new SynchronizationToolCoordinator(viewer);

                viewer.EventBroker.PresentationImageSelected += coordinator.OnPresentationImageSelected;
                viewer.EventBroker.TileSelected += coordinator.OnTileSelected;

                Coordinators.Add(viewer, coordinator);
            }

            DicomImagePlane.InitializeCache();

            ++Coordinators[viewer]._referenceCount;
            return(Coordinators[viewer]);
        }
Exemplo n.º 14
0
        public static SynchronizationToolCoordinator Get(IImageViewer viewer)
        {
            var coordinator = viewer.ExtensionData[typeof(ExtensionDataKey)] as SynchronizationToolCoordinator;

            if (coordinator == null)
            {
                viewer.ExtensionData[typeof(ExtensionDataKey)] = coordinator = new SynchronizationToolCoordinator(viewer);

                viewer.EventBroker.PresentationImageSelected += coordinator.OnPresentationImageSelected;
                viewer.EventBroker.TileSelected += coordinator.OnTileSelected;
            }

            DicomImagePlane.InitializeCache();

            ++coordinator._referenceCount;
            return(coordinator);
        }
            public Vector3D GetOffset(DicomImagePlane referenceImagePlane, DicomImagePlane targetImagePlane)
            {
                Vector3D offset = null;

                Plane referencePlane = FromDicomImagePlane(referenceImagePlane);

                if (_calibrationMatrix.ContainsKey(referencePlane))
                {
                    Plane targetPlane = FromDicomImagePlane(targetImagePlane);
                    if (!referencePlane.Equals(targetPlane))
                    {
                        offset = GetOffset(referencePlane, targetPlane, new List <Plane>());
                    }
                }

                return(offset);
            }
Exemplo n.º 16
0
 private void CalibrateFrameOfReferenceForVisibleImageBoxes()
 {
     foreach (IImageBox referenceImageBox in this.ImageViewer.PhysicalWorkspace.ImageBoxes)
     {
         DicomImagePlane referencePlane = DicomImagePlane.FromImage(referenceImageBox.TopLeftPresentationImage);
         if (referencePlane != null)
         {
             foreach (IImageBox imageBox in GetTargetImageBoxes(referenceImageBox))
             {
                 DicomImagePlane targetPlane = DicomImagePlane.FromImage(imageBox.TopLeftPresentationImage);
                 if (targetPlane != null)
                 {
                     _frameOfReferenceCalibrator.Calibrate(referencePlane, targetPlane);
                 }
             }
         }
     }
 }
Exemplo n.º 17
0
        private void Stop()
        {
            _referencePlane = null;
            _inUse          = false;

            foreach (CrossHair crosshair in _crosshairs)
            {
                crosshair.Image = null;
            }

            _coordinator.OnSpatialLocatorStopped();

            foreach (CrossHair crosshair in _crosshairs)
            {
                crosshair.Dispose();
            }

            _crosshairs.Clear();
        }
Exemplo n.º 18
0
        private void RefreshReferenceLines(IPresentationImage targetImage)
        {
            DicomImagePlane targetImagePlane = targetImage is BasicPresentationImage3D ? null : DicomImagePlane.FromImage(targetImage);

            if (targetImagePlane == null)
            {
                return;
            }

            ReferenceLineCompositeGraphic referenceLineCompositeGraphic = _coordinator.GetReferenceLineCompositeGraphic(targetImage);

            if (referenceLineCompositeGraphic == null)
            {
                return;
            }

            bool showReferenceLines = this.Active && _currentReferenceImagePlane != null &&
                                      _currentReferenceImagePlane.IsInSameFrameOfReference(targetImagePlane);

            if (!showReferenceLines)
            {
                referenceLineCompositeGraphic.HideAllReferenceLines();
                return;
            }

            int i = 0;

            foreach (ReferenceLine referenceLine in GetAllReferenceLines(targetImagePlane))
            {
                ReferenceLineGraphic referenceLineGraphic = referenceLineCompositeGraphic[i++];
                referenceLineGraphic.Point1  = referenceLine.StartPoint;
                referenceLineGraphic.Point2  = referenceLine.EndPoint;
                referenceLineGraphic.Text    = referenceLine.Label;
                referenceLineGraphic.Visible = true;
            }

            // make any that aren't valid invisible.
            for (int j = i; j < referenceLineCompositeGraphic.Graphics.Count; ++j)
            {
                referenceLineCompositeGraphic[j].Visible = false;
            }
        }
Exemplo n.º 19
0
        public bool GetIntersectionPoints(DicomImagePlane other, out Vector3D intersectionPointPatient1, out Vector3D intersectionPointPatient2)
        {
            intersectionPointPatient1 = intersectionPointPatient2 = null;

            Vector3D[,] lineSegmentsImagePlaneBounds = new Vector3D[, ]
            {
                // Bounding line segments of this (reference) image plane.
                { PositionPatientTopLeft, PositionPatientTopRight },
                { PositionPatientTopLeft, PositionPatientBottomLeft },
                { PositionPatientBottomRight, PositionPatientTopRight },
                { PositionPatientBottomRight, PositionPatientBottomLeft }
            };

            List <Vector3D> planeIntersectionPoints = new List <Vector3D>();

            for (int i = 0; i < 4; ++i)
            {
                // Intersect the bounding line segments of the reference image with the plane of the target image.
                Vector3D intersectionPoint = Vector3D.GetLinePlaneIntersection(other.Normal, other.PositionPatientCenterOfImage,
                                                                               lineSegmentsImagePlaneBounds[i, 0],
                                                                               lineSegmentsImagePlaneBounds[i, 1], true);
                if (intersectionPoint != null)
                {
                    planeIntersectionPoints.Add(intersectionPoint);
                }
            }

            if (planeIntersectionPoints.Count < 2)
            {
                return(false);
            }

            intersectionPointPatient1 = planeIntersectionPoints[0];
            intersectionPointPatient2 = CollectionUtils.SelectFirst(planeIntersectionPoints,
                                                                    delegate(Vector3D point)
            {
                return(!planeIntersectionPoints[0].Equals(point));
            });

            return(intersectionPointPatient1 != null && intersectionPointPatient2 != null);
        }
Exemplo n.º 20
0
        private void SetCurrentReferencePlane(IPresentationImage image)
        {
            if (CurrentReferenceImage == this.SelectedPresentationImage)
            {
                return;
            }

            _currentReferenceImagePlane = DicomImagePlane.FromImage(image);
            if (_currentReferenceImagePlane == null)
            {
                return;
            }

            ReferenceLineCompositeGraphic referenceLineCompositeGraphic =
                _coordinator.GetReferenceLineCompositeGraphic(CurrentReferenceImage);

            //Hide the current image's reference lines

            //if (referenceLineCompositeGraphic != null)
            //    referenceLineCompositeGraphic.HideAllReferenceLines();
        }
Exemplo n.º 21
0
        private void GetFirstAndLastReferenceLines(DicomImagePlane targetImagePlane, out ReferenceLine firstReferenceLine, out ReferenceLine lastReferenceLine)
        {
            firstReferenceLine = lastReferenceLine = null;

            float firstReferenceImageZComponent = float.MaxValue;
            float lastReferenceImageZComponent  = float.MinValue;

            // 1. Find all images in the same plane as the current reference image.
            foreach (DicomImagePlane parallelPlane in GetPlanesParallelToReferencePlane())
            {
                // 2. Use the Image Position (in the coordinate system of the Image Plane without moving the origin!)
                //    to determine the first and last reference line.  By transforming the Image Position (Patient) to
                //    the coordinate system of the image plane, we can then simply take the 2 images with
                //    the smallest and largest z-components, respectively, as the 'first' and 'last' reference images.

                // < keeps the first image as close to the beginning of the display set as possible.
                if (parallelPlane.PositionImagePlaneTopLeft.Z < firstReferenceImageZComponent)
                {
                    ReferenceLine referenceLine = GetReferenceLine(parallelPlane, targetImagePlane);
                    if (referenceLine != null)
                    {
                        firstReferenceImageZComponent = parallelPlane.PositionImagePlaneTopLeft.Z;
                        firstReferenceLine            = referenceLine;
                    }
                }

                // >= keeps the last image as close to the end of the display set as possible.
                if (parallelPlane.PositionImagePlaneTopLeft.Z >= lastReferenceImageZComponent)
                {
                    ReferenceLine referenceLine = GetReferenceLine(parallelPlane, targetImagePlane);
                    if (referenceLine != null)
                    {
                        lastReferenceImageZComponent = parallelPlane.PositionImagePlaneTopLeft.Z;
                        lastReferenceLine            = referenceLine;
                    }
                }
            }
        }
Exemplo n.º 22
0
		private void GetPlaneClosestToReferenceImagePoint(PointF referenceImagePoint,
							IEnumerable<DicomImagePlane> targetImagePlanes,
							out DicomImagePlane closestTargetImagePlane,
							out PointF closestTargetImagePoint)
		{
			closestTargetImagePlane = null;
			closestTargetImagePoint = PointF.Empty;

			float distanceToClosestImagePlane = float.MaxValue;

			Vector3D referencePositionPatient = _referencePlane.ConvertToPatient(referenceImagePoint);

			foreach (DicomImagePlane targetImagePlane in targetImagePlanes)
			{
				float halfThickness = Math.Abs(targetImagePlane.Thickness / 2);
				float halfSpacing = Math.Abs(targetImagePlane.Spacing / 2);
				float toleranceDistanceToImagePlane = Math.Max(halfThickness, halfSpacing);

				if (_referencePlane.IsInSameFrameOfReference(targetImagePlane))
				{
					if (toleranceDistanceToImagePlane > 0)
					{
						Vector3D positionTargetImagePlane = targetImagePlane.ConvertToImagePlane(referencePositionPatient);
						float distanceToTargetImagePlane = Math.Abs(positionTargetImagePlane.Z);

						if (distanceToTargetImagePlane <= toleranceDistanceToImagePlane && distanceToTargetImagePlane < distanceToClosestImagePlane)
						{
							distanceToClosestImagePlane = distanceToTargetImagePlane;
							//The coordinates need to be converted to pixel coordinates because right now they are in mm.
							closestTargetImagePoint = targetImagePlane.ConvertToImage(new PointF(positionTargetImagePlane.X, positionTargetImagePlane.Y));
							closestTargetImagePlane = targetImagePlane;
						}
					}
				}
			}
		}
Exemplo n.º 23
0
        private void GetPlaneClosestToReferenceImagePoint(PointF referenceImagePoint,
                                                          IEnumerable <DicomImagePlane> targetImagePlanes,
                                                          out DicomImagePlane closestTargetImagePlane,
                                                          out PointF closestTargetImagePoint)
        {
            closestTargetImagePlane = null;
            closestTargetImagePoint = PointF.Empty;

            float distanceToClosestImagePlane = float.MaxValue;

            Vector3D referencePositionPatient = _referencePlane.ConvertToPatient(referenceImagePoint);

            foreach (DicomImagePlane targetImagePlane in targetImagePlanes)
            {
                float halfThickness = Math.Abs(targetImagePlane.Thickness / 2);
                float halfSpacing   = Math.Abs(targetImagePlane.Spacing / 2);
                float toleranceDistanceToImagePlane = Math.Max(halfThickness, halfSpacing);

                if (_referencePlane.IsInSameFrameOfReference(targetImagePlane))
                {
                    if (toleranceDistanceToImagePlane > 0)
                    {
                        Vector3D positionTargetImagePlane   = targetImagePlane.ConvertToImagePlane(referencePositionPatient);
                        float    distanceToTargetImagePlane = Math.Abs(positionTargetImagePlane.Z);

                        if (distanceToTargetImagePlane <= toleranceDistanceToImagePlane && distanceToTargetImagePlane < distanceToClosestImagePlane)
                        {
                            distanceToClosestImagePlane = distanceToTargetImagePlane;
                            //The coordinates need to be converted to pixel coordinates because right now they are in mm.
                            closestTargetImagePoint = targetImagePlane.ConvertToImage(new PointF(positionTargetImagePlane.X, positionTargetImagePlane.Y));
                            closestTargetImagePlane = targetImagePlane;
                        }
                    }
                }
            }
        }
Exemplo n.º 24
0
		public bool IsInSameFrameOfReference(DicomImagePlane other)
		{
			Frame otherFrame = other._sourceFrame;

			if (_sourceFrame.ParentImageSop.StudyInstanceUid != otherFrame.ParentImageSop.StudyInstanceUid)
				return false;

			return this._sourceFrame.FrameOfReferenceUid == otherFrame.FrameOfReferenceUid;
		}
Exemplo n.º 25
0
		private void InitializeWithCachedData(DicomImagePlane cachedData)
		{
			Normal = cachedData.Normal;
			PositionPatientTopLeft = cachedData.PositionPatientTopLeft;
			PositionPatientTopRight = cachedData.PositionPatientTopRight;
			PositionPatientBottomLeft = cachedData.PositionPatientBottomLeft;
			PositionPatientBottomRight = cachedData.PositionPatientBottomRight;
			PositionPatientCenterOfImage = cachedData.PositionPatientCenterOfImage;
			PositionImagePlaneTopLeft = cachedData.PositionImagePlaneTopLeft;
		}
Exemplo n.º 26
0
		private void SetCurrentReferencePlane()
		{
			if (CurrentReferenceImage == this.SelectedPresentationImage)
				return;

			_currentReferenceImagePlane = DicomImagePlane.FromImage(this.SelectedPresentationImage);
			if (_currentReferenceImagePlane == null)
				return;

			ReferenceLineCompositeGraphic referenceLineCompositeGraphic =
				_coordinator.GetReferenceLineCompositeGraphic(CurrentReferenceImage);

			//Hide the current image's reference lines
			if (referenceLineCompositeGraphic != null)
				referenceLineCompositeGraphic.HideAllReferenceLines();
		}
Exemplo n.º 27
0
 private bool Start()
 {
     _referencePlane = DicomImagePlane.FromImage(base.SelectedPresentationImage);
     return(_referencePlane != null);
 }
		private DicomImagePlane GetClosestParallelImagePlane(DicomImagePlane referenceImagePlane, IEnumerable<DicomImagePlane> targetImagePlanes)
		{
			DicomImagePlane closestImagePlane = null;
			float distanceToClosestImagePlane = float.MaxValue;

			foreach (DicomImagePlane targetImagePlane in targetImagePlanes)
			{
				if (targetImagePlane.IsParallelTo(referenceImagePlane, SynchronizationToolSettingsHelper.Default.ParallelPlanesToleranceAngleRadians))
				{
					bool sameFrameOfReference = referenceImagePlane.IsInSameFrameOfReference(targetImagePlane);
					if (this.StudiesLinked || sameFrameOfReference)
					{
						Vector3D calibratedOffset = _frameOfReferenceCalibrator.GetOffset(referenceImagePlane, targetImagePlane) ?? Vector3D.Null;

						Vector3D distanceToImagePlane = referenceImagePlane.PositionPatientCenterOfImage + calibratedOffset - targetImagePlane.PositionPatientCenterOfImage;

						float absoluteDistanceToImagePlane = Math.Abs(distanceToImagePlane.Magnitude);

						if (absoluteDistanceToImagePlane < distanceToClosestImagePlane)
						{
							distanceToClosestImagePlane = absoluteDistanceToImagePlane;
							closestImagePlane = targetImagePlane;
						}
					}
				}
			}

			return closestImagePlane;
		}
Exemplo n.º 29
0
		public float GetAngleBetween(DicomImagePlane other)
		{
			return _sourceFrame.ImagePlaneHelper.GetAngleBetween(other._sourceFrame.ImagePlaneHelper);
		}
Exemplo n.º 30
0
		public float GetAngleBetween(DicomImagePlane other)
		{
			return Normal.GetAngleBetween(other.Normal);
		}
Exemplo n.º 31
0
		private void GetFirstAndLastReferenceLines(DicomImagePlane targetImagePlane, out ReferenceLine firstReferenceLine, out ReferenceLine lastReferenceLine)
		{
			firstReferenceLine = lastReferenceLine = null;

			float firstReferenceImageZComponent = float.MaxValue;
			float lastReferenceImageZComponent = float.MinValue;

			// 1. Find all images in the same plane as the current reference image.
			foreach (DicomImagePlane parallelPlane in GetPlanesParallelToReferencePlane())
			{
				// 2. Use the Image Position (in the coordinate system of the Image Plane without moving the origin!) 
				//    to determine the first and last reference line.  By transforming the Image Position (Patient) to 
				//    the coordinate system of the image plane, we can then simply take the 2 images with
				//    the smallest and largest z-components, respectively, as the 'first' and 'last' reference images.

				// < keeps the first image as close to the beginning of the display set as possible.
				if (parallelPlane.PositionImagePlaneTopLeft.Z < firstReferenceImageZComponent)
				{
					ReferenceLine referenceLine = GetReferenceLine(parallelPlane, targetImagePlane);
					if (referenceLine != null)
					{
						firstReferenceImageZComponent = parallelPlane.PositionImagePlaneTopLeft.Z;
						firstReferenceLine = referenceLine;
					}
				}

				// >= keeps the last image as close to the end of the display set as possible.
				if (parallelPlane.PositionImagePlaneTopLeft.Z >= lastReferenceImageZComponent)
				{
					ReferenceLine referenceLine = GetReferenceLine(parallelPlane, targetImagePlane);
					if (referenceLine != null)
					{
						lastReferenceImageZComponent = parallelPlane.PositionImagePlaneTopLeft.Z;
						lastReferenceLine = referenceLine;
					}
				}
			}
		}
Exemplo n.º 32
0
        private static ReferenceLine GetReferenceLine(DicomImagePlane referenceImagePlane, DicomImagePlane targetImagePlane)
        {
            // if planes are parallel within tolerance, then they do not intersect and thus no reference lines should be shown
            float parallelTolerance = SynchronizationToolSettingsHelper.Default.ParallelPlanesToleranceAngleRadians;

            if (referenceImagePlane.IsParallelTo(targetImagePlane, parallelTolerance))
            {
                return(null);
            }

            Vector3D intersectionPatient1, intersectionPatient2;

            if (!referenceImagePlane.GetIntersectionPoints(targetImagePlane, out intersectionPatient1, out intersectionPatient2))
            {
                return(null);
            }

            Vector3D intersectionImagePlane1 = targetImagePlane.ConvertToImagePlane(intersectionPatient1);
            Vector3D intersectionImagePlane2 = targetImagePlane.ConvertToImagePlane(intersectionPatient2);

            //The coordinates need to be converted to pixel coordinates because right now they are in mm.
            PointF intersectionImage1 = targetImagePlane.ConvertToImage(new PointF(intersectionImagePlane1.X, intersectionImagePlane1.Y));
            PointF intersectionImage2 = targetImagePlane.ConvertToImage(new PointF(intersectionImagePlane2.X, intersectionImagePlane2.Y));
            string label = referenceImagePlane.InstanceNumber.ToString();

            return(new ReferenceLine(intersectionImage1, intersectionImage2, label));
        }
Exemplo n.º 33
0
		private bool Start()
		{
			_referencePlane = DicomImagePlane.FromImage(base.SelectedPresentationImage);
			return _referencePlane != null;
		}
Exemplo n.º 34
0
 public bool GetIntersectionPoints(DicomImagePlane other, out Vector3D intersectionPointPatient1, out Vector3D intersectionPointPatient2)
 {
     return(_sourceFrame.ImagePlaneHelper.IntersectsWith(other._sourceFrame.ImagePlaneHelper, out intersectionPointPatient1, out intersectionPointPatient2));
 }
Exemplo n.º 35
0
        private IEnumerable <ReferenceLine> GetAllReferenceLines(DicomImagePlane targetImagePlane)
        {
            if (!ShowCrossReferenceLines)
            {
                ReferenceLine firstReferenceLine = null;
                ReferenceLine lastReferenceLine  = null;
                if (ShowFirstAndLastReferenceLines)
                {
                    GetFirstAndLastReferenceLines(targetImagePlane, out firstReferenceLine, out lastReferenceLine);
                }

                if (firstReferenceLine != null)
                {
                    yield return(firstReferenceLine);
                }

                if (lastReferenceLine != null)
                {
                    yield return(lastReferenceLine);
                }

                //return 'current' last, so it draws on top of the others.
                ReferenceLine currentReferenceLine = GetReferenceLine(_currentReferenceImagePlane, targetImagePlane);
                if (currentReferenceLine != null)
                {
                    yield return(currentReferenceLine);
                }
            }
            else
            {
                foreach (IPresentationImage currentImage in GetAllVisibleImages())
                {
                    _currentReferenceImagePlane = DicomImagePlane.FromImage(currentImage);
                    if (_currentReferenceImagePlane == null)
                    {
                        continue;
                    }
                    //
                    if (_currentReferenceImagePlane.IsInSameFrameOfReference(targetImagePlane) == false)
                    {
                        continue;
                    }
                    ReferenceLine firstReferenceLine = null;
                    ReferenceLine lastReferenceLine  = null;
                    if (ShowFirstAndLastReferenceLines)
                    {
                        GetFirstAndLastReferenceLines(targetImagePlane, out firstReferenceLine, out lastReferenceLine);
                    }

                    if (firstReferenceLine != null)
                    {
                        yield return(firstReferenceLine);
                    }

                    if (lastReferenceLine != null)
                    {
                        yield return(lastReferenceLine);
                    }

                    //return 'current' last, so it draws on top of the others.
                    ReferenceLine currentReferenceLine = GetReferenceLine(_currentReferenceImagePlane, targetImagePlane);
                    if (currentReferenceLine != null)
                    {
                        yield return(currentReferenceLine);
                    }
                }
            }
        }
Exemplo n.º 36
0
 public bool IsOrthogonalTo(DicomImagePlane other, float angleTolerance)
 {
     return(_sourceFrame.ImagePlaneHelper.IsOrthogonalTo(other._sourceFrame.ImagePlaneHelper, angleTolerance));
 }
Exemplo n.º 37
0
		private void Stop()
		{
			_referencePlane = null;
			_inUse = false;

			foreach (CrossHair crosshair in _crosshairs)
				crosshair.Image = null;

			_coordinator.OnSpatialLocatorStopped();

			foreach (CrossHair crosshair in _crosshairs)
				crosshair.Dispose();

			_crosshairs.Clear();
		}
Exemplo n.º 38
0
		public bool IsParallelTo(DicomImagePlane other, float angleTolerance)
		{
			return Normal.IsParallelTo(other.Normal, angleTolerance);
		}
Exemplo n.º 39
0
		public bool IsOrthogonalTo(DicomImagePlane other, float angleTolerance)
		{
			return Normal.IsOrthogonalTo(other.Normal, angleTolerance);
		}
			public void Calibrate(DicomImagePlane referenceImagePlane, DicomImagePlane targetImagePlane)
			{
				if (!referenceImagePlane.IsInSameFrameOfReference(targetImagePlane) && referenceImagePlane.IsParallelTo(targetImagePlane, _angleTolerance))
				{
					Plane referencePlane = FromDicomImagePlane(referenceImagePlane);
					Plane targetPlane = FromDicomImagePlane(targetImagePlane);

					Dictionary<Plane, Vector3D> referenceOffsets = GetOffsetDictionary(referencePlane);
					Dictionary<Plane, Vector3D> targetOffsets = GetOffsetDictionary(targetPlane);

					Vector3D offset = targetImagePlane.PositionPatientCenterOfImage - referenceImagePlane.PositionPatientCenterOfImage;
					
					referenceOffsets[targetPlane] = offset;
					targetOffsets[referencePlane] = -offset;
				}
			}
Exemplo n.º 41
0
		public bool GetIntersectionPoints(DicomImagePlane other, out Vector3D intersectionPointPatient1, out Vector3D intersectionPointPatient2)
		{
			intersectionPointPatient1 = intersectionPointPatient2 = null;

			Vector3D[,] lineSegmentsImagePlaneBounds = new Vector3D[,]
				{
					// Bounding line segments of this (reference) image plane.
					{ PositionPatientTopLeft, PositionPatientTopRight },
					{ PositionPatientTopLeft, PositionPatientBottomLeft },
					{ PositionPatientBottomRight, PositionPatientTopRight  },
					{ PositionPatientBottomRight, PositionPatientBottomLeft}
				};

			List<Vector3D> planeIntersectionPoints = new List<Vector3D>();

			for (int i = 0; i < 4; ++i)
			{
				// Intersect the bounding line segments of the reference image with the plane of the target image.
				Vector3D intersectionPoint = Vector3D.GetLinePlaneIntersection(other.Normal, other.PositionPatientCenterOfImage,
																		lineSegmentsImagePlaneBounds[i, 0],
																		lineSegmentsImagePlaneBounds[i, 1], true);
				if (intersectionPoint != null)
					planeIntersectionPoints.Add(intersectionPoint);
			}

			if (planeIntersectionPoints.Count < 2)
				return false;

			intersectionPointPatient1 = planeIntersectionPoints[0];
			intersectionPointPatient2 = CollectionUtils.SelectFirst(planeIntersectionPoints,
				delegate(Vector3D point)
				{
					return !planeIntersectionPoints[0].Equals(point);
				});

			return intersectionPointPatient1 != null && intersectionPointPatient2 != null;
		}
			public Vector3D GetOffset(DicomImagePlane referenceImagePlane, DicomImagePlane targetImagePlane)
			{
				Vector3D offset = null;

				Plane referencePlane = FromDicomImagePlane(referenceImagePlane);
				if (_calibrationMatrix.ContainsKey(referencePlane))
				{
					Plane targetPlane = FromDicomImagePlane(targetImagePlane);
					if (!referencePlane.Equals(targetPlane))
						offset = GetOffset(referencePlane, targetPlane, new List<Plane>());
				}

				return offset;
			}
Exemplo n.º 43
0
		public bool IsOrthogonalTo(DicomImagePlane other, float angleTolerance)
		{
			return _sourceFrame.ImagePlaneHelper.IsOrthogonalTo(other._sourceFrame.ImagePlaneHelper, angleTolerance);
		}
Exemplo n.º 44
0
 public float GetAngleBetween(DicomImagePlane other)
 {
     return(Normal.GetAngleBetween(other.Normal));
 }
Exemplo n.º 45
0
		protected override void Dispose(bool disposing)
		{
			base.ImageViewer.EventBroker.ImageDrawing -= OnImageDrawing;

			_coordinator.Release();
			_coordinator = null;
			_currentReferenceImagePlane = null;

			base.Dispose(disposing);
		}
Exemplo n.º 46
0
		private static ReferenceLine GetReferenceLine(DicomImagePlane referenceImagePlane, DicomImagePlane targetImagePlane)
		{
			// if planes are parallel within tolerance, then they do not intersect and thus no reference lines should be shown
			float parallelTolerance = SynchronizationToolSettingsHelper.Default.ParallelPlanesToleranceAngleRadians;
			if (referenceImagePlane.IsParallelTo(targetImagePlane, parallelTolerance))
				return null;

			Vector3D intersectionPatient1, intersectionPatient2;
			if (!referenceImagePlane.GetIntersectionPoints(targetImagePlane, out intersectionPatient1, out intersectionPatient2))
				return null;

			Vector3D intersectionImagePlane1 = targetImagePlane.ConvertToImagePlane(intersectionPatient1);
			Vector3D intersectionImagePlane2 = targetImagePlane.ConvertToImagePlane(intersectionPatient2);

			//The coordinates need to be converted to pixel coordinates because right now they are in mm.
			PointF intersectionImage1 = targetImagePlane.ConvertToImage(new PointF(intersectionImagePlane1.X, intersectionImagePlane1.Y));
			PointF intersectionImage2 = targetImagePlane.ConvertToImage(new PointF(intersectionImagePlane2.X, intersectionImagePlane2.Y));
			string label = referenceImagePlane.InstanceNumber.ToString();

			return new ReferenceLine(intersectionImage1, intersectionImage2, label);
		}
Exemplo n.º 47
0
		public bool GetIntersectionPoints(DicomImagePlane other, out Vector3D intersectionPointPatient1, out Vector3D intersectionPointPatient2)
		{
			return _sourceFrame.ImagePlaneHelper.IntersectsWith(other._sourceFrame.ImagePlaneHelper, out intersectionPointPatient1, out intersectionPointPatient2);
		}
Exemplo n.º 48
0
		private IEnumerable<ReferenceLine> GetAllReferenceLines(DicomImagePlane targetImagePlane)
		{
			ReferenceLine firstReferenceLine = null;
			ReferenceLine lastReferenceLine = null;
			if (ShowFirstAndLastReferenceLines)
				GetFirstAndLastReferenceLines(targetImagePlane, out firstReferenceLine, out lastReferenceLine);

			if (firstReferenceLine != null)
				yield return firstReferenceLine;

			if (lastReferenceLine != null)
				yield return lastReferenceLine;

			//return 'current' last, so it draws on top of the others.
			ReferenceLine currentReferenceLine = GetReferenceLine(_currentReferenceImagePlane, targetImagePlane);
			if (currentReferenceLine != null)
				yield return currentReferenceLine;
		}
Exemplo n.º 49
0
 public bool IsOrthogonalTo(DicomImagePlane other, float angleTolerance)
 {
     return(Normal.IsOrthogonalTo(other.Normal, angleTolerance));
 }
Exemplo n.º 50
0
		private static DicomImagePlane CreateFromCache(Frame frame)
		{
			string key = String.Format("{0}:{1}", frame.ParentImageSop.SopInstanceUid, frame.FrameNumber);

			DicomImagePlane cachedData;
			if (ImagePlaneDataCache.ContainsKey(key))
			{
				cachedData = ImagePlaneDataCache[key];
			}
			else
			{
				cachedData = CreateFromFrame(frame);
				if (cachedData != null)
					ImagePlaneDataCache[key] = cachedData;
			}

			if (cachedData != null)
			{
				DicomImagePlane plane = new DicomImagePlane();
				plane.InitializeWithCachedData(cachedData);
				return plane;
			}

			return null;
		}
Exemplo n.º 51
0
 public float GetAngleBetween(DicomImagePlane other)
 {
     return(_sourceFrame.ImagePlaneHelper.GetAngleBetween(other._sourceFrame.ImagePlaneHelper));
 }
Exemplo n.º 52
0
		private static DicomImagePlane CreateFromFrame(Frame frame)
		{
			int height = frame.Rows - 1;
			int width = frame.Columns - 1;

			DicomImagePlane plane = new DicomImagePlane();
			plane.PositionPatientTopLeft = frame.ImagePlaneHelper.ConvertToPatient(new PointF(0, 0));
			plane.PositionPatientTopRight = frame.ImagePlaneHelper.ConvertToPatient(new PointF(width, 0));
			plane.PositionPatientBottomLeft = frame.ImagePlaneHelper.ConvertToPatient(new PointF(0, height));
			plane.PositionPatientBottomRight = frame.ImagePlaneHelper.ConvertToPatient(new PointF(width, height));
			plane.PositionPatientCenterOfImage = frame.ImagePlaneHelper.ConvertToPatient(new PointF(width / 2F, height / 2F));

			plane.Normal = frame.ImagePlaneHelper.GetNormalVector();

			if (plane.Normal == null || plane.PositionPatientCenterOfImage == null)
				return null;

			// here, we want the position in the coordinate system of the image plane, 
			// without moving the origin (e.g. leave it at the patient origin).
			plane.PositionImagePlaneTopLeft = frame.ImagePlaneHelper.ConvertToImagePlane(plane.PositionPatientTopLeft, Vector3D.Null);

			return plane;
		}