Skip to content

Commit

Permalink
structured point clouds: implementation (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaierhofer committed Sep 22, 2023
1 parent 3b9583c commit 646b363
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Aardvark.Data.Points.Base/ParseConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public ParseConfig(ParseConfig x)
MinDist = x.MinDist;
ReadBufferSizeInBytes = x.ReadBufferSizeInBytes;
EnabledProperties = x.EnabledProperties;
PartIndexOffset = x.PartIndexOffset;
}

/// <summary></summary>
Expand Down
19 changes: 19 additions & 0 deletions src/Aardvark.Data.Points.Base/PartIndexUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,23 @@ public static class PartIndexUtils
}
}

public static Range1i ExtendedBy(in Range1i range, object? partIndices)
{
checked
{
return partIndices switch
{
null => range,
uint x => range.ExtendedBy((int)x),
IList<byte> xs => range.ExtendedBy((Range1i)new Range1b(xs)),
IList<short> xs => range.ExtendedBy((Range1i)new Range1s(xs)),
IList<int> xs => range.ExtendedBy(new Range1i(xs)),

_ => throw new Exception(
$"Unexpected part indices type {partIndices.GetType().FullName}. " +
$"Error 3915b996-1842-4418-9445-e4c4f1b678a6"
)
};
}
}
}
26 changes: 20 additions & 6 deletions src/Aardvark.Geometry.PointSet/Import/ImportChunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ public static PointSet Chunks(IEnumerable<Chunk> chunks, ImportConfig config)
{
config.ProgressCallback(0.0);

if (config.Verbose)
var partIndicesRange = Range1i.Invalid;
var chunkCount = 0;
chunks = chunks.Do(chunk =>
{
var chunkCount = 0;
chunks = chunks.Do(chunk =>
if (chunk.HasPartIndices)
{
partIndicesRange = PartIndexUtils.ExtendedBy(partIndicesRange, chunk.PartIndices);
}

if (config.Verbose)
{
if (chunk.Count == 0) Report.Warn($"[PointCloud.Chunks] empty chunk");
Report.Line($"[PointCloud.Chunks] processing chunk {Interlocked.Increment(ref chunkCount)}");
});
}
}
});

// reproject positions
if (config.Reproject != null)
Expand Down Expand Up @@ -176,7 +182,15 @@ Chunk map(Chunk x, CancellationToken ct)

// create final point set with specified key (or random key when no key is specified)
var key = config.Key ?? Guid.NewGuid().ToString();
final = new PointSet(config.Storage ?? throw new Exception($"No storage specified. Error 5b4ebfec-d418-4ddc-9c2f-646d270cf78c."), key, final.Root?.Value?.Id ?? Guid.Empty, config.OctreeSplitLimit);
final = new PointSet(
storage : config.Storage ?? throw new Exception($"No storage specified. Error 5b4ebfec-d418-4ddc-9c2f-646d270cf78c."),
pointSetId: key,
rootCellId: final.Root?.Value?.Id ?? Guid.Empty,
splitLimit: config.OctreeSplitLimit
)
{
PartIndexRange = partIndicesRange
};
config.Storage.Add(key, final);

return final;
Expand Down
2 changes: 2 additions & 0 deletions src/Aardvark.Geometry.PointSet/Octrees/InMemoryPointSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private InMemoryPointSet(ImmutableDictionary<Durable.Def, object> data, Cell cel

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

Expand Down Expand Up @@ -180,6 +181,7 @@ internal PointSetNode ToPointSetNode(Storage storage, bool isTemporaryImportNode
foreach (var kv in _octree.m_data)
{
if (kv.Key == Durable.Octree.PositionsGlobal3d) continue;
if (kv.Key == Durable.Octree.PerCellPartIndex1ui) continue;
var subset = kv.Value.Subset(_ia);
attributes = attributes.Add(kv.Key, subset);
}
Expand Down

0 comments on commit 646b363

Please sign in to comment.