Skip to content

Commit

Permalink
structured point clouds: implementation (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaierhofer committed Oct 5, 2023
1 parent a86b48f commit 37f418c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/Aardvark.Algodat.Tests/PartIndicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ private static bool cmp<T>(IReadOnlyList<T> xs, IReadOnlyList<T> ys) where T : I
[Test]
public void ConcatIndices_nulls()
{
{ Assert.True( PartIndexUtils.ConcatIndices(first: null, firstCount: 0, second: null, secondCount: 0) is null); }
{ Assert.Catch(() => PartIndexUtils.ConcatIndices(first: null, firstCount: 0, second: 1u, secondCount: 3)); }
{ Assert.Catch(() => PartIndexUtils.ConcatIndices(first: 1u, firstCount: 3, second: null, secondCount: 0)); }
{ Assert.True(PartIndexUtils.ConcatIndices(first: null, firstCount: 0, second: null, secondCount: 0) is null); }
{ Assert.True(PartIndexUtils.ConcatIndices(first: null, firstCount: 0, second: 1u, secondCount: 3) is uint x && x == 1u); }
{ Assert.True(PartIndexUtils.ConcatIndices(first: 1u, firstCount: 3, second: null, secondCount: 0) is uint x && x == 1u); }
}

[Test]
Expand Down
19 changes: 15 additions & 4 deletions src/Aardvark.Data.Points.Base/PartIndexUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
using Aardvark.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

Expand All @@ -30,6 +31,17 @@ namespace Aardvark.Data.Points;
/// </summary>
public static class PartIndexUtils
{
public static uint? Get(object? o, int index) => o switch
{
null => null,
uint x => x,
byte[] xs => (uint)xs[index],
short[] xs => (uint)xs[index],
int[] xs => (uint)xs[index],
_ => throw new Exception($"Unexpected type {o.GetType().FullName}. Invariant 98f41e6c-6065-4dd3-aa9e-6619cc71873d.")

};

/// <summary>
/// Concatenates part indices (uint, [byte|short|int] array).
/// </summary>
Expand All @@ -38,14 +50,13 @@ public static class PartIndexUtils
object? second, int secondCount
)
{
// expect: both defined, or both null
if ((first != null && second == null) || (first == null && second != null)) throw new Exception("Invariant 7e8345fc-c993-48fd-9862-33c9928aba3f.");

checked
{
return (first, second) switch
{
(null , null ) => null,
(null, null) => null,
(null, object y) => y,
(object x, null) => x,

(uint x, uint y) => (x == y) ? x : createArray1(x, firstCount, y, secondCount),

Expand Down
6 changes: 4 additions & 2 deletions src/Aardvark.Geometry.PointSet/Octrees/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ int splitLimit
var ns = root.HasNormals ? new List<V3f>() : null;
var js = root.HasIntensities ? new List<int>() : null;
var ks = root.HasClassifications ? new List<byte>() : null;
var qs = (object?)null;
foreach (var c in subnodes)
{
if (c != null) MergeExtensions.CollectEverything(c, psabs, cs, ns, js, ks);
if (c != null) MergeExtensions.CollectEverything(c, psabs, cs, ns, js, ks, ref qs);
}
Debug.Assert(psabs.Count == pointCountTree);
var psa = psabs.MapToArray((p) => (V3f)(p - root.Center));
Expand Down Expand Up @@ -495,9 +496,10 @@ int splitLimit
var ns = root.HasNormals ? new List<V3f>() : null;
var js = root.HasIntensities ? new List<int>() : null;
var ks = root.HasClassifications ? new List<byte>() : null;
var qs = (object?)null;
foreach (var c in subnodes)
{
if (c != null) MergeExtensions.CollectEverything(c, psabs, cs, ns, js, ks);
if (c != null) MergeExtensions.CollectEverything(c, psabs, cs, ns, js, ks, ref qs);
}
Debug.Assert(psabs.Count == pointCountTree);
var psa = psabs.MapToArray((p) => (V3f)(p - root.Center));
Expand Down
37 changes: 21 additions & 16 deletions src/Aardvark.Geometry.PointSet/Octrees/Merge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@ namespace Aardvark.Geometry.Points
/// </summary>
public static class MergeExtensions
{
internal static int CollectEverything(IPointCloudNode self, List<V3d> ps, List<C4b>? cs, List<V3f>? ns, List<int>? js, List<byte>? ks)
internal static int CollectEverything(IPointCloudNode self, List<V3d> ps, List<C4b>? cs, List<V3f>? ns, List<int>? js, List<byte>? ks, ref object? qs)
{
if (self == null) return 0;

if (self.IsLeaf)
{
if (self.HasPositions && ps != null)
{
var off = self.Center;
ps.AddRange(self.Positions.Value.Map(p => off + (V3d)p));
}
var initialCount = ps.Count;

var off = self.Center;
ps.AddRange(self.Positions.Value.Map(p => off + (V3d)p));

if (self.HasColors && cs != null) cs.AddRange(self.Colors.Value);
if (self.HasNormals && ns != null) ns.AddRange(self.Normals.Value);
if (self.HasIntensities && js != null) js.AddRange(self.Intensities.Value);
if (self.HasClassifications && ks != null) ks.AddRange(self.Classifications.Value);

qs = PartIndexUtils.ConcatIndices(qs, initialCount, self.PartIndices, self.PointCountCell);

return 1;
}
else
Expand All @@ -51,7 +53,7 @@ internal static int CollectEverything(IPointCloudNode self, List<V3d> ps, List<C
{
if (x != null)
{
leafs += CollectEverything(x!.Value!, ps, cs, ns, js, ks);
leafs += CollectEverything(x.Value, ps, cs, ns, js, ks, ref qs);
}
}
return leafs;
Expand All @@ -73,7 +75,8 @@ public static (IPointCloudNode, bool) CollapseLeafNodes(this IPointCloudNode sel
var nsla = new List<V3f>();
var jsla = new List<int>();
var ksla = new List<byte>();
var leaves = CollectEverything(self, psla, csla, nsla, jsla, ksla);
var qsla = (object?)null;
var leaves = CollectEverything(self, psla, csla, nsla, jsla, ksla, ref qsla);

// positions might be slightly (~eps) outside this node's bounds,
// due to floating point conversion from local sub-node space to global space
Expand Down Expand Up @@ -298,9 +301,10 @@ public static (IPointCloudNode, bool) Merge(this IPointCloudNode a, IPointCloudN
var nsla = new List<V3f>();
var jsla = new List<int>();
var ksla = new List<byte>();
var qsla = (object?)null;

CollectEverything(a, psla, csla, nsla, jsla, ksla);
CollectEverything(b, psla, csla, nsla, jsla, ksla);
CollectEverything(a, psla, csla, nsla, jsla, ksla, ref qsla);
CollectEverything(b, psla, csla, nsla, jsla, ksla, ref qsla);

var cell = new Cell(a.Cell, b.Cell);
var chunk = new Chunk(
Expand All @@ -309,10 +313,10 @@ public static (IPointCloudNode, bool) Merge(this IPointCloudNode a, IPointCloudN
nsla.Count > 0 ? nsla : null,
jsla.Count > 0 ? jsla : null,
ksla.Count > 0 ? ksla : null,
partIndices: null, // TODO
partIndices: qsla,
bbox: null
);
throw new NotImplementedException("PARTINDICES");

if (config.NormalizePointDensityGlobal)
{
chunk = chunk.ImmutableFilterMinDistByCell(cell, config.ParseConfig);
Expand Down Expand Up @@ -935,9 +939,9 @@ private static IPointCloudNode InjectPointsIntoTree(
var newNs = ns != null ? new List<V3f>(ns) : null; newNs?.AddRange(a.Normals!.Value);
var newJs = js != null ? new List<int>(js) : null; newJs?.AddRange(a.Intensities!.Value);
var newKs = ks != null ? new List<byte>(ks) : null; newKs?.AddRange(a.Classifications!.Value);
var newQs = PartIndexUtils.ConcatIndices(qs, psAbsolute.Count, a.PartIndices, a.PointCountCell);

var chunk = new Chunk(newPs, newCs, newNs, newJs, newKs, partIndices: null /* TODO */, cell.BoundingBox);
throw new NotImplementedException("PARTINDICES");
var chunk = new Chunk(newPs, newCs, newNs, newJs, newKs, partIndices: newQs, cell.BoundingBox);

if (config.NormalizePointDensityGlobal)
{
Expand Down Expand Up @@ -971,12 +975,14 @@ private static IPointCloudNode InjectPointsIntoTree(
if (ns != null) nss![j] = new List<V3f>();
if (js != null) iss![j] = new List<int>();
if (ks != null) kss![j] = new List<byte>();
if (qs != null) qss![j] = null;
}
pss[j].Add(psAbsolute[i]);
if (cs != null) css![j].Add(cs[i]);
if (ns != null) nss![j].Add(ns[i]);
if (js != null) iss![j].Add(js[i]);
if (ks != null) kss![j].Add(ks[i]);
if (qs != null) qss![j] = PartIndexUtils.Get(qs, i);
}

if (pss.Sum(x => x?.Count) != psAbsolute.Count) throw new InvalidOperationException();
Expand All @@ -988,8 +994,7 @@ private static IPointCloudNode InjectPointsIntoTree(
if (pss[j] != null)
{
if (x == null) throw new InvalidOperationException("Invariant 6afc7ca3-30da-4cb5-9a02-7572085e89bb.");
throw new NotImplementedException("PARTINDICES");
subcells[j] = InjectPointsIntoTree(pss[j], css?[j], nss?[j], iss?[j], kss?[j], qs: null /* TODO */, x, cell.GetOctant(j), config);
subcells[j] = InjectPointsIntoTree(pss[j], css?[j], nss?[j], iss?[j], kss?[j], qss?[j], x, cell.GetOctant(j), config);
}
else
{
Expand Down

0 comments on commit 37f418c

Please sign in to comment.