< Summary - ReFlex - Library

Information
Class: ReFlex.Core.Common.Components.VectorField2
Assembly: ReFlex.Core.Common
File(s): D:\a\reflex\reflex\library\src\Core\Common\Components\VectorField2.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 56
Coverable lines: 56
Total lines: 181
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
get_Item(...)0%4260%
set_Item(...)0%620%
get_Item(...)0%620%
set_Item(...)0%620%
get_Size()100%210%
get_SizeX()100%210%
get_SizeY()100%210%
get_Stride()100%210%
AsArray()100%210%
AsJaggedArray()100%210%
.ctor(...)0%620%
Update(...)100%210%
Populate(...)0%4260%
Initialize(...)100%210%

File(s)

D:\a\reflex\reflex\library\src\Core\Common\Components\VectorField2.cs

#LineLine coverage
 1using System;
 2using System.Threading.Tasks;
 3using ReFlex.Core.Common.Interfaces;
 4
 5namespace ReFlex.Core.Common.Components
 6{
 7    /// <inheritdoc />
 8    /// <summary>
 9    /// A ordered Quantity of <see cref="Vector2" />
 10    /// </summary>
 11    public class VectorField2 : IDepthImage<Vector2>
 12    {
 13        private Vector2[][] _values2D;
 14        private Vector2[] _values1D;
 15
 16        /// <inheritdoc />
 17        /// <summary>
 18        /// Gets or sets the <see cref="Vector2" /> at the specified index.
 19        /// </summary>
 20        /// <value>
 21        /// The <see cref="Vector2" />.
 22        /// </value>
 23        /// <param name="index">The index.</param>
 24        /// <returns></returns>
 25        public Vector2 this[int index]
 26        {
 27            get
 028            {
 029                if (index < 0 || index >= Size)
 030                    return new Vector2();
 031                return _values1D[index] ?? (_values1D[index] = new Vector2());
 032            }
 033            set => _values1D[index]?.Set(value);
 34        }
 35
 36        /// <inheritdoc />
 37        /// <summary>
 38        /// Gets or sets the <see cref="Vector2" /> with the specified x.
 39        /// </summary>
 40        /// <value>
 41        /// The <see cref="Vector2" />.
 42        /// </value>
 43        /// <param name="x">The x.</param>
 44        /// <param name="y">The y.</param>
 45        /// <returns></returns>
 46        public Vector2 this[int x, int y]
 47        {
 048            get => _values2D[x][y] ?? (_values2D[x][y] = new Vector2());
 049            set => _values2D[x][y]?.Set(value);
 50        }
 51
 52        /// <inheritdoc />
 53        /// <summary>
 54        /// Gets the size.
 55        /// </summary>
 56        /// <value>
 57        /// The size.
 58        /// </value>
 059        public int Size { get; private set; }
 60
 61        /// <inheritdoc />
 62        /// <summary>
 63        /// Gets the horizontal size.
 64        /// </summary>
 65        /// <value>
 66        /// The horizontal size.
 67        /// </value>
 068        public int SizeX { get; private set; }
 69
 70        /// <inheritdoc />
 71        /// <summary>
 72        /// Gets the vertical size.
 73        /// </summary>
 74        /// <value>
 75        /// The vertical size.
 76        /// </value>
 077        public int SizeY { get; private set; }
 78
 79        /// <summary>
 80        /// Gets the stride.
 81        /// </summary>
 82        /// <value>
 83        /// The stride.
 84        /// </value>
 085        public int Stride { get; }
 86
 87        /// <inheritdoc />
 88        /// <summary>
 89        /// Get [this] instance as an array.
 90        /// </summary>
 91        /// <returns>
 92        /// [this] instance as an array
 93        /// </returns>
 094        public Vector2[] AsArray() => _values1D;
 95
 96        /// <inheritdoc />
 97        /// <summary>
 98        /// Get [this] instance as an jagged array
 99        /// </summary>
 100        /// <returns>
 101        /// [this] instance as an jagged array
 102        /// </returns>
 0103        public Vector2[][] AsJaggedArray() => _values2D;
 104
 105        /// <summary>
 106        /// Initializes a new instance of the <see cref="VectorField2" /> class.
 107        /// </summary>
 108        /// <param name="sizeX">The size x.</param>
 109        /// <param name="sizeY">The size y.</param>
 110        /// <param name="stride">The stride.</param>
 0111        public VectorField2(int sizeX, int sizeY, int stride = 1)
 0112        {
 0113            Initialize(sizeX, sizeY);
 0114            Stride = stride > 0 ? stride : 1;
 0115        }
 116
 117        /// <inheritdoc />
 118        /// <summary>
 119        /// Updates [this] instance with the data of the specified source.
 120        /// </summary>
 121        /// <param name="source">The source value.</param>
 122        public void Update(ReadOnlyMemory<Vector2> source, float defualtZ)
 0123        {
 0124            Parallel.For(0, source.Length, i =>
 0125                {
 0126                    _values1D[i].Set(source.Span[i]);
 0127                }
 0128            );
 0129        }
 130
 131        /// <summary>
 132        /// Populates the vectorfield.
 133        /// </summary>
 134        /// <param name="source">The source.</param>
 135        public void Populate(PointCloud3 source)
 0136        {
 0137            var pointcloud = source.AsJaggedArray();
 138
 0139            for (var y = Stride; y < SizeY - Stride; ++y)
 0140            {
 0141                for (var x = Stride; x < SizeX - Stride; ++x)
 0142                {
 0143                    if (!pointcloud[x][y].IsValid)
 0144                    {
 0145                        _values2D[x][y].IsValid = false;
 0146                        _values2D[x][y].Set(0, 0);
 0147                        continue;
 148                    }
 149                    else
 0150                        _values2D[x][y].IsValid = true;
 151
 0152                    var x1 = pointcloud[x - Stride][y];
 0153                    var x2 = pointcloud[x + Stride][y];
 0154                    var y1 = pointcloud[x][y - Stride];
 0155                    var y2 = pointcloud[x][y + Stride];
 156
 0157                    var deltaX = x1.Z - x2.Z;
 0158                    var deltaY = y1.Z - y2.Z;
 159
 0160                    _values2D[x][y].Set(deltaX, deltaY);
 0161                }
 0162            }
 0163        }
 164
 165        /// <summary>
 166        /// Initializes the specified size y.
 167        /// </summary>
 168        /// <param name="sizeX">The size x.</param>
 169        /// <param name="sizeY">The size y.</param>
 170        private void Initialize(int sizeX, int sizeY)
 0171        {
 0172            SizeX = sizeX;
 0173            SizeY = sizeY;
 0174            Size = sizeX * sizeY;
 175
 0176            ArrayUtils.InitializeArray(out _values1D, Size);
 0177            ArrayUtils.InitializeArray(out _values2D, SizeX, SizeY);
 0178            ArrayUtils.ReferencingArrays(_values1D, _values2D);
 0179        }
 180    }
 181}