Skip to content

Commit

Permalink
Merge pull request #52 from andreiveselov/Support-coordinate-system-f…
Browse files Browse the repository at this point in the history
…eet-and-survey-feet

Changes to support coordinate system that use units other than meters.
  • Loading branch information
pierotofy committed Oct 6, 2023
2 parents f3a4c3e + ce87a18 commit 7ab8c4e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Obj2Tiles.Test/StagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ select new
Name = Path.GetFileNameWithoutExtension(file)
}).ToDictionary(item => item.Name, item => item.Bounds);

StagesFacade.Tile("TestData/Tile1", testPath, 1, new[] { boundsMapper });
StagesFacade.Tile("TestData/Tile1", testPath, 1, 100, new[] { boundsMapper });

}

Expand Down
6 changes: 6 additions & 0 deletions Obj2Tiles/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public sealed class Options

[Option("alt", Required = false, HelpText = "Altitude of the mesh (meters)", Default = 0)]
public double Altitude { get; set; }

[Option("scale", Required = false, HelpText = "Scale for data if using units other than meters ( 1200.0/3937.0 for survey ft)", Default = 1.0)]
public double Scale { get; set; }

[Option('e',"error", Required = false, HelpText = "Base error for root node", Default = 100.0)]
public double BaseError { get; set; }

[Option("use-system-temp", Required = false, HelpText = "Uses the system temp folder", Default = false)]
public bool UseSystemTempFolder { get; set; }
Expand Down
9 changes: 7 additions & 2 deletions Obj2Tiles/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,20 @@ private static async Task Run(Options opts)
return;

var gpsCoords = opts.Latitude != null && opts.Longitude != null
? new GpsCoords(opts.Latitude.Value, opts.Longitude.Value, opts.Altitude)
? new GpsCoords(opts.Latitude.Value, opts.Longitude.Value, opts.Altitude, opts.Scale)
: null;

Console.WriteLine();
Console.WriteLine($" => Tiling stage {(gpsCoords != null ? $"with GPS coords {gpsCoords}" : "")}");

var baseError = opts.BaseError;

Console.WriteLine();
Console.WriteLine($" => Tiling stage with baseError {baseError}");

sw.Restart();

StagesFacade.Tile(destFolderSplit, opts.Output, opts.LODs, boundsMapper, gpsCoords);
StagesFacade.Tile(destFolderSplit, opts.Output, opts.LODs, opts.BaseError, boundsMapper, gpsCoords);

Console.WriteLine(" ?> Tiling stage done in {0}", sw.Elapsed);
}
Expand Down
26 changes: 19 additions & 7 deletions Obj2Tiles/Stages/Model/GpsCoords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ public class GpsCoords
public double Latitude { get; set; }
public double Longitude { get; set; }
public double Altitude { get; set; }
public double Scale { get; set; }

public GpsCoords(double latitude, double longitude, double altitude)
public GpsCoords(double latitude, double longitude, double altitude, double scale)
{
Latitude = latitude;
Longitude = longitude;
Altitude = altitude;
Scale = scale;
}

public GpsCoords()
{
Latitude = 0;
Longitude = 0;
Altitude = 0;
Scale = 1;
}

public double[] ToEcefTransform()
{
var s = Scale;
var lat = Latitude * Math.PI / 180;
var lon = Longitude * Math.PI / 180;
var alt = Altitude;

const double a = 6378137;
const double b = 6356752.3142;
const double f = (a - b) / a;
var a = 6378137.0/s;
var b = 6356752.3142/s;
var f = (a - b) / a;

const double eSq = 2 * f - f * f;
var eSq = 2 * f - f * f;

var sinLat = Math.Sin(lat);
var cosLat = Math.Cos(lat);
Expand Down Expand Up @@ -63,9 +67,17 @@ public double[] ToEcefTransform()
0, 0, 0, 1
};

var scale = new double[]
{
s, 0, 0, 0,
0, s, 0, 0,
0, 0, s, 0,
0, 0, 0, 1
};

var mult = MultiplyMatrix(res, rot);

return ConvertToColumnMajorOrder(mult);
return MultiplyMatrix(ConvertToColumnMajorOrder(mult), scale);
}

public static readonly double[] rot = {
Expand Down Expand Up @@ -112,6 +124,6 @@ public static double[] MultiplyMatrix(double[] m1, double[] m2)

public override string ToString()
{
return $"{Latitude}, {Longitude}, {Altitude}";
return $"{Latitude}, {Longitude}, {Altitude}, {Scale}";
}
}
4 changes: 2 additions & 2 deletions Obj2Tiles/Stages/TilingStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Obj2Tiles.Stages;

public static partial class StagesFacade
{
public static void Tile(string sourcePath, string destPath, int lods, Dictionary<string, Box3>[] boundsMapper,
public static void Tile(string sourcePath, string destPath, int lods, double baseError, Dictionary<string, Box3>[] boundsMapper,
GpsCoords? coords = null)
{

Expand All @@ -29,7 +29,7 @@ public static partial class StagesFacade

// Don't ask me why 100, I have no idea but it works
// https://github.com/CesiumGS/3d-tiles/issues/162
const int baseError = 100;
//const int baseError = 100;

// Generate tileset.json
var tileset = new Tileset
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ You can download precompiled binaries for Windows, Linux and macOS from https://
--lat Latitude of the mesh
--lon Longitude of the mesh
--alt (Default: 0) Altitude of the mesh (meters)
-e, --error (Default: 100), baseError value for root node
--scale (Default: 1), scale for data if using units other than meters ( 1200.0/3937.0 for survey ft)
--use-system-temp (Default: false) Uses the system temp folder
--keep-intermediate (Default: false) Keeps the intermediate files (do not cleanup)
Expand Down

0 comments on commit 7ab8c4e

Please sign in to comment.