Skip to content

Commit

Permalink
structured point clouds: add tests (failing)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaierhofer committed Sep 19, 2023
1 parent 33fdf24 commit 69c600c
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 3 deletions.
113 changes: 110 additions & 3 deletions src/Aardvark.Algodat.Tests/ImportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void CanImport_DuplicateKey()
;


var pointcloud = PointCloud.Chunks(new Chunk[] { }, config);
var pointcloud = PointCloud.Chunks(Array.Empty<Chunk>(), config);
Assert.IsTrue(pointcloud.Id != null);
Assert.IsTrue(pointcloud.PointCount == 0);

Expand All @@ -244,13 +244,14 @@ public void CanImport_Empty()
;


var pointcloud = PointCloud.Chunks(new Chunk[] { }, config);
var pointcloud = PointCloud.Chunks(Array.Empty<Chunk>(), 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
Expand Down Expand Up @@ -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()
{
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -463,13 +547,36 @@ 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);
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));
}

#endregion
Expand Down
43 changes: 43 additions & 0 deletions src/Aardvark.Data.Points.Base/ParseConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@ public class EnabledProperties
/// Parse all available properties.
/// </summary>
public static readonly EnabledProperties All = new();

/// <summary> </summary>
public EnabledProperties() { }

/// <summary> </summary>
public EnabledProperties(EnabledProperties other)
{
Classifications = other.Classifications;
Colors = other.Colors;
Intensities = other.Intensities;
Normals = other.Normals;
PartIndices = other.PartIndices;
}

/// <summary></summary>
public EnabledProperties WithClassifications(bool enabled) => new(this) { Classifications = enabled };

/// <summary></summary>
public EnabledProperties WithColors(bool enabled) => new(this) { Colors = enabled };

/// <summary></summary>
public EnabledProperties WithIntensities(bool enabled) => new(this) { Intensities = enabled };

/// <summary></summary>
public EnabledProperties WithNormals(bool enabled) => new(this) { Normals = enabled };

/// <summary></summary>
public EnabledProperties WithPartIndices(bool enabled) => new(this) { PartIndices = enabled };
}

/// <summary>
Expand Down Expand Up @@ -185,5 +213,20 @@ public ParseConfig(ParseConfig x)
/// <summary></summary>
public ParseConfig WithPartIndexOffset(int v) => new(this) { PartIndexOffset = v };

/// <summary></summary>
public ParseConfig WithEnabledClassifications(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithClassifications(enabled) };

/// <summary></summary>
public ParseConfig WithEnabledColors(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithColors(enabled) };

/// <summary></summary>
public ParseConfig WithEnabledIntensities(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithIntensities(enabled) };

/// <summary></summary>
public ParseConfig WithEnabledNormals(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithNormals(enabled) };

/// <summary></summary>
public ParseConfig WithEnabledPartIndices(bool enabled) => new(this) { EnabledProperties = EnabledProperties.WithPartIndices(enabled) };

}
}
21 changes: 21 additions & 0 deletions src/Aardvark.Geometry.PointSet/Octrees/ImportConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ public ImportConfig(ImportConfig x)
/// <summary></summary>
public ImportConfig WithStorage(Storage x) => new(this) { Storage = x };

/// <summary></summary>
public ImportConfig WithPartIndexOffset(int x) => new(this) { ParseConfig = ParseConfig.WithPartIndexOffset(x) };

/// <summary></summary>
public ImportConfig WithEnabledProperties(EnabledProperties x) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(x) };

/// <summary></summary>
public ImportConfig WithEnabledClassifications(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithClassifications(enabled)) };

/// <summary></summary>
public ImportConfig WithEnabledColors(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithColors(enabled)) };

/// <summary></summary>
public ImportConfig WithEnabledIntensities(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithIntensities(enabled)) };

/// <summary></summary>
public ImportConfig WithEnabledNormals(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithNormals(enabled)) };

/// <summary></summary>
public ImportConfig WithEnabledPartIndices(bool enabled) => new(this) { ParseConfig = ParseConfig.WithEnabledProperties(ParseConfig.EnabledProperties.WithPartIndices(enabled)) };

#endregion
}
}

0 comments on commit 69c600c

Please sign in to comment.