Skip to content

Commit

Permalink
Command line args added.
Browse files Browse the repository at this point in the history
  • Loading branch information
halmaia committed Mar 2, 2023
1 parent cab5b8f commit e04cee1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
33 changes: 27 additions & 6 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public static void Main(string[] args) {

string expSelector = args[2].Trim().ToLowerInvariant();
switch (expSelector) {
case "-3d":
sl3reader.Export3D(output);
case "-3dm":
sl3reader.Export3D(output, false, true);
break;
case "-3dg":
sl3reader.Export3D(output, false, false);
break;
case "-route":
sl3reader.ExportToCSV(output);
Expand All @@ -45,15 +48,33 @@ public static void Main(string[] args) {
return;

static void PrintUsage() {
Console.WriteLine("Usage examples:");
Console.WriteLine("To export 3D points: SL3Reader.exe \"C:\\input.sl3\" \"D:\\output.csv\" -3d");
Console.WriteLine("To export route: SL3Reader.exe \"C:\\input.sl3\" \"D:\\output.csv\" -route");
Console.WriteLine("Usage examples:\n");

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

void PrintSummary() {
var indexByType = sl3reader.IndexByType;

Console.WriteLine("File statistics:");
Console.WriteLine("Number of frames: " + sl3reader.Frames.Count.ToString());
Console.WriteLine("Number of 3D frames: " + sl3reader.IndexByType[SurveyType.ThreeDimensional].Count.ToString());
Console.WriteLine("Number of primary frames: " + indexByType[SurveyType.Primary].Count.ToString());
Console.WriteLine("Number of primary frames: " + indexByType[SurveyType.Secondary].Count.ToString());
Console.WriteLine("Number of left sidescan frames: " + indexByType[SurveyType.LeftSidescan].Count.ToString());
Console.WriteLine("Number of right sidescan frames: " + indexByType[SurveyType.RightSidescan].Count.ToString());
Console.WriteLine("Number of sidescan frames: " + indexByType[SurveyType.SideScan].Count.ToString());
Console.WriteLine("Number of downscan frames: " + indexByType[SurveyType.DownScan].Count.ToString());
Console.WriteLine("Number of 3D frames: " + indexByType[SurveyType.ThreeDimensional].Count.ToString());

Console.WriteLine();
Console.ForegroundColor= ConsoleColor.Green;
Console.WriteLine("\nExport finished successfully.");
Console.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": "\"C:\\Users\\halmaia\\Desktop\\CardSave\\FEL.sl3\" \"F:\\op.csv\" -q"
"commandLineArgs": "\"C:\\Users\\halmaia\\Desktop\\CardSave\\FEL.sl3\" \"F:\\op.csv\" -3dm"
}
}
}
24 changes: 9 additions & 15 deletions SL3Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,35 +278,29 @@ public unsafe void ExamineUnknown8Datasets()
public unsafe void Export3D(string path, bool includeUnreliable = false, bool magneticHeading = false)
{
ArgumentNullException.ThrowIfNull(nameof(path));

path = Path.GetFullPath(path);

var frames = Frames;
var coords = AugmentedCoordinates;


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

using StreamWriter streamWriter = File.CreateText(path);

List<int> frames3D = IndexByType[SurveyType.ThreeDimensional];
int frames3DLength = frames3D.Count;
if (frames3DLength < 1) return;

// Test
// List<IFrame> framesSS = IndexByType[SurveyType.SideScan];
//framesSS[56].GetNearest3DFrame(frames3D, out IFrame? frm);
// END Test
using StreamWriter streamWriter = File.CreateText(path);
streamWriter.WriteLine("Campaign,X,Y,Z,Reliability");

List<GeoPoint> augmentedCoordinates = AugmentedCoordinates;
ThreeDimensionalFrameHeader header = new();
Span<byte> sHeader = new(&header, ThreeDimensionalFrameHeader.Size);
byte* measurements = stackalloc byte[400 * InterferometricMeasurement.Size],
reset = measurements;

for (int i = 0; i < frames3DLength; i++)
{
IFrame frame = frames[frames3D[i]];
var coord = coords[frames3D[i]]; // TODO: remove double ref.
int frame3DIndex = frames3D[i];
IFrame frame = frames[frame3DIndex];
GeoPoint augmentedCoordinate = augmentedCoordinates[frame3DIndex];
long offset = frame.DataOffset;
if (Seek(offset, SeekOrigin.Begin) != offset)
throw new IOException("Unable to seek!");
Expand All @@ -316,7 +310,7 @@ public unsafe void Export3D(string path, bool includeUnreliable = false, bool ma
ReadExactly(new(measurements, header.NumberOfUsedBytes));

uint campaignID = frame.CampaignID;
double centralX = coord.X, centralY = coord.Y, centralZ = .3048 * coord.Altitude;
double centralX = augmentedCoordinate.X, centralY = augmentedCoordinate.Y, centralZ = .3048 * augmentedCoordinate.Altitude;
(double sin, double cos) = double.SinCos((magneticHeading ? frame.MagneticHeading : frame.GNSSHeading) - .5 * double.Pi);

// Left side
Expand Down

0 comments on commit e04cee1

Please sign in to comment.