Пример #1
0
        public static PixelClass GetFourWeight(PixelClass pclass, ImgInfo inf)
        {
            int[] foutWeight = { 0, 0, 0, 0 };
            Point[] fourPoints = new Point[4];
            for (int i = 0; i < 4; i++)
            {
                fourPoints[i] = new Point(pclass.Center.X, pclass.Center.Y);
            }
            for (int i = pclass.Angles.Left.X; i < pclass.Angles.Right.X; i++)
                for (int j = pclass.Angles.Top.Y; j < pclass.Angles.Bottom.Y; j++)
                {
                    int index = 0;
                    if (i > pclass.Center.X)
                        index = 1;
                    if (j > pclass.Center.Y)
                        index += 2;
                    if (inf.Labels[i, j] == pclass.Class)
                    {
                        var olppoint = Math.Pow(fourPoints[index].X - pclass.Center.X, 2) +
                        Math.Pow(fourPoints[index].Y - pclass.Center.Y, 2);

                        var newp = Math.Pow(i - pclass.Center.X, 2) +
                        Math.Pow(j - pclass.Center.Y, 2);

                        if (olppoint < newp)
                            fourPoints[index] = new Point(i, j);
                        foutWeight[index] += 1;
                    }
                }


            int maxDiff = 0;
            for (int i = 0; i < 3; i++)
            {
                for (int j = i; j < 4; j++)
                {
                    if (maxDiff < Math.Abs(foutWeight[i] - foutWeight[j]))
                        maxDiff = Math.Abs(foutWeight[i] - foutWeight[j]);
                }
            }
            pclass.FourPoints = fourPoints;
            pclass.FourWeights = foutWeight;
            pclass.MaxDiff = maxDiff;
            return pclass;
        }
Пример #2
0
 public bool Decide(PixelClass p)
 {
     throw new NotImplementedException();
 }
    void RetreiveLevelLayout(Texture2D levelMap)
    {
        // note: it seems that the image is analysed from bottom/left to top/right.


        mapLengthColumnsX = levelMap.height;
        mapWidthRowsZ     = levelMap.width;

        pix = levelMap.GetPixels32();
        //Debug.Log("image pixel count: " +pix.Length);

        foreach (Color32 p in pix)
        {
            PixelClass pixelItem = new PixelClass();

            if (color32IsEqual(p, _black))           // BLACK   1

            {
                pixelItem.colourCompare = PixelClass.pixelReader.BLACK;
                pixelItem.pixelColor32  = _black;
                //Debug.Log("BLACK pixel");
            }
            else if (color32IsEqual(p, _red))       // RED  2

            {
                pixelItem.colourCompare = PixelClass.pixelReader.RED;
                pixelItem.pixelColor32  = _red;
                //Debug.Log("RED pixel");
            }
            else if (color32IsEqual(p, _green))      // GREEN (dark)    3

            {
                pixelItem.colourCompare = PixelClass.pixelReader.GREEN;
                pixelItem.pixelColor32  = _green;
                //Debug.Log("GREEN pixel");
            }
            else if (color32IsEqual(p, _blue))      // BLUE     4

            {
                pixelItem.colourCompare = PixelClass.pixelReader.BLUE;
                pixelItem.pixelColor32  = _blue;
                //Debug.Log("BLUE pixel");
            }
            else if (color32IsEqual(p, _grey))      // GREY     5

            {
                pixelItem.colourCompare = PixelClass.pixelReader.GREY;
                pixelItem.pixelColor32  = _grey;
                //Debug.Log("GREY pixel");
            }
            else if (color32IsEqual(p, _magenta))      // MAGENTA   6

            {
                pixelItem.colourCompare = PixelClass.pixelReader.MAGENTA;
                pixelItem.pixelColor32  = _magenta;
                //Debug.Log("MAGENTA pixel");
            }
            else if (color32IsEqual(p, _redDark))      // DARK_RED  7
            {
                pixelItem.colourCompare = PixelClass.pixelReader.DARK_RED;
                pixelItem.pixelColor32  = _redDark;
                //Debug.Log("DARK_RED pixel");
            }
            else if (color32IsEqual(p, _greenTeal))       // TEAL_GREEN     8
            {
                pixelItem.colourCompare = PixelClass.pixelReader.TEAL_GREEN;
                pixelItem.pixelColor32  = _greenTeal;
                //Debug.Log("TEAL_GREEN pixel");
            }
            else if (color32IsEqual(p, _greyDark))       // DARK_GREY       9
            {
                pixelItem.colourCompare = PixelClass.pixelReader.DARK_GREY;
                pixelItem.pixelColor32  = _greyDark;
                //Debug.Log("DARK_GREY pixel");
            }
            else
            {
                Debug.Log("Kek, you missed that one: " + p);
            }

            pixelItem.pixelIndex = pixelList.Count;
            pixelItem.name       = "Pixel n° " + pixelItem.pixelIndex;
            pixelList.Add(pixelItem);
        }

        //Debug.Log("List of pixel items count: " + pixelList.Count);  // Should be the same as "pix.Length"
    }
Пример #4
0
 public bool Decide(PixelClass p)
 {
     return DesignFunc != null && DesignFunc(p);
 }
Пример #5
0
 public bool Decide(PixelClass p)
 {
     return Designs.All(d => d.Decide(p));
 }