Skip to content

Commit

Permalink
debugging (sync)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaierhofer committed Nov 25, 2023
1 parent d8cd03f commit 5180225
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 71 deletions.
34 changes: 34 additions & 0 deletions src/Aardvark.Data.Points.Base/PartIndexUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,40 @@ namespace Aardvark.Data.Points;
/// </summary>
public static class PartIndexUtils
{
/// <summary>
/// Extract part index range (or null) from durable map.
/// </summary>
public static Range1i? GetRange(IReadOnlyDictionary<Durable.Def, object>? data)
{
if (data == null) return null;
data.TryGetValue(Durable.Octree.PartIndexRange, out var o);
return (Range1i?)o;
}

public static bool HasValidPartIndexData(IReadOnlyDictionary<Durable.Def, object> data)
{
if (!data.ContainsKey(Durable.Octree.PartIndexRange)) return false;

var i =
(data.ContainsKey(Durable.Octree.PerCellPartIndex1i) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerCellPartIndex1ui) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1b) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1bReference) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1s) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1sReference) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1i) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1iReference) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1bGz) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1bLz4) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1sGz) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1sLz4) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1iGz) ? 1 : 0) +
(data.ContainsKey(Durable.Octree.PerPointPartIndex1iLz4) ? 1 : 0)
;

return i == 1; // exactly one of the above must exist
}

/// <summary>
/// Compacts part indices.
/// If per-point indices are all identical, then return per-cell index.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ public static void CheckDerivedAttributes(this IPointCloudNode self)
"Missing MinTreeDepth. Invariant 2df9fb7b-684a-4103-8f14-07785607d2f4."
);

if (self.HasPartIndexRange && !self.HasPartIndices) throw new InvalidOperationException(
if (!self.IsTemporaryImportNode && self.HasPartIndexRange && !self.HasPartIndices) throw new InvalidOperationException(
"Missing part indices. Invariant fc4ff983-151f-4956-b882-54d649245049."
);

Expand Down
94 changes: 25 additions & 69 deletions src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ You should have received a copy of the GNU Affero General Public License
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 @@ -29,6 +31,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;

Check warning on line 34 in src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs

View workflow job for this annotation

GitHub Actions / build

The field 'InMemoryPointSet.m_hasPartIndices' is assigned but its value is never used

Check warning on line 34 in src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs

View workflow job for this annotation

GitHub Actions / build

The field 'InMemoryPointSet.m_hasPartIndices' is assigned but its value is never used

Check warning on line 34 in src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs

View workflow job for this annotation

GitHub Actions / build

The field 'InMemoryPointSet.m_hasPartIndices' is assigned but its value is never used

Check warning on line 34 in src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs

View workflow job for this annotation

GitHub Actions / build

The field 'InMemoryPointSet.m_hasPartIndices' is assigned but its value is never used

Check warning on line 34 in src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs

View workflow job for this annotation

GitHub Actions / build

The field 'InMemoryPointSet.m_hasPartIndices' is assigned but its value is never used

Check warning on line 34 in src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs

View workflow job for this annotation

GitHub Actions / build

The field 'InMemoryPointSet.m_hasPartIndices' is assigned but its value is never used

public static InMemoryPointSet Build(GenericChunk chunk, int octreeSplitLimit)
=> new(chunk.Data, new Cell(chunk.BoundingBox), octreeSplitLimit);
Expand Down Expand Up @@ -83,10 +86,8 @@ private InMemoryPointSet(ImmutableDictionary<Def, object> data, Cell cell, int o

foreach (var kv in data)
{
if (kv.Key == Octree.PerCellPartIndex1i ||
kv.Key == Octree.PerCellPartIndex1ui ||
kv.Key == Octree.PartIndexRange
) continue;
if (kv.Key == Octree.PerCellPartIndex1i || kv.Key == Octree.PerCellPartIndex1ui) continue;
if (kv.Key == Octree.PartIndexRange) { m_hasPartIndices = true; break; }
if (kv.Value is not Array) throw new ArgumentException($"Entry {kv.Key} must be array.");
}

Expand Down Expand Up @@ -263,6 +264,10 @@ void copy(Def def)
$"Invariant 42656f92-f5ac-43ca-a1b7-c7ec95fe9cb3."
);


if (!PartIndexUtils.HasValidPartIndexData(resultData)) Debugger.Break(); // TODO "PARTINDICES" remove

// create and store result
var result = new PointSetNode(resultData, storage, writeToStore: true);
if (storage.GetPointCloudNode(result.Id) == null) throw new InvalidOperationException("Invariant 9e863bc5-e9f4-4d39-bd53-3d81e12af6b1.");
return result;
Expand All @@ -285,6 +290,8 @@ void copy(Def def)
.Add(Octree.SubnodesGuids, subcellIds.Map(x => x ?? Guid.Empty))
;

#if DEBUG
// check if subnodes exist in store
for (var i = 0; i < 8; i++)
{
var x = subcellIds![i];
Expand All @@ -294,76 +301,25 @@ void copy(Def def)
if (storage.GetPointCloudNode(id) == null) throw new InvalidOperationException("Invariant 01830b8b-3c0e-4a8b-a1bd-bfd1b1be1844.");
}
}
#endif

