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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3291 - (view) (download)

1 : jhr 106 (* image-info.sml
2 :     *
3 : jhr 3291 * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
4 :     *
5 :     * COPYRIGHT (c) 2015 The University of Chicago
6 : jhr 106 * All rights reserved.
7 :     *
8 : jhr 1793 * Information about an image object.
9 : jhr 1116 *
10 :     * TODO:
11 : jhr 2805 * handle images where the symmetries are exploited.
12 : jhr 106 *)
13 :    
14 :     structure ImageInfo : sig
15 :    
16 : jhr 2010 type info
17 : jhr 284
18 : jhr 2796 (* Do the images have the same dimension and shape? *)
19 :     val sameShape : info * info -> bool
20 :    
21 :     (* Are two image infos the same? *)
22 : jhr 165 val same : info * info -> bool
23 :    
24 :     (* hash value (based on image file ID) *)
25 :     val hash : info -> word
26 :    
27 : jhr 2010 (* 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 : jhr 1793 *)
30 : jhr 2010 val fromNrrd : NrrdInfo.info * int * int list -> info option
31 : jhr 106
32 : jhr 2010 (* create a default image from a domain dimension and range shape. *)
33 :     val mkInfo : int * int list -> info
34 :    
35 : jhr 192 val toString : info -> string
36 : jhr 2805 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 : jhr 192
44 : jhr 106 end = struct
45 :    
46 : jhr 1793 (* Image voxels are tensors of some raw representation type *)
47 : jhr 1116 type voxel_ty = (int list * RawTypes.ty)
48 : jhr 284
49 : jhr 165 datatype info = ImgInfo of {
50 : jhr 2805 stamp : Stamp.stamp, (* unique ID *)
51 :     dim : int, (* dimension of space *)
52 : jhr 2010 sizes : int list, (* number of samples along each axis (not including
53 :     * the data axis); we follow the Nrrd convention of
54 : jhr 2805 * listing the axes in fast to slow order.
55 :     *)
56 :     ty : voxel_ty
57 : jhr 465 }
58 : jhr 135
59 : jhr 2805 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 : jhr 2796
62 : jhr 2010 fun same (ImgInfo{stamp=s1, ...}, ImgInfo{stamp=s2, ...}) = Stamp.same(s1, s2)
63 : jhr 2796
64 : jhr 2010 fun hash (ImgInfo{stamp, ...}) = Stamp.hash stamp
65 : jhr 165
66 : jhr 2010 (* make image info from a proxy Nrrd file, target domain dimension, and range shape *)
67 :     fun fromNrrd (nrrd, dim, dd) = let
68 : jhr 1793 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 : jhr 2010 else SOME(ImgInfo{
74 : jhr 2805 stamp = Stamp.new(),
75 :     dim = dim,
76 :     sizes = NrrdInfo.sizes nrrd,
77 :     ty = (dd, elemTy)
78 :     })
79 : jhr 1793 end
80 : jhr 135
81 : jhr 2010 fun mkInfo (dim, dd) = ImgInfo{
82 : jhr 2805 stamp = Stamp.new(),
83 :     dim = dim,
84 :     sizes = [], (* unknown *)
85 :     ty = (dd, !RawTypes.realTy)
86 :     }
87 : jhr 2010
88 :     fun toString (ImgInfo{dim, ty=(dd, rTy), ...}) = let
89 : jhr 2805 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 : jhr 1116
100 : jhr 2010 fun dim (ImgInfo{dim, ...}) = dim
101 : jhr 394
102 : jhr 2010 fun sizes (ImgInfo{sizes, ...}) = sizes
103 : jhr 1116
104 :     fun voxelShape (ImgInfo{ty=(dd, _), ...}) = dd
105 :    
106 :     fun voxelSzB (ImgInfo{ty=(dd, rTy), ...}) = let
107 : jhr 2805 val nSamples = List.foldl (op * ) 1 dd
108 :     in
109 :     nSamples * RawTypes.sizeb rTy
110 :     end
111 : jhr 1116
112 :     fun stride (ImgInfo{ty=(dd, rTy), ...}) = List.foldl (op * ) 1 dd
113 :    
114 :     fun sampleTy (ImgInfo{ty=(_, rTy), ...}) = rTy
115 :    
116 : jhr 106 end

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