| | 1 | | using System; |
| | 2 | | using System.Threading.Tasks; |
| | 3 | | using ReFlex.Core.Common.Interfaces; |
| | 4 | |
|
| | 5 | | namespace ReFlex.Core.Common.Components |
| | 6 | | { |
| | 7 | | /// <inheritdoc /> |
| | 8 | | /// <summary> |
| | 9 | | /// A ordered Quantity of <see cref="Point2"/> |
| | 10 | | /// </summary> |
| | 11 | | /// <seealso cref="IDepthImage{T}" /> |
| | 12 | | public class PointCloud2 : IDepthImage<Point2> |
| | 13 | | { |
| | 14 | | private Point2[] _values1D; |
| | 15 | | private Point2[][] _values2D; |
| | 16 | |
|
| | 17 | | /// <inheritdoc /> |
| | 18 | | /// <summary> |
| | 19 | | /// Gets or sets the <see cref="T:ReFlex.Core.Common.Components.Point2" /> at the specified index. |
| | 20 | | /// </summary> |
| | 21 | | /// <value> |
| | 22 | | /// The <see cref="T:ReFlex.Core.Common.Components.Point2" />. |
| | 23 | | /// </value> |
| | 24 | | /// <param name="index">The index.</param> |
| | 25 | | /// <returns></returns> |
| | 26 | | public Point2 this[int index] |
| | 27 | | { |
| | 28 | | get |
| 0 | 29 | | { |
| 0 | 30 | | if (index < 0 || index >= Size) |
| 0 | 31 | | return new Point2(); |
| 0 | 32 | | return _values1D[index] ?? (_values1D[index] = new Point2()); |
| 0 | 33 | | } |
| 0 | 34 | | set => _values1D[index]?.Set(value); |
| | 35 | | } |
| | 36 | |
|
| | 37 | | /// <inheritdoc /> |
| | 38 | | /// <summary> |
| | 39 | | /// Gets or sets the <see cref="Point2" /> with the specified x. |
| | 40 | | /// </summary> |
| | 41 | | /// <value> |
| | 42 | | /// The <see cref="Point2" />. |
| | 43 | | /// </value> |
| | 44 | | /// <param name="x">The x.</param> |
| | 45 | | /// <param name="y">The y.</param> |
| | 46 | | /// <returns></returns> |
| | 47 | | public Point2 this[int x, int y] |
| | 48 | | { |
| 0 | 49 | | get => _values2D[x][y] ?? (_values2D[x][y] = new Point2()); |
| 0 | 50 | | set => _values2D[x][y]?.Set(value); |
| | 51 | | } |
| | 52 | |
|
| | 53 | | /// <inheritdoc /> |
| | 54 | | /// <summary> |
| | 55 | | /// Gets the size. |
| | 56 | | /// </summary> |
| | 57 | | /// <value> |
| | 58 | | /// The size. |
| | 59 | | /// </value> |
| 0 | 60 | | public int Size { get; private set; } |
| | 61 | |
|
| | 62 | | /// <inheritdoc /> |
| | 63 | | /// <summary> |
| | 64 | | /// Gets the horizontal size. |
| | 65 | | /// </summary> |
| | 66 | | /// <value> |
| | 67 | | /// The horizontal size. |
| | 68 | | /// </value> |
| 0 | 69 | | public int SizeX { get; private set; } |
| | 70 | |
|
| | 71 | | /// <inheritdoc /> |
| | 72 | | /// <summary> |
| | 73 | | /// Gets the vertical size. |
| | 74 | | /// </summary> |
| | 75 | | /// <value> |
| | 76 | | /// The vertical size. |
| | 77 | | /// </value> |
| 0 | 78 | | public int SizeY { get; private set; } |
| | 79 | |
|
| | 80 | | /// <inheritdoc /> |
| | 81 | | /// <summary> |
| | 82 | | /// Get [this] instance as an array. |
| | 83 | | /// </summary> |
| | 84 | | /// <returns> |
| | 85 | | /// [this] instance as an array |
| | 86 | | /// </returns> |
| 0 | 87 | | public Point2[] AsArray() => _values1D; |
| | 88 | |
|
| | 89 | | /// <inheritdoc /> |
| | 90 | | /// <summary> |
| | 91 | | /// Get [this] instance as an jagged array |
| | 92 | | /// </summary> |
| | 93 | | /// <returns> |
| | 94 | | /// [this] instance as an jagged array |
| | 95 | | /// </returns> |
| 0 | 96 | | public Point2[][] AsJaggedArray() => _values2D; |
| | 97 | |
|
| | 98 | | /// <summary> |
| | 99 | | /// Initializes a new instance of the <see cref="PointCloud2"/> class. |
| | 100 | | /// </summary> |
| | 101 | | /// <param name="sizeX">The size x.</param> |
| | 102 | | /// <param name="sizeY">The size y.</param> |
| 0 | 103 | | public PointCloud2(int sizeX, int sizeY) => Initialize(sizeX, sizeY); |
| | 104 | |
|
| | 105 | | /// <summary> |
| | 106 | | /// Updates [this] instance with the data of the specified source. |
| | 107 | | /// </summary> |
| | 108 | | /// <param name="source">The source value.</param> |
| | 109 | | public void Update(ReadOnlyMemory<Point2> source, float defaultZ) |
| 0 | 110 | | { |
| 0 | 111 | | Parallel.For(0, source.Length, i => |
| 0 | 112 | | { |
| 0 | 113 | | var val = _values1D[i]; |
| 0 | 114 | | _values1D[i].Set(val.IsValid ? source.Span[i] : new Point2(0f,0f)); |
| 0 | 115 | | } |
| 0 | 116 | | ); |
| 0 | 117 | | } |
| | 118 | |
|
| | 119 | | /// <summary> |
| | 120 | | /// Initializes the specified size y. |
| | 121 | | /// </summary> |
| | 122 | | /// <param name="sizeX">The size x.</param> |
| | 123 | | /// <param name="sizeY">The size y.</param> |
| | 124 | | public void Initialize(int sizeX, int sizeY) |
| 0 | 125 | | { |
| 0 | 126 | | SizeX = sizeX; |
| 0 | 127 | | SizeY = sizeY; |
| 0 | 128 | | Size = sizeX * sizeY; |
| | 129 | |
|
| 0 | 130 | | ArrayUtils.InitializeArray(out _values1D, Size); |
| 0 | 131 | | ArrayUtils.InitializeArray(out _values2D, SizeX, SizeY); |
| 0 | 132 | | ArrayUtils.ReferencingArrays(_values1D, _values2D); |
| 0 | 133 | | } |
| | 134 | | } |
| | 135 | | } |