コード例 #1
0
        private Vector3[,] GeneratePositionsArray(LocalTexture worldPosition1Texture, LocalTexture worldPosition2Texture)
        {
            var imageSize = new IntVector2(worldPosition1Texture.Width, worldPosition1Texture.Height);
            var outArray  = new Vector3[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 p1        = worldPosition1Texture.GetPixel(x, y);
                    var p2        = worldPosition2Texture.GetPixel(x, y);
                    var positionX = ToFloat(p1[0], p1[1], _maxPosition);
                    var positionY = ToFloat(p1[2], p1[3], _maxPosition);
                    var positionZ = ToFloat(p2[0], p2[1], _maxPosition);

                    //CheckForOverfloat(p1[0], p1[1]);
                    //CheckForOverfloat(p1[2], p1[3]);
                    //CheckForOverfloat(p2[0], p2[1]);

                    outArray[x, y] = new Vector3(positionX, positionY, positionZ);
                }
            });

            return(outArray);
        }
コード例 #2
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);
        }
コード例 #3
0
        public LocalTexture Skeletonize(Texture hatchMainTexture)
        {
            Graphics.Blit(hatchMainTexture, _outTexture0, _skeletonizerMaterial, 1);

            for (int i = 0; i < _tapsCount; i++)
            {
                var src = CurrentRenderTexture;
                _currentOutTexture = (_currentOutTexture + 1) % 2;
                var dst = CurrentRenderTexture;
                Graphics.Blit(src, dst, _skeletonizerMaterial, 0);
            }

            return(LocalTexture.FromTexture2D(UltraTextureRenderer.RenderTextureToTexture2D(CurrentRenderTexture)));
        }
コード例 #4
0
        private MeasurementScreenshotsSet GenerateScreenshotsSet()
        {
            UltraTextureRenderer.RenderIntoExistingTexture2D(_hatchMainRenderTexture, this._hatchMainTex2D);
            UltraTextureRenderer.RenderIntoExistingTexture2D(_idRenderTexture, this._hatchIdTex2D);
            UltraTextureRenderer.RenderIntoExistingTexture2D(_worldPos1RenderTexture, this._worldPos1Tex2D);
            UltraTextureRenderer.RenderIntoExistingTexture2D(_worldPos2RenderTexture, this._worldPos2Tex2D);

            return(new MeasurementScreenshotsSet()
            {
                HatchIdTexture = LocalTexture.FromTexture2D(_hatchIdTex2D),
                HatchMainTexture = LocalTexture.FromTexture2D(_hatchMainTex2D),
                WorldPosition1Texture = LocalTexture.FromTexture2D(_worldPos1Tex2D),
                WorldPosition2Texture = LocalTexture.FromTexture2D(_worldPos2Tex2D),
            });
        }
コード例 #5
0
ファイル: GaugeUtils.cs プロジェクト: defacto2k15/PwMgr
        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);
        }
コード例 #6
0
ファイル: GaugeUtils.cs プロジェクト: defacto2k15/PwMgr
        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);
        }
コード例 #7
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);
        }
コード例 #8
0
        private Dictionary <uint, List <float> > GeneratePixelCountsDict(LocalTexture hatchMainTexture, bool[,] occurenceArray, uint[,] idsArray)
        {
            var imageSize   = new IntVector2(hatchMainTexture.Width, hatchMainTexture.Height);
            var strokesDict = new Dictionary <uint, List <float> >();

            for (int x = 0; x < imageSize.X; x++)
            {
                for (int y = 0; y < imageSize.Y; y++)
                {
                    var tParam = hatchMainTexture.GetPixel(x, y).b;
                    var id     = idsArray[x, y];
                    if (occurenceArray[x, y] && id != 0)
                    {
                        if (!strokesDict.ContainsKey(id))
                        {
                            strokesDict[id] = new List <float>();
                        }
                        strokesDict[id].Add(tParam);
                    }
                }
            }

            return(strokesDict);
        }
コード例 #9
0
        private Dictionary <uint, List <LinesLayoutSample> > GenerateSamplesDict(Vector3[,] positionsArray, uint[,] idArray, LocalTexture hatchMainTexture,
                                                                                 bool[,] occurenceArray)
        {
            var imageSize = new IntVector2(hatchMainTexture.Width, hatchMainTexture.Height);

            return(Enumerable.Range(0, imageSize.X).AsParallel().SelectMany(x =>
            {
                return Enumerable.Range(0, imageSize.Y).Select(y =>
                {
                    var tParam = hatchMainTexture.GetPixel(x, y).b;
                    var id = idArray[x, y];
                    if (id != 0 && occurenceArray[x, y])
                    {
                        var worldSpacePosition = positionsArray[x, y];
                        return new LinesLayoutSampleWithId()
                        {
                            Id = id,
                            Sample = new LinesLayoutSample()
                            {
                                TParam = tParam,
                                WorldSpacePosition = worldSpacePosition
                            }
                        };
                    }
                    else
                    {
                        return new LinesLayoutSampleWithId()
                        {
                            Id = 0,
                            Sample = null
                        };
                    }
                });
            })
                   .Where(c => c.Sample != null)
                   .GroupBy(c => c.Id)
                   .ToDictionary(c => c.Key, c => c.Select(r => r.Sample).ToList()));

            //var outDict = new Dictionary<int, List<LinesLayoutSample>>();
            //for (int x = 0; x < imageSize.X; x++)
            //{
            //    for (int y = 0; y < imageSize.Y; y++)
            //    {
            //        var tParam = hatchIdTexture.GetPixel(x, y).b;
            //        var id = idArray[x, y];
            //        if (id != 0 && occurenceArray[x,y])
            //        {
            //            var worldSpacePosition = positionsArray[x, y];

            //            if (!outDict.ContainsKey(id))
            //            {
            //                outDict[id] = new List<LinesLayoutSample>();
            //            }

            //            outDict[id].Add(new LinesLayoutSample()
            //            {
            //                TParam = tParam,
            //                WorldSpacePosition = worldSpacePosition
            //            });
            //        }
            //    }
            //}

            //return outDict;
        }