]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Values.hs
Import cleanup in Values.
[spline3.git] / src / Values.hs
1 {-# LANGUAGE FlexibleInstances #-}
2
3 module Values (
4 Values,
5 Values2D,
6 Values3D,
7 dims,
8 empty3d,
9 idx,
10 zoom_shape )
11 where
12
13 import Data.Array.Repa (
14 Array, U,
15 Z( Z ),
16 (:.)( (:.) ),
17 DIM2,
18 DIM3,
19 extent,
20 fromListUnboxed,
21 unsafeIndex )
22
23 import ScaleFactor ( ScaleFactor )
24
25
26 type Values sh = Array U sh Double
27 type Values2D = Values DIM2
28 type Values3D = Values DIM3
29
30
31 empty3d :: Values3D
32 empty3d = Data.Array.Repa.fromListUnboxed (Z :. 0 :. 0 :. 0) []
33
34
35 dims :: Values3D -> (Int, Int, Int)
36 dims v3d =
37 let (Z :. x :. y :. z) = extent v3d
38 in
39 (x,y,z)
40
41
42 idx :: Values3D -> Int -> Int -> Int -> Double
43 idx v3d i j k =
44 unsafeIndex v3d shape
45 where
46 shape :: DIM3
47 shape = (Z :. i :. j :. k)
48
49
50 zoom_shape :: ScaleFactor -> DIM3 -> DIM3
51 zoom_shape (sfx, sfy, sfz) sh =
52 let (Z :. x :. y :. z) = sh
53 x' = x * sfx
54 y' = y * sfy
55 z' = z * sfz
56 in
57 (Z :. x' :. y' :. z')