diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4fbbf92..db3f64d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,7 @@ +### 5.3.0-prerelease012 +- structured point clouds: filtered nodes +- structured point clouds: chunk TryGetPartIndices + ### 5.3.0-prerelease011 - updated base packages to 5.2.28 diff --git a/src/Aardvark.Data.Points.Base/Chunk.cs b/src/Aardvark.Data.Points.Base/Chunk.cs index 7fd1e88..5b701f8 100644 --- a/src/Aardvark.Data.Points.Base/Chunk.cs +++ b/src/Aardvark.Data.Points.Base/Chunk.cs @@ -95,6 +95,11 @@ public GenericChunk ToGenericChunk() [MemberNotNullWhen(true, nameof(PartIndexRange))] public bool HasPartIndexRange => PartIndexRange != null; + public IList? TryGetPartIndices() + { + return PartIndexUtils.Expand(PartIndices, Count); + } + public static Chunk ImmutableMerge(Chunk a, Chunk b) { if (a is null || a.IsEmpty) return b; diff --git a/src/Aardvark.Data.Points.Base/PartIndexUtils.cs b/src/Aardvark.Data.Points.Base/PartIndexUtils.cs index 1d51463..bed8db7 100644 --- a/src/Aardvark.Data.Points.Base/PartIndexUtils.cs +++ b/src/Aardvark.Data.Points.Base/PartIndexUtils.cs @@ -63,6 +63,27 @@ public static bool HasValidPartIndexData(IReadOnlyDictionary + /// Expands part indices: All input types are expanded into an int array. + /// + public static int[]? Expand(object? o, int ct) + { + switch (o) + { + case null: return null; + case int x: return new int[ct].Set(x); + case uint x: checked { return new int[ct].Set((int)x); } + case byte[] xs: return xs.Map(x => (int)x); + case short[] xs: return xs.Map(x => (int)x); + case int[] xs: return xs; + default: + throw new Exception( + $"Unexpected type {o.GetType().FullName}. " + + $"Error 278c88f6-d504-4a17-9752-8cca614505f1." + ); + } + } + /// /// Compacts part indices. /// If per-point indices are all identical, then return per-cell index. diff --git a/src/Aardvark.Geometry.PointSet/Octrees/PointSetNode.cs b/src/Aardvark.Geometry.PointSet/Octrees/PointSetNode.cs index d534445..5e5ba2a 100644 --- a/src/Aardvark.Geometry.PointSet/Octrees/PointSetNode.cs +++ b/src/Aardvark.Geometry.PointSet/Octrees/PointSetNode.cs @@ -940,19 +940,8 @@ public object? PartIndices /// public bool TryGetPartIndices([NotNullWhen(true)] out int[]? result) { - switch (PartIndices) - { - case null: result = null; return false; - case int x: result = new int[PointCountCell].Set(x); return true; - case uint x: checked { result = new int[PointCountCell].Set((int)x); return true; } - case byte[] xs: result = xs.Map(x => (int)x); return true; - case short[] xs: result = xs.Map(x => (int)x); return true; - case int[] xs: result = xs; return true; - default: throw new Exception( - $"Unexpected type {PartIndices.GetType().FullName}. " + - $"Error 278c88f6-d504-4a17-9752-8cca614505f1." - ); - } + result = PartIndexUtils.Expand(PartIndices, PointCountCell); + return result != null; } #endregion diff --git a/src/Aardvark.Geometry.PointSet/Views/FilteredNode.cs b/src/Aardvark.Geometry.PointSet/Views/FilteredNode.cs index e7e78d2..5835a17 100644 --- a/src/Aardvark.Geometry.PointSet/Views/FilteredNode.cs +++ b/src/Aardvark.Geometry.PointSet/Views/FilteredNode.cs @@ -12,6 +12,7 @@ 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.Base.Sorting; using Aardvark.Data; using Aardvark.Data.Points; using System; @@ -499,7 +500,7 @@ public Range1i? PartIndexRange /// /// Octree. Per-point or per-cell part indices. /// - public object? PartIndices => PartIndexUtils.Subset(Node.PartIndices, null!); + public object? PartIndices => SubsetIndexArray != null ? PartIndexUtils.Subset(Node.PartIndices, SubsetIndexArray) : Node.PartIndices; /// /// Get per-point part indices as an int array (regardless of internal representation). @@ -507,7 +508,7 @@ public Range1i? PartIndexRange /// public bool TryGetPartIndices([NotNullWhen(true)] out int[]? result) { - var qs = SubsetIndexArray != null ? PartIndexUtils.Subset(PartIndices, SubsetIndexArray) : PartIndices; + var qs = PartIndices; if (m_cache.TryGetValue(Octree.PerPointPartIndex1i.Id, out var _result)) { @@ -635,10 +636,9 @@ private int[]? SubsetIndexArray if (_subsetIndexArray != null) return _subsetIndexArray; if (m_activePoints == null) return null; - var imax = PointCountCell; - var xs = new List(); - for (var i = 0; i < imax; i++) if (m_activePoints.Contains(i)) xs.Add(i); - return _subsetIndexArray = xs.ToArray(); + var xs = m_activePoints.ToArray(); + xs.QuickSortAscending(); + return _subsetIndexArray = xs; } }