Skip to content

Commit

Permalink
[Aardvark.Data.Points.Chunk] added some quick exits for empty chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaierhofer committed Feb 22, 2021
1 parent f25625f commit 1a60aef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
34 changes: 25 additions & 9 deletions src/Aardvark.Algodat.Tests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,31 +1400,47 @@ internal static void Test_20210217_cpunz()

var store = new SimpleDiskStore(storeName).ToPointCloudStore(cache: default);
var pc = store.GetPointSet(key).Root.Value;
Report.Line($"filename : {key}");
Report.Line($"filename : {key}");
Report.Line($"total points: {pc.PointCountTree,10:N0}");
Report.Line($"bounding box: {pc.BoundingBoxExactGlobal:N2}");

Report.Line();
Report.BeginTimed("activating filter");
var queryBox = pc.BoundingBoxExactGlobal.GetOctant(0);
var pcFiltered = FilteredNode.Create(pc, new FilterInsideBox3d(queryBox));
Report.EndTimed();

Report.Line();
Report.BeginTimed("performing GridQueryXY on original point cloud");
var dummy1 = pc.EnumerateGridCellsXY(4).Select(x => x.Footprint.GetCenter()).ToArray();
Report.Line($"got {dummy1.Length} grid cells");
//var bb = pc.BoundingBoxExactGlobal;
//var queryBox = new Box3d(bb.Min, new V3d(bb.Max.X, bb.Center.Y, bb.Max.Z));//.GetOctant(0);
//var pcFiltered = FilteredNode.Create(pc, new FilterInsideBox3d(queryBox));

var planes = new Plane3d[] {
new Plane3d(new V3d(0.833098559959325, -0.55312456950826, 0.0), -148084.543321104),
new Plane3d(new V3d(0.553124569505628, 0.833098559961073, 0.0), 210175.952298119),
new Plane3d(new V3d(0.0, 0.0, -1.0), -705.281005859375),
new Plane3d(new V3d(-0.833098559959325, 0.55312456950826, 0.0), 148100.179131675),
new Plane3d(new V3d(-0.553124569505628, -0.833098559961073, 0.0), -210155.471521074),
new Plane3d(new V3d(0.0, 0.0, 1.0), 708.76618125843)
};
var tempFilter = new Hull3d(planes);
var pcFiltered = FilteredNode.Create(pc, new FilterInsideConvexHull3d(tempFilter));

Report.EndTimed();

//Report.Line();
//Report.BeginTimed("performing GridQueryXY on original point cloud");
//var dummy1 = pc.EnumerateGridCellsXY(-1).Select(x => x.Footprint.GetCenter()).ToArray();
//Report.Line($"got {dummy1.Length} grid cells");
//Report.EndTimed();

Report.Line();
Report.BeginTimed("performing GridQueryXY on filtered point cloud");
var dummy2 = pcFiltered.EnumerateGridCellsXY(4).Select(x => x.Footprint.GetCenter()).ToArray();
var dummy2 = pcFiltered.EnumerateGridCellsXY(-1).Select(x => V3d.OOO).ToArray();
Report.Line($"got {dummy2.Length} grid cells");
Report.EndTimed();
}

public static void Main(string[] _)
{
var buffer = File.ReadAllBytes(@"T:\Vgm\Stores\2021-02-16_madorjan\data.bin");

Test_20210217_cpunz();

//TestLaszip();
Expand Down
20 changes: 16 additions & 4 deletions src/Aardvark.Data.Points.Base/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public static Chunk ImmutableMerge(params Chunk[] chunks)
var offset = 0;
foreach (var chunk in chunks)
{
if (chunk.IsEmpty) continue;

#pragma warning disable CS8602
if (ps != null) chunk.Positions.CopyTo(ps, offset);
if (cs != null) chunk.Colors.CopyTo(cs, offset);
Expand Down Expand Up @@ -201,6 +203,8 @@ public static Chunk ImmutableMerge(IEnumerable<Chunk> chunks)
/// </summary>
public Chunk Union(Chunk other)
{
if (other.IsEmpty) return this;

var ps = Append(Positions, other.Positions);
if (ps == null) throw new Exception("Invariant c799ccc6-4edf-4530-b1eb-59d93ef69727.");
return new Chunk(
Expand Down Expand Up @@ -243,6 +247,7 @@ public Chunk Union(Chunk other)
/// </summary>
public Chunk ImmutableDeduplicate(bool verbose)
{
if (IsEmpty) return Empty;
if (!HasPositions || Positions == null) return this;

var dedup = new HashSet<V3d>();
Expand Down Expand Up @@ -281,7 +286,7 @@ public Chunk ImmutableDeduplicate(bool verbose)
}

public Chunk ImmutableMapPositions(Func<V3d, V3d> mapping)
=> new(Positions.Map(mapping), Colors, Normals, Intensities, Classifications);
=> IsEmpty ? Empty : new(Positions.Map(mapping), Colors, Normals, Intensities, Classifications);

public Chunk ImmutableMergeWith(IEnumerable<Chunk> others)
=> ImmutableMerge(this, ImmutableMerge(others));
Expand All @@ -294,6 +299,8 @@ public Chunk ImmutableMergeWith(params Chunk[] others)
/// </summary>
public Dictionary<TKey, Chunk> GroupBy<TKey>(Func<Chunk, int, TKey> keySelector)
{
if (IsEmpty) return new Dictionary<TKey, Chunk>();

var dict = new Dictionary<TKey, List<int>>();
for (var i = 0; i < Count; i++)
{
Expand Down Expand Up @@ -324,6 +331,8 @@ public Chunk ImmutableMergeWith(params Chunk[] others)
/// </summary>
public Chunk ImmutableFilter(Func<Chunk, int, bool> predicate)
{
if (IsEmpty) return Empty;

var ps = HasPositions ? new List<V3d>() : null;
var cs = HasColors ? new List<C4b>() : null;
var ns = HasNormals ? new List<V3f>() : null;
Expand Down Expand Up @@ -353,7 +362,8 @@ public Chunk ImmutableFilter(Func<Chunk, int, bool> predicate)
/// </summary>
public Chunk ImmutableFilterSequentialMinDistL2(double minDist)
{
if (minDist <= 0.0 || !HasPositions || Positions?.Count <= 1) return this;
if (IsEmpty) return Empty;
if (minDist <= 0.0 || !HasPositions) return this;
var minDistSquared = minDist * minDist;

var ps = new List<V3d>();
Expand Down Expand Up @@ -387,7 +397,8 @@ public Chunk ImmutableFilterSequentialMinDistL2(double minDist)
/// </summary>
public Chunk ImmutableFilterSequentialMinDistL1(double minDist)
{
if (minDist <= 0.0 || !HasPositions || Positions?.Count <= 1) return this;
if (IsEmpty) return Empty;
if (minDist <= 0.0 || !HasPositions) return this;

var ps = new List<V3d>();
var cs = Colors != null ? new List<C4b>() : null;
Expand Down Expand Up @@ -420,7 +431,8 @@ public Chunk ImmutableFilterSequentialMinDistL1(double minDist)
/// </summary>
public Chunk ImmutableFilterMinDistByCell(Cell bounds, ParseConfig config)
{
if (config.MinDist <= 0.0 || !HasPositions || Positions?.Count <= 1) return this;
if (IsEmpty) return Empty;
if (config.MinDist <= 0.0 || !HasPositions) return this;
if (Positions == null) throw new InvalidOperationException();

var smallestCellExponent = Fun.Log2(config.MinDist).Ceiling();
Expand Down

0 comments on commit 1a60aef

Please sign in to comment.