From 9bf7f50142286c958ecdd4533b53a83054b707fb Mon Sep 17 00:00:00 2001 From: Bert Temme Date: Mon, 10 Jun 2024 10:30:37 +0200 Subject: [PATCH] cleaning code --- src/Cesium/Axis.cs | 23 -------- src/Cesium/CesiumTransformer.cs | 10 ---- src/Cesium/Flatten.cs | 37 ------------ src/Cesium/SpatialConverter.cs | 15 ----- src/Cesium/Transforms.cs | 11 ---- src/DistanceCalculator.cs | 18 ------ src/InstancesRepository.cs | 1 - src/TileTransform.cs | 78 -------------------------- src/Tileset/TilesetClasses.cs | 1 - tests/Cesium/CesiumTransformerTests.cs | 46 --------------- tests/Cesium/SpatialConvertorTests.cs | 37 ------------ tests/DistanceCalculatorTests.cs | 21 ------- 12 files changed, 298 deletions(-) delete mode 100644 src/Cesium/Axis.cs delete mode 100644 src/Cesium/Flatten.cs delete mode 100644 src/Cesium/Transforms.cs delete mode 100644 src/DistanceCalculator.cs delete mode 100644 src/TileTransform.cs delete mode 100644 tests/DistanceCalculatorTests.cs diff --git a/src/Cesium/Axis.cs b/src/Cesium/Axis.cs deleted file mode 100644 index 97bf68c..0000000 --- a/src/Cesium/Axis.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Numerics; - -namespace i3dm.export.Cesium; -public static class Axis -{ - public static Matrix4x4 Z_UP_TO_Y_UP() - { - return new Matrix4x4( - 1, 0, 0, 0, - 0, 0, 1, 0, - 0, -1, 0, 0, - 0, 0, 0, 1); - } - - public static Matrix4x4 Y_UP_TO_Z_UP() - { - return new Matrix4x4( - 1, 0, 0, 0, - 0, 0, -1, 0, - 0, 1, 0, 0, - 0, 0, 0, 1); - } -} diff --git a/src/Cesium/CesiumTransformer.cs b/src/Cesium/CesiumTransformer.cs index f2ae951..2dd7759 100644 --- a/src/Cesium/CesiumTransformer.cs +++ b/src/Cesium/CesiumTransformer.cs @@ -1,20 +1,10 @@ using System; using System.Numerics; -using Wkx; namespace i3dm.export.Cesium; public static class CesiumTransformer { - public static double[] GetTransformer(Point p, decimal[] scale, double heading) - { - var center = SpatialConverter.GeodeticToEcef((double)p.X, (double)p.Y, (double)p.Z); - var GD_transform = SpatialConverter.EcefToEnu(center); - var transform = Flatten.Flattener(GD_transform, scale); - transform = Rotator.TransformRotateAroundZ(transform, heading); - return transform; - } - public static (Vector3 East, Vector3 Up) GetEastUp(Vector3 position, double rotation = 0) { var GD_transform = SpatialConverter.EcefToEnu(position); diff --git a/src/Cesium/Flatten.cs b/src/Cesium/Flatten.cs deleted file mode 100644 index 970faa3..0000000 --- a/src/Cesium/Flatten.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Numerics; - -namespace i3dm.export.Cesium; - -public static class Flatten -{ - public static double[] Flattener(Matrix4x4 m, decimal[] scale) - { - if (scale == null) - { - scale = new decimal[] { 1, 1, 1 }; - } - var res = new double[16]; - - res[0] = m.M11 * (float)scale[0]; - res[1] = m.M12 * (float)scale[1]; - res[2] = m.M13 * (float)scale[2]; - res[3] = m.M14; - - res[4] = m.M21 * (float)scale[0]; - res[5] = m.M22 * (float)scale[1]; - res[6] = m.M23 * (float)scale[2]; - res[7] = m.M24; - - res[8] = m.M31 * (float)scale[0]; - res[9] = m.M32 * (float)scale[1]; - res[10] = m.M33 * (float)scale[2]; - res[11] = m.M34; - - res[12] = m.M41; - res[13] = m.M42; - res[14] = m.M43; - res[15] = m.M44; - - return res; - } -} diff --git a/src/Cesium/SpatialConverter.cs b/src/Cesium/SpatialConverter.cs index b9ddb2f..4afd523 100644 --- a/src/Cesium/SpatialConverter.cs +++ b/src/Cesium/SpatialConverter.cs @@ -20,21 +20,6 @@ public static double[] ToWgs84FromSphericalMercator(double x, double y) return new double[] { lon, lat }; } - public static Vector3 GeodeticToEcef(double lon, double lat, double alt) - { - var ellipsoid = new Ellipsoid(); - double equatorialRadius = ellipsoid.SemiMajorAxis; - double eccentricity = ellipsoid.Eccentricity; - double latitudeRadians = Radian.ToRadius(lat); - double longitudeRadians = Radian.ToRadius(lon); - double altitudeRadians = alt; - double num = equatorialRadius / Math.Sqrt(1.0 - Math.Pow(eccentricity, 2.0) * Math.Pow(Math.Sin(latitudeRadians), 2.0)); - double x = (num + altitudeRadians) * Math.Cos(latitudeRadians) * Math.Cos(longitudeRadians); - double y = (num + altitudeRadians) * Math.Cos(latitudeRadians) * Math.Sin(longitudeRadians); - double z = ((1.0 - Math.Pow(eccentricity, 2.0)) * num + altitudeRadians) * Math.Sin(latitudeRadians); - return new Vector3((float)x, (float)y, (float)z); - } - public static Matrix4x4 EcefToEnu(Vector3 position) { var east = new Vector3(); diff --git a/src/Cesium/Transforms.cs b/src/Cesium/Transforms.cs deleted file mode 100644 index 473771e..0000000 --- a/src/Cesium/Transforms.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Numerics; - -namespace i3dm.export.Cesium; -public static class Transforms -{ - public static Matrix4x4 EastNorthUpToFixedFrame(Vector3 cartesian) - { - return Matrix4x4.Transpose(SpatialConverter.EcefToEnu(cartesian)); - } - -} \ No newline at end of file diff --git a/src/DistanceCalculator.cs b/src/DistanceCalculator.cs deleted file mode 100644 index 95b7f7e..0000000 --- a/src/DistanceCalculator.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -namespace i3dm.export; -public static class DistanceCalculator -{ - // got it from https://github.com/charlesRollandy/GeoCoordinate.NetStandard2/blob/master/src/GeoCoordinate.NetStandard2/GeoCoordinate.cs#L282 - public static double GetDistanceTo(double lon1, double lat1, double lon2, double lat2) - { - var d1 = lat1 * (Math.PI / 180.0); - var num1 = lon1 * (Math.PI / 180.0); - var d2 = lat2 * (Math.PI / 180.0); - var num2 = lon2 * (Math.PI / 180.0) - num1; - var d3 = Math.Pow(Math.Sin((d2 - d1) / 2.0), 2.0) + - Math.Cos(d1) * Math.Cos(d2) * Math.Pow(Math.Sin(num2 / 2.0), 2.0); - - return 6376500.0 * (2.0 * Math.Atan2(Math.Sqrt(d3), Math.Sqrt(1.0 - d3))); - } -} diff --git a/src/InstancesRepository.cs b/src/InstancesRepository.cs index 654e185..0b4fe9d 100644 --- a/src/InstancesRepository.cs +++ b/src/InstancesRepository.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Net.Http; using Wkx; namespace i3dm.export; diff --git a/src/TileTransform.cs b/src/TileTransform.cs deleted file mode 100644 index d806e15..0000000 --- a/src/TileTransform.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Numerics; - -namespace i3dm.export; - -public static class TileTransform -{ - public static double[] Flatten(Matrix4x4 m, decimal[] scale) - { - if (scale == null) - { - scale = new decimal[] { 1, 1, 1 }; - } - var res = new double[16]; - - res[0] = m.M11 * (float)scale[0]; - res[1] = m.M12 * (float)scale[1]; - res[2] = m.M13 * (float)scale[2]; - res[3] = m.M14; - - res[4] = m.M21 * (float)scale[0]; - res[5] = m.M22 * (float)scale[1]; - res[6] = m.M23 * (float)scale[2]; - res[7] = m.M24; - - res[8] = m.M31 * (float)scale[0]; - res[9] = m.M32 * (float)scale[1]; - res[10] = m.M33 * (float)scale[2]; - res[11] = m.M34; - - res[12] = m.M41; - res[13] = m.M42; - res[14] = m.M43; - res[15] = m.M44; - - return res; - } - - public static Matrix4x4 GetMatrix(Vector3 position, Vector3 eastNormalize, Vector3 northNormalized, Vector3 upNormalize) - { - var res = new Matrix4x4(); - res.M11 = eastNormalize.X; - res.M12 = eastNormalize.Y; - res.M13 = eastNormalize.Z; - res.M14 = 0; - - res.M21 = northNormalized.X; - res.M22 = northNormalized.Y; - res.M23 = northNormalized.Z; - res.M24 = 0; - - res.M31 = upNormalize.X; - res.M32 = upNormalize.Y; - res.M33 = upNormalize.Z; - res.M34 = 0; - - res.M41 = position.X; - res.M42 = position.Y; - res.M43 = position.Z; - res.M44 = 1; - return res; - } - - public static double[] GetTransform(Vector3 p, decimal[] scale, double heading, Format format) - { - var center = new Vector3(p.X, p.Y, p.Z); - var transform = GetLocalTransform(scale, heading, center, format); - return transform; - } - - public static double[] GetLocalTransform(decimal[] scale, double heading, Vector3 relativeCenter, Format format) - { - double[] transform; - var res = EnuCalculator.GetLocalEnu(format, heading, relativeCenter); - var m = GetMatrix(relativeCenter, res.East, res.North, res.Up); - transform = Flatten(m, scale); - return transform; - } -} diff --git a/src/Tileset/TilesetClasses.cs b/src/Tileset/TilesetClasses.cs index 28842dc..5774fad 100644 --- a/src/Tileset/TilesetClasses.cs +++ b/src/Tileset/TilesetClasses.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; namespace i3dm.export.Tileset; diff --git a/tests/Cesium/CesiumTransformerTests.cs b/tests/Cesium/CesiumTransformerTests.cs index ea62ff3..a58626c 100644 --- a/tests/Cesium/CesiumTransformerTests.cs +++ b/tests/Cesium/CesiumTransformerTests.cs @@ -7,52 +7,6 @@ namespace i3dm.export.tests.Cesium; class CesiumTransformerTests { - [Test] - public void TestCesiumTransformer1() - { - var lon = 4.8933281; - var lat = 52.3731013; - - var p = new Wkx.Point(lon, lat, 0); - - var globalTransform = CesiumTransformer.GetTransformer(p, new decimal[] { 1, 1, 1 }, 0); - } - - - [Test] - public void TestCesiumTransformer() - { - var lon = 5.139838; - var lat = 52.086577; - - var p = new Wkx.Point(lon, lat, 0); - - var globalTransform = CesiumTransformer.GetTransformer(p, new decimal[] { 1, 1, 1 }, 0); - var expectedTransform = new double[] { - -0.08958682417869568, - 0.9959790110588074, - -1.5050178021509955E-16, - 0.0, - -0.7857677936553955, - -0.07067863643169403, - 0.6144700050354004, - 0.0, - 0.6119993329048157, - 0.05504842475056648, - 0.7889401912689209, - 0.0, - 3911573.0, - 351840.15625, - 5008728.5, - 1.0 - }; - - for (var i = 0; i < 16; i++) - { - Assert.That(globalTransform[i].Equals(expectedTransform[i])); - } - } - [Test] public void TestGetEnuAnglesOnPosition() { diff --git a/tests/Cesium/SpatialConvertorTests.cs b/tests/Cesium/SpatialConvertorTests.cs index 7f806ca..04e30ec 100644 --- a/tests/Cesium/SpatialConvertorTests.cs +++ b/tests/Cesium/SpatialConvertorTests.cs @@ -22,43 +22,6 @@ public void TestMercatorProjection() Assert.That(Math.Round(res1[1], 3) == Math.Round(lat, 3)); } - [Test] - public void EastNorthUpTesting() - { - // sample from https://community.cesium.com/t/bounding-box-calculations-in-3d-tiles/7901/3 - var latRadians = 0.698858210; - var lonRadians = -1.3197004795898053; - - var lat = latRadians / (Math.PI / 180); - var lon = lonRadians / (Math.PI / 180); - var center = SpatialConverter.GeodeticToEcef(lon, lat, 0); - Assert.That(center.X == 1214930.9913739867f); - Assert.That(center.Y == -4736396.825676652f); - Assert.That(center.Z == 4081525.0998436413f); - - var GD_transform = SpatialConverter.EcefToEnu(center); - - Assert.That(GD_transform.M11 == 0.9686407230533828f); - Assert.That(GD_transform.M12 == 0.248465583f); - Assert.That(GD_transform.M13 == 0); - Assert.That(GD_transform.M14 == 0); - - Assert.That(GD_transform.M21 == -0.159848824f); - Assert.That(GD_transform.M22 == 0.6231691f); - Assert.That(GD_transform.M23 == 0.7655773f); - Assert.That(GD_transform.M24 == 0); - - Assert.That(GD_transform.M31 == 0.190219611f); - Assert.That(GD_transform.M32 == -0.74156934f); - Assert.That(GD_transform.M33 == 0.6433439f); - Assert.That(GD_transform.M34 == 0); - - Assert.That(GD_transform.M41 == center.X); - Assert.That(GD_transform.M42 == center.Y); - Assert.That(GD_transform.M43 == center.Z); - Assert.That(GD_transform.M44 == 1); - } - [Test] public void TestEcefToEnu() { diff --git a/tests/DistanceCalculatorTests.cs b/tests/DistanceCalculatorTests.cs deleted file mode 100644 index 5190c16..0000000 --- a/tests/DistanceCalculatorTests.cs +++ /dev/null @@ -1,21 +0,0 @@ -using NUnit.Framework; - -namespace i3dm.export.tests; -public class DistanceCalculatorTests -{ - [Test] - public void TestDistance() - { - // arrange - var longitude1 = -75.152408; - var latitude1 = 39.946975; - var longitude2 = -75.1511072856895; - var latitude2 = 39.947722248035234; - - // act - var distance = DistanceCalculator.GetDistanceTo(longitude2, latitude2, longitude1, latitude1); - - // assert - Assert.That(distance == 138.6781917667918); - } -}