From fbc0710350b385a1e53e647dbe4a2622eb4f41e7 Mon Sep 17 00:00:00 2001 From: andreiveselov <35749135+andreiveselov@users.noreply.github.com> Date: Mon, 14 Aug 2023 08:07:46 -0400 Subject: [PATCH 1/3] Changes to support coordinate system that use units other than meters. Added a scale factor that can be used for proper tiles scaling if coordinate system uses units other than meters (i.e. survey feet or feet that are common in US) Also added base Geometric error as a parameter. I found that 100 worked well for meters, but I need something like 300-500 for datasets that uses feet. --- Obj2Tiles/Options.cs | 6 ++++++ Obj2Tiles/Program.cs | 9 +++++++-- Obj2Tiles/Stages/Model/GpsCoords.cs | 26 +++++++++++++++++++------- Obj2Tiles/Stages/TilingStage.cs | 4 ++-- README.md | 2 ++ 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/Obj2Tiles/Options.cs b/Obj2Tiles/Options.cs index 8c5db04..18dfc6b 100644 --- a/Obj2Tiles/Options.cs +++ b/Obj2Tiles/Options.cs @@ -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; } diff --git a/Obj2Tiles/Program.cs b/Obj2Tiles/Program.cs index 57a51dc..eb3d616 100644 --- a/Obj2Tiles/Program.cs +++ b/Obj2Tiles/Program.cs @@ -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); } diff --git a/Obj2Tiles/Stages/Model/GpsCoords.cs b/Obj2Tiles/Stages/Model/GpsCoords.cs index 316c2d3..e8f2b73 100644 --- a/Obj2Tiles/Stages/Model/GpsCoords.cs +++ b/Obj2Tiles/Stages/Model/GpsCoords.cs @@ -5,12 +5,14 @@ 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() @@ -18,19 +20,21 @@ 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); @@ -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, s + }; + var mult = MultiplyMatrix(res, rot); - return ConvertToColumnMajorOrder(mult); + return MultiplyMatrix(ConvertToColumnMajorOrder(mult), scale); } public static readonly double[] rot = { @@ -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}"; } } \ No newline at end of file diff --git a/Obj2Tiles/Stages/TilingStage.cs b/Obj2Tiles/Stages/TilingStage.cs index 63bb2c9..c0f4731 100644 --- a/Obj2Tiles/Stages/TilingStage.cs +++ b/Obj2Tiles/Stages/TilingStage.cs @@ -11,7 +11,7 @@ namespace Obj2Tiles.Stages; public static partial class StagesFacade { - public static void Tile(string sourcePath, string destPath, int lods, Dictionary[] boundsMapper, + public static void Tile(string sourcePath, string destPath, int lods, double baseError, Dictionary[] boundsMapper, GpsCoords? coords = null) { @@ -29,7 +29,7 @@ public static void Tile(string sourcePath, string destPath, int lods, Dictionary // 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 diff --git a/README.md b/README.md index 326af25..629c65e 100644 --- a/README.md +++ b/README.md @@ -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) From b026ca7d1fb0b59c14a95f0ef89a1864e4f3609b Mon Sep 17 00:00:00 2001 From: andreiveselov <35749135+andreiveselov@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:46:55 -0400 Subject: [PATCH 2/3] Fixed failing test --- Obj2Tiles.Test/StagesTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obj2Tiles.Test/StagesTests.cs b/Obj2Tiles.Test/StagesTests.cs index fd6213f..2f3b2bf 100644 --- a/Obj2Tiles.Test/StagesTests.cs +++ b/Obj2Tiles.Test/StagesTests.cs @@ -47,7 +47,7 @@ public void TilingStage_Tile() 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 }); } From ce87a189d716c6b1e4e256c9b81bb9469acfecaf Mon Sep 17 00:00:00 2001 From: andreiveselov <35749135+andreiveselov@users.noreply.github.com> Date: Tue, 29 Aug 2023 08:57:14 -0400 Subject: [PATCH 3/3] Update GpsCoords.cs Fixed scale matrix to have last element to be 1 --- Obj2Tiles/Stages/Model/GpsCoords.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Obj2Tiles/Stages/Model/GpsCoords.cs b/Obj2Tiles/Stages/Model/GpsCoords.cs index e8f2b73..3713565 100644 --- a/Obj2Tiles/Stages/Model/GpsCoords.cs +++ b/Obj2Tiles/Stages/Model/GpsCoords.cs @@ -72,7 +72,7 @@ public double[] ToEcefTransform() s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, - 0, 0, 0, s + 0, 0, 0, 1 }; var mult = MultiplyMatrix(res, rot);