Skip to content

Commit

Permalink
[LodTreeInstance] PartIndices vertex attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
aszabo314 committed Oct 25, 2023
1 parent f0ea1dc commit 343c0b2
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 33 deletions.
43 changes: 30 additions & 13 deletions src/Aardvark.Rendering.PointSet/LodTreeInstance.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module LodTreeInstance =
module Semantic =
let Intensities = Sym.ofString "Intensities"
let Classifications = Sym.ofString "Classifications"
let PartIndices = Sym.ofString "PartIndices"

module private AsciiFormatParser =
open System.Text.RegularExpressions
Expand Down Expand Up @@ -105,6 +106,7 @@ module LodTreeInstance =
root : Option<PointTreeNode>,
parent : Option<PointTreeNode>,
level : int,
partIndexOffset : int,
self : IPointCloudNode) as this =

let customAttributeId = fst getCustomIndexedAttributes
Expand Down Expand Up @@ -134,7 +136,8 @@ module LodTreeInstance =
(self : IPointCloudNode)
(globalTrafo : Similarity3d)
(localBounds : Box3d)
(level : int) =
(level : int)
(partIndexOffset : int) =
let cid =
let customIndexedAttributeId = customIndexedAttributes |> MapExt.values |> Seq.map (fun ci -> string ci.Id) |> String.concat "."
cacheId self customIndexedAttributeId globalTrafo level
Expand Down Expand Up @@ -194,12 +197,25 @@ module LodTreeInstance =
attributes.[Semantic.Classifications] <- arr
vertexSize <- vertexSize + 4L

if MapExt.containsKey "PartIndices" ips then
let arr =
match self.TryGetPartIndices() with
| (true, v) ->
v |> Array.map (fun i -> i + partIndexOffset)
| _ ->
Array.replicate original.Length -1

attributes.[Semantic.PartIndices] <- arr
vertexSize <- vertexSize + 4L

customIndexedAttributes |> MapExt.iter (fun sym { AttribSize = size; Attrib = arr } ->
if MapExt.containsKey (sym.ToString()) ips then
attributes.[sym] <- arr
vertexSize <- vertexSize + size
)



if MapExt.containsKey "AvgPointDistance" ips then
let dist =
match self.HasPointDistanceAverage with
Expand Down Expand Up @@ -394,14 +410,14 @@ module LodTreeInstance =
//member x.AcquireChild() =
// Interlocked.Increment(&livingChildren) |> ignore

static member Create(pointCloudId : System.Guid, world : obj, cache : LruDictionary<string, obj>, source : Symbol, getCustomIndexedAttributes : Guid * (IPointCloudNode -> int -> MapExt<Symbol,CustomIndexedAttribute>), globalTrafo : Similarity3d, root : Option<PointTreeNode>, parent : Option<PointTreeNode>, level : int, self : IPointCloudNode) =
static member Create(pointCloudId : System.Guid, world : obj, cache : LruDictionary<string, obj>, source : Symbol, getCustomIndexedAttributes : Guid * (IPointCloudNode -> int -> MapExt<Symbol,CustomIndexedAttribute>), globalTrafo : Similarity3d, root : Option<PointTreeNode>, parent : Option<PointTreeNode>, level : int, partIndexOffset : int, self : IPointCloudNode) =
if isNull self then
None
else
PointTreeNode(pointCloudId, world, cache, source, getCustomIndexedAttributes, globalTrafo, root, parent, level, self) |> Some
PointTreeNode(pointCloudId, world, cache, source, getCustomIndexedAttributes, globalTrafo, root, parent, level, partIndexOffset, self) |> Some

static member Create(pointCloudId : System.Guid, world : obj, cache : LruDictionary<string, obj>, source : Symbol, globalTrafo : Similarity3d, root : Option<PointTreeNode>, parent : Option<PointTreeNode>, level : int, self : IPointCloudNode) =
PointTreeNode.Create(pointCloudId, world, cache, source, (Guid.NewGuid(),(fun _ _ -> MapExt.empty)), globalTrafo, root, parent, level, self)
static member Create(pointCloudId : System.Guid, world : obj, cache : LruDictionary<string, obj>, source : Symbol, globalTrafo : Similarity3d, root : Option<PointTreeNode>, parent : Option<PointTreeNode>, level : int, partIndexOffset : int, self : IPointCloudNode) =
PointTreeNode.Create(pointCloudId, world, cache, source, (Guid.NewGuid(),(fun _ _ -> MapExt.empty)), globalTrafo, root, parent, level, partIndexOffset, self)

