Skip to content

Commit

Permalink
added option to prevent construction of new files while loading kdtrees.
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldsteinlechner committed Feb 20, 2024
1 parent c526918 commit 1b443ea
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 37 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.5.0
- added option to prevent new file construction for read only file systems & to control loading runtime


### 1.4.1
- LazyKdTree caches need to be list not array (accidently introduced serialization issue)

Expand Down
2 changes: 1 addition & 1 deletion src/2D3DLinking/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ module App =
for h in patchHierarchies do

let rootTree = h.tree |> QTree.getRoot
let kd = (KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ OpcSelectionViewer.Serialization.binarySerializer false) false (fun _ -> failwith "no function for creating triangle sets")
let kd = (KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ OpcSelectionViewer.Serialization.binarySerializer false) false (fun _ -> failwith "no function for creating triangle sets") false

yield {
patchHierarchy = h
Expand Down
2 changes: 1 addition & 1 deletion src/3DGis/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ module App =
for h in patchHierarchies do

let rootTree = h.tree |> QTree.getRoot
let kd = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ OpcSelectionViewer.Serialization.binarySerializer false false (fun _ _ -> failwith "no triangleset function")
let kd = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ OpcSelectionViewer.Serialization.binarySerializer false false (fun _ _ -> failwith "no triangleset function") false

yield {
patchHierarchy = h
Expand Down
76 changes: 44 additions & 32 deletions src/OPCViewer.Base/KdTrees.fs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ module KdTrees =
(forceRebuild : bool)
(ignoreMasterKdTree : bool)
(loadTriangles : Trafo3d -> string -> TriangleSet)
(surpressFileConstruction : bool)
: HashMap<Box3d, Level0KdTree> =

let masterKdPath =
Expand All @@ -147,7 +148,7 @@ module KdTrees =

if not ignoreMasterKdTree && (File.Exists masterKdPath && not (Array.isEmpty missingKd0Paths)) && not forceRebuild then

Log.line "Found master kdtree - loading incore"
Log.warn "Found master kdtree - loading incore. THIS NEEDS A LOT OF MEMORY. CONSIDER CREATING PER-PATCH KD TREES. see: "
let tree = loadKdtree masterKdPath

let kd =
Expand All @@ -164,7 +165,8 @@ module KdTrees =

let kdTrees =
kd0Paths
|> Array.mapi (fun i (info,kdPath) ->
|> Array.indexed
|> Array.map (fun (i, (info,kdPath)) ->

let dir = h.opcPaths.Patches_DirAbsPath +/ info.Name
let pos =
Expand Down Expand Up @@ -196,41 +198,51 @@ module KdTrees =
let t =
if File.Exists kdPath && not forceRebuild then
try
loadKdtree kdPath
loadKdtree kdPath |> Some
with e ->
Log.warn "[KdTrees] could not load kdtree: %A" e
createConcreteTree()
else
createConcreteTree()



let lazyTree: LazyKdTree =
{ kdTree = None
objectSetPath = objectSetPath
coordinatesPath = dir +/ (List.head info.Coordinates)
texturePath = Patch.extractTexturePath (OpcPaths h.opcPaths.Opc_DirAbsPath) info 0
kdtreePath = kdPath
affine =
mode
|> ViewerModality.matchy info.Local2Global info.Local2Global2d
boundingBox = t.KdIntersectionTree.BoundingBox3d
}

Report.Progress(float i / float num)

(lazyTree.boundingBox, (LazyKdTree lazyTree)))
if surpressFileConstruction then None
else createConcreteTree() |> Some
elif not surpressFileConstruction then
createConcreteTree() |> Some
else
None


match t with
| Some t ->
let lazyTree: LazyKdTree =
{ kdTree = None
objectSetPath = objectSetPath
coordinatesPath = dir +/ (List.head info.Coordinates)
texturePath = Patch.extractTexturePath (OpcPaths h.opcPaths.Opc_DirAbsPath) info 0
kdtreePath = kdPath
affine =
mode
|> ViewerModality.matchy info.Local2Global info.Local2Global2d
boundingBox = t.KdIntersectionTree.BoundingBox3d
}

Report.Progress(float i / float num)

(lazyTree.boundingBox, (LazyKdTree lazyTree)) |> Some
| _ ->
None
)



Log.stop ()

kdTrees |> Array.toList |> save cacheFile b |> ignore

if load then
kdTrees |> HashMap.ofArray
else
if kdTrees |> Array.exists Option.isNone then
HashMap.empty
else
let trees = kdTrees |> Array.map Option.get |> Array.toList // safe because check above
trees |> save cacheFile b |> ignore

if load then
trees |> HashMap.ofList
else
HashMap.empty


if File.Exists cacheFile then
Expand All @@ -256,6 +268,6 @@ module KdTrees =
let loadKdTrees
(h: PatchHierarchy) (trafo: Trafo3d) (mode: ViewerModality)
(b: BinarySerializer) (forceRebuild : bool) (ignoreMasterKdTree : bool)
(loadTriangles : Trafo3d -> string -> TriangleSet) : HashMap<Box3d, Level0KdTree> =
(loadTriangles : Trafo3d -> string -> TriangleSet) (surpressFileConstruction : bool) : HashMap<Box3d, Level0KdTree> =

loadKdTrees' h trafo true mode b forceRebuild ignoreMasterKdTree loadTriangles
loadKdTrees' h trafo true mode b forceRebuild ignoreMasterKdTree loadTriangles surpressFileConstruction
2 changes: 1 addition & 1 deletion src/ViewPlannerDSS/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ module App =
for h in patchHierarchies do

let rootTree = h.tree |> QTree.getRoot
let kd = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ OpcSelectionViewer.Serialization.binarySerializer false false (fun _ _ -> failwith "no triangleset function")
let kd = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ OpcSelectionViewer.Serialization.binarySerializer false false (fun _ _ -> failwith "no triangleset function") false


yield {
Expand Down
2 changes: 1 addition & 1 deletion src/ViewerMain/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ module App =
for h in patchHierarchies do

let rootTree = h.tree |> QTree.getRoot
let kd = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ Serialization.binarySerializer false false (fun _ _ -> failwith "no function for creating triangle sets")
let kd = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ Serialization.binarySerializer false false (fun _ _ -> failwith "no function for creating triangle sets") false

yield {
patchHierarchy = h
Expand Down
2 changes: 1 addition & 1 deletion src/ViewerMain/Outline/OutlineApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module OutlineApp =
for h in patchHierarchies do

let rootTree = h.tree |> QTree.getRoot
let kd = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ Serialization.binarySerializer false false (fun _ -> failwith "no function for creating triangle sets")
let kd = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ Serialization.binarySerializer false false (fun _ -> failwith "no function for creating triangle sets") false

yield {
patchHierarchy = h
Expand Down

0 comments on commit 1b443ea

Please sign in to comment.