Exemplo n.º 1
0
        private void OnPatternMessageReceived(string message)
        {
            var spots = PatternMessage.Parse(message, Props);

            Target      = PatternAnalyser.SortList(spots, false).ToObservableCollection();
            CalibMatrix = AffineMatrix.CalculateMatrix(Spots, Target);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the new rectangle of an object in pixels.
        /// </summary>
        /// <param name="rect">The new rectangle of an object in pixels.</param>
        protected override void SetRect(Rectangle rect)
        {
            VintasoftImage image = _imageViewer.Image;

            if (image != null)
            {
                // get transform from control to the device independent pixels (DIP)
                AffineMatrix matrix = _imageViewer.GetTransformFromControlToDip();

                // convert location to the DIP
                PointF locationInDip = PointFAffineTransform.TransformPoint(matrix, rect.Location);

                if (HideContentOnTransform)
                {
                    // if comment control content is visible
                    if (!_isCommentControlContentHidden)
                    {
                        // hide comment control content
                        UpdateCommentControlContentVisibility(false);
                        _isCommentControlContentHidden = true;
                    }
                }

                // update comment bounding box
                CommentControl.Comment.BoundingBox = new RectangleF(locationInDip, rect.Size);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 現在のこのControlのWidth,Heightに対して、いい感じに描画できるようにaffine行列を設定する。
        /// </summary>
        public void FitToClientSize()
        {
            // ちらつかずにウインドウのaspect ratioを保つのは.NET Frameworkの範疇では不可能。
            // ClientSizeをResizeイベント中に変更するのは安全ではない。
            // cf.
            //   https://qiita.com/yu_ka1984/items/b4a3ce9ed7750bd67b86
            // → あきらめる

#if false
            // このコード、有効にするとハングする。
            double ratio = (double)h / w;
            if (ratio < 0.563)
            {
                w          = (int)(h / 0.563);
                ClientSize = new Size(w, h + menu_height);
            }
            else if (ratio > 0.726)
            {
                w          = (int)(h / 0.726);
                ClientSize = new Size(w, h + menu_height);
            }
#endif

            var scale = Math.Min((float)Height / board_img_size.Height, (float)Width / board_vert_size.Width);
            AffineMatrix.SetMatrix(scale, scale, (int)(Width - board_img_size.Width * scale) / 2, 0 /* Top (Formの場合)*/);

            //  縦長の画面なら駒台を縦長にする。

            double ratio = (double)Width / Height;
            //Console.WriteLine(ratio);

            PieceTableVersion = (ratio < 1.36) ? 1 : 0;
        }
        /// <summary>
        /// Returns center point of image viewer in coordinate space of specified image.
        /// </summary>
        /// <param name="image">An image.</param>
        /// <returns>
        /// Center point of image viewer in coordinate space of specified image.
        /// </returns>
        private PointF GetCenterPoint(VintasoftImage image)
        {
            // get old visible point
            PointF centerPoint = new PointF(ImageViewer.ClientSize.Width / 2.0f, ImageViewer.ClientSize.Height / 2.0f);
            // get transform from image space to viewer space
            AffineMatrix pointTransfrom = ImageViewer.GetTransformFromControlToImage(image);

            // transform the point
            return(PointFAffineTransform.TransformPoint(pointTransfrom, centerPoint));
        }
 public MatrixD(AffineMatrix affineMatrix) : this()
 {
     if (null != affineMatrix)
     {
         affineMatrix.GetAffineMatrix(out var modelX, out var modelY, out var modelA, out var resultX, out var resultY, out var resultA);
         ModelX  = modelX;
         ModelY  = modelY;
         ModelA  = modelA;
         ResultX = resultX;
         ResultY = resultY;
         ResultA = resultA;
     }
 }
        /// <summary>
        /// Returns a drawing box of annotation, in the image space.
        /// </summary>
        /// <param name="drawingSurface">The object that provides information about drawing surface.</param>
        /// <returns>Drawing box of annotation, in the image space.</returns>
        public override RectangleF GetDrawingBox(DrawingSurface drawingSurface)
        {
            using (IGraphicsPath path = GetAsGraphicsPath(DrawingFactory.Default))
            {
                using (IDrawingPen pen = DrawingFactory.Default.CreatePen(Data.Outline))
                {
                    // create transformation that allows to get correct bounding box
                    AffineMatrix transform = AffineMatrix.CreateRotation(MarkAnnoData.Rotation);
                    transform.Translate(MarkAnnoData.Location.X, MarkAnnoData.Location.Y);

                    return(path.GetBounds(pen, transform));
                }
            }
        }
Exemplo n.º 7
0
        private void TransformMatrixHandler()
        {
            CalibMatrix = AffineMatrix.CalculateMatrix(SelectedA, SelectedB);

            DecomposeMatrix = AffineMatrix.Decompose(CalibMatrix);

            PatternList.Add(new Pattern("None"));

            PatternList.Last().Points = AffineMatrix.CalculateBack(SelectedA.Points, CalibMatrix);

            var series = PlotModelHelper.CreateScatterSerie(PatternList.Last().Points, PatternList.Last().Color);

            PlotModelPattern.Series.Add(series);
            PlotModelPattern.InvalidatePlot(true);
        }
        /// <summary>
        /// Returns distance between point and image rectangle.
        /// </summary>
        /// <param name="point">A point in image viewer space.</param>
        /// <param name="image">An image.</param>
        /// <returns>Distance between point and image rectangle.</returns>
        private float GetDistanceBetweenPointAndImageRect(PointF point, VintasoftImage image)
        {
            AffineMatrix transformMatrix = ImageViewer.GetTransformFromImageToControl(image);
            // get image rectangle
            RectangleF      imageRect      = new RectangleF(0, 0, image.Width, image.Height);
            PointFTransform pointTransform = PointFAffineTransform.FromMatrix(transformMatrix);

            imageRect = PointFAffineTransform.TransformBoundingBox(pointTransform, imageRect);

            PointF imagePoint = PointF.Empty;

            // get X coordinate of point on image
            if (point.X < imageRect.X)
            {
                imagePoint.X = imageRect.X;
            }
            else if (point.X > imageRect.X + imageRect.Width)
            {
                imagePoint.X = imageRect.X + imageRect.Width;
            }
            else
            {
                imagePoint.X = point.X;
            }

            // get Y coordinate of point on image
            if (point.Y < imageRect.Y)
            {
                imagePoint.Y = imageRect.Y;
            }
            else if (point.Y > imageRect.Y + imageRect.Height)
            {
                imagePoint.Y = imageRect.Y + imageRect.Height;
            }
            else
            {
                imagePoint.Y = point.Y;
            }

            // calculate distance
            float dx = (point.X - imagePoint.X);
            float dy = (point.Y - imagePoint.Y);
            float distanceBetweenImageAndPoint = dx * dx + dy * dy;

            return(distanceBetweenImageAndPoint);
        }
        /// <summary>
        /// Gets an array that contains reference points in content space of this annotation.
        /// </summary>
        /// <returns></returns>
        public virtual PointF[] GetReferencePointsInContentSpace()
        {
            float width  = Size.Width;
            float height = Size.Height;
            float w      = Math.Min(width / 10, height / 10);

            PointF[] points;
            switch (MarkType)
            {
            case MarkAnnotationType.Rectangle:
                points = new PointF[] {
                    new PointF(-width / 2, -height / 2),
                    new PointF(width / 2, -height / 2),
                    new PointF(width / 2, height / 2),
                    new PointF(-width / 2, height / 2)
                };
                break;

            case MarkAnnotationType.Tick:
                points = new PointF[] {
                    new PointF(-width / 2, 0),
                    new PointF(0, height / 4),
                    new PointF(width / 2, -height / 2),
                    new PointF(0, height / 2),
                    new PointF(-width / 2, 0)
                };
                break;

            case MarkAnnotationType.Cross:
                points = new PointF[] {
                    new PointF(-width / 2, -w),
                    new PointF(-w, -w),
                    new PointF(-w, -height / 2),
                    new PointF(w, -height / 2),
                    new PointF(w, -w),
                    new PointF(width / 2, -w),
                    new PointF(width / 2, w),
                    new PointF(w, w),
                    new PointF(w, height / 2),
                    new PointF(-w, height / 2),
                    new PointF(-w, w),
                    new PointF(-width / 2, w)
                };
                break;

            case MarkAnnotationType.Star:
                points = new PointF[] {
                    new PointF(-width / 2, 0),
                    new PointF(-w, -w),
                    new PointF(0, -height / 2),
                    new PointF(w, -w),
                    new PointF(width / 2, 0),
                    new PointF(w, w),
                    new PointF(0, height / 2),
                    new PointF(-w, w),
                    new PointF(-width / 2, 0)
                };
                break;

            default:
                throw new NotImplementedException();
            }

            AffineMatrix matrix = new AffineMatrix();

            if (HorizontalMirrored)
            {
                matrix.ScalePrepend(-1, 1);
            }
            if (VerticalMirrored)
            {
                matrix.ScalePrepend(1, -1);
            }

            PointFAffineTransform.TransformPoints(matrix, points);

            return(points);
        }
Exemplo n.º 10
0
 /// <summary>
 /// 上記のAffine()の逆変換
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 private Point InverseAffine(Point p)
 {
     return(AffineMatrix.InverseAffine(p));
 }
Exemplo n.º 11
0
 private Rectangle Affine(Point p, Size s)
 {
     return(AffineMatrix.Affine(p, s));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Sizeに対してaffine変換を行う。
 /// offsetの加算は行わない。scaleのみ。
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 private Size AffineScale(Size s)
 {
     return(AffineMatrix.AffineScale(s));
 }
Exemplo n.º 13
0
        // -------------------------------------------------------------------------
        //  affine変換してのスクリーンへの描画
        // -------------------------------------------------------------------------

        /// <summary>
        /// ViewInstanceのOffsetX,OffsetY,ScaleX,ScaleY
        /// の値に基づいてaffine変換を行う
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        private Point Affine(Point p)
        {
            return(AffineMatrix.Affine(p));
        }
Exemplo n.º 14
0
        public int PixelValueAffine(int screenX, int screenY)
        {
            // Scrolling values set the origin so that BG 0,0 == Screen 0,0
            // Affine scroll are 24.8 fixed point numbers but as long as you shift away the fraction part at the end, you can just do integer math on them and they work
            int scrollX = AffineScrollX >> 8;
            int scrollY = AffineScrollY >> 8;

            // The game will have set up the matrix to be the inverse texture mapping matrix. I.E it maps from screen space to texture space. Just what we need!
            int textureSpaceX, textureSpaceY;

            AffineMatrix.Multiply(screenX, screenY, out textureSpaceX, out textureSpaceY);

            // Apply displacement vector (affine scroll)
            textureSpaceX += scrollX;
            textureSpaceY += scrollY;

            // BG Wrap?
            if (CntRegister.DisplayAreaOverflow)
            {
                while (textureSpaceX >= bgWidthInPixel)
                {
                    textureSpaceX -= bgWidthInPixel;
                }
                while (textureSpaceY >= bgHeightInPixel)
                {
                    textureSpaceY -= bgHeightInPixel;
                }
                while (textureSpaceX < 0)
                {
                    textureSpaceX += bgWidthInPixel;
                }
                while (textureSpaceY < 0)
                {
                    textureSpaceY += bgHeightInPixel;
                }
            }
            else
            {
                if (textureSpaceX < 0 || textureSpaceX > WidthInPixels())
                {
                    return(0);
                }
                if (textureSpaceY < 0 || textureSpaceY > HeightInPixels())
                {
                    return(0);
                }
            }

            // Coords (measured in tiles) of the tile we want to render
            int bgRow    = textureSpaceY / 8;
            int bgColumn = textureSpaceX / 8;

            // Which row / column within the tile we are rendering?
            int tileRow    = textureSpaceY % 8;
            int tileColumn = textureSpaceX % 8;

            // Affine BG's have one byte screen data (the tile index). Also all tiles are 8bpp
            // Affine BG's are also all square (they have their own size table which is different to regular tiled bg's)
            int tileInfoOffset = (bgRow * bgWidthInTiles) + bgColumn;

            int tileNumber = gba.Memory.VRam[(CntRegister.ScreenBlockBaseAddress * 2048) + tileInfoOffset];

            int tileVramOffset = (int)(tileDataVramOffset + (tileNumber * tileSize));

            int paletteIndex = TileHelpers.GetTilePixel(tileColumn, tileRow, true, gba.Memory.VRam, tileVramOffset, false, false);

            return(paletteIndex);
        }