Skip to content

Commit 84b36e9

Browse files
sync
1 parent bae6779 commit 84b36e9

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

src/Aardvark.Geometry.Quadtree/Builder.fs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ open Aardvark.Base
44
open System
55
open System.Collections.Generic
66
open Serialization
7+
open System.Diagnostics
78

89
#nowarn "1337"
910

@@ -116,15 +117,12 @@ module Builder =
116117
let result = { Id = Guid.NewGuid(); ExactBoundingBox = ebb; Cell = rootCell; SplitLimitExponent = BuildConfig.Default.SplitLimitPowerOfTwo; HasMask = hasMask; SubNodes = subNodes }
117118
result |> InMemoryInner
118119

119-
let rec private build'' (minSampleExponent : int) (rootCell : Cell2d) (patches : LayerSet[]) =
120+
let rec private build'' (rootCell : Cell2d) (patches : LayerSet[]) =
120121

121122
if debugOutput then
122123
printfn "[DEBUG] build' rootCell = %A, %d patches" rootCell patches.Length
123124

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
128126

129127
match patches.Length with
130128

@@ -192,7 +190,13 @@ module Builder =
192190
rootCell.Children
193191
|> Array.map (fun subCell ->
194192
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+
196200
(subCell, subPatches)
197201
)
198202

@@ -207,7 +211,7 @@ module Builder =
207211
let subNodes = patchesPerQuadrant |> Array.map (fun (subCell, subPatches) ->
208212
match subPatches.Length with
209213
| 0 -> NoNode
210-
| _ -> build'' minSampleExponent subCell subPatches
214+
| _ -> build'' subCell subPatches
211215
)
212216

213217
let hasMask = subNodes |> Array.exists (fun n -> n.HasMask)
@@ -219,9 +223,12 @@ module Builder =
219223
/// Creates a quadtree from many small patches.
220224
let Build (patches : LayerSet seq) : QNodeRef =
221225
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
225232

226233
/// Creates a quadtree from many small patches.
227234
type Builder () =
@@ -306,6 +313,15 @@ type Builder () =
306313
Quadtree.Merge Dominance.SecondDominates state item |> Some
307314
)
308315
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+
309325

310326
/// Enumerate all patches.
311327
member this.GetPatches () : seq<LayerSet> =

src/Aardvark.Geometry.Quadtree/DataMapping.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ type DataMapping(bufferOrigin : Cell2d, bufferSize : V2i, window : Box2l) =
136136
let max = Cell2d(window.Max, bufferOrigin.Exponent).BoundingBox.Min
137137
Box2d(min, max)
138138

139+
/// Returns this data mapping with new window (Some), or None if new window is not inside the current window.
139140
member this.WithWindow (newWindow : Box2l) =
140141
let o = window.Intersection(newWindow)
141142
if o.IsInvalid || o.Area = 0L then

src/Aardvark.Geometry.Quadtree/Layer.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ open System.Diagnostics
1212
type ILayer =
1313
abstract member Def : Durable.Def
1414
abstract member Mapping : DataMapping
15+
/// Returns this layer with new window w (Some), or None if new window is not inside the current layer window.
1516
abstract member WithWindow : Box2l -> ILayer option
1617
abstract member MapSingleCenteredSampleTo : Cell2d -> ILayer
1718
abstract member WithSemantic : Durable.Def -> ILayer
@@ -62,7 +63,8 @@ type Layer<'a when 'a : equality>(def : Durable.Def, data : 'a[], mapping : Data
6263

6364
member this.Mapping with get() = mapping
6465

65-
member this.WithWindow (w : Box2l) =
66+
/// Returns this layer with new window w (Some), or None if new window is not inside the current layer window.
67+
member this.WithWindow (w : Box2l) : ILayer option =
6668
mapping.WithWindow(w)
6769
|> Option.map (fun m -> Layer(def, data, m, mask) :> ILayer)
6870

src/Scratch/Program.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ let cp_20240202_quadtreetest () =
13281328
|> Seq.sumBy(fun patch -> patch.SampleWindow.Area)
13291329
printfn("total samples count with e = -3: %d") samplesCount
13301330

1331-
match x.Build () with
1331+
match x.Build2 () with
13321332
| None -> failwith ""
13331333
| Some qtree ->
13341334
let makeReturnValOfQueryResults (resultChunk : seq<Query.Result>) (def : Aardvark.Data.Durable.Def) =

0 commit comments

Comments
 (0)