| | | 1 | | using System; |
| | | 2 | | using System.Runtime.CompilerServices; |
| | | 3 | | |
| | | 4 | | [assembly: InternalsVisibleTo("ReFlex.Core.Implementation")] |
| | | 5 | | |
| | | 6 | | namespace ReFlex.Core.Common.Components |
| | | 7 | | { |
| | | 8 | | /// <summary>A completed sensor observation with a paired point cloud and vector field.</summary> |
| | | 9 | | public sealed class TrackingObservation |
| | | 10 | | { |
| | 116 | 11 | | internal bool OwnsRasters { get; } |
| | | 12 | | |
| | 174 | 13 | | public long Sequence { get; } |
| | 256 | 14 | | public double TimestampSeconds { get; } |
| | 104 | 15 | | public PointCloud3 PointCloud { get; } |
| | 106 | 16 | | public VectorField2 VectorField { get; } |
| | | 17 | | |
| | | 18 | | public TrackingObservation(long sequence, double timestampSeconds, PointCloud3 cloud, VectorField2 vectors) |
| | 88 | 19 | | : this(sequence, timestampSeconds, cloud, vectors, null) |
| | 88 | 20 | | { |
| | 88 | 21 | | } |
| | | 22 | | |
| | | 23 | | // The caller owns the spare and may reuse it only after all readers have finished. |
| | 118 | 24 | | internal TrackingObservation(long sequence, double timestampSeconds, PointCloud3 cloud, VectorField2 vectors, |
| | 118 | 25 | | TrackingObservation spare, bool copyRasters = true) |
| | 118 | 26 | | { |
| | 118 | 27 | | if (!double.IsFinite(timestampSeconds)) throw new ArgumentOutOfRangeException(nameof(timestampSeconds)); |
| | 118 | 28 | | Sequence = sequence; |
| | 118 | 29 | | TimestampSeconds = timestampSeconds; |
| | 118 | 30 | | OwnsRasters = copyRasters; |
| | 118 | 31 | | PointCloud = copyRasters ? CopyCloud(cloud, spare?.PointCloud) : cloud; |
| | 118 | 32 | | VectorField = copyRasters ? CopyVectors(vectors, spare?.VectorField) : vectors; |
| | 118 | 33 | | } |
| | | 34 | | |
| | | 35 | | internal static PointCloud3 CopyCloud(PointCloud3 cloud, PointCloud3 buffer = null) |
| | 110 | 36 | | { |
| | 110 | 37 | | if (cloud == null) return null; |
| | 110 | 38 | | if (buffer?.SizeX != cloud.SizeX || buffer.SizeY != cloud.SizeY) |
| | 104 | 39 | | buffer = new PointCloud3(cloud.SizeX, cloud.SizeY); |
| | | 40 | | |
| | 110 | 41 | | var source = cloud.AsArray(); |
| | 110 | 42 | | var target = buffer.AsArray(); |
| | 184752 | 43 | | for (var i = 0; i < source.Length; i++) |
| | 92266 | 44 | | { |
| | 92266 | 45 | | target[i].Set(source[i]); |
| | 92266 | 46 | | target[i].IsValid = source[i].IsValid; |
| | 92266 | 47 | | target[i].IsFiltered = source[i].IsFiltered; |
| | 92266 | 48 | | } |
| | 110 | 49 | | return buffer; |
| | 110 | 50 | | } |
| | | 51 | | |
| | | 52 | | internal static VectorField2 CopyVectors(VectorField2 vectors, VectorField2 buffer = null) |
| | 114 | 53 | | { |
| | 114 | 54 | | if (vectors == null) return null; |
| | 114 | 55 | | if (buffer?.SizeX != vectors.SizeX || buffer.SizeY != vectors.SizeY || buffer.Stride != vectors.Stride) |
| | 108 | 56 | | buffer = new VectorField2(vectors.SizeX, vectors.SizeY, vectors.Stride); |
| | | 57 | | |
| | 114 | 58 | | var source = vectors.AsArray(); |
| | 114 | 59 | | var target = buffer.AsArray(); |
| | 191960 | 60 | | for (var i = 0; i < source.Length; i++) |
| | 95866 | 61 | | { |
| | 95866 | 62 | | target[i].Set(source[i]); |
| | 95866 | 63 | | target[i].IsValid = source[i].IsValid; |
| | 95866 | 64 | | } |
| | 114 | 65 | | return buffer; |
| | 114 | 66 | | } |
| | | 67 | | } |
| | | 68 | | } |