Skip to content

Commit

Permalink
add convenience function `bool IPointCloudNode.TryGetPartIndices(out …
Browse files Browse the repository at this point in the history
…int[]? result)` + tests
  • Loading branch information
stefanmaierhofer committed Oct 8, 2023
1 parent 7952726 commit 05b1f1f
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 41 deletions.
11 changes: 8 additions & 3 deletions src/Aardvark.Algodat.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ internal static void Test_Import_Regression()
//var filenames = new[]
//{
// @"W:\Datasets\Vgm\Data\E57\JBs_Haus.e57",
// @"W:\Datasets\pointclouds\tests\JB_Haus_2022_KG.e57"
// //@"W:\Datasets\pointclouds\tests\JB_Haus_2022_KG.e57"
//};

var filenames = Directory.GetFiles(@"W:\Datasets\pointclouds\tests");
Expand All @@ -1775,7 +1775,7 @@ internal static void Test_Import_Regression()

var key = Path.GetFileName(filename);

var storePath = $@"W:\aardvark\stores\{key}";
var storePath = $@"W:\aardvark\stores_noparts\{key}";
Directory.CreateDirectory(storePath);
using var storeRaw = new SimpleDiskStore(Path.Combine(storePath, "data.uds"));
var store = storeRaw.ToPointCloudStore();
Expand All @@ -1796,7 +1796,7 @@ internal static void Test_Import_Regression()
.WithMinDist(0)
.WithNormalizePointDensityGlobal(false)
//.WithProgressCallback(p => { Report.Line($"{p:0.00}"); })
.WithEnabledPartIndices(true)
.WithEnabledPartIndices(false)
;

var pcl = PointCloud
Expand Down Expand Up @@ -2685,12 +2685,17 @@ static Task Parts_Test_20231006()
using var store = new SimpleDiskStore(Path.Combine(STOREPATH, "data.uds")).ToPointCloudStore();
var key = File.ReadAllText(Path.Combine(STOREPATH, "key.txt"));
var ps = store.GetPointSet(key);
var root = ps.Root.Value;

return Task.CompletedTask;
}

public static async Task Main(string[] _)
{
await Task.Delay(0); // avoid warnings if main contains no await



//await Parts_Test_20231006();

Test_Import_Regression();
Expand Down
38 changes: 38 additions & 0 deletions src/Aardvark.Algodat.Tests/ViewsTests/ViewsFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private static IPointCloudNode CreateNode(Storage storage, V3f[] psGlobal, int[]
.Add(Durable.Octree.PointCountTreeLeafs, psLocal.LongLength)
.Add(Durable.Octree.PositionsLocal3fReference, psLocalId)
.Add(Durable.Octree.PointRkdTreeFDataReference, kdLocalId)
.Add(Durable.Octree.PerCellPartIndex1ui, 42u)
;

if (intensities != null)
Expand All @@ -68,6 +69,19 @@ private static IPointCloudNode CreateNode(Storage storage, V3f[] psGlobal, int[]
return result;
}

private static void CheckPartIndices(IPointCloudNode n)
{
if (n.TryGetPartIndices(out var qs))
{
Assert.True(qs.Length == n.PointCountCell);
Assert.True(qs.All(q => q == 42));
}
else
{
Assert.Fail("Node has no part indices.");
}
}

#region FilterInsideBox3d

[Test]
Expand All @@ -80,6 +94,8 @@ public void FilterInsideBox3d_AllInside()
Assert.IsTrue(f.HasPositions);
var ps = f.PositionsAbsolute;
Assert.IsTrue(ps.Length == 100);

CheckPartIndices(f);
}

[Test]
Expand All @@ -90,6 +106,8 @@ public void FilterInsideBox3d_AllOutside()

var f = FilteredNode.Create(a, new FilterInsideBox3d(a.BoundingBoxExactGlobal + V3d.IOO));
Assert.IsTrue(f.PointCountCell == 0);

CheckPartIndices(f);
}

[Test]
Expand Down Expand Up @@ -128,6 +146,8 @@ public void FilterInsideBox3d_Partial()
var ps = f.PositionsAbsolute;
var count = ps.Count(p => p.Z <= 0.5);
Assert.IsTrue(ps.Length == count);

CheckPartIndices(f);
}

#endregion
Expand All @@ -144,6 +164,8 @@ public void FilterOutsideBox3d_AllInside()
Assert.IsTrue(f.HasPositions);
var ps = f.PositionsAbsolute;
Assert.IsTrue(ps.Length == 100);

CheckPartIndices(f);
}

[Test]
Expand All @@ -154,6 +176,8 @@ public void FilterOutsideBox3d_AllOutside()

var f = FilteredNode.Create(a, new FilterOutsideBox3d(a.BoundingBoxExactGlobal));
Assert.IsTrue(f.PointCountCell == 0);

