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

SCM Repository

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

Annotation of /trunk/src/compiler/fields/image-info.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

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

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