Skip to content

Commit

Permalink
Merge pull request #396 from pro3d-space/refactor/kdTreeCleanup
Browse files Browse the repository at this point in the history
KdTree cleanup
  • Loading branch information
haraldsteinlechner authored Jun 12, 2024
2 parents 78074a0 + 9c1c45b commit 9c4057e
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 66 deletions.
28 changes: 27 additions & 1 deletion docs/KdTrees.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,30 @@ KdTrees can be constructed:
- directly from within PRo3D. This is now available via the UI
![alt text](./images/createKdTree.png)
- the [library](https://www.nuget.org/packages/OPCViewer.Base) and in [particular](https://github.com/aardvark-platform/OpcViewer/blob/7fdf368e1e59a2c33c0cc7e5ca3e20b8c18a42a0/src/OPCViewer.Base/KdTrees.fs#L307).
- the OPC command-line tool. see [here](./OpcTool.md).
- the OPC command-line tool. see [here](./OpcTool.md).

## Behavior as of June 2024 (version 4.24.0)


## Loading behavior

| OPC | KdTree Kind | Loads as-is | Recommendation | Remark for PRo3D developers |
| --- | ----------- | ----------- | -------------- | ----- |
| OPC_JezeroTest1m_nokdtree | No kd Tree | Yes, no picking, prints `WARNING: [KdTrees] Kdtree not available, please build it manually using opc-tool or pro3d.` | Create KdTree using PRo3D or opc-tool ![alt text](images/createKdTree2.png) and reload the hierarchy. | - |
| OPC_JezeroTest1m_v2021 | OPC created using per patch kd trees | Yes, picking available fast loading, low memory | None | - |
| OPC_JezeroTest1m | OPC created without per patch kdTrees, but with master kd tree file (mostly late 2023) | Yes loads, but takes lot of memory since kdtree for whole opc is loaded. Also PRo3D reports this line in stdout `WARNING: Found master kdtree - loading incore. THIS NEEDS A LOT OF MEMORY. CONSIDER CREATING PER-PATCH KD TREES..` | Delete `*.aakd` and create new kd trees using PRo3D or opc-tool. Note that PRo3D never deletes the master kdtree file as whis would be cumbersome. Users confronted with this situation currently really need to delete unwanted huge kd tree files. | This beharior could be changed to [ignore the master kd tree](https://github.com/aardvark-platform/OpcViewer/blob/7fdf368e1e59a2c33c0cc7e5ca3e20b8c18a42a0/src/OPCViewer.Base/KdTrees.fs#L212) |


## File system behavior

Since OPCs with inconsistent `Patches` vs `patches` and `images` vs `Images` are in the wild, we introduced a mechanism to deal with those transparent to the user. This was a bad decision since it is overly complex.
Relevant parts are:
- [Probing paths](https://github.com/aardvark-platform/aardvark.rendering/blob/3a3044847739d07bf57eadae02923868357c3b4f/src/Aardvark.SceneGraph.Opc/OpcPaths.fs#L53)
- And several repair paths, [here](https://github.com/aardvark-platform/OpcViewer/blob/e401124e7636133a2e2ac26b5316d1662a0a1d0c/src/OPCViewer.Base/KdTrees.fs#L51), [here](https://github.com/aardvark-platform/OpcViewer/blob/e401124e7636133a2e2ac26b5316d1662a0a1d0c/src/OPCViewer.Base/KdTrees.fs#L66), and [here](https://github.com/aardvark-platform/OpcViewer/blob/e401124e7636133a2e2ac26b5316d1662a0a1d0c/src/OPCViewer.Base/KdTrees.fs#L80)

There are some dead-ends, of this approach, which happens concerned with .cache files. While wrong paths in .cache files can be fixed using [this](https://github.com/aardvark-platform/OpcViewer/blob/e401124e7636133a2e2ac26b5316d1662a0a1d0c/src/OPCViewer.Base/KdTrees.fs#L108), this might fail (especially when also path separators change and capitalization is completely messed up on case-sensitive systems with case insensitive external disks). Then the caches get rebuilt. Currently PRo3D tries to write the caches, even if the file system is readonly (like sometimes when mounting NTFS on mac). See relevant code [here](https://github.com/aardvark-platform/OpcViewer/blob/e401124e7636133a2e2ac26b5316d1662a0a1d0c/src/OPCViewer.Base/KdTrees.fs#L337).


## Partially currupt/deleted kd trees

Generally by using the `validateKdTrees` flag all sub-kdtrees would be verified and rebuilt if needed. For WSYWYG however this validation/repair does not take place automatically. Another reason for not repairing broken OPC directories is that it disables a fast path when cache files are broken. Generally we could change this. Relevant parts are [here](https://github.com/aardvark-platform/OpcViewer/blob/fb94d0c74f9759a3ab07a71dcccac82f8186e776/src/OPCViewer.Base/KdTrees.fs#L297).
Binary file added docs/images/createKdTree2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ nuget Aardvark.Base.FSharp ~> 5.2.13
nuget Aardvark.Geometry ~> 5.2.13
nuget Aardvark.PixImage.DevIL ~> 5.2.13

nuget SixLabors.ImageSharp ~> 2.1.7

nuget Aardvark.Rendering ~> 5.4.0
nuget Aardvark.Application.Slim ~> 5.4.0
Expand Down Expand Up @@ -50,7 +51,7 @@ nuget Aardvark.GeoSpatial.Opc ~> 5.10.8

nuget Aardium ~> 2.0.10-prerelease0007

nuget OPCViewer.Base ~> 1.6.1
nuget OPCViewer.Base ~> 1.7.2

nuget Uncodium.Eigensystems ~> 1.1.2
nuget Chiron ~> 6.3.1
Expand Down
122 changes: 61 additions & 61 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,45 @@ NUGET
Aardium (2.0.10-prerelease0007)
FSharp.Core (>= 4.7)
FSys (>= 0.0.1 < 0.1)
Aardvark.Application (5.4.9)
Aardvark.Application (5.4.10)
Aardvark.Base.Essentials (>= 5.2.27 < 5.3)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.Rendering (5.4.10)
FShade.Core (>= 5.5.3 < 5.6)
FShade.GLSL (>= 5.5.3)
FSharp.Core (>= 5.0.1)
Aardvark.Application.Slim (5.4.9)
Aardvark.Application (5.4.9)
Aardvark.Application.Slim (5.4.10)
Aardvark.Application (5.4.10)
Aardvark.Base.Essentials (>= 5.2.27 < 5.3)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Base.Runtime (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.Rendering (5.4.10)
FShade (>= 5.5.3 < 5.6)
FSharp.Core (>= 5.0.1)
Silk.NET.GLFW (2.15)
Unofficial.OpenTK (>= 3.0.21 < 3.1)
Aardvark.Application.Slim.GL (5.4.9)
Aardvark.Application (5.4.9)
Aardvark.Application.Slim (5.4.9)
Aardvark.Application.Slim.GL (5.4.10)
Aardvark.Application (5.4.10)
Aardvark.Application.Slim (5.4.10)
Aardvark.Base.Essentials (>= 5.2.27 < 5.3)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Base.Runtime (>= 5.2.27 < 5.3)
Aardvark.Base.Tensors (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.Rendering.GL (5.4.9)
Aardvark.Rendering (5.4.10)
Aardvark.Rendering.GL (5.4.10)
FShade (>= 5.5.3 < 5.6)
FSharp.Core (>= 5.0.1)
Silk.NET.Core (2.15)
Silk.NET.GLFW (2.15)
Unofficial.OpenTK (>= 3.0.21 < 3.1)
Aardvark.Application.Slim.Vulkan (5.4.9)
Aardvark.Application (5.4.9)
Aardvark.Application.Slim (5.4.9)
Aardvark.Application.Slim.Vulkan (5.4.10)
Aardvark.Application (5.4.10)
Aardvark.Application.Slim (5.4.10)
Aardvark.Base.Essentials (>= 5.2.27 < 5.3)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Base.Runtime (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.Rendering.Vulkan (5.4.9)
Aardvark.Rendering (5.4.10)
Aardvark.Rendering.Vulkan (5.4.10)
FShade (>= 5.5.3 < 5.6)
FSharp.Core (>= 5.0.1)
GLSLangSharp (>= 0.4.14 < 0.5)
Expand All @@ -54,54 +54,54 @@ NUGET
Aardvark.Base.Runtime (>= 5.2.7 < 5.3)
FSharp.Core (>= 5.0)
FSharp.Data.Adaptive (>= 1.2.13 < 1.3)
Aardvark.Base (5.2.29)
Aardvark.Base.Telemetry (5.2.29)
Aardvark.Base (5.2.31)
Aardvark.Base.Telemetry (5.2.31)
System.Collections.Immutable (>= 5.0)
System.Reflection.Metadata (>= 5.0) - restriction: || (&& (== net6.0) (< netcoreapp3.1)) (== netstandard2.0)
System.Text.Json (>= 4.7.2)
Aardvark.Base.Essentials (5.2.29)
Aardvark.Base (5.2.29)
Aardvark.Base.Essentials (5.2.31)
Aardvark.Base (5.2.31)
System.Collections.Immutable (>= 5.0)
Aardvark.Base.FSharp (5.2.29)
Aardvark.Base (5.2.29)
Aardvark.Base.FSharp (5.2.31)
Aardvark.Base (5.2.31)
Aardvark.Base.TypeProviders (>= 4.5.15 < 4.6)
FSharp.Core (>= 5.0)
FSharp.Data.Adaptive (>= 1.2 < 1.3)
FsPickler (>= 5.3.2 < 5.4)
System.Dynamic.Runtime (>= 4.3 < 4.4)
Aardvark.Base.Incremental (5.2.29)
Aardvark.Base (5.2.29)
Aardvark.Base.FSharp (5.2.29)
Aardvark.Base.Incremental (5.2.31)
Aardvark.Base (5.2.31)
Aardvark.Base.FSharp (5.2.31)
Aardvark.Base.TypeProviders (>= 4.5.15 < 4.6)
FSharp.Core (>= 5.0)
FSharp.Data.Adaptive (>= 1.2 < 1.3)
FsPickler (>= 5.3.2 < 5.4)
Aardvark.Base.IO (5.2.29)
Aardvark.Base (5.2.29)
Aardvark.Base.Tensors (5.2.29)
Aardvark.Base.IO (5.2.31)
Aardvark.Base (5.2.31)
Aardvark.Base.Tensors (5.2.31)
System.Dynamic.Runtime (>= 4.3 < 4.4)
Aardvark.Base.Runtime (5.2.29)
Aardvark.Base.FSharp (5.2.29)
Aardvark.Base.Incremental (5.2.29)
Aardvark.Base.Runtime (5.2.31)
Aardvark.Base.FSharp (5.2.31)
Aardvark.Base.Incremental (5.2.31)
Aardvark.Base.TypeProviders (>= 4.5.15 < 4.6)
FSharp.Core (>= 5.0)
FSharp.Data.Adaptive (>= 1.2 < 1.3)
FsPickler (>= 5.3.2 < 5.4)
Aardvark.Base.Telemetry (5.2.29)
Aardvark.Base.Tensors (5.2.29)
Aardvark.Base (5.2.29)
Aardvark.Base.FSharp (5.2.29)
Aardvark.Base.Telemetry (5.2.31)
Aardvark.Base.Tensors (5.2.31)
Aardvark.Base (5.2.31)
Aardvark.Base.FSharp (5.2.31)
FSharp.Core (>= 5.0)
SixLabors.ImageSharp (>= 2.1.3 < 2.2)
Aardvark.Base.TypeProviders (4.5.15)
FSharp.Core (>= 4.2.3)
Aardvark.Build (1.0.18)
Aardvark.Data.Wavefront (5.2.28)
Aardvark.Geometry.PolyMesh (5.2.28)
Aardvark.Geometry (5.2.29)
Aardvark.Base (5.2.29)
Aardvark.Base.FSharp (5.2.29)
Aardvark.Base.Tensors (5.2.29)
Aardvark.Geometry (5.2.31)
Aardvark.Base (5.2.31)
Aardvark.Base.FSharp (5.2.31)
Aardvark.Base.Tensors (5.2.31)
Aardvark.Base.TypeProviders (>= 4.5.15 < 4.6)
FSharp.Core (>= 5.0)
FSharp.Data.Adaptive (>= 1.2 < 1.3)
Expand Down Expand Up @@ -133,78 +133,78 @@ NUGET
Aardvark.SceneGraph.Opc (>= 5.4 < 5.5)
FSharp.Core (>= 5.0)
FSharp.Data.Adaptive (>= 1.2.13 < 1.3)
Aardvark.GPGPU (5.4.9)
Aardvark.GPGPU (5.4.10)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.Rendering (5.4.10)
FShade.Core (>= 5.5.3 < 5.6)
FShade.GLSL (>= 5.5.3)
FSharp.Core (>= 5.0.1)
Aardvark.PixImage.DevIL (5.2.29)
Aardvark.Base (5.2.29)
Aardvark.Base.Tensors (5.2.29)
Aardvark.PixImage.DevIL (5.2.31)
Aardvark.Base (5.2.31)
Aardvark.Base.Tensors (5.2.31)
DevILSharp
Aardvark.PixImage.Pfim (0.9.1)
Aardvark.Base.Tensors (>= 5.2.19 < 5.3)
FSharp.Core (>= 5.0.1)
Pfim (>= 0.11.2 < 0.12)
Aardvark.Rendering (5.4.9)
Aardvark.Rendering (5.4.10)
Aardvark.Base.Essentials (>= 5.2.27 < 5.3)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Base.Tensors (>= 5.2.27 < 5.3)
FShade.Core (>= 5.5.3 < 5.6)
FShade.GLSL (>= 5.5.3)
FSharp.Core (>= 5.0.1)
FSharp.Data.Adaptive (>= 1.2.13 < 1.3)
Aardvark.Rendering.GL (5.4.9)
Aardvark.Rendering.GL (5.4.10)
Aardvark.Assembler (>= 0.0.8 < 0.1)
Aardvark.Base.Essentials (>= 5.2.27 < 5.3)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Base.Runtime (>= 5.2.27 < 5.3)
Aardvark.Base.Tensors (>= 5.2.27 < 5.3)
Aardvark.Geometry (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.Rendering (5.4.10)
FShade (>= 5.5.3 < 5.6)
FSharp.Core (>= 5.0.1)
Unofficial.OpenTK (>= 3.0.21 < 3.1)
Aardvark.Rendering.Text (5.4.9)
Aardvark.Rendering.Text (5.4.10)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.SceneGraph (5.4.9)
Aardvark.Rendering (5.4.10)
Aardvark.SceneGraph (5.4.10)
CommonMark.NET (>= 0.15.1 < 0.16)
FShade.Core (>= 5.5.3 < 5.6)
FShade.GLSL (>= 5.5.3)
FSharp.Core (>= 5.0.1)
Unofficial.LibTessDotNet (>= 2.0.2 < 2.1)
Unofficial.Typography (>= 0.1 < 0.2)
Aardvark.Rendering.Vulkan (5.4.9)
Aardvark.Rendering.Vulkan (5.4.10)
Aardvark.Base.FSharp (>= 5.2.27 < 5.3)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Base.Runtime (>= 5.2.27 < 5.3)
Aardvark.Base.Tensors (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.Rendering (5.4.10)
FShade (>= 5.5.3 < 5.6)
FSharp.Core (>= 5.0.1)
GLSLangSharp (>= 0.4.14 < 0.5)
Aardvark.SceneGraph (5.4.9)
Aardvark.SceneGraph (5.4.10)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.Rendering (5.4.10)
FShade.Core (>= 5.5.3 < 5.6)
FShade.GLSL (>= 5.5.3)
FSharp.Core (>= 5.0.1)
Aardvark.SceneGraph.IO (5.4.9)
Aardvark.SceneGraph.IO (5.4.10)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Base.Tensors (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.SceneGraph (5.4.9)
Aardvark.Rendering (5.4.10)
Aardvark.SceneGraph (5.4.10)
AssimpNet (>= 5.0.0-beta1 < 5.1.0-beta)
FShade.Core (>= 5.5.3 < 5.6)
FShade.GLSL (>= 5.5.3)
FSharp.Core (>= 5.0.1)
Aardvark.SceneGraph.Opc (5.4.9)
Aardvark.SceneGraph.Opc (5.4.10)
Aardvark.Base.Incremental (>= 5.2.27 < 5.3)
Aardvark.Base.IO (>= 5.2.27 < 5.3)
Aardvark.Rendering (5.4.9)
Aardvark.SceneGraph (5.4.9)
Aardvark.Rendering (5.4.10)
Aardvark.SceneGraph (5.4.10)
FSharp.Core (>= 5.0.1)
SharpZipLib (>= 1.4.1 < 1.5)
Aardvark.Service (5.4.4)
Expand Down Expand Up @@ -418,7 +418,7 @@ NUGET
NETStandard.Library (2.0.3)
Microsoft.NETCore.Platforms (>= 1.1)
Newtonsoft.Json (13.0.2)
OPCViewer.Base (1.6.1)
OPCViewer.Base (1.7.2)
Aardvark.Base (>= 5.2.14 < 5.3)
Aardvark.Base.FSharp (>= 5.2.14 < 5.3)
Aardvark.Geometry.Intersection (>= 5.2.13 < 5.3)
Expand Down Expand Up @@ -453,7 +453,7 @@ NUGET
Silk.NET.GLFW (2.15)
Silk.NET.Core (>= 2.15)
Ultz.Native.GLFW (>= 3.3.3.1)
SixLabors.ImageSharp (2.1.3)
SixLabors.ImageSharp (2.1.8)
System.Buffers (>= 4.5.1) - restriction: || (&& (== net6.0) (>= net472)) (&& (== net6.0) (< netcoreapp2.1)) (== netstandard2.0)
System.Memory (>= 4.5.4) - restriction: || (&& (== net6.0) (>= net472)) (&& (== net6.0) (< netcoreapp2.1)) (== netstandard2.0)
System.Numerics.Vectors (>= 4.5) - restriction: || (&& (== net6.0) (>= net472)) (&& (== net6.0) (< netcoreapp2.1)) (== netstandard2.0)
Expand Down
2 changes: 1 addition & 1 deletion src/PRo3D.Core/Surface/Surface.Sg.fs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ module Sg =
for h in patchHierarchies do
if createKdTrees then
Log.startTimed "[KdTrees] Loading kdtrees: %s" h.opcPaths.Patches_DirAbsPath
let m = Aardvark.VRVis.Opc.KdTrees.loadKdTrees h Trafo3d.Identity ViewerModality.XYZ Serialization.binarySerializer false true DebugKdTreesX.loadTriangles' true
let m = Aardvark.VRVis.Opc.KdTrees.loadKdTrees h Trafo3d.Identity ViewerModality.XYZ Serialization.binarySerializer false false DebugKdTreesX.loadTriangles' true
Log.stop()
if HashMap.isEmpty m then
Log.warn "[KdTrees], KdTree map for %s is empty." h.opcPaths.Patches_DirAbsPath
Expand Down
2 changes: 1 addition & 1 deletion src/PRo3D.Core/Surface/SurfaceApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ module SurfaceApp =
Log.startTimed "[RebuildKdTrees] creating kdtrees"
let cnt =
hs |> Array.sumBy (fun h ->
let m = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ Serialization.binarySerializer true true PRo3D.Core.Surface.DebugKdTreesX.loadTriangles' false Aardvark.VRVis.Opc.KdTrees.KdTreeParameters.legacyDefault
let m = KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ Serialization.binarySerializer true true PRo3D.Core.Surface.DebugKdTreesX.loadTriangles' false false Aardvark.VRVis.Opc.KdTrees.KdTreeParameters.legacyDefault
HashMap.count m
)
Log.stop()
Expand Down
2 changes: 1 addition & 1 deletion src/opc-tool/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ let generateKdTrees (degreeOfParallelism : Option<int>) (forceKdTreeRebuild : bo


let kdTrees =
KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ serializer forceKdTreeRebuild ignoreMasterKdTree PRo3D.Core.Surface.DebugKdTreesX.loadTriangles' false Aardvark.VRVis.Opc.KdTrees.KdTreeParameters.legacyDefault
KdTrees.loadKdTrees' h Trafo3d.Identity true ViewerModality.XYZ serializer forceKdTreeRebuild ignoreMasterKdTree PRo3D.Core.Surface.DebugKdTreesX.loadTriangles' false false Aardvark.VRVis.Opc.KdTrees.KdTreeParameters.legacyDefault

for (bb,kdTree) in kdTrees do
match kdTree with
Expand Down

0 comments on commit 9c4057e

Please sign in to comment.