| | 1 | | using System; |
| | 2 | | using System.Threading.Tasks; |
| | 3 | | using ReFlex.Core.Common.Interfaces; |
| | 4 | |
|
| | 5 | | namespace ReFlex.Core.Common.Components |
| | 6 | | { |
| | 7 | | /// <summary> |
| | 8 | | /// A ordered Quantity of <see cref="Point3" /> |
| | 9 | | /// </summary> |
| | 10 | | /// <seealso cref="IPointCloud{Point3}" /> |
| | 11 | | /// <inheritdoc /> |
| | 12 | | public class PointCloud3 : IDepthImage<Point3> |
| | 13 | | { |
| | 14 | | #region fields |
| | 15 | |
|
| | 16 | | private Point3[] _values1D; |
| | 17 | | private Point3[][] _values2D; |
| | 18 | |
|
| | 19 | | #endregion |
| | 20 | |
|
| | 21 | | #region indexer |
| | 22 | |
|
| | 23 | | /// <summary> |
| | 24 | | /// Gets or sets the <see cref="Point3" /> at the specified index. |
| | 25 | | /// </summary> |
| | 26 | | /// <value> |
| | 27 | | /// The <see cref="Point3" />. |
| | 28 | | /// </value> |
| | 29 | | /// <param name="index">The index.</param> |
| | 30 | | /// <returns></returns> |
| | 31 | | /// <inheritdoc /> |
| | 32 | | public Point3 this[int index] |
| | 33 | | { |
| | 34 | | get |
| 0 | 35 | | { |
| 0 | 36 | | if(index < 0 || index >= Size) |
| 0 | 37 | | return new Point3(); |
| 0 | 38 | | return _values1D[index] ?? (_values1D[index] = new Point3()); |
| 0 | 39 | | } |
| 0 | 40 | | set => _values1D[index]?.Set(value); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | /// <summary> |
| | 44 | | /// Gets or sets the <see cref="Point3" /> with the specified x. |
| | 45 | | /// </summary> |
| | 46 | | /// <value> |
| | 47 | | /// The <see cref="Point3" />. |
| | 48 | | /// </value> |
| | 49 | | /// <param name="x">The x.</param> |
| | 50 | | /// <param name="y">The y.</param> |
| | 51 | | /// <returns></returns> |
| | 52 | | /// <inheritdoc /> |
| | 53 | | public Point3 this[int x, int y] |
| | 54 | | { |
| 0 | 55 | | get => _values2D[x][y] ?? (_values2D[x][y] = new Point3()); |
| 0 | 56 | | set => _values2D[x][y]?.Set(value); |
| | 57 | | } |
| | 58 | |
|
| | 59 | | #endregion |
| | 60 | |
|
| | 61 | | #region properties |
| | 62 | |
|
| | 63 | | /// <summary> |
| | 64 | | /// Gets the size. |
| | 65 | | /// </summary> |
| | 66 | | /// <value> |
| | 67 | | /// The size. |
| | 68 | | /// </value> |
| | 69 | | /// <inheritdoc /> |
| 0 | 70 | | public int Size { get; private set; } |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// Gets the horizontal size. |
| | 74 | | /// </summary> |
| | 75 | | /// <value> |
| | 76 | | /// The horizontal size. |
| | 77 | | /// </value> |
| | 78 | | /// <inheritdoc /> |
| 0 | 79 | | public int SizeX { get; private set; } |
| | 80 | |
|
| | 81 | | /// <summary> |
| | 82 | | /// Gets the vertical size. |
| | 83 | | /// </summary> |
| | 84 | | /// <value> |
| | 85 | | /// The vertical size. |
| | 86 | | /// </value> |
| | 87 | | /// <inheritdoc /> |
| 0 | 88 | | public int SizeY { get; private set; } |
| | 89 | |
|
| | 90 | | #endregion |
| | 91 | |
|
| | 92 | | #region constructor |
| | 93 | |
|
| | 94 | | /// <summary> |
| | 95 | | /// Initializes a new instance of the <see cref="PointCloud3" /> class. |
| | 96 | | /// </summary> |
| | 97 | | /// <param name="sizeX">The size x.</param> |
| | 98 | | /// <param name="sizeY">The size y.</param> |
| 0 | 99 | | public PointCloud3(int sizeX, int sizeY) => Initialize(sizeX, sizeY); |
| | 100 | |
|
| | 101 | | #endregion |
| | 102 | |
|
| | 103 | | #region methods |
| | 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 | | // /// <inheritdoc /> |
| | 110 | | // public void Update(Point3[] source) |
| | 111 | | // { |
| | 112 | | // for (int i = 0; i < source.Length; ++i) { |
| | 113 | | // _values1D[i].Set(source[i]); |
| | 114 | | // } |
| | 115 | | // } |
| | 116 | |
|
| | 117 | | /// <summary> |
| | 118 | | /// Updates [this] instance with the data of the specified source. |
| | 119 | | /// </summary> |
| | 120 | | /// <param name="source">The source value.</param> |
| | 121 | | /// <inheritdoc /> |
| | 122 | | public void Update(ReadOnlyMemory<Point3> source, float defaultZ) |
| 0 | 123 | | { |
| 0 | 124 | | Parallel.For(0, source.Length, i => |
| 0 | 125 | | { |
| 0 | 126 | | _values1D[i].Set(source.Span[i]); |
| 0 | 127 | |
|
| 0 | 128 | | var val = source.Span[i]; |
| 0 | 129 | | var target = _values1D[i]; |
| 0 | 130 | | _values1D[i].Set(target.IsValid |
| 0 | 131 | | ? source.Span[i] |
| 0 | 132 | | : new Point3(val.X, val.Y, defaultZ)); |
| 0 | 133 | | } |
| 0 | 134 | | ); |
| 0 | 135 | | } |
| | 136 | |
|
| | 137 | | /// <summary> |
| | 138 | | /// Initializes the specified size y. |
| | 139 | | /// </summary> |
| | 140 | | /// <param name="sizeX">The size x.</param> |
| | 141 | | /// <param name="sizeY">The size y.</param> |
| | 142 | | public void Initialize(int sizeX, int sizeY) |
| 0 | 143 | | { |
| 0 | 144 | | SizeX = sizeX; |
| 0 | 145 | | SizeY = sizeY; |
| 0 | 146 | | Size = sizeX * sizeY; |
| | 147 | |
|
| 0 | 148 | | ArrayUtils.InitializeArray(out _values1D, Size); |
| 0 | 149 | | ArrayUtils.InitializeArray(out _values2D, SizeX, sizeY); |
| 0 | 150 | | ArrayUtils.ReferencingArrays(_values1D, _values2D); |
| 0 | 151 | | } |
| | 152 | |
|
| 0 | 153 | | public Point3[] AsArray() => _values1D; |
| | 154 | |
|
| 0 | 155 | | public Span<Point3> AsSpan() => _values1D.AsSpan(); |
| | 156 | |
|
| 0 | 157 | | public Memory<Point3> AsMemory() => _values1D.AsMemory(); |
| | 158 | |
|
| 0 | 159 | | public Point3[][] AsJaggedArray() => _values2D; |
| | 160 | |
|
| | 161 | | #endregion |
| | 162 | | } |
| | 163 | | } |