/// <summary>
        /// Adds a new focal point to the image.
        /// </summary>
        /// <param name="subImageIndex">The sub image index.</param>
        /// <param name="focalPointId">The focal point Id.</param>
        /// <param name="focalPoint">The focal point rect.</param>
        /// <returns>A focal point.</returns>
        public FocalPoint CreateFocalPoint(int subImageIndex, int focalPointId, Rect focalPoint)
        {
            if (subImageIndex < this.SubImages.Count)
            {
                Point logicalBoxStartPoint = this.multiScaleImage.ElementToLogicalPoint(new Point(focalPoint.X, focalPoint.Y));
                Point logicalBoxEndPoint   = this.multiScaleImage.ElementToLogicalPoint(new Point(focalPoint.X + focalPoint.Width, focalPoint.Y + focalPoint.Height));

                Rect imageRect = GetLogicalSubImageRect(this.multiScaleImage.SubImages[subImageIndex]);

                Point startPoint = new Point(
                    (logicalBoxStartPoint.X - imageRect.X) / imageRect.Width,
                    (logicalBoxStartPoint.Y - imageRect.Y) / imageRect.Height);

                Point endPoint = new Point(
                    ((logicalBoxEndPoint.X - imageRect.X) / imageRect.Width) - startPoint.X,
                    ((logicalBoxEndPoint.Y - imageRect.Y) / imageRect.Height) - startPoint.Y);

                FocalPoint focalPointData = new FocalPoint()
                {
                    Id            = focalPointId,
                    Area          = new Rect(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y),
                    SubImageIndex = subImageIndex
                };

                return(focalPointData);
            }

            return(null);
        }
 /// <summary>
 /// Displays a focal point.
 /// </summary>
 /// <param name="focalPoint">The focal point to display.</param>
 public void DisplayFocalPoint(FocalPoint focalPoint)
 {
     if (focalPoint != null)
     {
         this.DisplayFocalPoint(this.multiScaleImage.SubImages[focalPoint.SubImageIndex], focalPoint);
     }
 }
        /// <summary>
        /// Gets the element position for a focal point.
        /// </summary>
        /// <param name="focalPoint">The focal point.</param>
        /// <returns>An rect with the element position.</returns>
        public Rect GetFocalPointElementPosition(FocalPoint focalPoint)
        {
            Rect imageRect = GetLogicalSubImageRect(this.multiScaleImage.SubImages[focalPoint.SubImageIndex]);

            Rect logicalFocalPointRect = new Rect(
                imageRect.X + (focalPoint.Area.X * imageRect.Width),
                imageRect.Y + (focalPoint.Area.Y * imageRect.Height),
                focalPoint.Area.Width * imageRect.Width,
                focalPoint.Area.Height * imageRect.Height);

            Point topLeft     = this.multiScaleImage.LogicalToElementPoint(new Point(logicalFocalPointRect.X, logicalFocalPointRect.Y));
            Point bottomRight = this.multiScaleImage.LogicalToElementPoint(new Point(logicalFocalPointRect.X + logicalFocalPointRect.Width, logicalFocalPointRect.Y + logicalFocalPointRect.Height));

            return(new Rect(
                       topLeft.X,
                       topLeft.Y,
                       bottomRight.X - topLeft.X,
                       bottomRight.Y - topLeft.Y));
        }
        /// <summary>
        /// Displays a focal point.
        /// </summary>
        /// <param name="subImage">The source subimage.</param>
        /// <param name="focalPoint">The focal point rect.</param>
        private void DisplayFocalPoint(MultiScaleSubImage subImage, FocalPoint focalPoint)
        {
            if (focalPoint == null)
            {
                return;
            }

            Rect subImageLogicalRect   = GetLogicalSubImageRect(subImage);
            Rect focalPointDisplayRect = new Rect(
                subImageLogicalRect.X + (subImageLogicalRect.Width * focalPoint.Area.X),
                subImageLogicalRect.Y + (subImageLogicalRect.Height * focalPoint.Area.Y),
                subImageLogicalRect.Width * focalPoint.Area.Width,
                subImageLogicalRect.Height * focalPoint.Area.Height);

            double width  = focalPointDisplayRect.Width;
            Point  origin = new Point(focalPointDisplayRect.Left, focalPointDisplayRect.Top);
            double focalPointAspectRatio = focalPointDisplayRect.Width / focalPointDisplayRect.Height;

            double num2 = this.multiScaleImage.ActualWidth / this.multiScaleImage.ActualHeight;

            if (num2 > focalPointAspectRatio)
            {
                width     = (num2 / focalPointAspectRatio) * focalPointDisplayRect.Width;
                origin.X += (focalPointDisplayRect.Width - width) / 2.0;
            }
            else
            {
                double num3 = (focalPointAspectRatio / num2) * focalPointDisplayRect.Height;
                origin.Y += (focalPointDisplayRect.Height - num3) / 2.0;
            }

            this.CalculateAspectRation(1.3, ref width, ref origin);

            focalPointDisplayRect.X     = origin.X;
            focalPointDisplayRect.Y     = origin.Y;
            focalPointDisplayRect.Width = width;

            this.multiScaleImage.ViewportOrigin = new Point(focalPointDisplayRect.Left, focalPointDisplayRect.Top);
            this.multiScaleImage.ViewportWidth  = focalPointDisplayRect.Width;

            this.zoomLevel = this.defaultWidth / focalPointDisplayRect.Width;
        }
        /// <summary>
        /// Displays a focal point.
        /// </summary>
        /// <param name="subImage">The source subimage.</param>
        /// <param name="focalPoint">The focal point rect.</param>
        private void DisplayFocalPoint(MultiScaleSubImage subImage, FocalPoint focalPoint)
        {
            if (focalPoint == null)
            {
                return;
            }

            Rect subImageLogicalRect = GetLogicalSubImageRect(subImage);
            Rect focalPointDisplayRect = new Rect(
                subImageLogicalRect.X + (subImageLogicalRect.Width * focalPoint.Area.X),
                subImageLogicalRect.Y + (subImageLogicalRect.Height * focalPoint.Area.Y),
                subImageLogicalRect.Width * focalPoint.Area.Width,
                subImageLogicalRect.Height * focalPoint.Area.Height);

            double width = focalPointDisplayRect.Width;
            Point origin = new Point(focalPointDisplayRect.Left, focalPointDisplayRect.Top);
            double focalPointAspectRatio = focalPointDisplayRect.Width / focalPointDisplayRect.Height;

            double num2 = this.multiScaleImage.ActualWidth / this.multiScaleImage.ActualHeight;
            if (num2 > focalPointAspectRatio)
            {
                width = (num2 / focalPointAspectRatio) * focalPointDisplayRect.Width;
                origin.X += (focalPointDisplayRect.Width - width) / 2.0;
            }
            else
            {
                double num3 = (focalPointAspectRatio / num2) * focalPointDisplayRect.Height;
                origin.Y += (focalPointDisplayRect.Height - num3) / 2.0;
            }

            this.CalculateAspectRation(1.3, ref width, ref origin);

            focalPointDisplayRect.X = origin.X;
            focalPointDisplayRect.Y = origin.Y;
            focalPointDisplayRect.Width = width;

            this.multiScaleImage.ViewportOrigin = new Point(focalPointDisplayRect.Left, focalPointDisplayRect.Top);
            this.multiScaleImage.ViewportWidth = focalPointDisplayRect.Width;

            this.zoomLevel = this.defaultWidth / focalPointDisplayRect.Width;
        }
        /// <summary>
        /// Gets the element position for a focal point.
        /// </summary>
        /// <param name="focalPoint">The focal point.</param>
        /// <returns>An rect with the element position.</returns>
        public Rect GetFocalPointElementPosition(FocalPoint focalPoint)
        {
            Rect imageRect = GetLogicalSubImageRect(this.multiScaleImage.SubImages[focalPoint.SubImageIndex]);

            Rect logicalFocalPointRect = new Rect(
                imageRect.X + (focalPoint.Area.X * imageRect.Width),
                imageRect.Y + (focalPoint.Area.Y * imageRect.Height),
                focalPoint.Area.Width * imageRect.Width,
                focalPoint.Area.Height * imageRect.Height);

            Point topLeft = this.multiScaleImage.LogicalToElementPoint(new Point(logicalFocalPointRect.X, logicalFocalPointRect.Y));
            Point bottomRight = this.multiScaleImage.LogicalToElementPoint(new Point(logicalFocalPointRect.X + logicalFocalPointRect.Width, logicalFocalPointRect.Y + logicalFocalPointRect.Height));

            return new Rect(
                topLeft.X,
                topLeft.Y,
                bottomRight.X - topLeft.X,
                bottomRight.Y - topLeft.Y);
        }
 /// <summary>
 /// Displays a focal point.
 /// </summary>
 /// <param name="focalPoint">The focal point to display.</param>
 public void DisplayFocalPoint(FocalPoint focalPoint)
 {
     if (focalPoint != null)
     {
         this.DisplayFocalPoint(this.multiScaleImage.SubImages[focalPoint.SubImageIndex], focalPoint);
     }
 }
        /// <summary>
        /// Adds a new focal point to the image.
        /// </summary>
        /// <param name="subImageIndex">The sub image index.</param>
        /// <param name="focalPointId">The focal point Id.</param>
        /// <param name="focalPoint">The focal point rect.</param>
        /// <returns>A focal point.</returns>
        public FocalPoint CreateFocalPoint(int subImageIndex, int focalPointId, Rect focalPoint)
        {
            if (subImageIndex < this.SubImages.Count)
            {
                Point logicalBoxStartPoint = this.multiScaleImage.ElementToLogicalPoint(new Point(focalPoint.X, focalPoint.Y));
                Point logicalBoxEndPoint = this.multiScaleImage.ElementToLogicalPoint(new Point(focalPoint.X + focalPoint.Width, focalPoint.Y + focalPoint.Height));

                Rect imageRect = GetLogicalSubImageRect(this.multiScaleImage.SubImages[subImageIndex]);

                Point startPoint = new Point(
                    (logicalBoxStartPoint.X - imageRect.X) / imageRect.Width,
                    (logicalBoxStartPoint.Y - imageRect.Y) / imageRect.Height);

                Point endPoint = new Point(
                    ((logicalBoxEndPoint.X - imageRect.X) / imageRect.Width) - startPoint.X,
                    ((logicalBoxEndPoint.Y - imageRect.Y) / imageRect.Height) - startPoint.Y);

                FocalPoint focalPointData = new FocalPoint()
                {
                    Id = focalPointId,
                    Area = new Rect(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y),
                    SubImageIndex = subImageIndex
                };

                return focalPointData;
            }

            return null;
        }