Esempio n. 1
0
    /// <summary>
    /// 是否数据一致
    /// </summary>
    protected override bool toDataEquals(BaseData data)
    {
        RectData mData = (RectData)data;

        if (this.ix != mData.ix)
        {
            return(false);
        }

        if (this.iy != mData.iy)
        {
            return(false);
        }

        if (this.iWidth != mData.iWidth)
        {
            return(false);
        }

        if (this.iHeight != mData.iHeight)
        {
            return(false);
        }

        return(true);
    }
        /// <summary>
        ///     Hides everything in this object and children objects that goes outside this objects rect
        /// </summary>
        /// <param name="parent">Parent Object for this Panel</param>
        /// <param name="rectData">Describes the panel's rectangle</param>
        /// <returns></returns>
        public static GameObject CreateRectMask2DPanel(GameObject parent, RectData rectData)
        {
            GameObject panel = CreateBasePanel(parent, rectData);

            panel.AddComponent <RectMask2D>();
            return(panel);
        }
Esempio n. 3
0
 /// <summary>
 /// 拷贝位置
 /// </summary>
 public void copyPos(RectData rect)
 {
     this.x      = rect.x;
     this.y      = rect.y;
     this.width  = rect.width;
     this.height = rect.height;
 }
Esempio n. 4
0
        public static GameObject CreateImagePanel(GameObject parent, Color32 color, RectData rectData)
        {
            GameObject panel = CreateBasePanel(parent, rectData);

            Image img = panel.AddComponent <Image>();

            img.color          = color;
            img.preserveAspect = true;
            return(panel);
        }
        /*
         * ██╗███╗   ███╗ █████╗  ██████╗ ███████╗
         * ██║████╗ ████║██╔══██╗██╔════╝ ██╔════╝
         * ██║██╔████╔██║███████║██║  ███╗█████╗
         * ██║██║╚██╔╝██║██╔══██║██║   ██║██╔══╝
         * ██║██║ ╚═╝ ██║██║  ██║╚██████╔╝███████╗
         * ╚═╝╚═╝     ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚══════╝
         */
        /// <summary>
        ///     Creates an Image Panel
        /// </summary>
        /// <param name="parent">The Parent GameObject for this image.</param>
        /// <param name="sprite">The Image/Sprite to use</param>
        /// <param name="rectData">The rectangle description for this sprite to inhabit</param>
        /// <returns></returns>
        public static GameObject CreateImagePanel(GameObject parent, Sprite sprite, RectData rectData)
        {
            GameObject panel = CreateBasePanel(parent, rectData);

            Image img = panel.AddComponent <Image>();

            img.sprite         = sprite;
            img.preserveAspect = true;
            return(panel);
        }
Esempio n. 6
0
            public override bool Equals(object obj)
            {
                RectData rect = obj as RectData;

                if (rect == null)
                {
                    return(false);
                }

                return(rect.Top == Top && rect.Left == Left && rect.Bottom == Bottom && rect.Right == Right);
            }
Esempio n. 7
0
    public static RectData Serialize(this Rect r)
    {
        RectData rectData = new RectData
        {
            x      = r.x,
            y      = r.y,
            width  = r.width,
            height = r.height
        };

        return(rectData);
    }
        /// <summary>
        /// Creates a base panel for other panels to use.
        /// </summary>
        /// <param name="parent">Parent Game Object under which this panel will be held</param>
        /// <param name="rd">Rectangle data for this panel</param>
        /// <returns></returns>
        public static GameObject CreateBasePanel(GameObject parent, RectData rd)
        {
            GameObject basePanel = new GameObject();

            if (parent != null)
            {
                basePanel.transform.SetParent(parent.transform);
                basePanel.transform.localScale = new Vector3(1, 1, 1);
            }
            basePanel.AddComponent <CanvasRenderer>();
            AddRectTransform(basePanel, rd);
            return(basePanel);
        }
Esempio n. 9
0
        public static void UpdateRectTransform(GameObject go, RectData rd)
        {
            RectTransform rt = go.GetComponent <RectTransform>();

            if (!(bool)rt)
            {
                return;
            }
            rt.anchorMax        = rd.AnchorMax;
            rt.anchorMin        = rd.AnchorMin;
            rt.pivot            = rd.AnchorPivot;
            rt.sizeDelta        = rd.RectSizeDelta;
            rt.anchoredPosition = rd.AnchorPosition;
        }
