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);
         }
     }
 }
 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);
             }
         }
     }
 }
 private IEnumerable <DicomImagePlane> GetPlanesParallelToReferencePlane()
 {
     foreach (IPresentationImage image in CurrentReferenceImage.ParentDisplaySet.PresentationImages)
     {
         DicomImagePlane plane = DicomImagePlane.FromImage(image);
         if (plane != null)
         {
             if (_currentReferenceImagePlane.IsInSameFrameOfReference(plane) &&
                 _currentReferenceImagePlane.IsParallelTo(plane, _oneDegreeInRadians))
             {
                 yield return(plane);
             }
         }
     }
 }
 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);
                 }
             }
         }
     }
 }
        private void RefreshReferenceLines(IPresentationImage targetImage)
        {
            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);

            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;
            }
        }
        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();
            }
        }
        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;
            }

            int lastIndex = targetImageBox.TopLeftPresentationImageIndex;

            targetImageBox.TopLeftPresentationImage = targetImagePlane.SourceImage;

            if (lastIndex != targetImageBox.TopLeftPresentationImageIndex)
            {
                if (!_imageBoxesToDraw.Contains(targetImageBox))
                {
                    _imageBoxesToDraw.Add(targetImageBox);
                }
            }
        }
 private bool Start()
 {
     _referencePlane = DicomImagePlane.FromImage(base.SelectedPresentationImage);
     return(_referencePlane != null);
 }