pro3d tsid...moving from c# oop wpf to f# fp ?gui? functional paradigm of immutable data //mutable...
TRANSCRIPT
![Page 1: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/1.jpg)
Planetary Robotics 3DViewer
PRo3D
GPU Days | 20190711-12 | THOMAS ORTNER | [email protected] | thomasortner.github.io
TSIDTunnel Surface Inspection
and Documentation
![Page 2: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/2.jpg)
Reconstruction3D
Surfaces
https://www.dibit.at/dienstleistungen/tunnelbau/tunnelscanning/
Images /Laser Scans
TSID
PRo3D
![Page 3: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/3.jpg)
Visualization Prototype
Short Timeto Market
LowBudget
![Page 4: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/4.jpg)
![Page 5: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/5.jpg)
![Page 6: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/6.jpg)
HiRISE (orbiter)
MOLA (orbiter)
HiRISE superres
Pancam(rover)
Pancamwidestereo
…
HandheldImages
Pointclouds
Triangles (OPC)
![Page 7: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/7.jpg)
![Page 8: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/8.jpg)
![Page 9: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/9.jpg)
Presentation
Interaction
![Page 10: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/10.jpg)
TSIDPRo3D+8 years in development
Ro
bert C
. Martin
–C
lean C
od
e
maintenanceDEADLOCK
![Page 11: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/11.jpg)
Sources of Complexity
▪Doing complex things
▪Interconnections between modules
▪3D / UI / logic separation
▪Changing scope
▪Make it work first optimize later
![Page 12: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/12.jpg)
How to tame Complexity?
Can’t remove inherent complexity
Rumor has it, Functional Programming might be the key
▪Concise
▪Convenient
▪Correctness
▪Concurrency
▪Composability*
https://fsharpforfunandprofit.com/why-use-fsharp/ https://live.staticflickr.com/2307/32063430274_bf8da24b81_b.jpg
![Page 13: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/13.jpg)
Functional Rewrite!
▪Two applications – 8+ years in development
▪Moving from C# OOP WPF to F# FP ?GUI?
▪Functional paradigm of Immutable Data//mutablepublic static void Add(Dictionary<string,int> d, string key, int value)
//immutablepublic static Map<string,int> Add(Map<string,int> m, string key, int value)
Immutable data feasible for a whole Application?public static Scene AddObject(Scene m, string filepath)
public static Scene ChangeCamera(Scene m, Matrix44f view)
![Page 14: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/14.jpg)
ELM Architecture
Action
update
Model
view
user
![Page 15: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/15.jpg)
type Polygon = { points : list<V2d> }
type Model ={
polygon : Polygoncursor : option<V2d>
}
type Message = | AddPoint of V2d| MoveCursor of V2d
let update (m : Model) (msg : Message) = match msg with| AddPoint pt ->
{ m with polygon = { points = pt :: p.points } }| MoveCursor v ->
{ m with cursor = Some v } // set the current cursor
![Page 16: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/16.jpg)
let view (m : Model) =let viewPolygon points =points |> pairwise |> List.map (
fun (p0,p1) -> line p0 p1 [style "stroke:rgb(0,0,0);"])
body [] [button [onClick Undo] [text "Undo"]span [] []button [onClick Redo] [text "Redo"]br []viewPolygon m.polygon.pointsbr []
]
![Page 17: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/17.jpg)
type Model ={
polygon : option<Polygon> cursor : option<V2d> past : option<Model> future : option<Model>
}
let update (m : Model) (msg : Message) =match msg with| AddPoint pt ->
{ m with polygon = { points = pt :: p.points}; past = Some m }| Undo _ ->
match m.past with| None -> m // no past => nothing to undo| Some p -> { p with future = Some m }
// puts the current model into the future of the new model
type Message = | AddPoint of V2d| MoveCursor of V2d| Undo| Redo
![Page 18: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/18.jpg)
Composition Action
user
Model
Drawing.Model
update
Drawing.update
view
Drawing.view
Drawing.Action
![Page 19: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/19.jpg)
type Model = { scene : Scenedrawing : Drawing.Model// ..about 20 other things
past : option<Model> future : option<Model>
}
let update (surf:Surface) (m:Model) (msg:Message) = match msg with| DrawAnnotation inner ->
let drawing = Drawing.update m.drawing inner{ m with drawing = drawing }
// … a lot of stuff
![Page 20: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/20.jpg)
Have we tamed complexity?
YES
![Page 21: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/21.jpg)
NO
What about efficiency?
![Page 22: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/22.jpg)
Performance and Efficiency
How can we deal with expensive visualization functions?
State s0 State s1
update Diff(s0, s1) = Δ VisualizeΔ
For 3D graphics: Functional programming vs high-performance computer graphics, GPU Day 2018
![Page 23: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/23.jpg)
Revisit of our 5Cs
▪Conciseless coding noise, fewer LOC, ‘reasonable’ code
▪Convenienttype system, pattern matching, higher order functions
▪Correctnesscompile time errors instead of runtime error,no null, no side effects
▪Concurrencyevent handling, sharing immutable states
▪Composabilitymaintainable, testable, reusable modules
![Page 24: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/24.jpg)
Take Home
(1) Don’t fear the rewrite, it pays of shortly
(2) Team▪ Increased motivation▪Steep learning curve (esp. for OOP trained)
(3) Don’t throw away and port tested code (rather wrap)
![Page 25: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/25.jpg)
Take Home
(4) FP fits high performance applications (if done right)▪Use diffing algorithm to translate immutable
snapshots to efficient GPU updates
(5) F# plays well with others ▪ .NET runtime / C++ marshalling▪GPU / compute shader
(6) Functional Programming can tame complexity !!!
![Page 27: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/27.jpg)
Further Reading
▪ “Elm: Concurrent FRP for functional GUIs”, Phd thesis 2012, Evan Czaplick https://elm-lang.org/assets/papers/concurrent-frp.pdf
▪ Elm diffing algorithm, https://github.com/elm/virtual-dom
▪ Aardvark platform, https://aardvark.graphics
▪ Aardvark’s high-performance ELM implementationhttps://github.com/aardvark-platform/aardvark.media
▪ Functional programming in the wild GPU Day 2018
▪ Functional programming vs high-performance computer graphics,GPU Day 2018
▪ Domain driven design https://fsharpforfunandprofit.com/ddd/
▪ PRo3D project page, http://pro3d.space/
▪ Will be open sourced soon...
![Page 28: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/28.jpg)
Call for collaboration
▪ VRVis Research Center▪ Visualization research in various fields▪ https://www.vrvis.at/
▪ aardworx▪ Commercial HPG▪ https://aardworx.com/
![Page 29: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/29.jpg)
explore, measure, analyze 3D data in 3D
Big (laser scan) points in browser
Remote (volume) rendering cloud services
● products and services from research● Functional programming consulting & advice
![Page 30: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/30.jpg)
Solving the performance problem
▪Computing difference is the key!
▪Elm, React uses this approach
▪For 3D graphics: Functional programming vs high-performance computer graphics, GPU Day 2018
▪Ongoing work: scientific paper on this topic
![Page 31: PRo3D TSID...Moving from C# OOP WPF to F# FP ?GUI? Functional paradigm of Immutable Data //mutable public static void Add(Dictionary d, string key, int value) //immutable](https://reader035.vdocuments.mx/reader035/viewer/2022062403/5ffca082b12ffc15594e7dd8/html5/thumbnails/31.jpg)
Functional rewrite timeline
October 2016, First ELM for 3D sketch
Feb 2017, Feasibility analysis
March 2017, First High-PerformanceELM implementation
October 2017, First PRo3D featurescompleted
Mid 2018,FP rewritestarted paying off