Пример #1
0
        public void Erode(SimpleHeightArray inHeightArray, ThermalErosionConfiguration configuration)
        {
            var tParam    = configuration.TParam;
            var cParam    = configuration.CParam;
            var stepCount = configuration.StepCount;
            var thermalErosionGroundMover = configuration.GroundMover;
            var neighbourChooser          = configuration.NeighboursChooser;

            var finalDifferenceArray = new SimpleHeightArray(inHeightArray.Width, inHeightArray.Height);

            for (int stepIndex = 0; stepIndex < stepCount; stepIndex++)
            {
                Parallel.For <SimpleHeightArray>(0, inHeightArray.Height,
                                                 new ParallelOptions {
                    MaxDegreeOfParallelism = 4
                },
                                                 () => new SimpleHeightArray(inHeightArray.Width, inHeightArray.Height),
                                                 (y, loop, localDifferenceArray) =>
                {
//                Parallel.For(0, inHeightArray.Height,new ParallelOptions { MaxDegreeOfParallelism = 3 }, y =>
//                for (int y = 0; y < inHeightArray.Height; y++)
//                {
                    for (int x = 0; x < inHeightArray.Width; x++)
                    {
                        var point      = new IntVector2(x, y);
                        var thisValue  = inHeightArray.GetValue(point);
                        var neighbours = configuration.NeighbourFinder.Find(inHeightArray, point)
                                         .Select(n => new NeighbourInfo(n, thisValue - inHeightArray.GetValue(n))).ToList();

                        neighbours = neighbours.Where(c => neighbourChooser.Choose(c, configuration)).ToList();
                        if (!neighbours.Any())
                        {
                            continue;
                        }

                        var changeArray = localDifferenceArray;
                        //changeArray = finalDifferenceArray;
                        thermalErosionGroundMover.Move(neighbours, configuration, changeArray, point);
                    }
                    return(localDifferenceArray);
                },
                                                 (localDifferenceArray) => { finalDifferenceArray.SumValue(localDifferenceArray); });


                for (int y = 0; y < inHeightArray.Height; y++)
                {
                    for (int x = 0; x < inHeightArray.Width; x++)
                    {
                        var point = new IntVector2(x, y);
                        inHeightArray.AddValue(point, finalDifferenceArray.GetValue(point));

                        finalDifferenceArray.SetValue(point, 0);
                    }
                }
            }
        }
Пример #2
0
        public void AtOnceErode(SimpleHeightArray inHeightArray, ThermalErosionConfiguration configuration)
        {
            var tParam    = configuration.TParam;
            var cParam    = configuration.CParam;
            var stepCount = configuration.StepCount;

            for (int stepIndex = 0; stepIndex < stepCount; stepIndex++)
            {
                for (int y = 0; y < inHeightArray.Height; y++)
                {
                    for (int x = 0; x < inHeightArray.Width; x++)
                    {
                        var point      = new IntVector2(x, y);
                        var thisValue  = inHeightArray.GetValue(point);
                        var neighbours = configuration.NeighbourFinder.Find(inHeightArray, point).Select(n => new
                        {
                            point      = n,
                            difference = thisValue - inHeightArray.GetValue(n)
                        }).ToList();

                        neighbours = neighbours.Where(c => c.difference > tParam).ToList();
                        if (!neighbours.Any())
                        {
                            continue;
                        }
                        var dTotal = neighbours.Sum(c => c.difference);
                        var dMax   = neighbours.Max(c => c.difference);

                        foreach (var aNeighbour in neighbours)
                        {
                            var movedGround = cParam * (dMax - tParam) * (aNeighbour.difference / dTotal);
                            inHeightArray.AddValue(aNeighbour.point, movedGround);
                            inHeightArray.AddValue(point, -movedGround);
                        }
                    }
                }
            }
        }
 public void Move(List <ThermalEroder.NeighbourInfo> neighbours, ThermalErosionConfiguration configuration,
                  SimpleHeightArray outArray, IntVector2 point)
 {
     _func(neighbours, configuration, outArray, point);
 }
Пример #4
0
        public void Erode(SimpleHeightArray inHeightArray, ThermalErosionConfiguration configuration)
        {
            var tParam    = configuration.TParam;
            var cParam    = configuration.CParam;
            var stepCount = configuration.StepCount;

            var finalDifferenceArray = new SimpleHeightArray(inHeightArray.Width, inHeightArray.Height);

            for (int stepIndex = 0; stepIndex < stepCount; stepIndex++)
            {
                Parallel.For <SimpleHeightArray>(0, inHeightArray.Height,
                                                 new ParallelOptions {
                    MaxDegreeOfParallelism = 4
                },
                                                 () => new SimpleHeightArray(inHeightArray.Width, inHeightArray.Height),
                                                 (y, loop, localDifferenceArray) =>
                {
//                Parallel.For(0, inHeightArray.Height,new ParallelOptions { MaxDegreeOfParallelism = 3 }, y =>
//                for (int y = 0; y < inHeightArray.Height; y++)
//                {
                    for (int x = 0; x < inHeightArray.Width; x++)
                    {
                        var point      = new IntVector2(x, y);
                        var thisValue  = inHeightArray.GetValue(point);
                        var neighbours = configuration.NeighbourFinder.Find(inHeightArray, point).Select(n => new
                        {
                            point      = n,
                            difference = thisValue - inHeightArray.GetValue(n)
                        }).ToList();

                        neighbours = neighbours.Where(c => c.difference < tParam && c.difference > 0).ToList();
                        if (!neighbours.Any())
                        {
                            continue;
                        }
                        var dTotal = neighbours.Sum(c => c.difference);
                        var dMax   = neighbours.Max(c => c.difference);

                        foreach (var aNeighbour in neighbours)
                        {
                            var movedGround = cParam * (dMax) * (aNeighbour.difference / dTotal);

                            //finalDifferenceArray.AddValue(aNeighbour.point, movedGround);
                            //finalDifferenceArray.AddValue(point, -movedGround);

                            localDifferenceArray.AddValue(aNeighbour.point, movedGround);
                            localDifferenceArray.AddValue(point, -movedGround);
                        }
                    }
                    return(localDifferenceArray);
                },
                                                 (localDifferenceArray) => { finalDifferenceArray.SumValue(localDifferenceArray); });


                for (int y = 0; y < inHeightArray.Height; y++)
                {
                    for (int x = 0; x < inHeightArray.Width; x++)
                    {
                        var point = new IntVector2(x, y);
                        inHeightArray.AddValue(point, finalDifferenceArray.GetValue(point));

                        finalDifferenceArray.SetValue(point, 0);
                    }
                }
            }
        }
Пример #5
0
 public bool Choose(ThermalEroder.NeighbourInfo neighbourInfo, ThermalErosionConfiguration conf)
 {
     return(_func(neighbourInfo, conf));
 }