// collect part-index-ranges from subnodes
{
var subRanges = subcells.Select(x => PartIndexUtils.GetRange(x?.Properties));
var partIndexRange = PartIndexUtils.MergeRanges(subRanges);
if (partIndexRange.HasValue)
{
resultData = resultData.Add(Octree.PartIndexRange, partIndexRange.Value);
}
}

if (!resultData.ContainsKey(Octree.PartIndexRange)) Debugger.Break(); // TODO "PARTINDICES" remove

// create and store result
var result = new PointSetNode(resultData, storage, writeToStore: true);
if (storage.GetPointCloudNode(result.Id) == null) throw new InvalidOperationException("Invariant 7b09eccb-b6a0-4b99-be7a-eeff53b6a98b.");
return result;
}

// stuff
//var attributes = ImmutableDictionary<Def, object>.Empty;

/*
* EXPLAINER:
*
* If _ia exists, then this means that a subset of all per-point attribute arrays (positions, colors, ...) has to be taken (according to the indices stored in _ia)
* otherwise these arrays can be used as they are
*
*/



//if (_ia != null)
//{
// var count = _ia.Count;

// // create all other attributes ...
// foreach (var kv in _octree.m_data)
// {
// if (kv.Key == Octree.PositionsGlobal3d ||
// kv.Key == Octree.PerCellPartIndex1i ||
// kv.Key == Octree.PerCellPartIndex1ui ||
// kv.Key == Octree.PerPointPartIndex1b ||
// kv.Key == Octree.PerPointPartIndex1s ||
// kv.Key == Octree.PerPointPartIndex1i ||
// kv.Key == Octree.PartIndexRange
// )
// continue;
// var subset = kv.Value.Subset(_ia);
// attributes = attributes.Add(kv.Key, subset);
// }
//}
//else
//{

//}


//// part indices ...
//{
// void copy(Def def)
// {
// if (_octree.m_data.TryGetValue(def, out var o))
// {
// data = data.Add(def, o);
// }
// }

// copy(Octree.PerCellPartIndex1i);
// copy(Octree.PerCellPartIndex1ui);
// copy(Octree.PartIndexRange);

// //if (
// // _octree.m_data.TryGetValue(Octree.PerPointPartIndex1b, out object? qs) ||
// // _octree.m_data.TryGetValue(Octree.PerPointPartIndex1s, out qs) ||
// // _octree.m_data.TryGetValue(Octree.PerPointPartIndex1i, out qs)
// // )
// //{
// // qs = _ia != null ? PartIndexUtils.Subset(qs, _ia) : qs;
// // if (qs != null) data = data.Add(PartIndexUtils.GetDurableDefForPartIndices(qs), qs);
// //}
//}

}

public Node Insert(int index)
Expand Down
7 changes: 6 additions & 1 deletion src/Aardvark.Geometry.PointSet/Octrees/PointSetNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ You should have received a copy of the GNU Affero General Public License
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -60,7 +61,9 @@ public class PointSetNode : IPointCloudNode
(Durable.Octree.AveragePointDistance, float.NaN),
(Durable.Octree.AveragePointDistanceStdDev, float.NaN),
(Durable.Octree.MinTreeDepth, 0),
(Durable.Octree.MaxTreeDepth, 0)
(Durable.Octree.MaxTreeDepth, 0),
(Durable.Octree.PartIndexRange, Range1i.Invalid),
(Durable.Octree.PerPointPartIndex1b, Array.Empty<byte>())
);

#region Construction
Expand Down Expand Up @@ -99,6 +102,8 @@ public PointSetNode(
Storage = storage;
Data = data;

if (!IsTemporaryImportNode && !PartIndexUtils.HasValidPartIndexData(data)) Debugger.Break(); // TODO "PARTINDICES" remove

//Report.Line($"{this.Id} {this.Cell}");
//if (Id == Guid.Empty) Debugger.Break();
//if (IsLeaf && !HasClassifications) Debugger.Break();
Expand Down

0 comments on commit 5180225

Please sign in to comment.