14 |
(* Image voxels are tensors of some raw representation type *) |
(* Image voxels are tensors of some raw representation type *) |
15 |
type voxel_ty = (int list * RawTypes.ty) |
type voxel_ty = (int list * RawTypes.ty) |
16 |
|
|
17 |
|
(* a subset of the Nrrd file axis kinds (see http://teem.sourceforge.net/nrrd/format.html#kinds) *) |
18 |
|
datatype axis_kind |
19 |
|
= SPACE |
20 |
|
| SCALAR |
21 |
|
| VEC of int (* 2, 3, or 4-vector *) |
22 |
|
| MAT of int (* 2x2 or 3x3 matrix *) |
23 |
|
|
24 |
datatype info = ImgInfo of { |
datatype info = ImgInfo of { |
25 |
id : OS.FileSys.file_id, (* ID of image file *) |
id : OS.FileSys.file_id, (* ID of image file *) |
26 |
dim : int, (* dimension of space *) |
dim : int, (* dimension of space *) |
27 |
ty : voxel_ty, (* types of image samples *) |
ty : voxel_ty, (* types of image samples *) |
28 |
origin : FloatLit.float list, (* center of first sample *) |
origin : FloatLit.float list, (* center of first sample *) |
29 |
sizes : int list (* number of samples along each axis; |
kinds : axis_kind list, (* the kinds of each axis; |
30 |
* we follow the Nrrd convention of |
* we follow the Nrrd convention of |
31 |
* listing the axes in fast to slow |
* listing the axes in fast to slow |
32 |
* order. |
* order. |
33 |
*) |
*) |
34 |
|
sizes : int list (* number of samples along each axis *) |
35 |
} |
} |
36 |
|
|
37 |
(* are the underlying files the same? *) |
(* are the underlying files the same? *) |
57 |
(* Image samples are tensors of some raw representation type *) |
(* Image samples are tensors of some raw representation type *) |
58 |
type voxel_ty = (int list * RawTypes.ty) |
type voxel_ty = (int list * RawTypes.ty) |
59 |
|
|
60 |
|
(* a subset of the Nrrd file axis kinds (see http://teem.sourceforge.net/nrrd/format.html#kinds) *) |
61 |
|
datatype axis_kind |
62 |
|
= SPACE |
63 |
|
| SCALAR |
64 |
|
| VEC of int (* 2, 3, or 4-vector *) |
65 |
|
| MAT of int (* 2x2 or 3x3 matrix *) |
66 |
|
|
67 |
datatype info = ImgInfo of { |
datatype info = ImgInfo of { |
68 |
id : OS.FileSys.file_id, (* ID of image file *) |
id : OS.FileSys.file_id, (* ID of image file *) |
69 |
dim : int, (* dimension of space *) |
dim : int, (* dimension of space *) |
70 |
ty : voxel_ty, (* types of image samples *) |
ty : voxel_ty, (* types of image samples *) |
71 |
origin : FloatLit.float list, (* center of first sample *) |
origin : FloatLit.float list, (* center of first sample *) |
72 |
sizes : int list (* number of samples along each axis; |
kinds : axis_kind list, (* the kinds of each axis; |
73 |
* we follow the Nrrd convention of |
* we follow the Nrrd convention of |
74 |
* listing the axes in fast to slow |
* listing the axes in fast to slow |
75 |
* order. |
* order. |
76 |
*) |
*) |
77 |
|
sizes : int list (* number of samples along each axis *) |
78 |
} |
} |
79 |
|
|
80 |
fun same (ImgInfo{id=a, ...}, ImgInfo{id=b, ...}) = (a = b) |
fun same (ImgInfo{id=a, ...}, ImgInfo{id=b, ...}) = (a = b) |
88 |
val ty = ref NONE |
val ty = ref NONE |
89 |
val totalDim = ref NONE |
val totalDim = ref NONE |
90 |
val dim = ref NONE |
val dim = ref NONE |
91 |
|
val kinds = ref NONE |
92 |
val sizes = ref NONE |
val sizes = ref NONE |
93 |
fun doValue ("type", v) = set(ty, RawTypes.fromString v) |
fun doValue ("type", v) = set(ty, RawTypes.fromString v) |
94 |
| doValue ("dimension", v) = set (totalDim, valOf(Int.fromString v)) |
| doValue ("dimension", v) = set (totalDim, valOf(Int.fromString v)) |
104 |
set (sizes, List.map atoi (fields v)) |
set (sizes, List.map atoi (fields v)) |
105 |
end |
end |
106 |
| doValue ("space directions", v) = () |
| doValue ("space directions", v) = () |
107 |
| doValue ("kinds", v) = () |
| doValue ("kinds", v) = let |
108 |
|
fun s2kind "space" = SPACE |
109 |
|
| s2kind "scalar" = SCALAR |
110 |
|
| s2kind "2-vector" = VEC 2 |
111 |
|
| s2kind "3-vector" = VEC 3 |
112 |
|
| s2kind "4-vector" = VEC 4 |
113 |
|
| s2kind "2D-matrix" = MAT 2 |
114 |
|
| s2kind "3D-matrix" = MAT 3 |
115 |
|
| s2kind k = raise Fail(concat["axis kind \"", k, "\" not supported"]) |
116 |
|
in |
117 |
|
set (kinds, List.map s2kind (fields v)) |
118 |
|
end |
119 |
| doValue ("endian", v) = () |
| doValue ("endian", v) = () |
120 |
| doValue ("encoding", v) = () |
| doValue ("encoding", v) = () |
121 |
| doValue ("space origin", v) = () |
| doValue ("space origin", v) = () |
143 |
dim = dim, |
dim = dim, |
144 |
ty = (rngShape, get ("type", ty)), |
ty = (rngShape, get ("type", ty)), |
145 |
origin = [], (* FIXME *) |
origin = [], (* FIXME *) |
146 |
|
kinds = get ("kinds", kinds), |
147 |
sizes = sizes |
sizes = sizes |
148 |
} |
} |
149 |
end |
end |