Ejemplo n.º 1
0
        private bool[,] OldGenerateLocalMaximaArray(LocalTexture mainTexture, float[,] distancesArray)
        {
            float EPSILON   = 0.00001f;
            var   imageSize = new IntVector2(mainTexture.Width, mainTexture.Height);
            var   outArray  = new bool[imageSize.X, imageSize.Y];

            Parallel.For(0, imageSize.X, x =>
                         //for (int x = 0; x < imageSize.X; x++)
            {
                for (int y = 0; y < imageSize.Y; y++)
                {
                    var centerPixelDistance = distancesArray[x, y];
                    var centerPixel         = mainTexture.GetPixel(x, y);
                    if (!GaugeUtils.PixelLiesOverShapeAndHatch(centerPixel))
                    {
                        outArray[x, y] = false;
                    }
                    else
                    {
                        float maximalDistance = float.MinValue;
                        int biggerPixelsCount = 0;
                        int allPixelsCount    = 0;

                        for (int ix = Math.Max(0, x - _localMaximaWindowSize.X / 2); ix < Math.Min(imageSize.X, x + _localMaximaWindowSize.X / 2); ix++)
                        {
                            for (int iy = Math.Max(0, y - _localMaximaWindowSize.Y / 2); iy < Math.Min(imageSize.Y, y + _localMaximaWindowSize.Y / 2); iy++)
                            {
                                allPixelsCount++;
                                var d = distancesArray[ix, iy];
                                if (d > 0)
                                {
                                    if (centerPixelDistance < d)
                                    {
                                        biggerPixelsCount++;
                                    }
                                    maximalDistance = Mathf.Max(d, maximalDistance);
                                }
                            }
                        }

                        bool isLocalMaxima = Mathf.Abs(maximalDistance - centerPixelDistance) < EPSILON;
                        isLocalMaxima      = false;
                        if (((float)biggerPixelsCount) / ((float)allPixelsCount) < 0.1)
                        {
                            isLocalMaxima = true;
                        }
                        outArray[x, y] = isLocalMaxima;
                    }
                }
            });

            return(outArray);
        }
        public IMeasurementResult TakeMeasurement(MeasurementScreenshotsSet inputSet)
        {
            var fillingInfos = new List <OneBlockSpecificationInformation>(_divisionSettings.BlockCount.X * _divisionSettings.BlockCount.Y);

            for (int bx = 0; bx < _divisionSettings.BlockCount.X; bx++)
            {
                for (int by = 0; by < _divisionSettings.BlockCount.Y; by++)
                {
                    var blockStartPosition  = new IntVector2(bx * _divisionSettings.BlockSize.X, by * _divisionSettings.BlockSize.Y);
                    var allShapePixelsCount = 0;
                    var hatchPixelsCount    = 0;
                    var lightIntensitySum   = 0f;

                    for (int x = blockStartPosition.X;
                         x < Math.Min(blockStartPosition.X + _divisionSettings.BlockSize.X, _divisionSettings.ScreenSize.X);
                         x++)
                    {
                        for (int y = blockStartPosition.Y;
                             y < Math.Min(blockStartPosition.Y + _divisionSettings.BlockSize.Y, _divisionSettings.ScreenSize.Y);
                             y++)
                        {
                            var hatchPix = inputSet.HatchMainTexture.GetPixel(x, y);
                            if (GaugeUtils.PixelLiesOverShape(hatchPix))
                            {
                                allShapePixelsCount++;
                                if (GaugeUtils.PixelLiesOverHatchInShape(hatchPix))
                                {
                                    hatchPixelsCount++;
                                }

                                lightIntensitySum += hatchPix.g;
                            }
                        }
                    }

                    fillingInfos.Add(new OneBlockSpecificationInformation()
                    {
                        AllShapePixels    = allShapePixelsCount,
                        HatchPixels       = hatchPixelsCount,
                        BlockPosition     = new IntVector2(bx, by),
                        LightIntensitySum = lightIntensitySum
                    });
                }
            }
            return(new BlockSpecificationResult(fillingInfos, _divisionSettings));
        }
Ejemplo n.º 3
0
        public static bool[,] GenerateHatchOccurenceArray(LocalTexture mainTexture)
        {
            var imageSize = new IntVector2(mainTexture.Width, mainTexture.Height);
            var outArray  = new bool[imageSize.X, imageSize.Y];

            Parallel.For(0, imageSize.X, x =>
                         //for (int x = 0; x < imageSize.X; x++)
            {
                for (int y = 0; y < imageSize.Y; y++)
                {
                    outArray[x, y] = GaugeUtils.PixelLiesOverShapeAndHatch(mainTexture.GetPixel(x, y));
                }
            });

            //var xc = Enumerable.Range(0, outArray.GetLength(0))
            //    .Any(x => Enumerable.Range(0, outArray.GetLength(1)).Any(y => outArray[x, y]));
            return(outArray);
        }
Ejemplo n.º 4
0
        public static uint[,] GenerateIdArray(LocalTexture idTexture)
        {
            var imageSize  = new IntVector2(idTexture.Width, idTexture.Height);
            var outIdArray = new uint[imageSize.X, imageSize.Y];

            Parallel.For(0, imageSize.X, x =>
                         //for (int x = 0; x < imageSize.X; x++)
            {
                for (int y = 0; y < imageSize.Y; y++)
                {
                    outIdArray[x, y] = GaugeUtils.RetriveId(idTexture.GetPixel(x, y));
                }
            });

            //var xc = Enumerable.Range(0, outIdArray.GetLength(0))
            //    .Any(x => Enumerable.Range(0, outIdArray.GetLength(1)).Any(y => outArray[x, y]));
            return(outIdArray);
        }
Ejemplo n.º 5
0
        private float[,] GenerateDistancesArray(LocalTexture mainTexture)
        {
            var imageSize        = new IntVector2(mainTexture.Width, mainTexture.Height);
            var outDistanceArray = new float[imageSize.X, imageSize.Y];

            Parallel.For(0, imageSize.X, x =>
                         //for (int x = 0; x < imageSize.X; x++)
            {
                for (int y = 0; y < imageSize.Y; y++)
                {
                    var centerPixel = mainTexture.GetPixel(x, y);
                    if (!GaugeUtils.PixelLiesOverShapeAndHatch(centerPixel))
                    {
                        outDistanceArray[x, y] = 0f;
                    }
                    else
                    {
                        float minimalDistance = (_distancesWindowSize.ToFloatVec() * 0.5f).magnitude;

                        for (int ix = Math.Max(0, x - _distancesWindowSize.X / 2); ix < Math.Min(imageSize.X, x + _distancesWindowSize.X / 2); ix++)
                        {
                            for (int iy = Math.Max(0, y - _distancesWindowSize.Y / 2); iy < Math.Min(imageSize.Y, y + _distancesWindowSize.Y / 2); iy++)
                            {
                                var p = mainTexture.GetPixel(ix, iy);
                                if (!GaugeUtils.PixelLiesOverShapeAndHatch(p))
                                {
                                    var distance    = Vector2.Distance(new Vector2(x, y), new Vector2(ix, iy));
                                    minimalDistance = Mathf.Min(distance, minimalDistance);
                                }
                            }
                        }

                        outDistanceArray[x, y] = minimalDistance;
                    }
                }
            });

            return(outDistanceArray);
        }