Skip to content

Commit

Permalink
[builder] quadtree build fix (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaierhofer committed Feb 9, 2024
1 parent 441076d commit 1e7c851
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 0.5.6
- [builder] quadtree build fix (experimental)

### 0.5.5
- [builder] flatten layer fix

Expand Down
33 changes: 29 additions & 4 deletions src/Aardvark.Geometry.Quadtree/Builder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,27 @@ module Builder =
let tileSize = 1 <<< config.SplitLimitPowerOfTwo
let rootBounds = getBoundsForExponent minSampleExponent rootCell

if rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize then

let patchesPerQuadrant =
rootCell.Children
|> Array.map (fun subCell ->
let subPatches =
patches
|> Array.choose (fun patch ->
let bbQuadrant = subCell.GetBoundsForExponent(patch.SampleExponent)
let r = patch.WithWindow bbQuadrant
//if config.Verbose && r.IsSome then
// printfn "[build''] | subCell=%A patch.Window=%A bbQuadrant=%A" subCell patch.SampleWindow r.Value.SampleWindow
r
)
(subCell, subPatches)
)

let patchesPerQuadrantCounts = patchesPerQuadrant |> Array.map (fun (_, ps) -> ps.Length)
let canMakeProgress = patchesPerQuadrantCounts |> Array.forall (fun count -> count < n)

//if rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize then
if rootCell.Exponent = minSampleExponent (*&& rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize*) then

// current tile size has reached the split limit:
// 1. sort all patches from fine to coarse (from small to large sample exponents)
Expand Down Expand Up @@ -235,8 +255,8 @@ module Builder =
|> Array.choose (fun patch ->
let bbQuadrant = subCell.GetBoundsForExponent(patch.SampleExponent)
let r = patch.WithWindow bbQuadrant
if config.Verbose && r.IsSome then
printfn "[build''] | subCell=%A patch.Window=%A bbQuadrant=%A" subCell patch.SampleWindow r.Value.SampleWindow
//if config.Verbose && r.IsSome then
// printfn "[build''] | subCell=%A patch.Window=%A bbQuadrant=%A" subCell patch.SampleWindow r.Value.SampleWindow
r
)
(subCell, subPatches)
Expand All @@ -252,7 +272,12 @@ module Builder =
let subNodes = patchesPerQuadrant |> Array.map (fun (subCell, subPatches) ->
match subPatches.Length with
| 0 -> NoNode
| _ -> build'' config subCell subPatches
| _ ->

let subnode = build'' config subCell subPatches
match subnode with
| NoNode -> failwith "AAAARGH"
| _ -> subnode
)

let hasMask = subNodes |> Array.exists (fun n -> n.HasMask)
Expand Down
15 changes: 12 additions & 3 deletions src/Aardvark.Geometry.Quadtree/Query.fs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ module Query =
else
// dominated sample IS NOT interfered with -> return
if config.Verbose then printfn "[mergeDominating] YIELD non-dominating sample: %A" (y.GetSampleCells())

//match y.Node with | NoNode -> failwith "Invariant 5e786252-dbfe-4ff2-9e6c-0d59460f7ac9" | _ -> ()

yield y

mergeDominatingT0.Stop()
Expand Down Expand Up @@ -280,9 +283,15 @@ module Query =
for i = 0 to 3 do
let aSub = a.SubNodes.[i]
let bSub = b.SubNodes.[i]
if config.Verbose then printfn "[QUADRANTS %d] %A %A" i aSub.ExactBoundingBox bSub.ExactBoundingBox
let r = recurse aSub bSub |> Seq.toList
if r.Length > 0 then yield! r

match aSub, bSub with
| NoNode, NoNode -> ()
| NoNode, _ -> failwith "Invariant 8f6fbd3d-658e-422b-9643-c4916f48c208."
| _ , NoNode -> failwith "Invariant 43f654ad-a1cc-490a-9902-b0b218da6a95."
| _ ->
if config.Verbose then printfn "[QUADRANTS %d] %A %A" i aSub.ExactBoundingBox bSub.ExactBoundingBox
let r = recurse aSub bSub |> Seq.toList
if r.Length > 0 then yield! r

| InMemoryInner a, InMemoryNode b ->
if firstContainsSecond then
Expand Down
23 changes: 21 additions & 2 deletions src/Scratch/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ let cp_20240202_quadtreetest () =
printfn("total samples count with e = %d: %d; count NaN = %d") e sampleCount sampleCountNan

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

Quadtree.PrintStructure true qtree

do

let sw = Stopwatch.StartNew()
let options = SerializationOptions.NewInMemoryStore(verbose = false)
let id = qtree |> Quadtree.Save options
sw.Stop()
printfn "[TIMING] save octree to store : %A" sw.Elapsed

let sw = Stopwatch.StartNew()
let qtreeReloaded = Quadtree.Load options id
sw.Stop()
printfn "[TIMING] load octree from store: %A" sw.Elapsed


printfn "quadtree (original) has a total of %d nodes" (Quadtree.CountNodes true qtree)
printfn "quadtree (reloaded) has a total of %d nodes" (Quadtree.CountNodes true qtreeReloaded)
()

//Quadtree.PrintStructure true qtree

printfn("SAMPLES: count=%d") samplesLength
let gs = samples
Expand Down

0 comments on commit 1e7c851

Please sign in to comment.