Skip to content

Commit 1e7c851

Browse files
[builder] quadtree build fix (experimental)
1 parent 441076d commit 1e7c851

File tree

4 files changed

+65
-9
lines changed

4 files changed

+65
-9
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 0.5.6
2+
- [builder] quadtree build fix (experimental)
3+
14
### 0.5.5
25
- [builder] flatten layer fix
36

src/Aardvark.Geometry.Quadtree/Builder.fs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,27 @@ module Builder =
163163
let tileSize = 1 <<< config.SplitLimitPowerOfTwo
164164
let rootBounds = getBoundsForExponent minSampleExponent rootCell
165165

166-
if rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize then
166+
167+
let patchesPerQuadrant =
168+
rootCell.Children
169+
|> Array.map (fun subCell ->
170+
let subPatches =
171+
patches
172+
|> Array.choose (fun patch ->
173+
let bbQuadrant = subCell.GetBoundsForExponent(patch.SampleExponent)
174+
let r = patch.WithWindow bbQuadrant
175+
//if config.Verbose && r.IsSome then
176+
// printfn "[build''] | subCell=%A patch.Window=%A bbQuadrant=%A" subCell patch.SampleWindow r.Value.SampleWindow
177+
r
178+
)
179+
(subCell, subPatches)
180+
)
181+
182+
let patchesPerQuadrantCounts = patchesPerQuadrant |> Array.map (fun (_, ps) -> ps.Length)
183+
let canMakeProgress = patchesPerQuadrantCounts |> Array.forall (fun count -> count < n)
184+
185+
//if rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize then
186+
if rootCell.Exponent = minSampleExponent (*&& rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize*) then
167187

168188
// current tile size has reached the split limit:
169189
// 1. sort all patches from fine to coarse (from small to large sample exponents)
@@ -235,8 +255,8 @@ module Builder =
235255
|> Array.choose (fun patch ->
236256
let bbQuadrant = subCell.GetBoundsForExponent(patch.SampleExponent)
237257
let r = patch.WithWindow bbQuadrant
238-
if config.Verbose && r.IsSome then
239-
printfn "[build''] | subCell=%A patch.Window=%A bbQuadrant=%A" subCell patch.SampleWindow r.Value.SampleWindow
258+
//if config.Verbose && r.IsSome then
259+
// printfn "[build''] | subCell=%A patch.Window=%A bbQuadrant=%A" subCell patch.SampleWindow r.Value.SampleWindow
240260
r
241261
)
242262
(subCell, subPatches)
@@ -252,7 +272,12 @@ module Builder =
252272
let subNodes = patchesPerQuadrant |> Array.map (fun (subCell, subPatches) ->
253273
match subPatches.Length with
254274
| 0 -> NoNode
255-
| _ -> build'' config subCell subPatches
275+
| _ ->
276+
277+
let subnode = build'' config subCell subPatches
278+
match subnode with
279+
| NoNode -> failwith "AAAARGH"
280+
| _ -> subnode
256281
)
257282

258283
let hasMask = subNodes |> Array.exists (fun n -> n.HasMask)

src/Aardvark.Geometry.Quadtree/Query.fs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ module Query =
170170
else
171171
// dominated sample IS NOT interfered with -> return
172172
if config.Verbose then printfn "[mergeDominating] YIELD non-dominating sample: %A" (y.GetSampleCells())
173+
174+
//match y.Node with | NoNode -> failwith "Invariant 5e786252-dbfe-4ff2-9e6c-0d59460f7ac9" | _ -> ()
175+
173176
yield y
174177

175178
mergeDominatingT0.Stop()
@@ -280,9 +283,15 @@ module Query =
280283
for i = 0 to 3 do
281284
let aSub = a.SubNodes.[i]
282285
let bSub = b.SubNodes.[i]
283-
if config.Verbose then printfn "[QUADRANTS %d] %A %A" i aSub.ExactBoundingBox bSub.ExactBoundingBox
284-
let r = recurse aSub bSub |> Seq.toList
285-
if r.Length > 0 then yield! r
286+
287+
match aSub, bSub with
288+
| NoNode, NoNode -> ()
289+
| NoNode, _ -> failwith "Invariant 8f6fbd3d-658e-422b-9643-c4916f48c208."
290+
| _ , NoNode -> failwith "Invariant 43f654ad-a1cc-490a-9902-b0b218da6a95."
291+
| _ ->
292+
if config.Verbose then printfn "[QUADRANTS %d] %A %A" i aSub.ExactBoundingBox bSub.ExactBoundingBox
293+
let r = recurse aSub bSub |> Seq.toList
294+
if r.Length > 0 then yield! r
286295

287296
| InMemoryInner a, InMemoryNode b ->
288297
if firstContainsSecond then

src/Scratch/Program.fs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ let cp_20240202_quadtreetest () =
13371337
printfn("total samples count with e = %d: %d; count NaN = %d") e sampleCount sampleCountNan
13381338

13391339
let sw = Stopwatch.StartNew()
1340-
let buildConfig = { BuildConfig.Default with Verbose = false }
1340+
let buildConfig = { BuildConfig.Default with Verbose = false; SplitLimitPowerOfTwo = 8 }
13411341
let maybeQuadtree = x.Build2 buildConfig
13421342
sw.Stop()
13431343
printfn "[TIMING] build: %A" sw.Elapsed
@@ -1372,7 +1372,26 @@ let cp_20240202_quadtreetest () =
13721372
sw.Stop()
13731373
printfn "[TIMING] query all samples: %A" sw.Elapsed
13741374

1375-
Quadtree.PrintStructure true qtree
1375+
1376+
do
1377+
1378+
let sw = Stopwatch.StartNew()
1379+
let options = SerializationOptions.NewInMemoryStore(verbose = false)
1380+
let id = qtree |> Quadtree.Save options
1381+
sw.Stop()
1382+
printfn "[TIMING] save octree to store : %A" sw.Elapsed
1383+
1384+
let sw = Stopwatch.StartNew()
1385+
let qtreeReloaded = Quadtree.Load options id
1386+
sw.Stop()
1387+
printfn "[TIMING] load octree from store: %A" sw.Elapsed
1388+
1389+
1390+
printfn "quadtree (original) has a total of %d nodes" (Quadtree.CountNodes true qtree)
1391+
printfn "quadtree (reloaded) has a total of %d nodes" (Quadtree.CountNodes true qtreeReloaded)
1392+
()
1393+
1394+
//Quadtree.PrintStructure true qtree
13761395

13771396
printfn("SAMPLES: count=%d") samplesLength
13781397
let gs = samples

0 commit comments

Comments
 (0)