Esempio n. 10
0
    /// <summary>
    /// 复制(潜拷贝)
    /// </summary>
    protected override void toShadowCopy(BaseData data)
    {
        if (!(data is RectData))
        {
            return;
        }

        RectData mData = (RectData)data;

        this.ix      = mData.ix;
        this.iy      = mData.iy;
        this.iWidth  = mData.iWidth;
        this.iHeight = mData.iHeight;
    }
        /// <summary>
        ///     Transforms the RectData into a RectTransform for the GameObject.
        /// </summary>
        /// <param name="go">GameObject to which this rectdata should be put into.</param>
        /// <param name="rd">Rectangle Data</param>
        public static void AddRectTransform(GameObject go, RectData rd)
        {
            // Create a rectTransform
            // Set the total size of the content
            // all you need to know is,
            // --

            // sizeDelta is size of the difference of the anchors multiplied by screen size so
            // the sizeDelta width is actually = ((anchorMax.x-anchorMin.x)*screenWidth) + sizeDelta.x
            // so assuming a streched horizontally rectTransform on a 1920 screen, this would be
            // ((1-0)*1920)+sizeDelta.x
            // 1920 + sizeDelta.x
            // so if you wanted a 100pixel wide box in the center of the screen you'd do -1820, height as 1920+-1820 = 100
            // and if you wanted a fullscreen wide box, its just 0 because 1920+0 = 1920
            // the same applies for height

            // anchorPosition is basically an offset to the center of the anchors multiplies by screen size so
            // a 0.5,0.5 min and 0.5,0.5 max, would put the anchor in the middle of the screen but anchorPosition just offsets that
            // i.e on a 1920x1080 screen
            // anchorPosition 100,100 would do (1920*0.5)+100,(1080*0.5)+100, so 1060,640

            // ANCHOR MIN / MAX
            // --
            // 0,0 = bottom left
            // 0,1 = top left
            // 1,0 = bottom right
            // 1,1 = top right
            // --


            // The only other rects I'd use are
            // anchorMin = 0.0, yyy anchorMax = 1.0, yyy (strech horizontally) y = 0.0 is bottom, y = 0.5 is center, y = 1.0 is top
            // anchorMin = xxx, 0.0 anchorMax = xxx, 1.0 (strech vertically) x = 0.0 is left, x = 0.5 is center, x = 1.0 is right
            // anchorMin = 0.0, 0.0 anchorMax = 1.0, 1.0 (strech to fill)
            // --
            // technically you can anchor these anywhere on the screen
            // you can even use negative values to float something offscreen

            // as for the pivot, the pivot determines where the "center" of the rect is which is useful if you want to rotate something by its corner, note that this DOES offset the anchor positions
            // i.e. with a 100x100 square, setting the pivot to be 1,1 will put the top right of the square at the anchor position (-50,-50 from its starting position)

            RectTransform rt = go.AddComponent <RectTransform>();

            rt.anchorMax        = rd.AnchorMax;
            rt.anchorMin        = rd.AnchorMin;
            rt.pivot            = rd.AnchorPivot;
            rt.sizeDelta        = rd.RectSizeDelta;
            rt.anchoredPosition = rd.AnchorPosition;
        }
        /*
         * ████████╗███████╗██╗  ██╗████████╗
         * ╚══██╔══╝██╔════╝╚██╗██╔╝╚══██╔══╝
         *    ██║   █████╗   ╚███╔╝    ██║
         *    ██║   ██╔══╝   ██╔██╗    ██║
         *    ██║   ███████╗██╔╝ ██╗   ██║
         *    ╚═╝   ╚══════╝╚═╝  ╚═╝   ╚═╝
         */
        /// <summary>
        ///     Creates a Text Object
        /// </summary>
        /// <param name="parent">The GameObject that this text will be put into.</param>
        /// <param name="text">The text that will be shown with this object</param>
        /// <param name="fontSize">The text's font size.</param>
        /// <param name="textAnchor">The location within the rectData where the text anchor should be.</param>
        /// <param name="rectData">Rectangle Data to describe the Text Panel.</param>
        /// <param name="font">The Font to use</param>
        /// <returns></returns>
        public static GameObject CreateTextPanel(GameObject parent, string text, int fontSize, TextAnchor textAnchor,
                                                 RectData rectData, Font font)
        {
            GameObject panel = CreateBasePanel(parent, rectData);

            Text textObj = panel.AddComponent <Text>();

            textObj.font = font;

            textObj.text            = text;
            textObj.supportRichText = true;
            textObj.fontSize        = fontSize;
            textObj.alignment       = textAnchor;
            return(panel);
        }
Esempio n. 13
0
 public SpriteData(ViewportData Viewport, Sprite Sprite)
 {
     this.X        = Sprite.X;
     this.Y        = Sprite.Y;
     this.OX       = Sprite.OX;
     this.OY       = Sprite.OY;
     this.ZoomX    = Sprite.ZoomX;
     this.ZoomY    = Sprite.ZoomY;
     this.Opacity  = Sprite.Opacity;
     this.Angle    = Sprite.Angle;
     this.MirrorX  = Sprite.MirrorX;
     this.MirrorY  = Sprite.MirrorY;
     this.Bitmap   = new BitmapData(Sprite.Bitmap);
     this.SrcRect  = new RectData(Sprite.SrcRect);
     this.Color    = new ColorData(Sprite.Color);
     this.Tone     = new ToneData(Sprite.Tone);
     this.Disposed = Sprite.Disposed;
     this.Visible  = Sprite.Visible;
     this.Viewport = Viewport;
     this.Z        = Sprite.Z;
 }
