Skip to content

Commit

Permalink
Itermediate state. Do not use!
Browse files Browse the repository at this point in the history
  • Loading branch information
halmaia committed Feb 1, 2023
1 parent bff5468 commit d0e8412
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
20 changes: 13 additions & 7 deletions Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ public interface IFrame
[field: FieldOffset(28)] public readonly float UnknownAt28 { get; } // (28)
[field: FieldOffset(32)] public readonly float UnknownAt32 { get; } // (32)
[field: FieldOffset(36)] public readonly float UnknownAt36 { get; } // (36)

[field: FieldOffset(40)] public readonly uint HardwareTime { get; } // (40)

[field: FieldOffset(44)] public readonly uint LengthOfEchoData { get; } // (44)
[field: FieldOffset(48)] public readonly float WaterDepth { get; } // (48)
[field: FieldOffset(52)] public readonly Frequency Frequency { get; } // (52)
Expand All @@ -119,15 +117,16 @@ public interface IFrame
[field: FieldOffset(72)] public readonly float UnknownAt72 { get; } // (72)
[field: FieldOffset(76)] public readonly float UnknownAt76 { get; } // (76)
[field: FieldOffset(80)] public readonly float UnknownAt80 { get; } // (80)

[field: FieldOffset(84)] public readonly float GNSSSpeed { get; } // (84)
[field: FieldOffset(88)] public readonly float WaterTemperature { get; } // (88)

[field: FieldOffset(92)] public readonly int X { get; } // (92)
[field: FieldOffset(96)] public readonly int Y { get; } // (96)

[field: FieldOffset(100)] public readonly float WaterSpeed { get; } // (100)

/// <summary>
/// Heading of the vessel, calculation based on GNSS readings only.
/// (No drift was taken into account.) Unit: radians. Direction: azimuthal (↻⁻;
/// north is zero or 2·π, east is π/2.)
/// </summary>
[field: FieldOffset(104)] public readonly float GNSSHeading { get; } // (104)
[field: FieldOffset(108)] public readonly float GNSSAltitude { get; } // (108)
[field: FieldOffset(112)] public readonly float MagneticHeading { get; } // (112)
Expand Down Expand Up @@ -260,7 +259,14 @@ private readonly string GetDebuggerDisplay() =>
#region Unpack support
public (double x, double y, double v, double t, double d) UnpackNavParameters()
{
return (X, Y, (1825d / 3600d) * GNSSSpeed, Milliseconds / 1000d, (double.Pi / 2d) - GNSSHeading);
const double KnotsToMPS = 1852d / 3600d;
const double HalfPI = double.Pi / 2d;
const double MillisecondsToSeconds = 1d / 1000d;

return (X, Y,
KnotsToMPS * GNSSSpeed,
MillisecondsToSeconds * Milliseconds,
HalfPI - GNSSHeading);
}
#endregion Unpack support
}
Expand Down
34 changes: 23 additions & 11 deletions SL3Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using static System.Runtime.InteropServices.NativeMemory;
using Microsoft.Win32.SafeHandles;
using System.Numerics;

namespace SL3Reader
{
Expand Down Expand Up @@ -55,6 +56,16 @@ private List<IFrame> CreateNewFrameList(IEnumerable<IFrame> collection)

#endregion Frame support

#region Augmented Coordinates
private List<Vector2> augmentedCoordinates;
public List<Vector2> AugmentedCoordinates => augmentedCoordinates ??= CreateNewCoordinateList();
private List<Vector2> CreateNewCoordinateList()
{
const long averageFrameSize = 2118L; // Empirically set value to avoid frequent resize of the underlying array.
return new((int)(Length / averageFrameSize));
}
#endregion Augmented Coordinates

#region Indices
private SortedDictionary<SurveyType, List<IFrame>> indexByType;
private SortedDictionary<uint, List<IFrame>> indexByCampaign;
Expand Down Expand Up @@ -347,28 +358,29 @@ public unsafe void Export3D(string path)

internal void AugmentTrajectory()
{
using StreamWriter streamWriter = File.CreateText(@"F:\ox.csv");
streamWriter.WriteLine("X,Y");
const double lim = 1.2d;
const double C = 1.4326d; // Emirical

List<Vector2> crds = AugmentedCoordinates;

int frameCount = Frames.Count; // Initialize the frames.
if (frameCount < 1) return;

(double x, double y, double v, double t, double d) =
Frames[0].UnpackNavParameters();
streamWriter.WriteLine(x.ToString() + "," + y.ToString());
crds.Add(new((float)x, (float)y));

for (int i = 1; i < frameCount; i++)
{
const double lim = 1.2d;
const double gyk = 1.4326d; // Emirical
IFrame frame = Frames[i];
(double nx, double ny, double nv, double nt, double nd) =
frame.UnpackNavParameters();
double sv = nv + nv, dt = nt - t;
double vec = gyk * .5d * sv * dt, ad = (nv * nd + v * d) / sv;
(double Sin, double Cos) = double.SinCos(ad);
double sv = v + nv, dt = nt - t;
double vec = C * .5d * sv * dt, ad = (nv * nd + v * d) / sv;
(double sin, double cos) = double.SinCos(ad);

y = double.FusedMultiplyAdd(vec, Sin, y);
x = double.FusedMultiplyAdd(vec, Cos, x);
y = double.FusedMultiplyAdd(vec, sin, y);
x = double.FusedMultiplyAdd(vec, cos, x);
t = nt;
v = nv;
d = nd;
Expand All @@ -384,7 +396,7 @@ internal void AugmentTrajectory()
if (double.Abs(dx) > lim)
x = nx + double.CopySign(lim, dx);
}
streamWriter.WriteLine(x.ToString() + "," + y.ToString());
crds.Add(new((float)x, (float)y));
}
}

Expand Down

0 comments on commit d0e8412

Please sign in to comment.