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); }
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(); }); }
private GenericSubGridTree <float, GenericLeafSubGrid_Float> ConstructSingleSubGridElevationSubGridTreeAtOrigin(float elevation) { var tree = new GenericSubGridTree <float, GenericLeafSubGrid_Float>(); var subGrid = tree.ConstructPathToCell(SubGridTreeConsts.DefaultIndexOriginOffset, SubGridTreeConsts.DefaultIndexOriginOffset, SubGridPathConstructionType.CreateLeaf) as GenericLeafSubGrid <float>; DataSmoothingTestUtilities.ConstructElevationSubGrid(subGrid, elevation); return(tree); }
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); }