@@ -4,6 +4,7 @@ open Aardvark.Base
4
4
open System
5
5
open System.Collections .Generic
6
6
open Serialization
7
+ open System.Diagnostics
7
8
8
9
#nowarn " 1337"
9
10
@@ -116,15 +117,12 @@ module Builder =
116
117
let result = { Id = Guid.NewGuid(); ExactBoundingBox = ebb; Cell = rootCell; SplitLimitExponent = BuildConfig.Default.SplitLimitPowerOfTwo; HasMask = hasMask; SubNodes = subNodes }
117
118
result |> InMemoryInner
118
119
119
- let rec private build '' ( minSampleExponent : int ) ( rootCell : Cell2d ) ( patches : LayerSet []) =
120
+ let rec private build '' ( rootCell : Cell2d ) ( patches : LayerSet []) =
120
121
121
122
if debugOutput then
122
123
printfn " [DEBUG] build' rootCell = %A , %d patches" rootCell patches.Length
123
124
124
- for p in patches do
125
- invariantm ( p.SampleExponent >= minSampleExponent)
126
- ( fun () -> sprintf " Patch sample exponent %d is smaller than specified minimum sample exponent %d ." p.SampleExponent minSampleExponent)
127
- " 28d1fdd1-2da6-4329-a065-c134c1351ffc"
125
+ let minSampleExponent = patches |> Seq.map ( fun p -> p.SampleExponent) |> Seq.min
128
126
129
127
match patches.Length with
130
128
@@ -192,7 +190,13 @@ module Builder =
192
190
rootCell.Children
193
191
|> Array.map ( fun subCell ->
194
192
let bbQuadrant = subCell.GetBoundsForExponent( minSampleExponent)
195
- let subPatches = patches |> Array.choose ( fun b -> b.WithWindow bbQuadrant)
193
+ let subPatches =
194
+ patches // TODO: ensure that bbQuadrant is in same resolution as patch ?!?
195
+ |> Array.choose ( fun patch ->
196
+ if patch.SampleExponent <> minSampleExponent then Debugger.Break()
197
+ patch.WithWindow bbQuadrant
198
+ )
199
+
196
200
( subCell, subPatches)
197
201
)
198
202
@@ -207,7 +211,7 @@ module Builder =
207
211
let subNodes = patchesPerQuadrant |> Array.map ( fun ( subCell , subPatches ) ->
208
212
match subPatches.Length with
209
213
| 0 -> NoNode
210
- | _ -> build'' minSampleExponent subCell subPatches
214
+ | _ -> build'' subCell subPatches
211
215
)
212
216
213
217
let hasMask = subNodes |> Array.exists ( fun n -> n.HasMask)
@@ -219,9 +223,12 @@ module Builder =
219
223
/// Creates a quadtree from many small patches.
220
224
let Build ( patches : LayerSet seq ) : QNodeRef =
221
225
let patches = patches |> Array.ofSeq
222
- let rootCell = patches |> Array.map ( fun patch -> patch.BoundingBox) |> Box2d |> Cell2d
223
- let sampleExponent = ( patches |> Array.distinctBy ( fun x -> x.SampleExponent) |> Array.exactlyOne) .SampleExponent
224
- build' sampleExponent rootCell patches
226
+ let rootCell = patches |> Seq.map ( fun patch -> patch.BoundingBox) |> Box2d |> Cell2d
227
+
228
+ //let sampleExponent = (patches |> Array.distinctBy (fun x -> x.SampleExponent) |> Array.exactlyOne).SampleExponent
229
+ //build' sampleExponent rootCell patches
230
+
231
+ build'' rootCell patches
225
232
226
233
/// Creates a quadtree from many small patches.
227
234
type Builder () =
@@ -306,6 +313,15 @@ type Builder () =
306
313
Quadtree.Merge Dominance.SecondDominates state item |> Some
307
314
)
308
315
None // initial state
316
+
317
+ /// Build a quadtree from all the patches that have been added to this builder.
318
+ member this.Build2 () : QNodeRef option =
319
+
320
+ let mutable mergesCount = 0
321
+
322
+ let allPatches = this.GetPatches()
323
+ Builder.Build allPatches |> Some
324
+
309
325
310
326
/// Enumerate all patches.
311
327
member this.GetPatches () : seq < LayerSet > =
0 commit comments