Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/fields/image-info.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/fields/image-info.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3446 - (view) (download)

1 : jhr 3446 (* image-info.sml
2 :     *
3 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 :     * All rights reserved.
7 :     *
8 :     * Information about an image object.
9 :     *
10 :     * TODO:
11 :     * handle images where the symmetries are exploited.
12 :     *)
13 :    
14 :     structure ImageInfo : sig
15 :    
16 :     type info
17 :    
18 :     (* Do the images have the same dimension and shape? *)
19 :     val sameShape : info * info -> bool
20 :    
21 :     (* Are two image infos the same? *)
22 :     val same : info * info -> bool
23 :    
24 :     (* hash value (based on image file ID) *)
25 :     val hash : info -> word
26 :    
27 :     (* make image info from a proxy Nrrd file, target domain dimension, and range shape;
28 :     * return NONE if the domain and/or range do not match the structure of the nrrd file.
29 :     *)
30 :     val fromNrrd : NrrdInfo.info * int * int list -> info option
31 :    
32 :     (* create a default image from a domain dimension and range shape. *)
33 :     val mkInfo : int * int list -> info
34 :    
35 :     val toString : info -> string
36 :     val dim : info -> int (* dimension of space *)
37 :     val sizes : info -> int list (* size of each dimension (not including the data axis) *)
38 :     val voxelShape : info -> int list (* shape of voxels; empty list for scalars *)
39 :     val voxelSzB : info -> int (* size in bytes of a voxel *)
40 :     val stride : info -> int (* for non-scalar images, this returns the *)
41 :     (* number of samples between voxels *)
42 :     val sampleTy : info -> RawTypes.ty (* representation type of samples *)
43 :    
44 :     end = struct
45 :    
46 :     (* Image voxels are tensors of some raw representation type *)
47 :     type voxel_ty = (int list * RawTypes.ty)
48 :    
49 :     datatype info = ImgInfo of {
50 :     stamp : Stamp.stamp, (* unique ID *)
51 :     dim : int, (* dimension of space *)
52 :     sizes : int list, (* number of samples along each axis (not including
53 :     * the data axis); we follow the Nrrd convention of
54 :     * listing the axes in fast to slow order.
55 :     *)
56 :     ty : voxel_ty
57 :     }
58 :    
59 :     fun sameShape (ImgInfo{stamp=s1, dim=d1, ty=(dd1, _), ...}, ImgInfo{stamp=s2, dim=d2, ty=(dd2, _), ...}) =
60 :     Stamp.same(s1, s2) orelse ((d1 = d2) andalso (dd1 = dd2))
61 :    
62 :     fun same (ImgInfo{stamp=s1, ...}, ImgInfo{stamp=s2, ...}) = Stamp.same(s1, s2)
63 :    
64 :     fun hash (ImgInfo{stamp, ...}) = Stamp.hash stamp
65 :    
66 :     (* make image info from a proxy Nrrd file, target domain dimension, and range shape *)
67 :     fun fromNrrd (nrrd, dim, dd) = let
68 :     val {elemTy, nElems, ...} = NrrdInfo.voxelInfo nrrd
69 :     val nElems' = List.foldl (op * ) 1 dd
70 :     in
71 :     if (NrrdInfo.dim nrrd <> dim) orelse (nElems <> nElems')
72 :     then NONE
73 :     else SOME(ImgInfo{
74 :     stamp = Stamp.new(),
75 :     dim = dim,
76 :     sizes = NrrdInfo.sizes nrrd,
77 :     ty = (dd, elemTy)
78 :     })
79 :     end
80 :    
81 :     fun mkInfo (dim, dd) = ImgInfo{
82 :     stamp = Stamp.new(),
83 :     dim = dim,
84 :     sizes = [], (* unknown *)
85 :     ty = (dd, !RawTypes.realTy)
86 :     }
87 :    
88 :     fun toString (ImgInfo{dim, ty=(dd, rTy), ...}) = let
89 :     val shape = (case dd
90 :     of [] => "[]"
91 :     | [d] => concat["[", Int.toString d, "]"]
92 :     | dd => concat["[", String.concatWith "," (List.map Int.toString dd), "]"]
93 :     (* end case *))
94 :     in
95 :     concat[
96 :     "IMAGE", Int.toString dim, "D<", RawTypes.toString rTy, shape, ">"
97 :     ]
98 :     end
99 :    
100 :     fun dim (ImgInfo{dim, ...}) = dim
101 :    
102 :     fun sizes (ImgInfo{sizes, ...}) = sizes
103 :    
104 :     fun voxelShape (ImgInfo{ty=(dd, _), ...}) = dd
105 :    
106 :     fun voxelSzB (ImgInfo{ty=(dd, rTy), ...}) = let
107 :     val nSamples = List.foldl (op * ) 1 dd
108 :     in
109 :     nSamples * RawTypes.sizeb rTy
110 :     end
111 :    
112 :     fun stride (ImgInfo{ty=(dd, rTy), ...}) = List.foldl (op * ) 1 dd
113 :    
114 :     fun sampleTy (ImgInfo{ty=(_, rTy), ...}) = rTy
115 :    
116 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0