Esempio n. 14
0
            public string CompareWith(RectData Rect)
            {
                string Diff = "(Rect ";

                if (this.X != Rect.X)
                {
                    Diff += $"(X {this.X}->{Rect.X}) ";
                }
                if (this.Y != Rect.Y)
                {
                    Diff += $"(Y {this.Y}->{Rect.Y}) ";
                }
                if (this.Width != Rect.Width)
                {
                    Diff += $"(Width {this.Width}->{Rect.Width}) ";
                }
                if (this.Height != Rect.Height)
                {
                    Diff += $"(Height {this.Height}->{Rect.Height}) ";
                }
                return(Diff == "(Rect " ? "" : Diff.Substring(0, Diff.Length - 1) + ")");
            }
Esempio n. 15
0
        /*
         * ██████╗ ██╗   ██╗████████╗████████╗ ██████╗ ███╗   ██╗
         * ██╔══██╗██║   ██║╚══██╔══╝╚══██╔══╝██╔═══██╗████╗  ██║
         * ██████╔╝██║   ██║   ██║      ██║   ██║   ██║██╔██╗ ██║
         * ██╔══██╗██║   ██║   ██║      ██║   ██║   ██║██║╚██╗██║
         * ██████╔╝╚██████╔╝   ██║      ██║   ╚██████╔╝██║ ╚████║
         * ╚═════╝  ╚═════╝    ╚═╝      ╚═╝    ╚═════╝ ╚═╝  ╚═══╝
         */
        /// <summary>
        ///     Creates a Button
        /// </summary>
        /// <param name="parent">The Parent GameObject for this Button</param>
        /// <param name="action">Action to take when butotn is clicked</param>
        /// <param name="id">Id passed to the action</param>
        /// <param name="spr">Sprite to use for the button</param>
        /// <param name="text">Text for the button</param>
        /// <param name="fontSize">Size of the Text</param>
        /// <param name="textAnchor">Where to Anchor the text within the button</param>
        /// <param name="rectData">The rectangle description for this button</param>
        /// <param name="bold">If Set, uses Trajan-Bold, else Trajan for the font</param>
        /// <param name="extraSprites">
        ///     Size 3 array of other sprite states for the button.  0 = Highlighted Sprite, 1 = Pressed
        ///     Sprited, 2 = Disabled Sprite
        /// </param>
        /// <returns></returns>
        public static GameObject CreateButton(GameObject parent, Action <int> action, int id, Sprite spr, string text,
                                              int fontSize, TextAnchor textAnchor, RectData rectData, bool bold = true, params Sprite[] extraSprites)
        {
            GameObject panel = CreateBasePanel(parent, rectData);

            CreateTextPanel(panel, text, fontSize, textAnchor, new RectData(new Vector2(0, 0), new Vector2(0, 0)),
                            bold);

            Image img = panel.AddComponent <Image>();

            img.sprite = spr;

            Button button = panel.AddComponent <Button>();

            button.targetGraphic = img;
            button.onClick.AddListener(delegate { action(id); });

            if (extraSprites.Length == 3)
            {
                button.transition    = Selectable.Transition.SpriteSwap;
                button.targetGraphic = img;
                SpriteState sprState = new SpriteState
                {
                    highlightedSprite = extraSprites[0],
                    pressedSprite     = extraSprites[1],
                    disabledSprite    = extraSprites[2]
                };

                button.spriteState = sprState;
            }
            else
            {
                button.transition = Selectable.Transition.None;
            }

            return(panel);
        }
Esempio n. 16
0
 public static Rect Deserialize(this RectData rectData)
 {
     return(new Rect(rectData.x, rectData.y, rectData.width, rectData.height));
 }
Esempio n. 17
0
 public bool isEquals(RectData rect)
 {
     return(MathUtils.floatEquals(x, rect.x) && MathUtils.floatEquals(y, rect.y) && MathUtils.floatEquals(width, rect.width) && MathUtils.floatEquals(height, rect.height));
 }
