private void GetFirstAndLastReferenceLines(DicomImagePlane targetImagePlane, out ReferenceLine firstReferenceLine, out ReferenceLine lastReferenceLine)
        {
            firstReferenceLine = lastReferenceLine = null;

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

            foreach (DicomImagePlane parallelPlane in GetPlanesParallelToReferencePlane())
            {
                if (parallelPlane.PositionImagePlaneTopLeft.Z < firstReferenceImageZComponent)
                {
                    ReferenceLine referenceLine = GetReferenceLine(parallelPlane, targetImagePlane);
                    if (referenceLine != null)
                    {
                        firstReferenceImageZComponent = parallelPlane.PositionImagePlaneTopLeft.Z;
                        firstReferenceLine            = referenceLine;
                    }
                }

                if (parallelPlane.PositionImagePlaneTopLeft.Z >= lastReferenceImageZComponent)
                {
                    ReferenceLine referenceLine = GetReferenceLine(parallelPlane, targetImagePlane);
                    if (referenceLine != null)
                    {
                        lastReferenceImageZComponent = parallelPlane.PositionImagePlaneTopLeft.Z;
                        lastReferenceLine            = referenceLine;
                    }
                }
            }
        }
        private IEnumerable <ReferenceLine> GetAllReferenceLines(DicomImagePlane targetImagePlane)
        {
            ReferenceLine firstReferenceLine = null;
            ReferenceLine lastReferenceLine  = null;

            GetFirstAndLastReferenceLines(targetImagePlane, out firstReferenceLine, out lastReferenceLine);

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

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

            ReferenceLine currentReferenceLine = GetReferenceLine(_currentReferenceImagePlane, targetImagePlane);

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