@@ -112,6 +112,7 @@ module Builder =
112
112
113
113
let rec private build '' ( config : BuildConfig ) ( rootCell : Cell2d ) ( patches : LayerSet []) =
114
114
115
+ // sample size (sample exponent) of highest-resolution patch
115
116
let minSampleExponent = patches |> Seq.map ( fun p -> p.SampleExponent) |> Seq.min
116
117
117
118
if config.Verbose then
@@ -125,13 +126,17 @@ module Builder =
125
126
126
127
| 0 ->
127
128
129
+ //printfn "[00000] %d" rootCell.Exponent
130
+
128
131
if config.Verbose then
129
132
printfn " [build''] ZERO patches"
130
133
131
134
NoNode
132
135
133
136
| 1 ->
134
137
138
+ //printfn "[11111] %d" rootCell.Exponent
139
+
135
140
if config.Verbose then
136
141
printfn " [build''] SINGLE patch (%A )" patches[ 0 ]. SampleWindow
137
142
@@ -141,6 +146,8 @@ module Builder =
141
146
142
147
| 2 ->
143
148
149
+ //printfn "[22222] %d" rootCell.Exponent
150
+
144
151
if config.Verbose then
145
152
printfn " [build''] TWO patches (%A , %A )" patches[ 0 ]. SampleWindow patches[ 1 ]. SampleWindow
146
153
@@ -151,6 +158,8 @@ module Builder =
151
158
152
159
| n -> // n patches
153
160
161
+ //printfn "[nnnnn] %d" rootCell.Exponent
162
+
154
163
if config.Verbose then
155
164
printfn " [build''] MULTIPLE patches (n=%d )" patches.Length
156
165
@@ -160,30 +169,41 @@ module Builder =
160
169
( fun () -> sprintf " Expected config.SplitLimitPowerOfTwo to be non-negative, but found %d ." config.SplitLimitPowerOfTwo)
161
170
" 95c43529-9649-42d6-9b47-c6f8fb6da301"
162
171
163
- let tileSize = 1 <<< config.SplitLimitPowerOfTwo
164
- let rootBounds = getBoundsForExponent minSampleExponent rootCell
172
+ let mutable forceFlatten = false
173
+ // let tileSize = 1 <<< config.SplitLimitPowerOfTwo
165
174
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
181
177
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)
184
204
185
205
//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
187
207
188
208
// current tile size has reached the split limit:
189
209
// 1. sort all patches from fine to coarse (from small to large sample exponents)
0 commit comments