From be3579284a4803d625928ca6381c533273d783a0 Mon Sep 17 00:00:00 2001 From: Stefan Maierhofer Date: Thu, 30 Nov 2023 09:32:53 +0100 Subject: [PATCH] fix part index handling in JoinNonOverlappingTrees --- .../Octrees/InMemoryPointSet.cs | 6 ++---- src/Aardvark.Geometry.PointSet/Octrees/Merge.cs | 10 +++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs b/src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs index 2d64bf0f..fa63c562 100644 --- a/src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs +++ b/src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs @@ -12,7 +12,6 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ using Aardvark.Base; -using Aardvark.Data; using Aardvark.Data.Points; using System; using System.Collections.Generic; @@ -20,7 +19,6 @@ You should have received a copy of the GNU Affero General Public License using System.Diagnostics; using System.IO; using System.Linq; -using static Aardvark.Base.MultimethodTest; using static Aardvark.Data.Durable; namespace Aardvark.Geometry.Points @@ -31,7 +29,7 @@ public class InMemoryPointSet private readonly int m_splitLimit; private readonly Node m_root; private readonly IList m_ps; - private readonly bool m_hasPartIndices = false; + //private readonly bool m_hasPartIndices = false; public static InMemoryPointSet Build(GenericChunk chunk, int octreeSplitLimit) => new(chunk.Data, new Cell(chunk.BoundingBox), octreeSplitLimit); @@ -87,7 +85,7 @@ private InMemoryPointSet(ImmutableDictionary data, Cell cell, int o foreach (var kv in data) { if (kv.Key == Octree.PerCellPartIndex1i || kv.Key == Octree.PerCellPartIndex1ui) continue; - if (kv.Key == Octree.PartIndexRange) { m_hasPartIndices = true; break; } + if (kv.Key == Octree.PartIndexRange) continue; if (kv.Value is not Array) throw new ArgumentException($"Entry {kv.Key} must be array."); } diff --git a/src/Aardvark.Geometry.PointSet/Octrees/Merge.cs b/src/Aardvark.Geometry.PointSet/Octrees/Merge.cs index d3b1fc90..3984d447 100644 --- a/src/Aardvark.Geometry.PointSet/Octrees/Merge.cs +++ b/src/Aardvark.Geometry.PointSet/Octrees/Merge.cs @@ -639,12 +639,13 @@ private static IPointCloudNode JoinNonOverlappingTrees(Cell rootCell, IPointClou // PRE: we further assume, that both trees are non-empty if (a.PointCountTree == 0 && b.PointCountTree == 0) throw new InvalidOperationException(); - // PRE: + // PRE: assume that part indices are available in both trees or in no tree (but not in one or the other) if (a.HasPartIndexRange != b.HasPartIndexRange) throw new Exception("Invariant b3feedfd-927d-4436-9eb9-350d377ab852."); #endregion #region Case reduction + // REDUCE CASES: // if one tree ('a' or 'b') is centered at origin, then ensure that 'a' is centered // (by swapping 'a' and 'b' if necessary) @@ -785,6 +786,13 @@ private static IPointCloudNode JoinNonOverlappingTrees(Cell rootCell, IPointClou .Add(Durable.Octree.PointCountTreeLeafs, a.PointCountTree + b.PointCountTree) .Add(Durable.Octree.SubnodesGuids, subcells.Map(x => x?.Id ?? Guid.Empty)) ; + + if (a.HasPartIndexRange) + { + var mergedPartIndexRange = PartIndexUtils.MergeRanges(a.PartIndexRange, b.PartIndexRange) ?? throw new Exception("Invariant d4ed616f-a348-4303-8e64-651d669cb7bc."); + data = data.Add(Durable.Octree.PartIndexRange, mergedPartIndexRange); + } + var result = new PointSetNode(data, config.Storage, writeToStore: false).CollapseLeafNodes(config).Item1; #if DEBUG