SCM Repository
Annotation of /trunk/src/compiler/fields/image-info.sml
Parent Directory
|
Revision Log
Revision 239 - (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 | 165 | datatype info = ImgInfo of { |
12 : | id : OS.FileSys.file_id, (* ID of image file *) | ||
13 : | jhr | 106 | dim : int, (* dimension of space *) |
14 : | ty : RawTypes.ty, (* types of scalar samples *) | ||
15 : | origin : FloatLit.float list, (* center of first sample *) | ||
16 : | jhr | 135 | sizes : int list (* number of samples along each axis *) |
17 : | jhr | 106 | } |
18 : | jhr | 165 | |
19 : | (* are the underlying files the same? *) | ||
20 : | val same : info * info -> bool | ||
21 : | |||
22 : | (* hash value (based on image file ID) *) | ||
23 : | val hash : info -> word | ||
24 : | |||
25 : | (* get image info from a Nrrd file *) | ||
26 : | jhr | 130 | val getInfo : string -> info |
27 : | jhr | 106 | |
28 : | jhr | 192 | val toString : info -> string |
29 : | |||
30 : | jhr | 106 | end = struct |
31 : | |||
32 : | jhr | 165 | datatype info = ImgInfo of { |
33 : | id : OS.FileSys.file_id, (* ID of image file *) | ||
34 : | jhr | 135 | dim : int, (* dimension of space *) |
35 : | ty : RawTypes.ty, (* types of scalar samples *) | ||
36 : | origin : FloatLit.float list, (* center of first sample *) | ||
37 : | sizes : int list (* number of samples along each axis *) | ||
38 : | } | ||
39 : | |||
40 : | jhr | 165 | fun same (ImgInfo{id=a, ...}, ImgInfo{id=b, ...}) = (a = b) |
41 : | |||
42 : | fun hash (ImgInfo{id, ...}) = OS.FileSys.hash id | ||
43 : | |||
44 : | jhr | 135 | fun getInfo fileName = let |
45 : | jhr | 239 | (* FIXME: check that file exists! *) |
46 : | jhr | 135 | val {version, header} = RunDNorm.run fileName |
47 : | jhr | 239 | fun set (r, v) = (r := SOME v) |
48 : | fun get (tag, r) = (case !r of NONE => raise Fail("missing "^tag) | SOME v => v) | ||
49 : | val ty = ref NONE | ||
50 : | val dim = ref NONE | ||
51 : | fun doValue ("type", v) = set(ty, RawTypes.fromString v) | ||
52 : | | doValue ("dimension", v) = () | ||
53 : | | doValue ("space dimension", v) = set (dim, valOf(Int.fromString v)) | ||
54 : | | doValue ("sizes", v) = () | ||
55 : | | doValue ("space directions", v) = () | ||
56 : | | doValue ("kinds", v) = () | ||
57 : | | doValue ("endian", v) = () | ||
58 : | | doValue ("encoding", v) = () | ||
59 : | | doValue ("space origin", v) = () | ||
60 : | | doValue _ = () | ||
61 : | jhr | 135 | in |
62 : | jhr | 238 | Log.msg (concat[fileName, " file header:\n"]); |
63 : | List.app (fn (tag, value) => Log.msg(concat[" ", tag, ": ", value, "\n"])) header; | ||
64 : | jhr | 239 | List.app doValue header; |
65 : | ImgInfo{ | ||
66 : | id = OS.FileSys.fileId fileName, | ||
67 : | dim = get ("space dimension", dim), | ||
68 : | ty = get ("type", ty), | ||
69 : | origin = [], (* FIXME *) | ||
70 : | sizes = [] (* FIXME *) | ||
71 : | } | ||
72 : | jhr | 135 | end |
73 : | |||
74 : | jhr | 192 | fun toString (ImgInfo{...}) = "IMAGE" (* FIXME *) |
75 : | |||
76 : | jhr | 106 | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |