From 747946e0401114d0a63ced3c9ef6eded56590b53 Mon Sep 17 00:00:00 2001 From: Attila Szabo Date: Mon, 4 Dec 2023 09:52:27 +0100 Subject: [PATCH] scratch --- src/Apps/ScratchFSharp/Program.fs | 85 +++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 26 deletions(-) diff --git a/src/Apps/ScratchFSharp/Program.fs b/src/Apps/ScratchFSharp/Program.fs index 69ed1124..b8fcfe51 100644 --- a/src/Apps/ScratchFSharp/Program.fs +++ b/src/Apps/ScratchFSharp/Program.fs @@ -23,41 +23,74 @@ module Bla = - let storePath = @"C:\bla\store\teststore\data.uds" + let storePath = @"C:\bla\stores\test\data.uds" let key = "3d9654b1-c37a-4d41-ba83-393d58a9bdce" - let bounds = Box3d(V3d.III*2.0, V3d.III*20.0) let rnd = RandomSystem() - let rec genPoints loc = - let mutable phi = 0.0 - let mutable theta = 0.0 - let dPhi = 1.0 * Constant.RadiansPerDegree - let dTheta = 1.1 * Constant.RadiansPerDegree - let ps = System.Collections.Generic.List() - while phi < Constant.PiTimesTwo do - theta <- 0.0 - while theta < Constant.PiTimesTwo do - let d = V2d(phi,theta).CartesianFromSpherical() - let r = Ray3d(loc+999.0*d,-d) - let mutable t = 0.0 - if bounds.Intersects(r,&t) then - let p = r.GetPointOnRay(t) - ps.Add p |> ignore - theta <- theta+dTheta - phi <- phi+dPhi - ps |> CSharpList.toArray + let mkChunk (locationCount : int) (partIndexOffset : int) (bounds : Box3d) = + let rec genPoints loc = + let mutable phi = 0.0 + let mutable theta = 0.0 + let dPhi = 1.0 * Constant.RadiansPerDegree + let dTheta = 1.1 * Constant.RadiansPerDegree + let ps = System.Collections.Generic.List() + while phi < Constant.PiTimesTwo do + theta <- 0.0 + while theta < Constant.PiTimesTwo do + let d = V2d(phi,theta).CartesianFromSpherical() + let r = Ray3d(loc+999.0*d,-d) + let mutable t = 0.0 + if bounds.Intersects(r,&t) then + let p = r.GetPointOnRay(t) + ps.Add p |> ignore + theta <- theta+dTheta + phi <- phi+dPhi + ps |> CSharpList.toArray + + let locations = Array.init locationCount (fun _ -> rnd.UniformV3d(Box3d.FromCenterAndSize(bounds.Center,bounds.Size*0.8))) + + let pointsAndPartindices = + locations |> Array.mapi (fun i loc -> + let pts = genPoints loc + let pis = Array.replicate pts.Length (i+partIndexOffset) + pts,pis + ) + + let points = pointsAndPartindices |> Array.collect (fun (d,_) -> d) + let partIndices = pointsAndPartindices |> Array.collect (fun (_,d) -> d) + Chunk(points,null,null,null,null,partIndices,Range1i(partIndices),bounds) - let locations = Array.init 5 (fun _ -> rnd.UniformV3d(Box3d.FromCenterAndSize(bounds.Center,bounds.Size*0.8))) let chunks = - locations |> Array.mapi (fun i loc -> - let pts = genPoints loc - Chunk(pts,null,null,null,null,i,Range1i(i),bounds) - ) + let bounds = + [| + for x in 0..3 do + for y in 0..3 do + let dx = float x * 21.0 + let dy = float y * 21.0 + yield Box3d.FromCenterAndSize(V3d(11.0,11.0,11.0), V3d(20.0,20.0,20.0)).Transformed(Trafo3d.Translation(dx,dy,0.0)) + |] + Log.startTimed $"gen {bounds.Length} chunks" + let mutable i = 0 + let mutable pio = 0 + let res = + bounds + |> Array.collect (fun bound -> + Report.Progress(float i / float bounds.Length) + let locationCount = 5+rnd.UniformInt(5) + let chunks = mkChunk locationCount pio bound + pio <- pio+locationCount + i <- i+1 + [|chunks|] + ) + Report.Progress 1.0 + Log.stop() + res let store = new Uncodium.SimpleStore.SimpleDiskStore(storePath,System.Action<_>(fun ss -> ss |> Array.iter (printfn "%A"))) + Log.line $"add to store at {storePath}" let add = Action>(fun (name : string) (value : obj) (create : Func) -> store.Add(name, create.Invoke())) @@ -87,4 +120,4 @@ module Bla = let pc = PointCloud.Chunks(chunks,config) File.WriteAllText(Path.Combine(Path.GetDirectoryName(storePath),"key.txt"),key) Log.line "done %A %A" pc.PointCount pc.Id - 0 \ No newline at end of file + 0