School of Computing - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

School of Computing

Description:

Interpolate along edges to find intersection points. Note ambiguity in cases 5 and 10! ... 1 triangle in a cell = edge interpolation repeated within cell ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 22
Provided by: nes6
Category:

less

Transcript and Presenter's Notes

Title: School of Computing


1
School of Computing Faculty of Engineering
Meshing with Grids Toward Functional
Abstractions for Grid-based Visualization Rita
Borgo David Duke Visualization Virtual
Reality Group School of Computing University of
Leeds, UK Colin Runciman Malcolm
Wallace Department of Computer Science University
of York, UK
2
Overview
  • Why functional programming (still) matters
  • Project a lazy polytypic grid
  • Marching cubes
  • Streaming
  • Making it generic
  • Performance
  • Looking back, looking forwards

3
Why Functional Programming Still Matters
  • Academic arguments
  • J. Hughes, Why Functional Programming Matters
  • Problem decomposition ? program composition
  • Absence of side-effects
  • Higher-order functions
  • Laziness
  • Practical arguments
  • Natural progression OO ? service-orientation
  • Tower of Babel
  • Novel solutions come from working against the OO
    grain!

4
Introduction to FP and Haskell
  • Functional building blocks
  • square Int -gt Int
  • square x xx
  • map (a -gt b) -gt a -gt b
  • map _
  • map f (aas) (f a)(map f as)
  • (.) (b -gt c) -gt (a -gt b) -gt (a -gt c)
  • (f . g) x f(g(x))
  • sqList ls map square ls
  • sqsqList ls map sqList (map sqList ls)
  • (map sqList . map sqList) ls
  • map (sqList . sqList) ls
  • fibs 0,1 ab (a,b) lt- zip fibs (tail
    fibs)

Note loop fusion law encoded as a rule in GHC
compiler
5
Why FP matters (to grid-enabled vis)
  • pipeline architecture widespread in visualization
  • supports distribution and streaming

reader
ozone levels
isosurface
normals
display
geo-reference
normals
isosurface
reader
temperature
  • However
  • Streaming is ad-hoc and coarse grained
  • Algorithms depend on mesh type
  • Data traversed multiple times

Note analogy of pipeline composition and
function composition f . g
6
(No Transcript)
7
Isosurfaces
  • Widely-used technique for both 2D and 3D scalar
    data
  • Two general approaches
  • Contour tracking follow a feature through the
    dataset
  • Marching traverse dataset, processing each cell
    as encountered
  • in-core versus out-of-core variations
  • 2D examples skull cross-section isoline for t5

8
Marching Squares
  • Input a dataset, and a threshold value to be
    contoured
  • Output line segments representing contour's path
    within dataset
  • Algorithm
  • For each cell, compare field value at point with
    threshold
  • Sixteen possible cases index into case-table to
    find edges
  • Interpolate along edges to find intersection
    points
  • Note ambiguity in cases 5 and 10!

9
Marching Cubes ... and beyond
  • 3D surface generalizes 2D case
  • Isolines become surfaces composed of triangles
  • 16-case lookup table becomes 256-case table
  • (15 cases if we use symmetry)
  • Tetrahedral cells also common
  • Other cell types possible
  • common pattern of processing
  • need appropriate case-table

10
Implementation 1 Functional Arrays
  • Basic types
  • type XYZ (Int,Int,Int)
  • type Num a gt Dataset a Array XYZ a
  • type Cell a (a,a,a,a,a,a,a,a)
  • Top-level traversal
  • isoA (Ord a, Intgeral a) gt a -gt Dataset a -gt
    Triangle
  • isoA th sampleArr
  • concat . zipWith1 (mcubeA th lookup) addrs
  • where
  • addrs (i,j,k) k lt- 1..ksz-1, j
    lt- 1..jsz-1, i lt- 1..isz-1
  • lookup arr (x,y,z) (arr!(x,y,z),
    arr!(x1,y,z), .., arr!(x1,y1,z1))
  • Worker function
  • mcubeA (Ord a, Intgeral a) gt a -gt (XYZ -gt
    Cell a) -gt XYZ -gt Triangle
  • mcubeA th lookup xyz

11
Problems
  • Entire dataset must be resident in memory
  • Vertex shared by n cells ? threshold comparison
    repeated n times
  • gt 1 triangle in a cell gt edge interpolation
    repeated within cell
  • Edge shared by m cells ? interpolation repeated m
    times

