@@ -126,17 +126,13 @@ module Builder =
126
126
127
127
| 0 ->
128
128
129
- //printfn "[00000] %d" rootCell.Exponent
130
-
131
129
if config.Verbose then
132
130
printfn " [build''] ZERO patches"
133
131
134
132
NoNode
135
133
136
134
| 1 ->
137
135
138
- //printfn "[11111] %d" rootCell.Exponent
139
-
140
136
if config.Verbose then
141
137
printfn " [build''] SINGLE patch (%A )" patches[ 0 ]. SampleWindow
142
138
@@ -146,8 +142,6 @@ module Builder =
146
142
147
143
| 2 ->
148
144
149
- //printfn "[22222] %d" rootCell.Exponent
150
-
151
145
if config.Verbose then
152
146
printfn " [build''] TWO patches (%A , %A )" patches[ 0 ]. SampleWindow patches[ 1 ]. SampleWindow
153
147
@@ -158,52 +152,37 @@ module Builder =
158
152
159
153
| n -> // n patches
160
154
161
- //printfn "[nnnnn] %d" rootCell.Exponent
162
-
163
155
if config.Verbose then
164
156
printfn " [build''] MULTIPLE patches (n=%d )" patches.Length
165
157
166
- let ebb = patches |> Seq.map ( fun patch -> patch.BoundingBox) |> Box2d
167
-
168
158
invariantm ( config.SplitLimitPowerOfTwo >= 0 )
169
159
( fun () -> sprintf " Expected config.SplitLimitPowerOfTwo to be non-negative, but found %d ." config.SplitLimitPowerOfTwo)
170
160
" 95c43529-9649-42d6-9b47-c6f8fb6da301"
171
-
172
- let mutable forceFlatten = false
173
- // let tileSize = 1 <<< config.SplitLimitPowerOfTwo
174
-
175
- // bounds of root cell at level of highest-resolution patch
161
+
162
+ // exact bounding box in global space
163
+ let ebb = patches |> Seq.map ( fun patch -> patch.BoundingBox ) |> Box2d
164
+
165
+ // bounds of root cell in sample space ( at sample level of highest-resolution patch)
176
166
let rootBounds = getBoundsForExponent minSampleExponent rootCell
177
167
178
168
// if all remaining patches have the same resolution, then we can flatten all layers
179
169
// (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
170
+ let allRemainingPatchesHaveSameResolution =
171
+ ( patches |> Seq.distinctBy ( fun p -> p.SampleExponent) |> Seq.tryExactlyOne) .IsSome
172
+
173
+ if config.Verbose then
174
+ if allRemainingPatchesHaveSameResolution then
175
+ printfn " [build''] FLATTEN all %d patches, because they have same resolution" patches.Length
176
+ else
177
+ printfn " [build''] DO NOT FLATTEN %d patches, because different resolutions" patches.Length
178
+
182
179
183
180
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)
204
-
205
- //if rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize then
206
- if rootCell.Exponent = minSampleExponent || forceFlatten (* && rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize*) then
181
+ let forceFlatten = patchesWithMinExp |> Array.exists ( fun p -> p.SampleWindow.Contains( rootBounds))
182
+
183
+ let stopRecursion = rootCell.Exponent = minSampleExponent || forceFlatten || ( allRemainingPatchesHaveSameResolution && rootCell.Exponent < minSampleExponent + config.SplitLimitPowerOfTwo)
184
+
185
+ if stopRecursion then
207
186
208
187
// current tile size has reached the split limit:
209
188
// 1. sort all patches from fine to coarse (from small to large sample exponents)
@@ -213,7 +192,10 @@ module Builder =
213
192
// -> a mask indicates non-defined samples
214
193
215
194
if config.Verbose then
216
- printfn " [build''] MERGE %d patches; because reached split limit" n
195
+ if forceFlatten then
196
+ printfn " [build''] MERGE %d patches (forceFlatten = true)" n
197
+ else
198
+ printfn " [build''] MERGE %d patches; because reached split limit" n
217
199
218
200
//if debugOutput then
219
201
// let bbWindow = patches |> Seq.map (fun patch -> patch.SampleWindow) |> Box2l
@@ -228,24 +210,25 @@ module Builder =
228
210
229
211
let mutable rootCell = rootCell
230
212
231
- if requiredRootCellExponent <> rootCell.Exponent then
213
+ if not forceFlatten then
214
+ if requiredRootCellExponent <> rootCell.Exponent then
232
215
233
- invariantm ( rootCell.Exponent < requiredRootCellExponent)
234
- ( fun () -> sprintf " Expected root cell exponent %d to be smaller than requiredRootCellExponent %d ." rootCell.Exponent requiredRootCellExponent)
235
- " 4911adf3-7b87-4234-9bcc-bc3076df846e"
216
+ invariantm ( rootCell.Exponent < requiredRootCellExponent)
217
+ ( fun () -> sprintf " Expected root cell exponent %d to be smaller than requiredRootCellExponent %d ." rootCell.Exponent requiredRootCellExponent)
218
+ " 4911adf3-7b87-4234-9bcc-bc3076df846e"
236
219
237
- if config.Verbose then
238
- printfn " [build''] | must adjust root cell %A exponent to %d ..." rootCell requiredRootCellExponent
220
+ if config.Verbose then
221
+ printfn " [build''] | must adjust root cell %A exponent to %d ..." rootCell requiredRootCellExponent
239
222
240
- while rootCell.Exponent < requiredRootCellExponent do rootCell <- rootCell.Parent
223
+ while rootCell.Exponent < requiredRootCellExponent do rootCell <- rootCell.Parent
241
224
242
- if config.Verbose then
243
- printfn " [build''] | adjusted root cell is %A " rootCell
225
+ if config.Verbose then
226
+ printfn " [build''] | adjusted root cell is %A " rootCell
244
227
245
- else
228
+ else
246
229
247
- if config.Verbose then
248
- printfn " [build''] | root cell %A already has requiredRootCellExponent %d " rootCell requiredRootCellExponent
230
+ if config.Verbose then
231
+ printfn " [build''] | root cell %A already has requiredRootCellExponent %d " rootCell requiredRootCellExponent
249
232
250
233
let flattended = LayerSet.Flatten config.Verbose patches
251
234
0 commit comments