@@ -13,7 +13,7 @@ module Builder =
13
13
let rec private build ' ( config : BuildConfig ) ( sampleExponent : int ) ( rootCell : Cell2d ) ( patches : LayerSet []) =
14
14
15
15
if config.Verbose then
16
- printfn " [DEBUG] build' rootCell = %A , %d patches" rootCell patches.Length
16
+ printfn " [build'] rootCell = %A , %d patches" rootCell patches.Length
17
17
18
18
for p in patches do
19
19
invariantm ( p.SampleExponent = sampleExponent)
@@ -29,7 +29,7 @@ module Builder =
29
29
let theSinglePatch = patches[ 0 ]
30
30
31
31
if config.Verbose then
32
- printfn " [DEBUG ] SINGLE patch (%A )" theSinglePatch.SampleWindow
32
+ printfn " [build' ] SINGLE patch (%A )" theSinglePatch.SampleWindow
33
33
34
34
Quadtree.Build BuildConfig.Default theSinglePatch.Layers
35
35
@@ -43,11 +43,11 @@ module Builder =
43
43
let bbWindow = patches |> Seq.map ( fun patch -> patch.SampleWindow) |> Box2l
44
44
45
45
if config.Verbose then
46
- printfn " [DEBUG ] MERGE %d patches; %A " n ( bbWindow - rootBounds.Min)
46
+ printfn " [build' ] MERGE %d patches; %A " n ( bbWindow - rootBounds.Min)
47
47
48
48
//if debugOutput then
49
49
// for patch in patches do
50
- // printfn "[DEBUG ] %A (exact %A)" (patch.SampleWindow - rootBounds.Min) (bbWindow - rootBounds.Min)
50
+ // printfn "[build' ] %A (exact %A)" (patch.SampleWindow - rootBounds.Min) (bbWindow - rootBounds.Min)
51
51
52
52
// adjust root cell for split limit
53
53
let requiredRootCellSplitLimit = sampleExponent + BuildConfig.Default.SplitLimitPowerOfTwo
@@ -61,18 +61,18 @@ module Builder =
61
61
" 4911adf3-7b87-4234-9bcc-bc3076df846e"
62
62
63
63
if config.Verbose then
64
- printfn " [DEBUG ] must adjust root cell %A exponent to %d " rootCell requiredRootCellSplitLimit
64
+ printfn " [build' ] must adjust root cell %A exponent to %d " rootCell requiredRootCellSplitLimit
65
65
66
66
while rootCell.Exponent < requiredRootCellSplitLimit do rootCell <- rootCell.Parent
67
67
68
68
if config.Verbose then
69
- printfn " [DEBUG ] adjusted root cell is %A " rootCell
69
+ printfn " [build' ] adjusted root cell is %A " rootCell
70
70
71
71
let merged = LayerSet.Merge patches
72
72
let qnode = QNode( Guid.NewGuid(), ebb, rootCell, BuildConfig.Default.SplitLimitPowerOfTwo, merged)
73
73
74
74
if config.Verbose then
75
- printfn " [DEBUG ] CREATED QNode with split limit = %d " qnode.SplitLimitExponent
75
+ printfn " [build' ] CREATED QNode with split limit = %d " qnode.SplitLimitExponent
76
76
77
77
//let xs = qnode |> InMemoryNode |> Query.All Query.Config.Default |> Seq.map (fun x -> x.GetSamples<V4f>(Defs.HeightsBilinear4f)) |> Array.ofSeq |> Array.collect id
78
78
//for x in xs do printfn "%A" x
@@ -92,7 +92,7 @@ module Builder =
92
92
93
93
94
94
if config.Verbose then
95
- printfn " [DEBUG ] SPLIT %d patches" n
95
+ printfn " [build' ] SPLIT %d patches" n
96
96
97
97
//for i in 0..3 do
98
98
// let (subCell, subPatches) = patchesPerQuadrant[i]
@@ -106,14 +106,14 @@ module Builder =
106
106
107
107
let hasMask = subNodes |> Array.exists ( fun n -> n.HasMask)
108
108
if config.Verbose && hasMask then
109
- printfn " [DEBUG ] has mask %A " rootCell
109
+ printfn " [build' ] has mask %A " rootCell
110
110
let result = { Id = Guid.NewGuid(); ExactBoundingBox = ebb; Cell = rootCell; SplitLimitExponent = BuildConfig.Default.SplitLimitPowerOfTwo; HasMask = hasMask; SubNodes = subNodes }
111
111
result |> InMemoryInner
112
112
113
113
let rec private build '' ( config : BuildConfig ) ( rootCell : Cell2d ) ( patches : LayerSet []) =
114
114
115
115
if config.Verbose then
116
- printfn " [DEBUG] build' rootCell = %A , %d patches" rootCell patches.Length
116
+ printfn " [build''] rootCell = %A , %d patches" rootCell patches.Length
117
117
118
118
let minSampleExponent = patches |> Seq.map ( fun p -> p.SampleExponent) |> Seq.min
119
119
@@ -122,14 +122,14 @@ module Builder =
122
122
| 0 ->
123
123
124
124
if config.Verbose then
125
- printfn " [DEBUG][ build''] ZERO patches"
125
+ printfn " [build''] ZERO patches"
126
126
127
127
NoNode
128
128
129
129
| 1 ->
130
130
131
131
if config.Verbose then
132
- printfn " [DEBUG][ build''] SINGLE patch (%A )" patches[ 0 ]. SampleWindow
132
+ printfn " [build''] SINGLE patch (%A )" patches[ 0 ]. SampleWindow
133
133
134
134
let theSinglePatch = patches[ 0 ]
135
135
@@ -138,7 +138,7 @@ module Builder =
138
138
| 2 ->
139
139
140
140
if config.Verbose then
141
- printfn " [DEBUG][ build''] TWO patches (%A , %A )" patches[ 0 ]. SampleWindow patches[ 1 ]. SampleWindow
141
+ printfn " [build''] TWO patches (%A , %A )" patches[ 0 ]. SampleWindow patches[ 1 ]. SampleWindow
142
142
143
143
let p0 = Quadtree.Build' config patches[ 0 ]
144
144
let p1 = Quadtree.Build' config patches[ 1 ]
@@ -148,7 +148,7 @@ module Builder =
148
148
| n -> // n patches
149
149
150
150
if config.Verbose then
151
- printfn " [DEBUG][ build''] n=%d patches " patches.Length
151
+ printfn " [build''] MULTIPLE patches ( n=%d ) " patches.Length
152
152
153
153
let ebb = patches |> Seq.map ( fun patch -> patch.BoundingBox) |> Box2d
154
154
@@ -161,8 +161,17 @@ module Builder =
161
161
162
162
if rootBounds.Size.X <= tileSize && rootBounds.Size.Y <= tileSize then
163
163
164
+ // current tile size has reached the split limit:
165
+ // 1. sort all patches from fine to coarse (from small to large sample exponents)
166
+ // 2. flatten all patches/layers into a single patch/layer
167
+ // -> resulting layer has finest resolution of all patches
168
+ // -> coarser layers will be subsampled
169
+ // -> a mask indicates non-defined samples
170
+
164
171
if config.Verbose then
165
- printfn " [DEBUG][build''] MERGE %d patches; because reached split limit" n
172
+ printfn " [build''] MERGE %d patches; because reached split limit" n
173
+ for patch in patches do
174
+ printfn " [build''] | e=%d origin=%A size=%A " patch.SampleExponent patch.SampleWindow.Min patch.SampleWindow.Size
166
175
167
176
failwith " TODO"
168
177
@@ -184,46 +193,49 @@ module Builder =
184
193
" 4911adf3-7b87-4234-9bcc-bc3076df846e"
185
194
186
195
if config.Verbose then
187
- printfn " [DEBUG][ build''] must adjust root cell %A exponent to %d " rootCell requiredRootCellSplitLimit
196
+ printfn " [build''] must adjust root cell %A exponent to %d " rootCell requiredRootCellSplitLimit
188
197
189
198
while rootCell.Exponent < requiredRootCellSplitLimit do rootCell <- rootCell.Parent
190
199
191
200
if config.Verbose then
192
- printfn " [DEBUG][ build''] adjusted root cell is %A " rootCell
201
+ printfn " [build''] adjusted root cell is %A " rootCell
193
202
194
203
let merged = LayerSet.Merge patches
195
204
let qnode = QNode( Guid.NewGuid(), ebb, rootCell, config.SplitLimitPowerOfTwo, merged)
196
205
197
206
if config.Verbose then
198
- printfn " [DEBUG][ build''] CREATED QNode with split limit = %d " qnode.SplitLimitExponent
207
+ printfn " [build''] CREATED QNode with split limit = %d " qnode.SplitLimitExponent
199
208
200
209
//let xs = qnode |> InMemoryNode |> Query.All Query.Config.Default |> Seq.map (fun x -> x.GetSamples<V4f>(Defs.HeightsBilinear4f)) |> Array.ofSeq |> Array.collect id
201
210
//for x in xs do printfn "%A" x
202
211
qnode |> InMemoryNode
203
212
204
213
else
205
214
206
- if config.Verbose then
207
- printfn " [DEBUG][build''] SPLIT %d patches into quadrants of %A ... " n rootCell
208
-
209
- //let bbQuadrants = rootCell.Children |> Array.map (fun subCell -> subCell.GetBoundsForExponent(sampleExponent))
215
+ // current tile size is still above split limit:
216
+ // we sort all patches into the current cell's quadrants, and
217
+ // if a patch overlaps multiple quadrants, then we split the patch (according to the quadrants)
210
218
219
+ if config.Verbose then
220
+ printfn " [build''] SPLIT %d patches into quadrants of %A ..." n rootCell
221
+
211
222
let patchesPerQuadrant =
212
223
rootCell.Children
213
224
|> Array.map ( fun subCell ->
214
225
let subPatches =
215
- patches // TODO: ensure that bbQuadrant is in same resolution as patch ?!?
226
+ patches
216
227
|> Array.choose ( fun patch ->
217
228
let bbQuadrant = subCell.GetBoundsForExponent( patch.SampleExponent)
218
- //if patch.SampleExponent <> minSampleExponent then Debugger.Break()
219
- patch.WithWindow bbQuadrant
229
+ let r = patch.WithWindow bbQuadrant
230
+ if config.Verbose && r.IsSome then
231
+ printfn " [build''] | subCell=%A patch.Window=%A bbQuadrant=%A " subCell patch.SampleWindow r.Value.SampleWindow
232
+ r
220
233
)
221
-
222
234
( subCell, subPatches)
223
235
)
224
236
225
237
if config.Verbose then
226
- printfn " [DEBUG][ build''] SPLIT %d patches into quadrants of %A --> %A " n rootCell ( patchesPerQuadrant |> Array.map( fun ( _ , xs ) -> xs.Length))
238
+ printfn " [build''] SPLIT %d patches into quadrants of %A --> %A " n rootCell ( patchesPerQuadrant |> Array.map( fun ( _ , xs ) -> xs.Length))
227
239
228
240
//for i in 0..3 do
229
241
// let (subCell, subPatches) = patchesPerQuadrant[i]
@@ -237,7 +249,7 @@ module Builder =
237
249
238
250
let hasMask = subNodes |> Array.exists ( fun n -> n.HasMask)
239
251
if config.Verbose && hasMask then
240
- printfn " [DEBUG][ build''] has mask %A " rootCell
252
+ printfn " [build''] has mask %A " rootCell
241
253
let result = { Id = Guid.NewGuid(); ExactBoundingBox = ebb; Cell = rootCell; SplitLimitExponent = config.SplitLimitPowerOfTwo; HasMask = hasMask; SubNodes = subNodes }
242
254
result |> InMemoryInner
243
255
0 commit comments