Skip to content

Commit

Permalink
WorldFile added
Browse files Browse the repository at this point in the history
  • Loading branch information
halmaia committed May 19, 2023
1 parent b0efc71 commit a5fed01
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 21 deletions.
5 changes: 4 additions & 1 deletion GeoPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ namespace SL3Reader
{
public readonly struct GeoPoint
{
public GeoPoint(double x, double y, double heading, double altitude)
public GeoPoint(double x, double y, double heading, double altitude, double distance)
{
X = x;
Y = y;
Altitude = altitude;
Heading = heading;
Distance = distance;
}

public readonly double X { get; }
public readonly double Y { get; }
public readonly double Altitude { get; }
public readonly double Heading { get; }

public readonly double Distance { get; }

public override readonly string ToString()
{
CultureInfo invariantCulture = CultureInfo.InvariantCulture;
Expand Down
41 changes: 25 additions & 16 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
using static System.Console;
using System.Runtime.CompilerServices;

namespace SL3Reader {

public static class Program {
public static void Main(string[] args) {
if (args.Length != 3) {
namespace SL3Reader
{
public static class Program
{
public static void Main(string[] args)
{
if (args!.Length != 3) // Always non-null.
{
PrintUsage();
return;
}

string input = GetFullPath(args[0]);
if (!Exists(input)) {
string input = GetFullPath(args![0]);
if (!Exists(input))
{
WriteLine("Input file not found!");
PrintUsage();
return;
}

string output = GetFullPath(args[1]);
if (!Exists(GetDirectoryName(output))) {
if (!Exists(GetDirectoryName(output)))
{
WriteLine("Directory not found for the output file!");
PrintUsage();
return;
Expand All @@ -30,7 +35,8 @@ public static void Main(string[] args) {
using SL3Reader sl3reader = new(input);

string expSelector = args[2].Trim().ToLowerInvariant();
switch (expSelector) {
switch (expSelector)
{
case "-3dm":
sl3reader.Export3D(output, false, true);
PrintGreen("3D content with magnetic heading exported successfully.\n");
Expand All @@ -48,7 +54,7 @@ public static void Main(string[] args) {
PrintGreen("Side scan imagery exported successfully.\n");
break;
case "-ps":
sl3reader.ExportImagery(output,SurveyType.Primary);
sl3reader.ExportImagery(output, SurveyType.Primary);
PrintGreen("Primary scan imagery exported successfully.\n");
break;
case "-ses":
Expand All @@ -73,17 +79,18 @@ public static void Main(string[] args) {

return;

static void PrintUsage() {
static void PrintUsage()
{
WriteLine("Usage examples:\n");

WriteLine("To export route:");

WriteLine("SL3Reader.exe \"C:\\input.sl3\" \"D:\\output.csv\" -route\n");
WriteLine("To export 3D points with magnetic heading (e.g. measured with devices like Precision–9):");
WriteLine("SL3Reader.exe \"C:\\input.sl3\" \"D:\\output.csv\" -3dm\n");
WriteLine("To export 3D points with GNSS heading (e.g. in-built GPS):");
WriteLine("SL3Reader.exe \"C:\\input.sl3\" \"D:\\output.csv\" -3dg\n");

WriteLine("To export side scan imagery:");
WriteLine("SL3Reader.exe \"C:\\input.sl3\" \"D:\\OutputFolder\" -ss\n");
WriteLine("To export primary scan imagery:");
Expand All @@ -105,7 +112,8 @@ static void PrintUsage() {
}

[SkipLocalsInit]
void PrintSummary() {
void PrintSummary()
{
SortedDictionary<SurveyType, List<int>> indexByType = sl3reader.IndexByType;

WriteLine("File statistics:");
Expand All @@ -117,14 +125,15 @@ void PrintSummary() {
WriteLine("\tNumber of sidescan frames: " + indexByType[SurveyType.SideScan].Count.ToString("# ##0"));
WriteLine("\tNumber of downscan frames: " + indexByType[SurveyType.DownScan].Count.ToString("# ##0"));
WriteLine("\tNumber of 3D frames: " + indexByType[SurveyType.ThreeDimensional].Count.ToString("# ##0"));

WriteLine();
PrintGreen("\nExport finished successfully.");
}

[SkipLocalsInit]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void PrintGreen(string message) {
static void PrintGreen(string message)
{
ForegroundColor = ConsoleColor.Green;
WriteLine(message);
ForegroundColor = ConsoleColor.White;
Expand Down
2 changes: 1 addition & 1 deletion Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"SL3Reader": {
"commandName": "Project",
"commandLineArgs": "\"F:\\Sonar0000saar.sl3\" \"F:\\op.csv\" -3dm"
"commandLineArgs": "\"C:\\Users\\halmaia\\Desktop\\CardSave\\M2\\CPLE.sl3\" \"F:\\SS\" -ss"
}
}
}
29 changes: 26 additions & 3 deletions SL3Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Globalization;
using System.Buffers;
using System.Diagnostics.CodeAnalysis;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace SL3Reader
{
Expand Down Expand Up @@ -209,6 +210,26 @@ public void ExportImagery(string path, SurveyType surveyType = SurveyType.SideSc
using SafeFileHandle handle = File.OpenHandle(Path.Combine(path, prefix + final + ".bmp"),
FileMode.CreateNew, FileAccess.Write, FileShare.None, FileOptions.SequentialScan);
RandomAccess.Write(handle, fileBuffer, 0);

// World file
CultureInfo InvariantCulture = CultureInfo.InvariantCulture;
var firstStrip = AugmentedCoordinates[imageFrames[first]];
var lastStrip = AugmentedCoordinates[imageFrames[final - 1]];
var lastFrame = frames[imageFrames[final - 1]];

double XSize = -(lastStrip.Distance - firstStrip.Distance) / (final - first - 1);
double YSize = -10 * lastFrame.MaxRange * .3048 / numberOfColumns;
string WorldString = string.Join("\r\n",
new string[6]
{"0",
YSize.ToString(InvariantCulture),
XSize.ToString(InvariantCulture),
"0",
lastStrip.Distance.ToString(InvariantCulture),
lastFrame.SurveyType is SurveyType.SideScan ? (-1400*YSize).ToString(): "0"}, 0, 6);

File.WriteAllText(Path.Combine(path, prefix + final + ".bpw"), WorldString);
// End world file
}
}

Expand Down Expand Up @@ -431,8 +452,8 @@ internal void AugmentTrajectory()
if (frameCount < 1) return;

(double x0, double y0, double z0, double v0, double t0, double d0) = frames[0].QueryMetric();
coordinates.Add(new(x0, y0, d0, z0));

coordinates.Add(new(x0, y0, d0, z0, 0)); // The first one.
double distance = 0, xprev = x0, yprev = y0;

for (int i = 1; i < frameCount; i++)
{
Expand Down Expand Up @@ -466,7 +487,9 @@ internal void AugmentTrajectory()
if (double.Abs(dx) > lim)
x0 = x1 + double.CopySign(lim, dx);
}
coordinates.Add(new(x0, y0, d0, z1));

coordinates.Add(new(x0, y0, d0, z1, distance += double.Hypot(x0 - xprev, y0 - yprev)));
xprev = x0; yprev = y0;
}
}

Expand Down

0 comments on commit a5fed01

Please sign in to comment.