< Summary - ReFlex - Library

Information
Class: PointCloud.Benchmark.Filter.FastBoxFilter
Assembly: ReFlex.PointCloud.Benchmark
File(s): D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Filter\FastBoxFilter.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 57
Coverable lines: 57
Total lines: 129
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 22
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Radius()100%210%
set_Radius(...)100%210%
get_DefaultValue()100%210%
.ctor(...)100%210%
Filter(...)0%506220%
SetRadius(...)100%210%

File(s)

D:\a\reflex\reflex\test\Library\Performance\PointCloud.Benchmark\Filter\FastBoxFilter.cs

#LineLine coverage
 1using PointCloud.Benchmark.Common;
 2
 3namespace PointCloud.Benchmark.Filter;
 4
 5/// <summary>
 6/// A two-dimensional box-blur with separated kernels
 7/// </summary>
 8public class FastBoxFilter
 9{
 10    #region fields
 11
 12    private int _radius;
 13
 14    #endregion
 15
 16    #region properties
 17
 18    /// <summary>
 19    /// Gets or sets the radius.
 20    /// </summary>
 21    /// <value>
 22    /// The radius.
 23    /// </value>
 24    public int Radius
 25    {
 026        get => _radius;
 027        set => SetRadius(value);
 28    }
 29
 030    public float DefaultValue { get; set; }
 31
 32    #endregion
 33
 34    #region constructor
 35
 36    /// <summary>
 37    /// Initializes a new instance of the <see cref="BoxFilter"/> class.
 38    /// </summary>
 39    /// <param name="radius">The radius.</param>
 040    public FastBoxFilter(int radius) => SetRadius(radius);
 41
 42    #endregion
 43
 44    #region methods
 45
 46    /// <summary>
 47    /// Filters highly frequented changes in a field of <see cref="ReFlex.Core.Common.Components.Point3"/>.
 48    /// </summary>
 49    public void Filter(PointCloud3 target)
 050    {
 051        var targetRef = target.AsJaggedArray();
 052        var width = target.SizeX;
 053        var height = target.SizeY;
 54
 055        if (_radius % 2 == 0)
 056            _radius++;
 57
 058        var avg = 1f / _radius;
 59
 060        for (var j = 0; j < height; j++)
 061        {
 062            var hSum = 0f;
 63
 064            for (var x = 0; x < _radius; x++)
 065            {
 066                hSum += targetRef[x][j].Z;
 067            }
 68
 069            var iAvg = hSum * avg;
 70
 071            for (var i = 0; i < width; i++)
 072            {
 073                if (i - _radius / 2 >= 0 && i + 1 + _radius / 2 < width)
 074                {
 075                    hSum -= targetRef[i - _radius / 2][j].Z;
 76
 077                    var tmp = targetRef[i + 1 + _radius / 2][j].Z;
 078                    hSum += tmp;
 79
 080                    iAvg = hSum * avg;
 081                }
 82
 083                targetRef[i][j].Z = iAvg;
 084            }
 085        }
 86
 87        // need copy ?
 88        // Bitmap total = Hblur.Clone();
 89
 090        for (var i = 0; i < width; i++)
 091        {
 092            var tSum = 0f;
 093            for (var y = 0; y < _radius; y++)
 094            {
 095                var tmpColor = targetRef[i][y].Z;
 096                tSum += tmpColor;
 097            }
 98
 099            var iAvg = tSum * avg;
 100
 0101            for (var j = 0; j < height; j++)
 0102            {
 0103                if (j - _radius / 2 >= 0 && j + 1 + _radius / 2 < height)
 0104                {
 0105                    var tmpPColor = targetRef[i][j - _radius / 2].Z;
 0106                    tSum -= tmpPColor;
 107
 0108                    var tmpNColor = targetRef[i][j + 1 + _radius / 2].Z;
 0109                    tSum += tmpNColor;
 110                    //
 0111                    iAvg = tSum * avg;
 0112                }
 113
 0114                targetRef[i][j].Z = iAvg;
 0115            }
 0116        }
 0117    }
 118
 119    /// <summary>
 120    /// Sets the radius and calculates the diameter.
 121    /// </summary>
 122    /// <param name="radius">The radius.</param>
 123    private void SetRadius(int radius)
 0124    {
 0125        _radius = radius;
 0126    }
 127
 128    #endregion
 129}