예제 #1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            PatternType svr    = (PatternType)value;
            string      svrstr = svr.ToString().ToLower();

            switch (svr)
            {
            case PatternType.RegexWord:
                svrstr = "regex-word";
                break;
            }
            writer.WriteValue(svrstr);
            writer.WriteValue(svr.ToString().ToLower());
        }
예제 #2
0
        public static void Erase(string path, List <PatternType> patterns, int scale, MagickColor color)
        {
            if (patterns.Count < 1)
            {
                return;
            }
            MagickImage img = IOUtils.ReadImage(path);

            if (img == null)
            {
                return;
            }
            PatternType chosenPattern = GetRandomPatternType(patterns);

            PreProcessing(path, "- Pattern: " + chosenPattern.ToString());
            Random      rand       = new Random();
            MagickImage patternImg = new MagickImage(GetInpaintImage(chosenPattern));

            patternImg.FilterType = FilterType.Point;
            patternImg.Colorize(color, new Percentage(100));
            patternImg.BackgroundColor = MagickColors.Transparent;
            patternImg.Rotate(RandRange(0, 360));
            double geomW = img.Width * RandRange(1.0f, 2.0f) * GetScaleMultiplier(scale);
            double geomH = img.Height * RandRange(1.0f, 2.0f) * GetScaleMultiplier(scale);
            //Logger.Log("geomW: " + geomW + " - geomH: " + geomW);
            MagickGeometry upscaleGeom = new MagickGeometry(Math.Round(geomW) + "x" + Math.Round(geomH) + "!");

            patternImg.Resize(upscaleGeom);
            patternImg.BitDepth(Channels.Alpha, 1);
            img.Composite(patternImg, Gravity.Center, CompositeOperator.Over);
            img.Write(path);
            PostProcessing(img, path, path);
        }
        public void DoPatternExample(PatternType patternType)
        {
            string          patternTypeName = patternType.ToString();
            IPatternExample patternExample  = (IPatternExample)Assembly.Load("designPatterns").CreateInstance($"designPatterns.{patternTypeName}.{patternTypeName}Example");

            patternExample.DoWork();
        }
예제 #4
0
        private static string GetPatternKey(IReadOnlyList <PhraseElement> elements, int windowStart, int windowEnd, PatternType patternType)
        {
            var key = patternType.ToString();

            for (var i = windowStart; i <= windowEnd; i++)
            {
                key += ","
                       + elements[i].Note
                       + "_"
                       + elements[i].Duration;
            }
            return(key);
        }
        /// <summary>
        /// Creates prefabs in the given pattern
        /// </summary>
        void Start()
        {
            //Create Pattern using PatternFactory class
            Pattern pattern = PatternFactory.CreatePattern(type, size); //type selected from dropdown in Unity editor

            //Create folder to file each prefab in
            folder = new GameObject(type.ToString() + " Prefabs (" + pattern.Count + ")");
            folder.transform.SetParent(transform);

            //Generate a prefab facing up and down at each point
            foreach (Vector3 point in pattern)
            {
                GeneratePrefab(point, maxHeight);
                GeneratePrefab(point, -1 * maxHeight);
            }
        }