CheckPartIndices(f);
}

[Test]
Expand All @@ -167,6 +191,8 @@ public void FilterOutsideBox3d_Partial()
var ps = f.PositionsAbsolute;
var count = ps.Count(p => p.Z <= 0.5);
Assert.IsTrue(ps.Length == count);

CheckPartIndices(f);
}

#endregion
Expand All @@ -184,6 +210,8 @@ public void FilterIntensity_AllInside()
Assert.IsTrue(f.HasIntensities);
var js = f.Intensities.Value;
Assert.IsTrue(js.Length == 100);

CheckPartIndices(f);
}

[Test]
Expand All @@ -194,6 +222,8 @@ public void FilterIntensity_AllOutside()

var f = FilteredNode.Create(a, new FilterIntensity(new Range1i(-30000, -10000)));
Assert.IsTrue(f.PointCountCell == 0);

CheckPartIndices(f);
}

[Test]
Expand All @@ -211,6 +241,8 @@ public void FilterIntensity_Partial()
Assert.IsTrue(js.Length == 2);
Assert.IsTrue(js[0] == 10000);
Assert.IsTrue(js[1] == 20000);

CheckPartIndices(f);
}

#endregion
Expand Down Expand Up @@ -328,10 +360,14 @@ public void EncodeDecodeRoundtrip()
var buffer = ((IPointCloudNode)f).Encode();
Assert.IsTrue(buffer != null);

CheckPartIndices(f);

var g = FilteredNode.Decode(storage, buffer);
Assert.IsTrue(f.Id == g.Id);
Assert.IsTrue(f.Node.Id == g.Node.Id);

CheckPartIndices(g);

var fFilterJson = f.Filter.Serialize().ToString();
var gFilterJson = g.Filter.Serialize().ToString();
Assert.IsTrue(fFilterJson == gFilterJson);
Expand Down Expand Up @@ -366,6 +402,8 @@ public void CanDeletePoints()
Assert.IsTrue(!b.QueryAllPoints().SelectMany(chunk => chunk.Positions).Any(p => q1.Contains(p)));

Assert.IsTrue(b.HasCentroidLocal);

CheckPartIndices(f);
}

#endregion
Expand Down
6 changes: 3 additions & 3 deletions src/Aardvark.Data.E57/ASTM_E57.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static class ASTM_E57
/// <summary>
/// Physical E57 file offset.
/// </summary>
public struct E57PhysicalOffset
public readonly struct E57PhysicalOffset
{
public readonly long Value;
public E57PhysicalOffset(long value) => Value
Expand All @@ -59,7 +59,7 @@ public E57PhysicalOffset(long value) => Value
/// <summary>
/// Logical E57 file offset.
/// </summary>
public struct E57LogicalOffset
public readonly struct E57LogicalOffset
{
public readonly long Value;
public E57LogicalOffset(long value) { Value = value; }
Expand Down Expand Up @@ -2263,7 +2263,7 @@ public struct E57DataPacketHeader
/// </summary>
internal ushort ByteStreamCount;

internal bool CompressorRestart => (PacketFlags & 0b00000001) != 0;
internal readonly bool CompressorRestart => (PacketFlags & 0b00000001) != 0;

internal static E57DataPacketHeader Parse(byte[] buffer) => new()
{
Expand Down
10 changes: 9 additions & 1 deletion src/Aardvark.Geometry.PointSet/Octrees/IPointCloudNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,22 @@ public interface IPointCloudNode

#region PartIndices

/// <summary></summary>
/// <summary>
/// True if this node has part indices.
/// </summary>
bool HasPartIndices { get; }

/// <summary>
/// Octree. Per-point or per-cell part indices.
/// </summary>
object? PartIndices { get; }

/// <summary>
/// Get per-point part indices as an int array (regardless of internal representation).
/// Returns false if node has no part indices.
/// </summary>
bool TryGetPartIndices([NotNullWhen(true)] out int[]? result);

#endregion

#region Velocities
Expand Down
1 change: 1 addition & 0 deletions src/Aardvark.Geometry.PointSet/Octrees/Lod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ internal static Array AggregateSubArrays(int[] counts, int splitLimit, object[]
if (xss.All(xs => xs == null || xs is uint))
{
var perCellIndices = xss.Where(xs => xs != null).Select(xs => (uint)xs!).ToArray();
if (perCellIndices.Length == 0) return null;
var allIdentical = true;
for (var i = 1; i < perCellIndices.Length; i++) if (perCellIndices[i] != perCellIndices[0]) { allIdentical = false; break; }
if (allIdentical) return perCellIndices[0];
Expand Down
Loading

0 comments on commit 05b1f1f

Please sign in to comment.