member x.ReleaseChildren() =
let old =
Expand Down Expand Up @@ -430,6 +446,7 @@ module LodTreeInstance =
None,
None,
0,
partIndexOffset,
r
) |> Some

Expand All @@ -442,7 +459,7 @@ module LodTreeInstance =
if isNull n then
None
else
PointTreeNode(System.Guid.NewGuid(), world, cache, source, (customAttributeId,getCustomIndexedAttributes), globalTrafo, root, parent, level, n) |> Some
PointTreeNode(System.Guid.NewGuid(), world, cache, source, (customAttributeId,getCustomIndexedAttributes), globalTrafo, root, parent, level, partIndexOffset, n) |> Some

member x.Acquire() =
()
Expand Down Expand Up @@ -515,7 +532,7 @@ module LodTreeInstance =
unbox<ILodTreeNode> n |> Some
| _ ->
//Log.warn "alloc %A" id
PointTreeNode(pointCloudId, world, cache, source, (customAttributeId,getCustomIndexedAttributes), globalTrafo, Some this.Root, Some this, level + 1, c) :> ILodTreeNode |> Some
PointTreeNode(pointCloudId, world, cache, source, (customAttributeId,getCustomIndexedAttributes), globalTrafo, Some this.Root, Some this, level + 1, partIndexOffset, c) :> ILodTreeNode |> Some
with
| :? ObjectDisposedException ->
None
Expand All @@ -533,7 +550,7 @@ module LodTreeInstance =
member x.Id = id

member x.GetData(ct, ips) =
load ct ips cache (getCustomIndexedAttributes self level) self globalTrafo localBounds level
load ct ips cache (getCustomIndexedAttributes self level) self globalTrafo localBounds level partIndexOffset

member x.ShouldSplit (splitfactor : float, quality : float, view : Trafo3d, proj : Trafo3d) =
if isOrtho proj then
Expand Down Expand Up @@ -880,7 +897,7 @@ module LodTreeInstance =

let trafo = Similarity3d(1.0, Euclidean3d(Rot3d.Identity, -bounds.Center))
let source = Symbol.Create sourceName
let root = PointTreeNode.Create(System.Guid.NewGuid(), null, store.Cache, source, trafo, None, None, 0, root)
let root = PointTreeNode.Create(System.Guid.NewGuid(), null, store.Cache, source, trafo, None, None, 0, 0, root)
match root with
| Some root ->
let uniforms = MapExt.ofList uniforms
Expand Down Expand Up @@ -917,9 +934,9 @@ module LodTreeInstance =



let ofPointSet (uniforms : list<string * IAdaptiveValue>) (set : PointSet) =
let ofPointSet (uniforms : list<string * IAdaptiveValue>) (partIndexOffset : int) (set : PointSet) =
let store = set.Storage
let root = PointTreeNode.Create(System.Guid.NewGuid(), null, store.Cache, Symbol.CreateNewGuid(), Similarity3d.Identity, None, None, 0, set.Root.Value)
let root = PointTreeNode.Create(System.Guid.NewGuid(), null, store.Cache, Symbol.CreateNewGuid(), Similarity3d.Identity, None, None, 0, partIndexOffset, set.Root.Value)
match root with
| Some root ->
let uniforms = MapExt.ofList uniforms
Expand All @@ -930,9 +947,9 @@ module LodTreeInstance =
| None ->
None

let ofPointCloudNode (uniforms : list<string * IAdaptiveValue>) (root : IPointCloudNode) =
let ofPointCloudNode (uniforms : list<string * IAdaptiveValue>) (partIndexOffset : int) (root : IPointCloudNode) =
let store = root.Storage
let root = PointTreeNode.Create(System.Guid.NewGuid(), null, store.Cache, Symbol.CreateNewGuid(), Similarity3d.Identity, None, None, 0, root)
let root = PointTreeNode.Create(System.Guid.NewGuid(), null, store.Cache, Symbol.CreateNewGuid(), Similarity3d.Identity, None, None, 0, partIndexOffset, root)
match root with
| Some root ->
let uniforms = MapExt.ofList uniforms
Expand Down
28 changes: 24 additions & 4 deletions src/Aardvark.Rendering.PointSet/LodTreeSceneGraph.fs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ module private DeferredPointSetShaders =
[<PointCoord>] c : V2d
[<Normal>] n : V3d
[<Semantic("TreeId")>] id : int
[<Semantic("PartIndices")>] partIndex : int
[<Semantic("MaxTreeDepth")>] treeDepth : int
[<Semantic("Normal32"); Interpolation(InterpolationMode.Flat)>] n32 : int
[<FragCoord>] fc : V4d
Expand All @@ -209,11 +210,30 @@ module private DeferredPointSetShaders =
[<Inline>]
let div (v : V4d) = v.XYZ / v.W