12
(No Transcript)
13
Discontinuities
  • Two solutions
  • Rewrite mkStream, considering dataset boundaries
    or
  • Strip phantom cells from output of mkStream
  • disContinuities XYZ -gt b -gt b
  • disContinuities (isz,jsz,ksz) step (0,0,0)
  • where
  • step (i,j,k) (xxs)
  • i(isz-1) step (0,j1,k) xs
  • j(jsz-1) step (0,0,k1) (drop
    (isz-1) xs)
  • k(ksz-1)
  • otherwise x step (i1,j,k) xs
  • cellStream disContinuities size . stream

14
Implementations 2 3 Streams
  • Version 2 replace array lookup with stream
    access
  • isoS th samples
  • concat . zipWith2 (mcubeS th) addrs cells
  • where cells stream size samples
  • mcubeS a -gt XYZ -gt Cell a -gt Triangle
  • mcubeS th xyz cell
  • group3 . map (interp th cell xyz) .
    mctable! . toByte . map8 (gtth) cell
  • Version 3 share vertex comparison by creating
    a stream of case-indices
  • isoT th samples
  • concat . zipWith3 (mcubeS th) addrs cells
    indices
  • where indices map toByte . stream . map
    (gtth)
  • mcubeT a -gt XYZ -gt Cell a -gt Byte -gt
    Triangle
  • mcubeT th xyz cell index
  • group3 . map (interp th cell xyz) .
    mctable! index

15
From generic cells ...
  • Functions already polymorphic ..
  • generic over one or more type variables
  • constraints may limit instantiation
  • isoA (Ord a, Intgeral a, Fractional b) gt a -gt
    Dataset a -gt Triangle b
  • ... and abstracting from Cell type is (nearly)
    straightforward
  • mcubeRec (Num a, Floating b) gt a -gt XYZ -gt
    CellR a -gt Triangle b
  • mcubeRec th xyz cell
  • group3 . map (interp th cell xyz ) .
    mcTable! . toByte8 . map8 (gtth) cell
  • mcubeTet (Num a, Floating b) gt a -gt
    CellT a -gt CellT b -gt Triangle b
  • mcubeTet th g cell verts
  • group3 . map (interp th cell verts) .
    mtTable! . toByte4 . map4 (gtth) cell
  • Can capture general pattern within a type-class
  • class Cell T where

16
... to generic meshes
  • Dealing with different mesh-type organizations is
    harder ...
  • Regular meshes implicit geometry and topology
  • Irregular meshes implicit geometry
  • Unstructured meshes geometry and topology
    explicit
  • Polytypic functions are independent of data
    organization
  • Haskell data constructions isomorphic to
    sum-of-products type
  • Foundation on categorical model of data type
    structure
  • Examples
  • data List a Nil Cons a (List a)
  • --gt
  • List 1 (a x List)
  • data Tree a Leaf a Node (Tree a) a (Tree a)
  • --gt
  • Tree a (Tree x a x Tree)

17
Polytypism in practice
  • From Generic Haskell Practice Theory, Hinze
    Jeuring, 2001
  • define generic function by induction over type
    structure
  • generic version can then be instantiated for any
    SoP type
  • mapG tkind Map kind t t
  • mapG Char c c
  • mapG Int i i
  • mapG Unit Unit Unit
  • mapG mapa mapb (InL a) InL (mapa a)
  • mapG mapa mapb (InR b) InR (mapb b)
  • mapG mapa mapb a b mapa a mapb
    b
  • data Tree a Leaf a Node (Tree a) a (Tree a)
  • mapList mapG List -- standard Haskell
    map
  • mapTree mapG Tree -- apply function to
    each node in the tree
  • Research question can we actually apply this
    idea to mesh traversal?

18
Sample Results
19
Performance
  • Performance difference decreases with surface
    size
  • D.J. Duke, M. Wallace, R. Borgo, and C. Runciman,
    Fine-grained visualization pipelines and lazy
    functional languages,to appear in Proc. IEEE
    Vis06

20
Conclusions and Future Work
  • What we've achieved
  • re-constructed fundamental visualization
    algorithms
  • Implemented fine-grained streaming
  • demonstrated that FP can be (surprisingly)
    efficient
  • What we're doing now
  • generalizing from specific types of mesh
  • exploring capabilities of generic programming
  • Where we are going next
  • grid-enabled Haskell pipelines
  • some prior work GRID-GUM, Michaelson, Trinder,
    Al Zain
  • build into York Haskell Compiler (bytecode) RTS
  • want simple, lightweight grid tools!

21
Finally ...
  • Thanks to
  • EPSRC Fundamental Computing for e-Science
    Programme
  • Further information hackage.haskell.org/trac/Poly
    FunViz/
  • Any Questions?
Write a Comment
User Comments (0)
About PowerShow.com