Esempio n. 18
0
        private static RectData ExtractRects([NotNull] UIElement element, ref Vector3 resolution)
        {
            var rects = new RectData
            {
                // note: render offset is calculated relatively to the container (which can be the same as the parent)
                Element = new RectangleF(element.RenderOffsets.X, element.RenderOffsets.Y, element.ActualWidth, element.ActualHeight)
            };
            var parent = element.VisualParent;

            if (parent is GridBase)
            {
                var rowIndex = element.GetGridRow();
                var rowSpan  = element.GetGridRowSpan();
                var colIndex = element.GetGridColumn();
                var colSpan  = element.GetGridColumnSpan();
                var grid     = parent as Grid;
                if (grid != null)
                {
                    var actualColumnDefinitions = grid.ActualColumnDefinitions;
                    var actualRowDefinitions    = grid.ActualRowDefinitions;

                    var accWidth = 0.0f;
                    for (var i = 0; i < colIndex && i < actualColumnDefinitions.Count; i++)
                    {
                        var definition = actualColumnDefinitions[i];
                        accWidth += definition.ActualSize;
                    }
                    var accHeight = 0.0f;
                    for (var i = 0; i < rowIndex && i < actualRowDefinitions.Count; i++)
                    {
                        var definition = actualRowDefinitions[i];
                        accHeight += definition.ActualSize;
                    }
                    rects.Parent = new RectangleF
                    {
                        X = -accWidth, Y = -accHeight, Width = parent.ActualWidth, Height = parent.ActualHeight,
                    };
                    accWidth = 0.0f;
                    for (var i = colIndex; i < colIndex + colSpan && i < actualColumnDefinitions.Count; i++)
                    {
                        var definition = actualColumnDefinitions[i];
                        accWidth += definition.ActualSize;
                    }
                    accHeight = 0.0f;
                    for (var i = rowIndex; i < rowIndex + rowSpan && i < actualRowDefinitions.Count; i++)
                    {
                        var definition = actualRowDefinitions[i];
                        accHeight += definition.ActualSize;
                    }
                    rects.Container = new RectangleF
                    {
                        X = 0, Y = 0, Width = accWidth, Height = accHeight,
                    };
                }
                var uniformGrid = parent as UniformGrid;
                if (uniformGrid != null)
                {
                    var cellWidth  = uniformGrid.ActualWidth / uniformGrid.Columns;
                    var cellHeight = uniformGrid.ActualHeight / uniformGrid.Rows;
                    rects.Parent = new RectangleF
                    {
                        X = -MathUtil.Clamp(colIndex, 0, uniformGrid.Columns - 1) * cellWidth, Y = -MathUtil.Clamp(rowIndex, 0, uniformGrid.Rows - 1) * cellHeight, Width = parent.ActualWidth, Height = parent.ActualHeight,
                    };
                    rects.Container = new RectangleF
                    {
                        X = 0, Y = 0, Width = MathUtil.Clamp(uniformGrid.Columns - colIndex, 1, colSpan) * cellWidth, Height = MathUtil.Clamp(uniformGrid.Rows - rowIndex, 1, rowSpan) * cellHeight,
                    };
                }
                rects.Siblings = (from c in parent.VisualChildren where c != element && c.GetGridRow() == rowIndex && c.GetGridColumn() == colIndex select new RectangleF(c.RenderOffsets.X, c.RenderOffsets.Y, c.ActualWidth, c.ActualHeight)).ToArray();
            }
            else if (parent != null)
            {
                rects.Parent    = new RectangleF(0, 0, parent.ActualWidth, parent.ActualHeight);
                rects.Container = rects.Parent;
                rects.Siblings  = (from c in parent.VisualChildren where c != element select new RectangleF(c.RenderOffsets.X, c.RenderOffsets.Y, c.ActualWidth, c.ActualHeight)).ToArray();
            }
            else
            {
                // no parent, take the whole UI resolution
                rects.Parent    = new RectangleF(0, 0, resolution.X, resolution.Y);
                rects.Container = rects.Parent;
                rects.Siblings  = new RectangleF[0];
            }
            return(rects);
        }
