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 465 - (view) (download)
Original Path: trunk/src/compiler/fields/image-info.sml

1 : jhr 106 (* image-info.sml
2 :     *
3 : jhr 435 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4 : jhr 106 * All rights reserved.
5 :     *
6 :     * Information about a NRRD file
7 :     *)
8 :    
9 :     structure ImageInfo : sig
10 :    
11 : jhr 284 (* Image samples are tensors of some raw representation type *)
12 :     type sample_ty = (int list * RawTypes.ty)
13 :    
14 : jhr 165 datatype info = ImgInfo of {
15 : jhr 465 id : OS.FileSys.file_id, (* ID of image file *)
16 :     dim : int, (* dimension of space *)
17 :     ty : sample_ty, (* types of image samples *)
18 :     origin : FloatLit.float list, (* center of first sample *)
19 :     sizes : int list (* number of samples along each axis;
20 :     * we follow the Nrrd convention of
21 :     * listing the axes in fast to slow
22 :     * order.
23 :     *)
24 :     }
25 : jhr 165
26 :     (* are the underlying files the same? *)
27 :     val same : info * info -> bool
28 :    
29 :     (* hash value (based on image file ID) *)
30 :     val hash : info -> word
31 :    
32 :     (* get image info from a Nrrd file *)
33 : jhr 130 val getInfo : string -> info
34 : jhr 106
35 : jhr 192 val toString : info -> string
36 : jhr 394 val dim : info -> int (* dimension of space *)
37 : jhr 192
38 : jhr 106 end = struct
39 :    
40 : jhr 284 (* Image samples are tensors of some raw representation type *)
41 :     type sample_ty = (int list * RawTypes.ty)
42 :    
43 : jhr 165 datatype info = ImgInfo of {
44 : jhr 465 id : OS.FileSys.file_id, (* ID of image file *)
45 :     dim : int, (* dimension of space *)
46 :     ty : sample_ty, (* types of image samples *)
47 :     origin : FloatLit.float list, (* center of first sample *)
48 :     sizes : int list (* number of samples along each axis;
49 :     * we follow the Nrrd convention of
50 :     * listing the axes in fast to slow
51 :     * order.
52 :     *)
53 :     }
54 : jhr 135
55 : jhr 165 fun same (ImgInfo{id=a, ...}, ImgInfo{id=b, ...}) = (a = b)
56 :    
57 :     fun hash (ImgInfo{id, ...}) = OS.FileSys.hash id
58 :    
59 : jhr 135 fun getInfo fileName = let
60 : jhr 239 (* FIXME: check that file exists! *)
61 : jhr 135 val {version, header} = RunDNorm.run fileName
62 : jhr 239 fun set (r, v) = (r := SOME v)
63 :     fun get (tag, r) = (case !r of NONE => raise Fail("missing "^tag) | SOME v => v)
64 :     val ty = ref NONE
65 : jhr 284 val totalDim = ref NONE
66 : jhr 239 val dim = ref NONE
67 :     fun doValue ("type", v) = set(ty, RawTypes.fromString v)
68 : jhr 284 | doValue ("dimension", v) = set (totalDim, valOf(Int.fromString v))
69 : jhr 239 | doValue ("space dimension", v) = set (dim, valOf(Int.fromString v))
70 :     | doValue ("sizes", v) = ()
71 :     | doValue ("space directions", v) = ()
72 :     | doValue ("kinds", v) = ()
73 :     | doValue ("endian", v) = ()
74 :     | doValue ("encoding", v) = ()
75 :     | doValue ("space origin", v) = ()
76 :     | doValue _ = ()
77 : jhr 135 in
78 : jhr 238 Log.msg (concat[fileName, " file header:\n"]);
79 :     List.app (fn (tag, value) => Log.msg(concat[" ", tag, ": ", value, "\n"])) header;
80 : jhr 239 List.app doValue header;
81 :     ImgInfo{
82 :     id = OS.FileSys.fileId fileName,
83 :     dim = get ("space dimension", dim),
84 : jhr 284 (* FIXME: in general, the type is a tensor of raw values *)
85 :     ty = ([], get ("type", ty)),
86 : jhr 239 origin = [], (* FIXME *)
87 :     sizes = [] (* FIXME *)
88 :     }
89 : jhr 135 end
90 :    
91 : jhr 394 fun toString (ImgInfo{dim, ...}) = concat["IMAGE", Int.toString dim, "D"] (* FIXME *)
92 : jhr 192
93 : jhr 394 fun dim (ImgInfo{dim, ...}) = dim
94 :    
95 : jhr 106 end

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