let colorOrWhite (v : Effects.Vertex) =

let mapColors =
[|
C4b(141uy, 211uy, 199uy, 255uy)
C4b(255uy, 255uy, 179uy, 255uy)
C4b(190uy, 186uy, 218uy, 255uy)
C4b(251uy, 128uy, 114uy, 255uy)
C4b(128uy, 177uy, 211uy, 255uy)
C4b(253uy, 180uy, 98uy, 255uy)
C4b(179uy, 222uy, 105uy, 255uy)
C4b(252uy, 205uy, 229uy, 255uy)
C4b(217uy, 217uy, 217uy, 255uy)
C4b(188uy, 128uy, 189uy, 255uy)
C4b(204uy, 235uy, 197uy, 255uy)

|] |> Array.map (fun c -> c.ToC4f().ToV4d())


let colorOrWhite (v : PointVertex) =
vertex {
let mutable color = v.c
if not uniform?ShowColors then color <- V4d.IIII
return { v with c = color }
let mutable color = v.col
if not uniform?ShowColors then
color <- mapColors.[(v.partIndex+11)%11]
return { v with col = color }
}

let lodPointSize (v : PointVertex) =
Expand Down
8 changes: 5 additions & 3 deletions src/Apps/Viewer/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ open Aardvark.Algodat.App.Viewer

[<EntryPoint>]
let main args =
//let pts = @"C:\Users\Spot\Desktop\Laserscan-MS60_Beiglboeck-2015.pts"
//import pts @"C:\Users\Spot\Desktop\teststore" "a" (Args.parse [||])
//let pts = @"C:\bla\TEST DATEI_resampled.laz"
//import pts @"C:\bla\TestdateiStore\data.uds" "a" (Args.parse [||])
//exit 0

//view @"C:\stores\innen_store" ["a2b7e0c1-e672-48d3-8958-9ff8678f2dc4"] (Args.parse [||])
//view @"C:\Users\sm\Downloads\C_31EN2.LAZ.store" [File.readAllText @"C:\Users\sm\Downloads\C_31EN2.LAZ.key"] (Args.parse [||])
//view @"C:\Users\sm\Downloads\C_30DN2.LAZ.store" [File.readAllText @"C:\Users\sm\Downloads\C_30DN2.LAZ.key"] (Args.parse [||])
//view @"C:\Users\sm\Downloads\test.store" ["128330b1-8761-4a07-b160-76bcd7e2f70a"; "ab2f6f76-7eae-47c9-82d1-ad28b816abb9"] (Args.parse [||])

let store = @"E:\e57tests\stores\inference_full.binary.ply\data.uds"
let store = @"C:\bla\store\lowergetikum\data.bin"
let key = Path.combine [System.IO.Path.GetDirectoryName store;"key.txt"] |> File.readAllText
view store [key] (Args.parse [||])

Expand Down
47 changes: 34 additions & 13 deletions src/Apps/Viewer/Rendering.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ module Rendering =
let picktrees : cmap<ILodTreeNode,SimplePickTree> = cmap()
let config =
{
pointSize = AVal.init 0.8
pointSize = AVal.init 0.225
overlayAlpha = AVal.init 0.0
maxSplits = AVal.init 8
renderBounds = AVal.init false
sort = AVal.init false
splitfactor = AVal.init 0.45
splitfactor = AVal.init 0.1
budget = AVal.init -(256L <<< 10)
lighting = AVal.init true
colors = AVal.init false
Expand All @@ -133,7 +133,7 @@ module Rendering =
ssaoSharpness = AVal.init 4.0
}



