SCM Repository
Annotation of /trunk/src/compiler/fields/image-info.sml
Parent Directory
|
Revision Log
Revision 284 - (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 : | |||
33 : | jhr | 106 | end = struct |
34 : | |||
35 : | jhr | 284 | (* Image samples are tensors of some raw representation type *) |
36 : | type sample_ty = (int list * RawTypes.ty) | ||
37 : | |||
38 : | jhr | 165 | datatype info = ImgInfo of { |
39 : | id : OS.FileSys.file_id, (* ID of image file *) | ||
40 : | jhr | 135 | dim : int, (* dimension of space *) |
41 : | jhr | 284 | ty : sample_ty, (* types of image samples *) |
42 : | jhr | 135 | origin : FloatLit.float list, (* center of first sample *) |
43 : | sizes : int list (* number of samples along each axis *) | ||
44 : | } | ||
45 : | |||
46 : | jhr | 165 | fun same (ImgInfo{id=a, ...}, ImgInfo{id=b, ...}) = (a = b) |
47 : | |||
48 : | fun hash (ImgInfo{id, ...}) = OS.FileSys.hash id | ||
49 : | |||
50 : | jhr | 135 | fun getInfo fileName = let |
51 : | jhr | 239 | (* FIXME: check that file exists! *) |
52 : | jhr | 135 | val {version, header} = RunDNorm.run fileName |
53 : | jhr | 239 | fun set (r, v) = (r := SOME v) |
54 : | fun get (tag, r) = (case !r of NONE => raise Fail("missing "^tag) | SOME v => v) | ||
55 : | val ty = ref NONE | ||
56 : | jhr | 284 | val totalDim = ref NONE |
57 : | jhr | 239 | val dim = ref NONE |
58 : | fun doValue ("type", v) = set(ty, RawTypes.fromString v) | ||
59 : | jhr | 284 | | doValue ("dimension", v) = set (totalDim, valOf(Int.fromString v)) |
60 : | jhr | 239 | | doValue ("space dimension", v) = set (dim, valOf(Int.fromString v)) |
61 : | | doValue ("sizes", v) = () | ||
62 : | | doValue ("space directions", v) = () | ||
63 : | | doValue ("kinds", v) = () | ||
64 : | | doValue ("endian", v) = () | ||
65 : | | doValue ("encoding", v) = () | ||
66 : | | doValue ("space origin", v) = () | ||
67 : | | doValue _ = () | ||
68 : | jhr | 135 | in |
69 : | jhr | 238 | Log.msg (concat[fileName, " file header:\n"]); |
70 : | List.app (fn (tag, value) => Log.msg(concat[" ", tag, ": ", value, "\n"])) header; | ||
71 : | jhr | 239 | List.app doValue header; |
72 : | ImgInfo{ | ||
73 : | id = OS.FileSys.fileId fileName, | ||
74 : | dim = get ("space dimension", dim), | ||
75 : | jhr | 284 | (* FIXME: in general, the type is a tensor of raw values *) |
76 : | ty = ([], get ("type", ty)), | ||
77 : | jhr | 239 | origin = [], (* FIXME *) |
78 : | sizes = [] (* FIXME *) | ||
79 : | } | ||
80 : | jhr | 135 | end |
81 : | |||
82 : | jhr | 192 | fun toString (ImgInfo{...}) = "IMAGE" (* FIXME *) |
83 : | |||
84 : | jhr | 106 | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |