Esempio n. 1
0
        public void Smooth()
        {
            const float  elevation = 10.0f;
            const double oneNinth  = 1d / 9d;

            var source        = DataSmoothingTestUtilities.ConstructSingleSubGridElevationSubGridTreeAtOrigin(elevation);
            var sourceSubGrid = source.LocateSubGridContaining(SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.SubGridTreeLevels) as GenericLeafSubGrid <float>;

            sourceSubGrid.Should().NotBeNull();

            var tools  = new ConvolutionTools <float>();
            var accum  = new ConvolutionAccumulator_Float(CellPassConsts.NullHeight, ConvolutionMaskSize.Mask3X3);
            var filter = new double[3, 3] {
                {
                    oneNinth, oneNinth, oneNinth
                },
                {
                    oneNinth, oneNinth, oneNinth
                },
                {
                    oneNinth, oneNinth, oneNinth
                }
            };

            var smoother = new TreeDataSmoother <float>(tools, ConvolutionMaskSize.Mask3X3, accum,
                                                        (accum, size) => new FilterConvolver <float>(accum, filter, NullInfillMode.NoInfill));

            var result = smoother.Smooth(source);

            var resultSubGrid = result.LocateSubGridContaining(SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.SubGridTreeLevels) as GenericLeafSubGrid <float>;

            resultSubGrid.Should().NotBeNull();
            resultSubGrid.Items.Should().BeEquivalentTo(sourceSubGrid.Items);
        }
Esempio n. 2
0
        public void Smooth()
        {
            const double oneNinth = 1d / 9d;

            var sourceArray = new float[10, 10];

            for (var i = 0; i < 10; i++)
            {
                for (var j = 0; j < 10; j++)
                {
                    sourceArray[i, j] = 10.0f;
                }
            }

            var tools  = new ConvolutionTools <float>();
            var accum  = new ConvolutionAccumulator_Float(CellPassConsts.NullHeight, ConvolutionMaskSize.Mask3X3);
            var filter = new double[3, 3] {
                {
                    oneNinth, oneNinth, oneNinth
                },
                {
                    oneNinth, oneNinth, oneNinth
                },
                {
                    oneNinth, oneNinth, oneNinth
                }
            };

            var smoother = new ArrayDataSmoother <float>(tools, ConvolutionMaskSize.Mask3X3, accum,
                                                         (accum, size) => new FilterConvolver <float>(accum, filter, NullInfillMode.NoInfill));

            var result = smoother.Smooth(sourceArray);

            result.Should().BeEquivalentTo(sourceArray);
        }
Esempio n. 3
0
        public void SingleSubGrid_AtOrigin(ConvolutionMaskSize contextSize)
        {
            const float ELEVATION = 10.0f;

            var tree    = DataSmoothingTestUtilities.ConstructSingleSubGridElevationSubGridTreeAtOrigin(ELEVATION);
            var subGrid = tree.LocateSubGridContaining(SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.SubGridTreeLevels) as GenericLeafSubGrid <float>;

            subGrid.Should().NotBeNull();

            var result = DataSmoothingTestUtilities.ConstructElevationSubGrid(CellPassConsts.NullHeight);

            result.Should().NotBeNull();

            var accumulator = new ConvolutionAccumulator_Float(CellPassConsts.NullHeight, contextSize);
            var filter      = new MeanFilter <float>(accumulator, contextSize, NullInfillMode.NoInfill);
            var smoother    = new ConvolutionTools <float>();

            smoother.Convolve(subGrid, result, filter);

            // All cell values should remain mostly unchanged due to non-null values around perimeter of subgrid in smoothing context
            // Check all acquired values in the single subgrid are the same elevation, except for the perimeter values which
            // will be 2/3 * Elevation due to null values. Some corner vales will have 0.44444 * ElEVATION for same reason
            SubGridUtilities.SubGridDimensionalIterator((x, y) =>
            {
                var ok = Math.Abs(result.Items[x, y] = ELEVATION) < 0.0001 ||
                         Math.Abs(result.Items[x, y] = (2 / 3) * ELEVATION) < 0.0001 ||
                         Math.Abs(result.Items[x, y] = 0.44444f * ELEVATION) < 0.0001;
                ok.Should().BeTrue();
            });
        }
Esempio n. 4
0
    public void Creation()
    {
      var tools = new ConvolutionTools<float>();

      var smoother = new ElevationTreeSmoother(tools, ConvolutionMaskSize.Mask3X3, NullInfillMode.NoInfill);

      smoother.Should().NotBeNull();
    }
Esempio n. 5
0
        public void FilterConvolverAssertsDimensionsMatch()
        {
            var accumulator = new ConvolutionAccumulator_Float(CellPassConsts.NullHeight, ConvolutionMaskSize.Mask3X3);
            var filter      = new FilterConvolver <float>(accumulator, new double[3, 3], NullInfillMode.NoInfill);
            var smoother    = new ConvolutionTools <float>();

            Action act = () => smoother.Convolve(new float[3, 3], new float[4, 4], filter);

            act.Should().Throw <ArgumentException>().WithMessage("Dimensions of source and destination data are not the same");
        }
Esempio n. 6
0
        public void Creation()
        {
            var tools  = new ConvolutionTools <float>();
            var accum  = new ConvolutionAccumulator_Float(CellPassConsts.NullHeight, ConvolutionMaskSize.Mask3X3);
            var filter = new double[3, 3];

            var smoother = new TreeDataSmoother <float>(tools, ConvolutionMaskSize.Mask3X3, accum,
                                                        (acc, size) => new FilterConvolver <float>(accum, filter, NullInfillMode.NoInfill));

            smoother.Should().NotBeNull();
            smoother.AdditionalBorderSize.Should().Be(3 / 2);
        }
Esempio n. 7
0
    public void Smooth()
    {
      const float elevation = 10.0f;

      var source = DataSmoothingTestUtilities.ConstructSingleSubGridElevationSubGridTreeAtOrigin(elevation);
      var sourceSubGrid = source.LocateSubGridContaining(SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.SubGridTreeLevels) as GenericLeafSubGrid<float>;
      sourceSubGrid.Should().NotBeNull();

      var tools = new ConvolutionTools<float>();
      var smoother = new ElevationTreeSmoother(tools, ConvolutionMaskSize.Mask3X3, NullInfillMode.NoInfill);

      var result = smoother.Smooth(source);

      var resultSubGrid = result.LocateSubGridContaining(SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.SubGridTreeLevels) as GenericLeafSubGrid<float>;
      resultSubGrid.Should().NotBeNull();
      resultSubGrid.Items.Should().BeEquivalentTo(sourceSubGrid.Items);
    }
Esempio n. 8
0
        public void Smooth()
        {
            var source = new float[10, 10];

            for (var i = 0; i < 10; i++)
            {
                for (var j = 0; j < 10; j++)
                {
                    source[i, j] = 10.0f;
                }
            }

            var tools    = new ConvolutionTools <float>();
            var smoother = new ElevationArraySmoother(tools, ConvolutionMaskSize.Mask3X3, NullInfillMode.NoInfill);

            var result = smoother.Smooth(source);

            result.Should().BeEquivalentTo(source);
        }
Esempio n. 9
0
        public void Creation()
        {
            var smoother = new ConvolutionTools <float>();

            smoother.Should().NotBeNull();
        }