Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaierhofer committed Feb 10, 2024
1 parent 1e7c851 commit 47ccb8a
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions src/Aardvark.Geometry.Quadtree/Builder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ module Builder =

let rec private build'' (config : BuildConfig) (rootCell : Cell2d) (patches : LayerSet[]) =

// sample size (sample exponent) of highest-resolution patch
let minSampleExponent = patches |> Seq.map (fun p -> p.SampleExponent) |> Seq.min

if config.Verbose then
Expand All @@ -125,13 +126,17 @@ module Builder =

| 0 ->

//printfn "[00000] %d" rootCell.Exponent

if config.Verbose then
printfn "[build''] ZERO patches"

NoNode

| 1 ->

//printfn "[11111] %d" rootCell.Exponent

if config.Verbose then
printfn "[build''] SINGLE patch (%A)" patches[0].SampleWindow

Expand All @@ -141,6 +146,8 @@ module Builder =

| 2 ->

//printfn "[22222] %d" rootCell.Exponent

if config.Verbose then
printfn "[build''] TWO patches (%A, %A)" patches[0].SampleWindow patches[1].SampleWindow

Expand All @@ -151,6 +158,8 @@ module Builder =

| n -> // n patches

//printfn "[nnnnn] %d" rootCell.Exponent

if config.Verbose then
printfn "[build''] MULTIPLE patches (n=%d)" patches.Length

Expand All @@ -160,30 +169,41 @@ module Builder =
(fun () -> sprintf "Expected config.SplitLimitPowerOfTwo to be non-negative, but found %d." config.SplitLimitPowerOfTwo)
"95c43529-9649-42d6-9b47-c6f8fb6da301"

let tileSize = 1 <<< config.SplitLimitPowerOfTwo
let rootBounds = getBoundsForExponent minSampleExponent rootCell
let mutable forceFlatten = false
//let tileSize = 1 <<< config.SplitLimitPowerOfTwo


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)
)
// bounds of root cell at level of highest-resolution patch
let rootBounds = getBoundsForExponent minSampleExponent rootCell

let patchesPerQuadrantCounts = patchesPerQuadrant |> Array.map (fun (_, ps) -> ps.Length)
let canMakeProgress = patchesPerQuadrantCounts |> Array.forall (fun count -> count < n)
// if all remaining patches have the same resolution, then we can flatten all layers
// (because there can be no troubles with overlapping samples of different sizes)
if (patches |> Seq.distinctBy (fun p -> p.SampleExponent) |> Seq.tryExactlyOne).IsSome then
forceFlatten <- true

let patchesWithMinExp = patches |> Array.filter (fun p -> p.SampleExponent = minSampleExponent)
if patchesWithMinExp |> Array.exists (fun p -> p.SampleWindow.Contains(rootBounds)) then
forceFlatten <- true

//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
if rootCell.Exponent = minSampleExponent || forceFlatten (*&& 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

0 comments on commit 47ccb8a

Please sign in to comment.