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 394 - (view) (download)

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

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