Esempio n. 19
0
        public RectData FindRect(HObject ho_Image, int threshold)
        {
            RectData myResult = new RectData();

            myResult.Found = false;

            try
            {
                HTuple  hv_Width, hv_Height, hv_Y, hv_X, hv_AngRad, hv_HalfWidth, hv_HalfLength, hv_PtOrder, hv_Mean, hv_Deviation;
                HObject hv_border, hv_selectedShape, hv_connection, ho_Rectangle, ho_ImageReduced;
                hv_Width      = new HTuple();
                hv_Height     = new HTuple();
                hv_Y          = new HTuple();
                hv_X          = new HTuple();
                hv_AngRad     = new HTuple();
                hv_HalfWidth  = new HTuple();
                hv_HalfLength = new HTuple();
                hv_PtOrder    = new HTuple();
                HTuple hv_Number = new HTuple();
                hv_Mean = new HTuple(); hv_Deviation = new HTuple();
                HOperatorSet.GenEmptyObj(out hv_border);
                HOperatorSet.GenEmptyObj(out hv_selectedShape);
                HOperatorSet.GenEmptyObj(out hv_connection);
                HOperatorSet.GenEmptyObj(out ho_Rectangle);
                HOperatorSet.GenEmptyObj(out ho_ImageReduced);

                HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
                HOperatorSet.SetWindowAttr("background_color", "black");

                HTuple hv_Row, hv_Column, hv_Phi;
                HTuple hv_Length1, hv_Length2;
                //Create template
                hv_Row     = 972;
                hv_Column  = 1290;
                hv_Phi     = 0;
                hv_Length1 = 1270;
                hv_Length2 = 500;

                string DataFileName = @"D:\Images\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\";
                //if (!Directory.Exists(DataFileName))
                //    Directory.CreateDirectory(DataFileName);
                //string temp1 = DataFileName + "Inspected" + DateTime.Now.ToString("HH_mm_ss");
                //HOperatorSet.WriteImage(ho_Image, "bmp", 0, temp1);

                ho_Rectangle.Dispose();
                HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Row, hv_Column, hv_Phi, hv_Length1, hv_Length2);

                //ho_ImageReduced.Dispose();
                //HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out ho_ImageReduced);

                //string temp1 = DataFileName + "ReducedInspected" + DateTime.Now.ToString("HH_mm_ss");
                //HOperatorSet.WriteImage(ho_ImageReduced, "bmp", 0, temp1);

                HOperatorSet.ThresholdSubPix(ho_Image, out hv_border, threshold);
                //HOperatorSet.EdgesSubPix(ho_Image, out hv_border, "canny", 0.9, 20, 40);
                HOperatorSet.SelectShapeXld(hv_border, out hv_selectedShape, "area", "and", 250000, 600000); //Alvin 28July16 2500


                HOperatorSet.CountObj(hv_selectedShape, out hv_Number);

                HOperatorSet.FitRectangle2ContourXld(hv_selectedShape, "tukey", -1, 0, 0, 3, 2, out hv_Y, out hv_X, out hv_AngRad,
                                                     out hv_HalfWidth, out hv_HalfLength, out hv_PtOrder);

                if (hv_X.Length != 0)
                {
                    for (int i = 0; i < hv_X.Length; i++)
                    {
                        ho_Rectangle.Dispose();
                        HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Y[i].D, hv_X[i].D, hv_AngRad[i].D, hv_HalfWidth[i].D, hv_HalfLength[i].D);
                        //HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Y[i], hv_X[i], hv_AngRad[i], hv_HalfWidth[i], hv_HalfLength[i]);
                        //string temp1 = DataFileName + "InspectedRectangle" + DateTime.Now.ToString("HH_mm_ss");
                        //HOperatorSet.WriteImage(ho_Rectangle, "bmp", 0, temp1);
                        HOperatorSet.Intensity(ho_Rectangle, ho_Image, out hv_Mean, out hv_Deviation);
                        myResult.Means = hv_Mean.D;

                        if (myResult.Means < 220)
                        {
                            myResult.Found    = true;
                            myResult.X        = hv_X[i].D;
                            myResult.Y        = hv_Y[i].D;
                            myResult.Angle    = hv_AngRad[i].D;
                            myResult.Width    = hv_HalfWidth[i].D * 2;
                            myResult.Height   = hv_HalfLength[i].D * 2;
                            myResult.isCircle = false;
                            //myResult.rect_border = ho_Rectangle;//hv_selectedShape;

                            if ((myResult.X < 200) || (myResult.Height < 170) || (myResult.Y < 300))
                            {
                                myResult.Found = false;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            { }

            return(myResult);

            //}
            //catch (HalconException HDevExpDefaultException)
            //{
            //    return myResult;
            //}
        }
Esempio n. 20
0
        public RectData FindCircle(HObject ho_Image)
        {
            RectData myResult = new RectData();
            HTuple   hv_Width, hv_Height, hv_Mean, hv_Deviation;

            HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
            HOperatorSet.SetWindowAttr("background_color", "black");
            HTuple  hv_RadiusCircle, hv_SizeSynthImage;
            HObject ho_Circle, ho_EmptyImage, ho_SyntheticModelImage, ho_ShapeModelImage, ho_ShapeModelRegion;
            HObject ho_ShapeModel;
            HTuple  hv_ModelID, hv_RowCheck = new HTuple(), hv_ColumnCheck = new HTuple();
            HTuple  hv_AngleCheck = new HTuple(), hv_ScaleCheck = new HTuple();
            HTuple  hv_Score = new HTuple(), hv_j = new HTuple(), hv_MovementOfObject = new HTuple();
            HTuple  hv_MoveAndScaleOfObject = new HTuple();

            hv_Mean = new HTuple();  hv_Deviation = new HTuple();
            HObject hV_reducedImg;

            //Init Variable
            HOperatorSet.GenEmptyObj(out ho_Circle);
            HOperatorSet.GenEmptyObj(out ho_EmptyImage);
            HOperatorSet.GenEmptyObj(out ho_SyntheticModelImage);
            HOperatorSet.GenEmptyObj(out ho_ShapeModelImage);
            HOperatorSet.GenEmptyObj(out ho_ShapeModelRegion);
            HOperatorSet.GenEmptyObj(out ho_ShapeModel);
            HOperatorSet.GenEmptyObj(out hV_reducedImg);
            //step 1: Generate Default Circle Shape
            hv_RadiusCircle   = 190;
            hv_SizeSynthImage = (2 * hv_RadiusCircle) + 10;
            ho_Circle.Dispose();
            HOperatorSet.GenEllipseContourXld(out ho_Circle, hv_SizeSynthImage / 2, hv_SizeSynthImage / 2,
                                              0, hv_RadiusCircle, hv_RadiusCircle, 0, 6.28318, "positive", 1.5);

            //step 2: create an image and insert the XLD
            ho_EmptyImage.Dispose();
            HOperatorSet.GenImageConst(out ho_EmptyImage, "byte", hv_SizeSynthImage, hv_SizeSynthImage);
            ho_SyntheticModelImage.Dispose();
            HOperatorSet.PaintXld(ho_Circle, ho_EmptyImage, out ho_SyntheticModelImage, 128);

            //step 3: create the model
            ho_ShapeModelImage.Dispose();
            ho_ShapeModelRegion.Dispose();
            HOperatorSet.InspectShapeModel(ho_SyntheticModelImage, out ho_ShapeModelImage, out ho_ShapeModelRegion, 1, 30);
            HOperatorSet.CreateScaledShapeModel(ho_SyntheticModelImage, "auto", 0, 0, 0.01,
                                                0.8, 1.2, "auto", "none", "use_polarity", 30, 10, out hv_ModelID);
            ho_ShapeModel.Dispose();
            HOperatorSet.GetShapeModelContours(out ho_ShapeModel, hv_ModelID, 1);



            //Step 4 : Find the Circle
            HOperatorSet.FindScaledShapeModel(ho_Image, hv_ModelID, 0, 0, 0.4,
                                              1.6, 0.6, 0, 0.5, "least_squares", 3, 0, out hv_RowCheck, out hv_ColumnCheck,
                                              out hv_AngleCheck, out hv_ScaleCheck, out hv_Score);

            List <DPoint> CirCtr = new List <DPoint>();

            if ((hv_Score.Length != 0) && (hv_RadiusCircle > 100))
            {
                for (int i = 0; i < hv_Score.Length; i++)
                {
                    CirCtr.Add(new DPoint(hv_ColumnCheck[i].D, hv_RowCheck[i].D));

                    HObject ho_Rect = new HObject();
                    HOperatorSet.GenCircle(out ho_Rect, hv_RowCheck[i].D, hv_ColumnCheck[i].D, hv_RadiusCircle * hv_ScaleCheck[i].D);
                    HOperatorSet.Intensity(ho_Rect, ho_Image, out hv_Mean, out hv_Deviation);
                    //myResult.Means = hv_Mean.D;
                    //HOperatorSet.RegionToLabel(ho_Rect, out myResult.InspectedImage, "byte", hv_RadiusCircle * hv_ScaleCheck[i].D * 2, hv_RadiusCircle * hv_ScaleCheck[i].D * 2);

                    //string DataFileName = @"D:\";
                    //string temp1 = DataFileName + "Test";
                    //HOperatorSet.WriteImage(myResult.InspectedImage, "bmp", 0, temp1);

                    if ((hv_Mean.D > 100))//(myResult.Means < 220) &&
                    {
                        HOperatorSet.ReduceDomain(ho_Image, ho_Rect, out hV_reducedImg);
                        HOperatorSet.CropDomain(hV_reducedImg, out myResult.InspectedImage);
                        myResult.Found    = true;
                        myResult.X        = hv_ColumnCheck[i].D;
                        myResult.Y        = hv_RowCheck[i].D;
                        myResult.Radius   = hv_RadiusCircle * hv_ScaleCheck[i].D;
                        myResult.isCircle = true;
                        myResult.Means    = hv_Mean.D;
                        //break;
                    }
                    //myResult.InspectedImage = ho_Rect;
                }
            }


            //if (myResult.Found)
            //{
            //    if (CirCtr.Count == 2)
            //    {
            //        myResult.Angle = Helper.GetRadianAngleBetween(CirCtr[0], CirCtr[1]);
            //    }
            //}
            return(myResult);
        }
Esempio n. 21
0
        public RectData FindRectNew(HObject ho_Image, double calival)
        {
            RectData myResult = new RectData();

            myResult.Found = false;

            try
            {
                HTuple  hv_Width, hv_Height, hv_Mean, hv_Deviation;
                HObject ho_Rect, ho_EmptyImage, hv_selectedShape, ho_ConnectedRegion, ho_ShapeModelRegion, hV_reducedImg;
                HObject ho_ShapeModel;
                HTuple  hv_RowCheck = new HTuple(), hv_ColumnCheck = new HTuple();
                HTuple  hv_AngleCheck = new HTuple(), hv_ScaleCheck = new HTuple();
                HTuple  hv_Score = new HTuple(), hv_j = new HTuple(), hv_MovementOfObject = new HTuple();
                HTuple  hv_MoveAndScaleOfObject = new HTuple();
                hv_Mean = new HTuple(); hv_Deviation = new HTuple();

                HTuple  hv_Y, hv_X, hv_AngRad, hv_HalfWidth, hv_HalfLength, hv_PtOrder;
                HObject ho_Rectangle;
                hv_Width      = new HTuple();
                hv_Height     = new HTuple();
                hv_Y          = new HTuple();
                hv_X          = new HTuple();
                hv_AngRad     = new HTuple();
                hv_HalfWidth  = new HTuple();
                hv_HalfLength = new HTuple();
                hv_PtOrder    = new HTuple();
                HTuple hv_Number = new HTuple();

                //Init Variable
                HOperatorSet.GenEmptyObj(out ho_Rect);
                HOperatorSet.GenEmptyObj(out ho_EmptyImage);
                HOperatorSet.GenEmptyObj(out hv_selectedShape);
                HOperatorSet.GenEmptyObj(out ho_ConnectedRegion);
                HOperatorSet.GenEmptyObj(out ho_ShapeModelRegion);
                HOperatorSet.GenEmptyObj(out ho_ShapeModel);
                HOperatorSet.GenEmptyObj(out hV_reducedImg);
                //HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
                //HOperatorSet.SetWindowAttr("background_color", "black");

                HOperatorSet.Threshold(ho_Image, out ho_ShapeModelRegion, Para.Threshold, 255);
                HOperatorSet.Connection(ho_ShapeModelRegion, out ho_ConnectedRegion);
                //HOperatorSet.CountObj(ho_ConnectedRegion, out hv_Number);

                HOperatorSet.SelectShape(ho_ConnectedRegion, out hv_selectedShape, "area", "and", 150000, 330000); //Alvin 28July16 2500
                HOperatorSet.SmallestRectangle2(hv_selectedShape, out hv_Y, out hv_X, out hv_AngRad, out hv_HalfWidth, out hv_HalfLength);


                if (hv_X.Length != 0)
                {
                    //20161224@Brando
                    int    i      = 0;
                    HTuple h_temp = 0;
                    for (int t = 0; t < hv_X.Length; t++)
                    {
                        if (hv_Y[t] > h_temp)
                        {
                            h_temp = hv_Y[t];
                            i      = t;
                        }
                    }
                    HOperatorSet.GenRectangle2(out ho_Rectangle, hv_Y[i].D, hv_X[i].D, hv_AngRad[i].D, hv_HalfWidth[i].D, hv_HalfLength[i].D);
                    HOperatorSet.Intensity(ho_Rectangle, ho_Image, out hv_Mean, out hv_Deviation);
                    myResult.Means = hv_Mean.D;
                    //20161027
                    HOperatorSet.ReduceDomain(ho_Image, ho_Rectangle, out hV_reducedImg);
                    HOperatorSet.CropDomain(hV_reducedImg, out myResult.InspectedImage);
                    if ((myResult.Means < 230))//20161101 FROM 220 TO 230
                    {
                        myResult.Found    = true;
                        myResult.X        = hv_X[i].D;
                        myResult.Y        = hv_Y[i].D;
                        myResult.Angle    = hv_AngRad[i].D;
                        myResult.Width    = hv_HalfWidth[i].D * 2;
                        myResult.Height   = hv_HalfLength[i].D * 2;
                        myResult.isCircle = false;
                        //myResult.rect_border = ho_Rectangle;//hv_selectedShape;

                        if (Para.isWidth818)
                        {
                            if ((myResult.X < 200) || (myResult.Height < 170) || (myResult.Y < 300) || (myResult.Width < (7.721 / calival)) || (myResult.Width > (8.639 / calival)) || (myResult.Angle * 180 / 3.14 > 10) || (myResult.Angle * 180 / 3.14 < -10))
                            {
                                myResult.Found = false;
                            }
                        }
                        else
                        {
                            if ((myResult.X < 200) || (myResult.Height < 170) || (myResult.Y < 300) || (myResult.Width < (8.74 / calival)) || (myResult.Width > 9.66 / calival) || (myResult.Angle * 180 / 3.14 > 10) || (myResult.Angle * 180 / 3.14 < -10))
                            {
                                myResult.Found = false;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            { }
            return(myResult);
        }
        /*
         *   ██████╗██╗  ██╗███████╗ ██████╗██╗  ██╗██████╗  ██████╗ ██╗  ██╗
         *  ██╔════╝██║  ██║██╔════╝██╔════╝██║ ██╔╝██╔══██╗██╔═══██╗╚██╗██╔╝
         *  ██║     ███████║█████╗  ██║     █████╔╝ ██████╔╝██║   ██║ ╚███╔╝
         *  ██║     ██╔══██║██╔══╝  ██║     ██╔═██╗ ██╔══██╗██║   ██║ ██╔██╗
         *  ╚██████╗██║  ██║███████╗╚██████╗██║  ██╗██████╔╝╚██████╔╝██╔╝ ██╗
         *   ╚═════╝╚═╝  ╚═╝╚══════╝ ╚═════╝╚═╝  ╚═╝╚═════╝  ╚═════╝ ╚═╝  ╚═╝
         */
        /// <summary>
        ///     Creates a checkbox
        /// </summary>
        /// <param name="parent">The Parent GameObject for this Checkbox</param>
        /// <param name="action">Action to take when butotn is clicked</param>
        /// <param name="boxBgSprite">Sprite to use for the background of the box</param>
        /// <param name="boxFgSprite">Sprite to use for the foreground of the box</param>
        /// <param name="text">Text for the Checkbox</param>
        /// <param name="fontSize">Size of the Text</param>
        /// <param name="textAnchor">Where to Anchor the text within the checkbox</param>
        /// <param name="rectData">The rectangle description for this checkbox</param>
        /// <param name="bold">If Set, uses Trajan-Bold, else Trajan for the font</param>
        /// <param name="isOn">Determines if the initial state of the checkbox is checked or not</param>
        /// <returns></returns>
        public static GameObject CreateToggle(GameObject parent, Action <bool> action, Sprite boxBgSprite,
                                              Sprite boxFgSprite, string text, int fontSize, TextAnchor textAnchor, RectData rectData, bool bold = true,
                                              bool isOn = false)
        {
            GameObject panel = CreateBasePanel(parent, rectData);

            GameObject boxBg = CreateImagePanel(panel, boxBgSprite, rectData);
            GameObject boxFg = CreateImagePanel(boxBg, boxFgSprite, rectData);
            //GameObject label = CreateTextPanel(panel, text, fontSize, TextAnchor.UpperLeft, rectData, bold);

            Toggle toggle = panel.AddComponent <Toggle>();

            toggle.isOn = isOn;

            toggle.targetGraphic = boxBg.GetComponent <Image>();
            toggle.graphic       = boxFg.GetComponent <Image>();

            toggle.transition = Selectable.Transition.ColorTint;

            ColorBlock cb = new ColorBlock
            {
                normalColor      = new Color(1, 1, 1, 1),
                highlightedColor = new Color(1, 1, 1, 1),
                pressedColor     = new Color(0.8f, 0.8f, 0.8f, 1.0f),
                disabledColor    = new Color(0.8f, 0.8f, 0.8f, 0.5f),
                fadeDuration     = 0.1f
            };

            toggle.colors = cb;

            toggle.onValueChanged.AddListener(delegate(bool b) { action(b); });

            ToggleGroup group = parent.GetComponent <ToggleGroup>();

            if (group != null)
            {
                toggle.group = group;
            }

            return(panel);
        }
Esempio n. 23
0
        public static GameObject CreateTMProPanel(GameObject parent, string text, float fontSize, TextAnchor textAnchor, RectData rectData)
        {
            GameObject panel = CreateBasePanel(parent, rectData);

            TextMeshProUGUI textObj = panel.AddComponent <TextMeshProUGUI>();

            textObj.font     = UIFont;
            textObj.text     = text;
            textObj.fontSize = fontSize;

            return(panel);
        }
 /// <summary>
 ///     Creates a Text Object
 /// </summary>
 /// <param name="parent">The GameObject that this text will be put into.</param>
 /// <param name="text">The text that will be shown with this object</param>
 /// <param name="fontSize">The text's font size.</param>
 /// <param name="textAnchor">The location within the rectData where the text anchor should be.</param>
 /// <param name="rectData">Rectangle Data to describe the Text Panel.</param>
 /// <param name="bold">If True, TrajanBold will be the font used, else TrajanNormal</param>
 /// <returns></returns>
 public static GameObject CreateTextPanel(GameObject parent, string text, int fontSize, TextAnchor textAnchor,
                                          RectData rectData, bool bold = true)
 {
     return(CreateTextPanel(parent, text, fontSize, textAnchor, rectData, bold ? TrajanBold : TrajanNormal));
 }
Esempio n. 25
0
        /// <summary>
        /// 区画を細かく分割する
        /// </summary>
        /// <param name="rparentData"></param>
        /// <param name="isVertical"></param>
        private IEnumerator <float> SplitRect(RectData parentData, bool isVertical)
        {
            // 分ける区画情報を取得
            var parentRect = parentData.rect;
            var data       = _builderData;

            RectData childRect = null;

            int pointA, pointB, distance, point;

            // 分割する
            if (isVertical)
            {
                // 縦

                if (parentRect.height < (data.RoomMinSize + 3) * 2 + 1)
                {
                    yield break;
                }

                // 上部のA点を求める
                pointA = data.RoomMinSize + 3;

                // 下部のB点を求める
                pointB = parentRect.height - data.RoomMinSize - 4;

                // ABの距離を求める
                distance = pointB - pointA;

                // AB間のどこかに決定する
                point = pointA + UnityEngine.Random.Range(0, distance + 1);

                // 新しく右の区画を作成する
                childRect = _mapRect.CreateRect(parentRect.xMin, parentRect.yMin + point, parentRect.xMax, parentRect.yMax);

                // 元の区画の下をpointに移動させて、上側の区間とする
                parentData.rect.yMax = childRect.rect.yMin;
            }
            else
            {
                // 横

                // 区分を分割できるか?チェック
                if (parentRect.width < (data.RoomMinSize + 3) * 2 + 1)
                {
                    // 分割できるほど広くないので終了
                    yield break;
                }

                // 左端のA点を求める
                pointA = data.RoomMinSize + 3;

                // 右端のB点を求める
                pointB = parentRect.width - data.RoomMinSize - 4;

                // ABの距離を求める
                distance = pointB - pointA;

                // AB間のどこかに決定する
                point = pointA + UnityEngine.Random.Range(0, distance + 1);

                // 新しく右の区画を作成する
                childRect = _mapRect.CreateRect(parentRect.xMin + point, parentRect.yMin, parentRect.xMax, parentRect.yMax);

                // 元の区画の右をpointに移動させて、左側の区間とする
                parentData.rect.xMax = childRect.rect.xMin;
            }

            // 隣接している区画のデータ
            _mapRect.ConnectNeighbor(childRect);


            // 最新のRectを返すか一個前のRectを返すかをランダムで決める
            if (UnityEngine.Random.Range(0, 2) == 1)
            {
                var tmp = parentData.rect;
                parentData.rect = childRect.rect;
                childRect.rect  = tmp;
            }

            yield return(0.5f);

            var enumerator = SplitRect(childRect, isVertical: !isVertical);

            while (enumerator.MoveNext())
            {
                yield return(enumerator.Current);
            }
        }