< Summary - ReFlex - Library

Information
Class: ReFlex.Core.Calibration.Components.GradientProcessor
Assembly: ReFlex.Core.Calibration
File(s): D:\a\reflex\reflex\library\src\Core\Calibration\Components\GradientProcessor.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 49
Coverable lines: 49
Total lines: 94
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
.ctor(...)100%210%
Process(...)0%420200%

File(s)

D:\a\reflex\reflex\library\src\Core\Calibration\Components\GradientProcessor.cs

#LineLine coverage
 1using System;
 2using MathNet.Numerics.LinearAlgebra;
 3
 4namespace ReFlex.Core.Calibration.Components
 5{
 6    public class GradientProcessor : DepthProcessorBase
 7    {
 8        #region Fields;
 9
 10        // private int _threshold;
 11        private readonly int _skip;
 12        private Vector<double>[,] _lastProcessed;
 13        private Util.Calibration _calibration;
 14
 015        private static readonly int[] XWeights = { -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -1, 0, 1, 2, 2, 2, 1, 0, -1, -2 };
 016        private static readonly int[] YWeights = { 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 1 };
 17
 18        #endregion
 19
 20        #region constructor
 21
 022        public GradientProcessor(Util.Calibration calibration, int width, int height, int skip) : base(width, height)
 023        {
 024            _skip = skip;
 025            _calibration = calibration;
 026        }
 27
 28        #endregion
 29
 30        #region Implementation of Abstract Methods
 31
 32
 33        public override Vector<double>[,] Process(double[] depthValues)
 034        {
 035            var result = new Vector<double>[Width / _skip, Height / _skip];
 036            var offset = -1;
 37
 038            for (int i = 0; i < depthValues.Length; i += _skip)
 039            {
 040                var vec = Vector<double>.Build.Sparse(3);
 041                var curr = depthValues[i];
 42
 43                // Smoothing: Can be removed ?
 44
 045                for (var j = 0; j < XWeights.Length; j++)
 046                {
 047                    var n = i + ConvertDim21(XWeights[j], YWeights[j]);
 048                    if (n < depthValues.Length && n >= 0 && Math.Abs(depthValues[0] - MaxDepthValue) > double.Epsilon)
 049                    {
 050                        var diff = depthValues[n] - curr;
 051                        var sub = new[] { XWeights[j] * diff, YWeights[j] * diff, 0 };
 052                        vec = vec.Subtract(Vector<double>.Build.DenseOfArray(sub));
 053                    }
 54                    else
 055                    {
 056                        vec[0] = 0;
 057                        vec[1] = 0;
 058                    }
 059                }
 60
 61                // Smoothing: end
 62
 063                if (i % (Width * _skip) == 0)
 064                    offset++;
 065                vec = vec.Multiply(.1);
 66
 067                if (vec.Norm(2) > 3)
 068                    vec = vec.Normalize(2).Multiply(3.0);
 69
 070                if (curr > _calibration.UpperThreshold && curr < _calibration.LowerThreshold)
 071                {
 072                    result[i % Width / _skip, offset] = Vector<double>.Build.Sparse(3);
 073                    continue;
 74                }
 75
 076                if (_lastProcessed == null)
 077                {
 078                    result[i % Width / _skip, offset] = vec;
 079                }
 80                else
 081                {
 082                    var last = _lastProcessed[i % Width / _skip, offset];
 083                    result[i % Width / _skip, offset] = InterpolateVector(vec, last, 0.7);
 084                }
 085            }
 86
 087            _lastProcessed = result;
 088            return result;
 089        }
 90
 91        #endregion
 92    }
 93
 94}