예제 #6
0
        /// <summary>
        /// Generate a OpenCV compatible pattern for recognition.
        /// </summary>
        /// <param name="patternSize"></param>
        /// <param name="patternType"></param>
        /// <param name="resolution"></param>
        /// <param name="renderTexture"></param>
        /// <param name="material"></param>
        /// <param name="border">Relative to tile size</param>
        /// <param name="invert"></param>
        /// <returns>Border size (uv space)</returns>
        public static Vector2 RenderPattern(Vector2Int patternSize, PatternType patternType, int resolutionMax, ref RenderTexture renderTexture, ref Material material, float border = 0, bool invert = false)
        {
            // Sanitize.
            if (border < 0)
            {
                border = 0;
            }
            int patternSizeMin = patternType == PatternType.Chessboard ? 3 : 2;

            if (patternSize.x < patternSizeMin)
            {
                patternSize.x = patternSizeMin;
            }
            if (patternSize.y < patternSizeMin)
            {
                patternSize.y = patternSizeMin;
            }

            // Compute placement.
            bool       isAsym    = patternType == PatternType.AsymmetricCircleGrid;
            Vector2Int tileCount = patternSize - Vector2Int.one;
            Vector2    step;

            if (isAsym)
            {
                step = new Vector2(1 / (tileCount.x + 0.5f), 1 / (float)tileCount.y);
            }
            else
            {
                step = new Vector2(1 / (float)tileCount.x, 1 / (float)tileCount.y);
            }
            step.x = step.x / (1 + step.x * border * 2);
            step.y = step.y / (1 + step.y * border * 2 * (isAsym ? 2 : 1));
            Vector2 tilCountWithBorders = tileCount + Vector2.one * (border * 2);
            float   textureAspect;

            if (isAsym)
            {
                textureAspect = (tilCountWithBorders.x + 0.5f) / (tilCountWithBorders.y - tileCount.y * 0.5f);
            }
            else
            {
                textureAspect = tilCountWithBorders.x / tilCountWithBorders.y;
            }
            Vector2    textureProportion = textureAspect > 1 ? new Vector2(1, 1 / textureAspect) : new Vector2(textureAspect, 1);
            Vector2Int resolution        = new Vector2Int(Mathf.RoundToInt(textureProportion.x * resolutionMax), Mathf.RoundToInt(textureProportion.y * resolutionMax));
            Vector2    zero = new Vector2(step.x * border, 1 - step.y * border);

            if (isAsym)
            {
                zero.y = 1 - step.y * border * 2;
            }

            // Ensure resources.
            if (renderTexture == null || renderTexture.width != resolution.x || renderTexture.height != resolution.y)
            {
                if (renderTexture)
                {
                    renderTexture.Release();
                }
                renderTexture = new RenderTexture(resolution.x, resolution.y, 16, GraphicsFormat.R8G8B8A8_UNorm);
                renderTexture.Create();
                renderTexture.name     = patternType.ToString();
                renderTexture.wrapMode = TextureWrapMode.Repeat;
            }
            if (!material)
            {
                material = new Material(Shader.Find("Unlit/Color"));
            }

            // Setup.
            Graphics.SetRenderTarget(renderTexture);
            GL.modelview = Matrix4x4.identity;
            GL.LoadOrtho();
            GL.Clear(true, true, invert ? Color.black : Color.white);

            // Render.
            material.color = invert ? Color.white : Color.black;
            material.SetPass(0);
            switch (patternType)
            {
            case PatternType.Chessboard:
                GL.Begin(GL.QUADS);
                for (int ny = 0; ny < tileCount.y; ny++)
                {
                    float y = zero.y - ny * step.y;
                    for (int nx = 0; nx < tileCount.x; nx++)
                    {
                        if ((nx + (ny % 2 == 0 ? 1 : 0)) % 2 == 1)
                        {
                            continue;                                          // Upper-left corner must be white.
                        }
                        float x = zero.x + nx * step.x;                        // - 1;
                        GL.Vertex3(x, y, 0);
                        GL.Vertex3(x + step.x, y, 0);
                        GL.Vertex3(x + step.x, y - step.y, 0);
                        GL.Vertex3(x, y - step.y, 0);
                    }
                }
                GL.End();
                break;

            case PatternType.CircleGrid:
            case PatternType.AsymmetricCircleGrid:

                // These values are set from experimentation.
                const float asymCircleSize   = 0.10f;                                   // When too large, the points are also recognised as a chess pattern
                const float symCircleSyize   = 0.08f;
                const int   circleResolution = 128;

                Vector2 circleSize = new Vector2(1 / textureProportion.x, 1 / textureProportion.y) * (textureAspect > 1 ? step.x : step.y * 2);
                circleSize *= isAsym ? asymCircleSize : symCircleSyize;
                for (int ny = 0; ny < patternSize.y; ny++)
                {
                    float y  = zero.y - ny * step.y;
                    float ax = isAsym && ny % 2 == 1 ? step.x * 0.5f : 0;
                    for (int nx = 0; nx < patternSize.x; nx++)
                    {
                        float x = zero.x + nx * step.x + ax;
                        GL.Begin(GL.TRIANGLE_STRIP);
                        for (int p = 0; p < circleResolution; p++)
                        {
                            float a = (p / (float)circleResolution) * Mathf.PI * 2;
                            GL.Vertex3(x + Mathf.Cos(a) * circleSize.x, y + Mathf.Sin(a) * circleSize.y, 0);
                            GL.Vertex3(x, y, 0);
                        }
                        GL.Vertex3(x + circleSize.x, y, 0);
                        GL.End();
                    }
                }
                break;
            }

            // Finish.
            Graphics.SetRenderTarget(null);

            return(new Vector2(zero.x, 1 - zero.y));
        }
예제 #7
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            PatternType svr = (PatternType)value;

            writer.WriteValue(svr.ToString().ToLower());
        }
