Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 6 additions & 31 deletions src/InstancesRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ public static List<Instance> GetInstances(NpgsqlConnection conn, string geometry
var toX = ToInvariantCulture(bbox.XMax);
var toY = ToInvariantCulture(bbox.YMax);

var scaleNonUniform = useScaleNonUniform ? "scale_non_uniform as scalenonuniform, " : string.Empty;
conn.Open();
var columns = GetColumns(conn, geometryTable);
var scaleSelect = GetScaleSelectFromColumns(columns, useScaleNonUniform, geometryTable);
var select = keepProjection?
$"SELECT ST_ASBinary(st_force3d({geometryColumn})) as position, {scaleSelect} model, tags":
$"SELECT ST_ASBinary(ST_Transform(st_force3d({geometryColumn}), {target_epsg})) as position, {scaleSelect} model, tags";
$"SELECT ST_ASBinary(st_force3d({geometryColumn})) as position, scale, {scaleNonUniform} model, tags":
$"SELECT ST_ASBinary(ST_Transform(st_force3d({geometryColumn}), {target_epsg})) as position, scale, {scaleNonUniform} model, tags";

var orientationSelect = GetOrientationSelect(columns, geometryTable, useGpuInstancing);
var orientationSelect = GetOrientationSelect(conn, geometryTable, useGpuInstancing);
select += orientationSelect;

var sql = FormattableString.Invariant($"{select} FROM {geometryTable} where {GetWhere(geometryColumn, where, fromX, fromY, toX, toY, source_epsg, keepProjection)}");
Expand Down Expand Up @@ -105,8 +104,9 @@ public static (BoundingBox bbox, double zmin, double zmax) GetBoundingBoxForTabl
return (bbox, zmin, zmax);
}

private static string GetOrientationSelect(HashSet<string> columns, string geometryTable, bool useGpuInstancing)
private static string GetOrientationSelect(NpgsqlConnection conn, string geometryTable, bool useGpuInstancing)
{
var columns = GetColumns(conn, geometryTable);
var select = GetOrientationSelectFromColumns(columns, useGpuInstancing, geometryTable, out var usesDeprecatedRotation);

if (usesDeprecatedRotation)
Expand Down Expand Up @@ -158,31 +158,6 @@ private static string GetOrientationSelectFromColumns(HashSet<string> columns, b
throw new InvalidOperationException($"Missing orientation columns for {mode}. Expected columns yaw/pitch/roll. For non-GPU you can use legacy rotation (deprecated).\n\nMigration example:\n alter table {geometryTable} add column if not exists yaw double precision default 0;\n alter table {geometryTable} add column if not exists pitch double precision default 0;\n alter table {geometryTable} add column if not exists roll double precision default 0;\n update {geometryTable} set yaw = rotation where rotation is not null;");
}

private static string GetScaleSelectFromColumns(HashSet<string> columns, bool useScaleNonUniform, string geometryTable)
{
var hasScale = columns.Contains("scale");
var hasScaleNonUniform = columns.Contains("scale_non_uniform");

if (useScaleNonUniform)
{
if (!hasScaleNonUniform)
{
throw new InvalidOperationException($"Missing column 'scale_non_uniform' on table {geometryTable}. Add it with:\n alter table {geometryTable} add column if not exists scale_non_uniform double precision[3];");
}

// scale column is optional when using scale_non_uniform
var scalePart = hasScale ? "scale, " : string.Empty;
return $"{scalePart}scale_non_uniform as scalenonuniform, ";
}

if (!hasScale)
{
throw new InvalidOperationException($"Missing column 'scale' on table {geometryTable}. Add it with:\n alter table {geometryTable} add column if not exists scale double precision default 1;");
}

return "scale, ";
}

private static void WriteRotationDeprecatedWarning(string geometryTable)
{
if (_rotationDeprecatedWarningWritten) return;
Expand Down
6 changes: 3 additions & 3 deletions src/i3dm.export.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
<PackageReference Include="Accord.MachineLearning" Version="3.8.0" />
<PackageReference Include="cmpt-tile" Version="0.2.4" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Dapper" Version="2.1.79" />
<PackageReference Include="Dapper" Version="2.1.72" />
<PackageReference Include="i3dm.tile" Version="1.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Npgsql" Version="10.0.3" />
<PackageReference Include="Npgsql" Version="10.0.2" />
<PackageReference Include="SharpGLTF.Ext.3DTiles" Version="1.0.6" />
<PackageReference Include="SharpGLTF.Toolkit" Version="1.0.6" />
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
<PackageReference Include="subtree" Version="1.7.0" />
<PackageReference Include="System.Text.Json" Version="10.0.10" />
<PackageReference Include="System.Text.Json" Version="10.0.5" />
<PackageReference Include="Wkx" Version="0.5.1" />
</ItemGroup>

Expand Down
53 changes: 7 additions & 46 deletions tests/InstancesRepositoryCompatibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ public void OrientationSelect_WhenYawPitchRollMissing_NonGpuFallsBackToRotation(
[Test]
public void OrientationSelect_WhenYawPitchRollMissing_GpuThrows()
{
Action action = () =>
InvokeGetOrientationSelectFromColumns(
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"rotation"
},
useGpuInstancing: true);

Assert.Throws<TargetInvocationException>(action);
Assert.Throws<TargetInvocationException>(() =>
{
InvokeGetOrientationSelectFromColumns(new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"rotation"
}, useGpuInstancing: true);
});
}

private static (string Select, bool UsedRotation) InvokeGetOrientationSelectFromColumns(HashSet<string> columns, bool useGpuInstancing)
Expand All @@ -60,41 +58,4 @@ private static (string Select, bool UsedRotation) InvokeGetOrientationSelectFrom
var usedRotation = (bool)args[3];
return (select, usedRotation);
}

[Test]
public void ScaleSelect_WhenUseScaleNonUniformTrue_AndOnlyScaleNonUniformColumnExists_DoesNotRequireScaleColumn()
{
// Table only has scale_non_uniform, no scale column
var select = InvokeGetScaleSelectFromColumns(new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"scale_non_uniform"
}, useScaleNonUniform: true);

Assert.That(select, Does.Not.Contain("scale,"));
Assert.That(select, Does.Contain("scale_non_uniform as scalenonuniform"));
}

[Test]
public void ScaleSelect_WhenUseScaleNonUniformFalse_AndScaleColumnMissing_Throws()
{
Action action = () =>
InvokeGetScaleSelectFromColumns(new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"scale_non_uniform"
}, useScaleNonUniform: false);

Assert.Throws<TargetInvocationException>(action);
}

private static string InvokeGetScaleSelectFromColumns(HashSet<string> columns, bool useScaleNonUniform)
{
var method = typeof(InstancesRepository).GetMethod(
"GetScaleSelectFromColumns",
BindingFlags.NonPublic | BindingFlags.Static);

Assert.That(method, Is.Not.Null);

var args = new object[] { columns, useScaleNonUniform, "public.instances" };
return (string)method!.Invoke(null, args)!;
}
}
8 changes: 4 additions & 4 deletions tests/i3dm.export.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Npgsql" Version="10.0.3" />
<PackageReference Include="NUnit" Version="4.6.1" />
<PackageReference Include="Npgsql" Version="10.0.2" />
<PackageReference Include="NUnit" Version="4.5.1" />
<PackageReference Include="NUnit3TestAdapter" Version="6.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.8.1" />
<PackageReference Include="System.Text.Json" Version="10.0.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="System.Text.Json" Version="10.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading