From 69c600c474d07090fa789f099f9dba873672454c Mon Sep 17 00:00:00 2001 From: Stefan Maierhofer Date: Tue, 19 Sep 2023 11:29:13 +0200 Subject: [PATCH] structured point clouds: add tests (failing) --- src/Aardvark.Algodat.Tests/ImportTests.cs | 113 +++++++++++++++++- src/Aardvark.Data.Points.Base/ParseConfig.cs | 43 +++++++ .../Octrees/ImportConfig.cs | 21 ++++ 3 files changed, 174 insertions(+), 3 deletions(-) diff --git a/src/Aardvark.Algodat.Tests/ImportTests.cs b/src/Aardvark.Algodat.Tests/ImportTests.cs index 41eafa42..055f2f2f 100644 --- a/src/Aardvark.Algodat.Tests/ImportTests.cs +++ b/src/Aardvark.Algodat.Tests/ImportTests.cs @@ -218,7 +218,7 @@ public void CanImport_DuplicateKey() ; - var pointcloud = PointCloud.Chunks(new Chunk[] { }, config); + var pointcloud = PointCloud.Chunks(Array.Empty(), config); Assert.IsTrue(pointcloud.Id != null); Assert.IsTrue(pointcloud.PointCount == 0); @@ -244,13 +244,14 @@ public void CanImport_Empty() ; - var pointcloud = PointCloud.Chunks(new Chunk[] { }, config); + var pointcloud = PointCloud.Chunks(Array.Empty(), config); Assert.IsTrue(pointcloud.Id == "test"); Assert.IsTrue(pointcloud.PointCount == 0); var reloaded = config.Storage.GetPointSet("test"); Assert.IsTrue(reloaded.Id == "test"); Assert.IsTrue(reloaded.PointCount == 0); + Assert.IsTrue(reloaded.HasPartIndexRange == false); } #endregion @@ -385,7 +386,7 @@ public void CanParsePtsFile() Assert.IsTrue(ps.Length == 3); Assert.IsTrue(ps[0].ApproximateEquals(new V3d(1, 2, 9), 1e-10)); } - + [Test] public void CanImportPtsFile() { @@ -396,10 +397,30 @@ public void CanImportPtsFile() var config = ImportConfig.Default .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) .WithKey("test") + .WithEnabledProperties(EnabledProperties.All.WithPartIndices(false)) ; var pointset = PointCloud.Import(filename, config); Assert.IsTrue(pointset != null); Assert.IsTrue(pointset.PointCount == 3); + Assert.IsTrue(pointset.PartIndexRange == Range1i.Invalid); + } + + [Test] + public void CanImportPtsFile_PartIndex() + { + Assert.IsTrue(Data.Points.Import.Pts.PtsFormat != null); + var filename = Path.Combine(Config.TestDataDir, "test.pts"); + if (!File.Exists(filename)) Assert.Ignore($"File not found: {filename}"); + TestContext.WriteLine($"testfile is '{filename}'"); + var config = ImportConfig.Default + .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) + .WithKey("test") + .WithPartIndexOffset(42) + ; + var pointset = PointCloud.Import(filename, config); + Assert.IsTrue(pointset != null); + Assert.IsTrue(pointset.PointCount == 3); + Assert.IsTrue(pointset.PartIndexRange == new Range1i(42, 42)); } [Test] @@ -412,10 +433,30 @@ public void CanImportPtsFile_MinDist() var config = ImportConfig.Default .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) .WithKey("test") + .WithEnabledPartIndices(false) .WithMinDist(10.0); ; var pointset = PointCloud.Import(filename, config); Assert.IsTrue(pointset.PointCount < 3); + Assert.IsTrue(pointset.HasPartIndexRange == false); + } + + [Test] + public void CanImportPtsFile_MinDist_PartIndex() + { + Assert.IsTrue(Data.Points.Import.Pts.PtsFormat != null); + var filename = Path.Combine(Config.TestDataDir, "test.pts"); + if (!File.Exists(filename)) Assert.Ignore($"File not found: {filename}"); + TestContext.WriteLine($"testfile is '{filename}'"); + var config = ImportConfig.Default + .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) + .WithKey("test") + .WithPartIndexOffset(42) + .WithMinDist(10.0); + ; + var pointset = PointCloud.Import(filename, config); + Assert.IsTrue(pointset.PointCount < 3); + Assert.IsTrue(pointset.PartIndexRange == new Range1i(42, 42)); } [Test] @@ -428,11 +469,32 @@ public void CanImportPtsFileAndLoadFromStore() var config = ImportConfig.Default .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) .WithKey("test") + .WithEnabledPartIndices(false) ; _ = PointCloud.Import(filename, config); var pointset2 = config.Storage.GetPointSet("test"); Assert.IsTrue(pointset2 != null); Assert.IsTrue(pointset2.PointCount == 3); + Assert.IsTrue(pointset2.HasPartIndexRange == false); + } + + [Test] + public void CanImportPtsFileAndLoadFromStore_PartIndex() + { + Assert.IsTrue(Data.Points.Import.Pts.PtsFormat != null); + var filename = Path.Combine(Config.TestDataDir, "test.pts"); + if (!File.Exists(filename)) Assert.Ignore($"File not found: {filename}"); + TestContext.WriteLine($"testfile is '{filename}'"); + var config = ImportConfig.Default + .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) + .WithKey("test") + .WithPartIndexOffset(42) + ; + _ = PointCloud.Import(filename, config); + var pointset2 = config.Storage.GetPointSet("test"); + Assert.IsTrue(pointset2 != null); + Assert.IsTrue(pointset2.PointCount == 3); + Assert.IsTrue(pointset2.PartIndexRange == new Range1i(42, 42)); } [Test] @@ -445,12 +507,34 @@ public void CanImportPtsFileAndLoadFromStore_CheckKey() var config = ImportConfig.Default .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) .WithKey("test") + .WithEnabledPartIndices(false) + ; + var pointset = PointCloud.Import(filename, config); + Assert.IsTrue(pointset.Id == "test"); + var pointset2 = config.Storage.GetPointSet("test"); + Assert.IsTrue(pointset2 != null); + Assert.IsTrue(pointset2.PointCount == 3); + Assert.IsTrue(pointset2.HasPartIndexRange == false); + } + + [Test] + public void CanImportPtsFileAndLoadFromStore_CheckKey_PartIndex() + { + Assert.IsTrue(Data.Points.Import.Pts.PtsFormat != null); + var filename = Path.Combine(Config.TestDataDir, "test.pts"); + if (!File.Exists(filename)) Assert.Ignore($"File not found: {filename}"); + TestContext.WriteLine($"testfile is '{filename}'"); + var config = ImportConfig.Default + .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) + .WithKey("test") + .WithPartIndexOffset(42) ; var pointset = PointCloud.Import(filename, config); Assert.IsTrue(pointset.Id == "test"); var pointset2 = config.Storage.GetPointSet("test"); Assert.IsTrue(pointset2 != null); Assert.IsTrue(pointset2.PointCount == 3); + Assert.IsTrue(pointset2.PartIndexRange == new Range1i(42, 42)); } [Test] @@ -463,6 +547,28 @@ public void CanParsePtsChunksThenImportThenLoadFromStore() var config = ImportConfig.Default .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) .WithKey("test") + .WithEnabledPartIndices(false) + ; + var ptsChunks = Data.Points.Import.Pts.Chunks(filename, config.ParseConfig); + var pointset = PointCloud.Chunks(ptsChunks, config); + Assert.IsTrue(pointset.Id == "test"); + var pointset2 = config.Storage.GetPointSet("test"); + Assert.IsTrue(pointset2 != null); + Assert.IsTrue(pointset2.PointCount == 3); + Assert.IsTrue(pointset2.HasPartIndexRange == false); + } + + [Test] + public void CanParsePtsChunksThenImportThenLoadFromStore_PartIndex() + { + Assert.IsTrue(Data.Points.Import.Pts.PtsFormat != null); + var filename = Path.Combine(Config.TestDataDir, "test.pts"); + if (!File.Exists(filename)) Assert.Ignore($"File not found: {filename}"); + TestContext.WriteLine($"testfile is '{filename}'"); + var config = ImportConfig.Default + .WithStorage(PointCloud.CreateInMemoryStore(cache: default)) + .WithKey("test") + .WithPartIndexOffset(42) ; var ptsChunks = Data.Points.Import.Pts.Chunks(filename, config.ParseConfig); var pointset = PointCloud.Chunks(ptsChunks, config); @@ -470,6 +576,7 @@ public void CanParsePtsChunksThenImportThenLoadFromStore() var pointset2 = config.Storage.GetPointSet("test"); Assert.IsTrue(pointset2 != null); Assert.IsTrue(pointset2.PointCount == 3); + Assert.IsTrue(pointset2.PartIndexRange == new Range1i(42, 42)); } #endregion diff --git a/src/Aardvark.Data.Points.Base/ParseConfig.cs b/src/Aardvark.Data.Points.Base/ParseConfig.cs index caae8668..5130d958 100644 --- a/src/Aardvark.Data.Points.Base/ParseConfig.cs +++ b/src/Aardvark.Data.Points.Base/ParseConfig.cs @@ -53,6 +53,34 @@ public class EnabledProperties /// Parse all available properties. /// public static readonly EnabledProperties All = new(); + + /// + public EnabledProperties() { } + + /// + public EnabledProperties(EnabledProperties other) + { + Classifications = other.Classifications; + Colors = other.Colors; + Intensities = other.Intensities; + Normals = other.Normals; + PartIndices = other.PartIndices; + } + + /// + public EnabledProperties WithClassifications(bool enabled) => new(this) { Classifications = enabled }; + + /// + public EnabledProperties WithColors(bool enabled) => new(this) { Colors = enabled }; + + /// + public EnabledProperties WithIntensities(bool enabled) => new(this) { Intensities = enabled }; + + /// + public EnabledProperties WithNormals(bool enabled) => new(this) { Normals = enabled }; + + /// + public EnabledProperties WithPartIndices(bool enabled) => new(this) { PartIndices = enabled }; } /// @@ -185,5 +213,20 @@ public ParseConfig(ParseConfig x) /// public ParseConfig WithPartIndexOffset(int v) => new(this) { PartIndexOffset = v }; + /// + public ParseConfig WithEnabledClassifications(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithClassifications(enabled) }; + + /// + public ParseConfig WithEnabledColors(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithColors(enabled) }; + + /// + public ParseConfig WithEnabledIntensities(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithIntensities(enabled) }; + + /// + public ParseConfig WithEnabledNormals(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithNormals(enabled) }; + + /// + public ParseConfig WithEnabledPartIndices(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithPartIndices(enabled) }; + } } diff --git a/src/Aardvark.Geometry.PointSet/Octrees/ImportConfig.cs b/src/Aardvark.Geometry.PointSet/Octrees/ImportConfig.cs index f790cdb4..e2c7d4b6 100644 --- a/src/Aardvark.Geometry.PointSet/Octrees/ImportConfig.cs +++ b/src/Aardvark.Geometry.PointSet/Octrees/ImportConfig.cs @@ -136,6 +136,27 @@ public ImportConfig(ImportConfig x) /// public ImportConfig WithStorage(Storage x) => new(this) { Storage = x }; + /// + public ImportConfig WithPartIndexOffset(int x) => new(this) { ParseConfig = ParseConfig.WithPartIndexOffset(x) }; + + /// + public ImportConfig WithEnabledProperties(EnabledProperties x) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(x) }; + + /// + public ImportConfig WithEnabledClassifications(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithClassifications(enabled)) }; + + /// + public ImportConfig WithEnabledColors(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithColors(enabled)) }; + + /// + public ImportConfig WithEnabledIntensities(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithIntensities(enabled)) }; + + /// + public ImportConfig WithEnabledNormals(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithNormals(enabled)) }; + + /// + public ImportConfig WithEnabledPartIndices(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithPartIndices(enabled)) }; + #endregion } }