예제 #8
0
 public override string ToString()
 {
     return($"Index: {Index}, Length: {Length}, Pattern: {(HasPattern ? Pattern.ToString() : false.ToString())}, Exponent: {(HasExponent ? Exponent.ToString() : false.ToString())}, Nb: {(OverrideGlobalNb ? NeededBits.ToString() : false.ToString())}, Method: {Method?.GetType().Name}");
 }
예제 #9
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);
            if (e.Index >= 0)
            {
                PatternType pattern1 = (PatternType)Enum.Parse(typeof(PatternType), base.Items[e.Index].ToString(), false);
                Color       color1   = this.backColor;
//                DrawItemState state1 = e.State;
                Rectangle rectangle1 = e.Bounds;
                rectangle1.Inflate(-1, -1);
                rectangle1.Height--;
                if (e.State == DrawItemState.Selected)
                {
                    e.Graphics.DrawRectangle(SystemPens.Highlight, rectangle1);
                }
                if (pattern1 == PatternType.None)
                {
                    this.stringFormate.Alignment = StringAlignment.Center;
                    e.Graphics.DrawString("нч", e.Font, Brushes.Black, (RectangleF)e.Bounds, this.stringFormate);
                }
                else
                {
                    if (pattern1 < PatternType.Center)
                    {
                        this.stringFormate.Alignment = StringAlignment.Near;
                        HatchStyle style1 = (HatchStyle)Enum.Parse(typeof(HatchStyle), pattern1.ToString(), false);
                        using (Brush brush1 = new HatchBrush(style1, this.foreColor, color1))
                        {
                            rectangle1.Width           = 30;
                            e.Graphics.RenderingOrigin = rectangle1.Location;
                            e.Graphics.FillRectangle(brush1, rectangle1);
                            e.Graphics.DrawRectangle(Pens.Black, rectangle1);
                            e.Graphics.DrawString(pattern1.ToString(), e.Font, Brushes.Black, new RectangleF((float)(rectangle1.Right + 6), (float)rectangle1.Y, (float)e.Bounds.Width, (float)rectangle1.Height), this.stringFormate);
                            return;
                        }
                    }
                    this.stringFormate.Alignment = StringAlignment.Near;
                    using (GraphicsPath path1 = new GraphicsPath())
                    {
                        float[] singleArray1;
                        Color[] colorArray1;
                        switch (pattern1)
                        {
                        case PatternType.Center:
                        {
                            break;
                        }

                        case PatternType.DiagonalLeft:
                        {
                            goto Label_05AC;
                        }

                        case PatternType.DiagonalRight:
                        {
                            goto Label_06D0;
                        }

                        case PatternType.HorizontalCenter:
                        {
                            goto Label_0488;
                        }

                        case PatternType.LeftRight:
                        {
                            goto Label_07F4;
                        }

                        case PatternType.TopBottom:
                        {
                            goto Label_08FC;
                        }

                        case PatternType.VerticalCenter:
                        {
                            goto Label_0364;
                        }

                        default:
                        {
                            return;
                        }
                        }
                        path1.AddEllipse(rectangle1.X, rectangle1.Y, 30, rectangle1.Height);
                        using (PathGradientBrush brush2 = new PathGradientBrush(path1))
                        {
                            rectangle1.Width = 30;
                            ColorBlend blend1 = new ColorBlend();
                            singleArray1               = new float[2];
                            singleArray1[1]            = 1f;
                            blend1.Positions           = singleArray1;
                            colorArray1                = new Color[] { this.backColor, this.foreColor };
                            blend1.Colors              = colorArray1;
                            brush2.InterpolationColors = blend1;
                            brush2.CenterPoint         = new PointF(rectangle1.X + (((float)rectangle1.Width) / 2f), rectangle1.Y + (((float)rectangle1.Height) / 2f));
                            e.Graphics.FillRectangle(new SolidBrush(this.backColor), rectangle1);
                            e.Graphics.FillRectangle(brush2, rectangle1);
                            e.Graphics.DrawRectangle(Pens.Black, rectangle1);
                            blend1 = null;
                            e.Graphics.DrawString(pattern1.ToString(), e.Font, Brushes.Black, new RectangleF((float)(rectangle1.Right + 6), (float)rectangle1.Y, (float)e.Bounds.Width, (float)rectangle1.Height), this.stringFormate);
                            return;
                        }
Label_0364:
                        rectangle1.Width = 30;
                        using (LinearGradientBrush brush3 = new LinearGradientBrush(rectangle1, this.backColor, this.foreColor, LinearGradientMode.Vertical))
                        {
                            ColorBlend blend2 = new ColorBlend();
                            singleArray1               = new float[3];
                            singleArray1[1]            = 0.5f;
                            singleArray1[2]            = 1f;
                            blend2.Positions           = singleArray1;
                            colorArray1                = new Color[] { this.backColor, this.foreColor, this.backColor };
                            blend2.Colors              = colorArray1;
                            brush3.InterpolationColors = blend2;
                            e.Graphics.FillRectangle(brush3, rectangle1);
                            e.Graphics.DrawRectangle(Pens.Black, rectangle1);
                            blend2 = null;
                            e.Graphics.DrawString(pattern1.ToString(), e.Font, Brushes.Black, new RectangleF((float)(rectangle1.Right + 6), (float)rectangle1.Y, (float)e.Bounds.Width, (float)rectangle1.Height), this.stringFormate);
                            return;
                        }
Label_0488:
                        rectangle1.Width = 30;
                        using (LinearGradientBrush brush4 = new LinearGradientBrush(rectangle1, this.backColor, this.foreColor, LinearGradientMode.Horizontal))
                        {
                            ColorBlend blend3 = new ColorBlend();
                            singleArray1               = new float[3];
                            singleArray1[1]            = 0.5f;
                            singleArray1[2]            = 1f;
                            blend3.Positions           = singleArray1;
                            colorArray1                = new Color[] { this.backColor, this.foreColor, this.backColor };
                            blend3.Colors              = colorArray1;
                            brush4.InterpolationColors = blend3;
                            e.Graphics.FillRectangle(brush4, rectangle1);
                            e.Graphics.DrawRectangle(Pens.Black, rectangle1);
                            blend3 = null;
                            e.Graphics.DrawString(pattern1.ToString(), e.Font, Brushes.Black, new RectangleF((float)(rectangle1.Right + 6), (float)rectangle1.Y, (float)e.Bounds.Width, (float)rectangle1.Height), this.stringFormate);
                            return;
                        }
Label_05AC:
                        rectangle1.Width = 30;
                        using (LinearGradientBrush brush5 = new LinearGradientBrush(rectangle1, this.backColor, this.foreColor, LinearGradientMode.ForwardDiagonal))
                        {
                            ColorBlend blend4 = new ColorBlend();
                            singleArray1               = new float[3];
                            singleArray1[1]            = 0.5f;
                            singleArray1[2]            = 1f;
                            blend4.Positions           = singleArray1;
                            colorArray1                = new Color[] { this.backColor, this.foreColor, this.backColor };
                            blend4.Colors              = colorArray1;
                            brush5.InterpolationColors = blend4;
                            e.Graphics.FillRectangle(brush5, rectangle1);
                            e.Graphics.DrawRectangle(Pens.Black, rectangle1);
                            blend4 = null;
                            e.Graphics.DrawString(pattern1.ToString(), e.Font, Brushes.Black, new RectangleF((float)(rectangle1.Right + 6), (float)rectangle1.Y, (float)e.Bounds.Width, (float)rectangle1.Height), this.stringFormate);
                            return;
                        }
Label_06D0:
                        rectangle1.Width = 30;
                        using (LinearGradientBrush brush6 = new LinearGradientBrush(rectangle1, this.backColor, this.foreColor, LinearGradientMode.BackwardDiagonal))
                        {
                            ColorBlend blend5 = new ColorBlend();
                            singleArray1               = new float[3];
                            singleArray1[1]            = 0.5f;
                            singleArray1[2]            = 1f;
                            blend5.Positions           = singleArray1;
                            colorArray1                = new Color[] { this.backColor, this.foreColor, this.backColor };
                            blend5.Colors              = colorArray1;
                            brush6.InterpolationColors = blend5;
                            e.Graphics.FillRectangle(brush6, rectangle1);
                            e.Graphics.DrawRectangle(Pens.Black, rectangle1);
                            blend5 = null;
                            e.Graphics.DrawString(pattern1.ToString(), e.Font, Brushes.Black, new RectangleF((float)(rectangle1.Right + 6), (float)rectangle1.Y, (float)e.Bounds.Width, (float)rectangle1.Height), this.stringFormate);
                            return;
                        }
Label_07F4:
                        rectangle1.Width = 30;
                        using (LinearGradientBrush brush7 = new LinearGradientBrush(rectangle1, this.backColor, this.foreColor, LinearGradientMode.Horizontal))
                        {
                            ColorBlend blend6 = new ColorBlend();
                            singleArray1               = new float[2];
                            singleArray1[1]            = 1f;
                            blend6.Positions           = singleArray1;
                            colorArray1                = new Color[] { this.backColor, this.foreColor };
                            blend6.Colors              = colorArray1;
                            brush7.InterpolationColors = blend6;
                            e.Graphics.FillRectangle(brush7, rectangle1);
                            e.Graphics.DrawRectangle(Pens.Black, rectangle1);
                            blend6 = null;
                            e.Graphics.DrawString(pattern1.ToString(), e.Font, Brushes.Black, new RectangleF((float)(rectangle1.Right + 6), (float)rectangle1.Y, (float)e.Bounds.Width, (float)rectangle1.Height), this.stringFormate);
                            return;
                        }
Label_08FC:
                        rectangle1.Width = 30;
                        using (LinearGradientBrush brush8 = new LinearGradientBrush(rectangle1, this.backColor, this.foreColor, LinearGradientMode.Vertical))
                        {
                            ColorBlend blend7 = new ColorBlend();
                            singleArray1               = new float[2];
                            singleArray1[1]            = 1f;
                            blend7.Positions           = singleArray1;
                            colorArray1                = new Color[] { this.backColor, this.foreColor };
                            blend7.Colors              = colorArray1;
                            brush8.InterpolationColors = blend7;
                            e.Graphics.FillRectangle(brush8, rectangle1);
                            e.Graphics.DrawRectangle(Pens.Black, rectangle1);
                            blend7 = null;
                            e.Graphics.DrawString(pattern1.ToString(), e.Font, Brushes.Black, new RectangleF((float)(rectangle1.Right + 6), (float)rectangle1.Y, (float)e.Bounds.Width, (float)rectangle1.Height), this.stringFormate);
                        }
                    }
                }
            }
        }
예제 #10
0
        private void timerPattern_Tick(object sender, EventArgs e)
        {
            PatCount++;
            frmPtrnOnDspl.SetPattern(pType, (PatSize + 1) / 2, dir, PatSize % 2 == 1);
            if (chbxPattern.Checked)
            {
                frmPtrnOnDspl.DrawToBitmap(fposbmp, new Rectangle(0, 0, frmPtrnOnDspl.Width, frmPtrnOnDspl.Height));
                fposbmp.Save(linkLabel1.Text + "\\" + pType.ToString() + dir.ToString() + ((PatSize + 1) / 2).ToString() + (PatSize % 2 == 1).ToString() + ".png");
            }
            if (chbxCamA.Checked && picBoxA.Image != null)
            {
                picBoxA.Image.Save(linkLabel1.Text + "\\" + pType.ToString() + dir.ToString() + ((PatSize + 1) / 2).ToString() + (PatSize % 2 == 1).ToString() + "CamA.png");
            }
            if (chbxCamB.Checked && picBoxB.Image != null)
            {
                picBoxB.Image.Save(linkLabel1.Text + "\\" + pType.ToString() + dir.ToString() + ((PatSize + 1) / 2).ToString() + (PatSize % 2 == 1).ToString() + "CamB.png");
            }
            if (chbxCamC.Checked && picBoxC.Image != null)
            {
                picBoxC.Image.Save(linkLabel1.Text + "\\" + pType.ToString() + dir.ToString() + ((PatSize + 1) / 2).ToString() + (PatSize % 2 == 1).ToString() + "CamB.png");
            }
            if (chbxCamD.Checked && picBoxD.Image != null)
            {
                picBoxD.Image.Save(linkLabel1.Text + "\\" + pType.ToString() + dir.ToString() + ((PatSize + 1) / 2).ToString() + (PatSize % 2 == 1).ToString() + "CamB.png");
            }

            if (PatSize % 2 == 0)
            {
                PatSize--;
            }
            else
            {
                PatSize = 1 + PatSize / 2;
                if (PatSize % 2 == 1)
                {
                    PatSize--;
                }
                if (PatSize < 8)
                {
                    if (pType == PatternType.Strip)
                    {
                        if (dir == Orientation.Horizontal)
                        {
                            dir     = Orientation.Vertical;
                            PatSize = (frmPtrnOnDspl.Width / 3) * 2;
                        }
                        else
                        {
                            pType   = PatternType.Lattice;
                            PatSize = (frmPtrnOnDspl.Width / 3) * 2;
                        }
                    }
                    else
                    {
                        sw.Stop();
                        lblInfo.Text         = "Number of Patterns : " + PatCount.ToString() + " , Elapsed Time = " + sw.ElapsedMilliseconds.ToString() + " (ms)";
                        timerPattern.Enabled = false;
                        btnDoIt.Text         = "Do It!";
                    }
                }
            }
        }
예제 #11
0
 public void SetPatternType(PatternType ptype)
 {
     PlayerPrefs.SetString("PatternType", ptype.ToString());
 }