let pcs =
pcs |> ASet.map (fun t ->
Expand Down Expand Up @@ -322,10 +322,10 @@ module Rendering =
| Keys.D9 -> transact (fun () -> config.ssaoSigma.Value <- max 0.0 (config.ssaoSigma.Value - 0.1)); Log.line "sigma: %A" config.ssaoSigma.Value

| Keys.D8 -> transact (fun () -> config.ssaoSamples.Value <- min 8 (config.ssaoSamples.Value + 1)); Log.line "samples: %A" config.ssaoSamples.Value
| Keys.D7 -> transact (fun () -> config.ssaoSamples.Value <- max 1 (config.ssaoSamples.Value - 1)); Log.line "samples: %A" config.ssaoSamples.Value
//| Keys.D7 -> transact (fun () -> config.ssaoSamples.Value <- max 1 (config.ssaoSamples.Value - 1)); Log.line "samples: %A" config.ssaoSamples.Value

| Keys.D6 -> transact (fun () -> config.ssaoSampleDirections.Value <- min 8 (config.ssaoSampleDirections.Value + 1)); Log.line "dirs: %A" config.ssaoSampleDirections.Value
| Keys.D5 -> transact (fun () -> config.ssaoSampleDirections.Value <- max 1 (config.ssaoSampleDirections.Value - 1)); Log.line "dirs: %A" config.ssaoSampleDirections.Value
// | Keys.D6 -> transact (fun () -> config.ssaoSampleDirections.Value <- min 8 (config.ssaoSampleDirections.Value + 1)); Log.line "dirs: %A" config.ssaoSampleDirections.Value
//| Keys.D5 -> transact (fun () -> config.ssaoSampleDirections.Value <- max 1 (config.ssaoSampleDirections.Value - 1)); Log.line "dirs: %A" config.ssaoSampleDirections.Value

| Keys.D4 -> transact (fun () -> config.ssaoRadius.Value <- min 2.0 (config.ssaoRadius.Value + 0.01)); Log.line "radius: %A" config.ssaoRadius.Value
| Keys.D3 -> transact (fun () -> config.ssaoRadius.Value <- max 0.01 (config.ssaoRadius.Value - 0.01)); Log.line "radius: %A" config.ssaoRadius.Value
Expand Down Expand Up @@ -528,19 +528,40 @@ module Rendering =
V3d.III * 6.0, V3d.Zero
)
let speed = AVal.init 2.0

let initial = CameraView.ofTrafo <| Trafo3d.Parse "[[[-0.707106781186548, 0.707106781186548, 0, 0], [-0.408248290463863, -0.408248290463863, 0.816496580927726, 0], [0.577350269189626, 0.577350269189626, 0.577350269189626, -342.288592930008], [0, 0, 0, 1]], [[-0.707106781186548, -0.408248290463863, 0.577350269189626, 197.620411268678], [0.707106781186548, -0.408248290463863, 0.577350269189626, 197.620411268678], [0, 0.816496580927726, 0.577350269189626, 197.620411268678], [0, 0, 0, 1]]]"
let target = CameraView.ofTrafo <| Trafo3d.Parse "[[[-0.567502843343406, 0.823371436714408, 0, -0.0700798647066693], [-0.362138228540449, -0.249601170524128, 0.898084160367263, 0.212820843806073], [0.739456845412046, 0.509665314570097, 0.439823647496845, -1.68800745703926], [0, 0, 0, 1]], [[-0.567502843343406, -0.362138228540449, 0.739456845412046, 1.28550871010452], [0.823371436714408, -0.249601170524128, 0.509665314570097, 0.971140942202795], [0, 0.898084160367263, 0.439823647496845, 0.551294567938653], [0, 0, 0, 1]]]"



let custom = AVal.init None
let camera =
custom |> AVal.bind (fun (custom : Option<CameraView>) ->
printfn "%A" (locAndCenter |> AVal.force)
printfn "%A" (initial.Location)
match custom with
| None ->
locAndCenter |> AVal.bind (fun (loc, center) ->
CameraView.lookAt loc center V3d.OOI
|> DefaultCameraController.controlWithSpeed speed win.Mouse win.Keyboard win.Time
)
| Some cv ->
locAndCenter |> AVal.map (fun (_,center) ->
cv.WithLocation (cv.Location + center)
)
//AVal.constant cv
)
//let bb = Box3d.FromCenterAndSize(V3d.Zero, V3d.III * 300.0)

win.Keyboard.DownWithRepeats.Values.Add(function
| Keys.PageUp | Keys.Up -> transact(fun () -> speed.Value <- speed.Value * 1.5)
| Keys.PageDown | Keys.Down -> transact(fun () -> speed.Value <- speed.Value / 1.5)
| Keys.D5 -> transact(fun () -> custom.Value <- Some initial)
| Keys.D6 -> transact(fun () -> custom.Value <- Some target)
| Keys.D7 -> transact(fun () -> custom.Value <- None)
| _ -> ()
)

let camera =
locAndCenter |> AVal.bind (fun (loc, center) ->
CameraView.lookAt loc center V3d.OOI
|> DefaultCameraController.controlWithSpeed speed win.Mouse win.Keyboard win.Time
)
//let bb = Box3d.FromCenterAndSize(V3d.Zero, V3d.III * 300.0)

let frustum =
AVal.custom (fun t ->
let s = win.Sizes.GetValue t
Expand Down

0 comments on commit 343c0b2

Please sign in to comment.