Skip to content

Commit 47ccb8a

Browse files
sync
1 parent 1e7c851 commit 47ccb8a

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

src/Aardvark.Geometry.Quadtree/Builder.fs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ module Builder =
112112

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

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

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

126127
| 0 ->
127128

129+
//printfn "[00000] %d" rootCell.Exponent
130+
128131
if config.Verbose then
129132
printfn "[build''] ZERO patches"
130133

131134
NoNode
132135

133136
| 1 ->
134137

138+
//printfn "[11111] %d" rootCell.Exponent
139+
135140
if config.Verbose then
136141
printfn "[build''] SINGLE patch (%A)" patches[0].SampleWindow
137142

@@ -141,6 +146,8 @@ module Builder =
141146

142147
| 2 ->
143148

149+
//printfn "[22222] %d" rootCell.Exponent
150+
144151
if config.Verbose then
145152
printfn "[build''] TWO patches (%A, %A)" patches[0].SampleWindow patches[1].SampleWindow
146153

@@ -151,6 +158,8 @@ module Builder =
151158

152159
| n -> // n patches
153160

161+
//printfn "[nnnnn] %d" rootCell.Exponent
162+
154163
if config.Verbose then
155164
printfn "[build''] MULTIPLE patches (n=%d)" patches.Length
156165

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

163-
let tileSize = 1 <<< config.SplitLimitPowerOfTwo
164-
let rootBounds = getBoundsForExponent minSampleExponent rootCell
172+
let mutable forceFlatten = false
173+
//let tileSize = 1 <<< config.SplitLimitPowerOfTwo
165174

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

182-
let patchesPerQuadrantCounts = patchesPerQuadrant |> Array.map (fun (_, ps) -> ps.Length)
183-
let canMakeProgress = patchesPerQuadrantCounts |> Array.forall (fun count -> count < n)
178+
// if all remaining patches have the same resolution, then we can flatten all layers
179+
// (because there can be no troubles with overlapping samples of different sizes)
180+
if (patches |> Seq.distinctBy (fun p -> p.SampleExponent) |> Seq.tryExactlyOne).IsSome then
181+
forceFlatten <- true
182+
183+
let patchesWithMinExp = patches |> Array.filter (fun p -> p.SampleExponent = minSampleExponent)
184+
if patchesWithMinExp |> Array.exists (fun p -> p.SampleWindow.Contains(rootBounds)) then
185+
forceFlatten <- true
186+
187+
//let patchesPerQuadrant =
188+
// rootCell.Children
189+
// |> Array.map (fun subCell ->
190+
// let subPatches =
191+
// patches
192+
// |> Array.choose (fun patch ->
193+
// let bbQuadrant = subCell.GetBoundsForExponent(patch.SampleExponent)
194+
// let r = patch.WithWindow bbQuadrant
195+
// //if config.Verbose && r.IsSome then
196+
// // printfn "[build''] | subCell=%A patch.Window=%A bbQuadrant=%A" subCell patch.SampleWindow r.Value.SampleWindow
197+
// r
198+
// )
199+
// (subCell, subPatches)
200+
// )
201+
202+
//let patchesPerQuadrantCounts = patchesPerQuadrant |> Array.map (fun (_, ps) -> ps.Length)
203+
//let canMakeProgress = patchesPerQuadrantCounts |> Array.forall (fun count -> count < n)
184204

185205
//if rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize then
186-
if rootCell.Exponent = minSampleExponent (*&& rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize*) then
206+
if rootCell.Exponent = minSampleExponent || forceFlatten (*&& rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize*) then
187207

188208
// current tile size has reached the split limit:
189209
// 1. sort all patches from fine to coarse (from small to large sample exponents)

0 commit comments

Comments
 (0)