Skip to content

Commit

Permalink
fix part index handling in JoinNonOverlappingTrees
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaierhofer committed Nov 30, 2023
1 parent 8389d75 commit be35792
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Aardvark.Base;
using Aardvark.Data;
using Aardvark.Data.Points;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static Aardvark.Base.MultimethodTest;
using static Aardvark.Data.Durable;

namespace Aardvark.Geometry.Points
Expand All @@ -31,7 +29,7 @@ public class InMemoryPointSet
private readonly int m_splitLimit;
private readonly Node m_root;
private readonly IList<V3d> 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);
Expand Down Expand Up @@ -87,7 +85,7 @@ private InMemoryPointSet(ImmutableDictionary<Def, object> 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.");
}

Expand Down
10 changes: 9 additions & 1 deletion src/Aardvark.Geometry.PointSet/Octrees/Merge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit be35792

Please sign in to comment.