SCM Repository
Annotation of /branches/vis12/src/compiler/common/nrrd-enums.sml
Parent Directory
|
Revision Log
Revision 1790 - (view) (download)
1 : | jhr | 1789 | (* nrrd-enums.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | * | ||
6 : | * Support for dealing with some of the enumeration types used in nrrd file headers. | ||
7 : | * This support includes understanding the output of dnorm and converting to the | ||
8 : | * symbolic names used in <teem/nrrdEnums.h>. | ||
9 : | *) | ||
10 : | |||
11 : | structure NrrdEnums = | ||
12 : | struct | ||
13 : | |||
14 : | (* the subset of the axis kinds that Diderot can read and write *) | ||
15 : | datatype axis_kind | ||
16 : | = KindSpace (* spatial domain *) | ||
17 : | | KindList (* flat vector of values; used to represent tensors that do *) | ||
18 : | (* not have one of the shapes recoognized by Teem *) | ||
19 : | | KindScalar (* scalar *) | ||
20 : | | Kind2Vector (* 2 component vector *) | ||
21 : | | Kind3Vector (* 3-component vector *) | ||
22 : | | Kind4Vector (* 4-component vector *) | ||
23 : | | Kind2DMatrix (* 2x2 matrix: Mxx Mxy Myx Myy *) | ||
24 : | | Kind3DMatrix (* 3x3 matrix: Mxx Mxy Mxz Myx Myy Myz Mzx Mzy Mzz *) | ||
25 : | |||
26 : | (* convert from the string representation of an axis kind (see | ||
27 : | * http://teem.sourceforge.net/nrrd/format.html#kinds for info) | ||
28 : | *) | ||
29 : | fun kindFromString s = (case s | ||
30 : | of "space" => SOME KindSpace | ||
31 : | | "list" => SOME KindList | ||
32 : | | "scalar" => SOME KindScalar | ||
33 : | | "2-vector" => SOME Kind2Vector | ||
34 : | | "3-vector" => SOME Kind3Vector | ||
35 : | | "4-vector" => SOME Kind4Vector | ||
36 : | | "2D-matrix" => SOME Kind2DMatrix | ||
37 : | | "3D-matrix" => SOME Kind3DMatrix | ||
38 : | | _ => NONE | ||
39 : | (* end case *)) | ||
40 : | |||
41 : | (* convert an axis kind to its nrrd enum constant *) | ||
42 : | fun kindToEnum k = (case k | ||
43 : | of KindSpace => "nrrdKindSpace" | ||
44 : | | KindList => "nrrdKindList" | ||
45 : | | KindScalar => "nrrdKindScalar" | ||
46 : | | Kind2Vector => "nrrdKind2Vector" | ||
47 : | | Kind3Vector => "nrrdKind3Vector" | ||
48 : | | Kind4Vector => "nrrdKind4Vector" | ||
49 : | | Kind2DMatrix => "nrrdKind2DMatrix" | ||
50 : | | Kind3DMatrix => "nrrdKind3DMatrix" | ||
51 : | (* end case *)) | ||
52 : | |||
53 : | (* nrrd types *) | ||
54 : | datatype ty | ||
55 : | = TypeChar (* 8-bit signed integer *) | ||
56 : | | TypeUChar (* 8-bit unsigned integer *) | ||
57 : | | TypeShort (* 16-bit signed integer *) | ||
58 : | | TypeUShort (* 16-bit unsigned integer *) | ||
59 : | | TypeInt (* 32-bit signed integer *) | ||
60 : | | TypeUInt (* 32-bit unsigned integer *) | ||
61 : | | TypeLLong (* 64-bit signed integer *) | ||
62 : | | TypeULLong (* 64-bit unsigned integer *) | ||
63 : | | TypeFloat (* 32-bit floating-point number *) | ||
64 : | | TypeDouble (* 64-bit floating-point number *) | ||
65 : | |||
66 : | (* convert from the string representation of a nrrd type (see | ||
67 : | * http://teem.sourceforge.net/nrrd/format.html#type for info) | ||
68 : | *) | ||
69 : | fun tyFromString s = (case s | ||
70 : | of "signed char" => SOME TypeChar | ||
71 : | | "int8" => SOME TypeChar | ||
72 : | | "int8_t" => SOME TypeChar | ||
73 : | | "uchar" => SOME TypeUChar | ||
74 : | | "unsigned char" => SOME TypeUChar | ||
75 : | | "uint8" => SOME TypeUChar | ||
76 : | | "uint8_t" => SOME TypeUChar | ||
77 : | | "short" => SOME TypeShort | ||
78 : | | "short int" => SOME TypeShort | ||
79 : | | "signed short" => SOME TypeShort | ||
80 : | | "signed short int" => SOME TypeShort | ||
81 : | | "int16" => SOME TypeShort | ||
82 : | | "int16_t" => SOME TypeShort | ||
83 : | | "ushort" => SOME TypeUShort | ||
84 : | | "unsigned short" => SOME TypeUShort | ||
85 : | | "unsigned short int" => SOME TypeUShort | ||
86 : | | "uint16" => SOME TypeUShort | ||
87 : | | "uint16_t" => SOME TypeUShort | ||
88 : | | "int" => SOME TypeInt | ||
89 : | | "signed int" => SOME TypeInt | ||
90 : | | "int32" => SOME TypeInt | ||
91 : | | "int32_t" => SOME TypeInt | ||
92 : | | "uint" => SOME TypeUInt | ||
93 : | | "unsigned int" => SOME TypeUInt | ||
94 : | | "uint32" => SOME TypeUInt | ||
95 : | | "uint32_t" => SOME TypeUInt | ||
96 : | | "longlong" => SOME TypeLLong | ||
97 : | | "long long" => SOME TypeLLong | ||
98 : | | "long long int" => SOME TypeLLong | ||
99 : | | "signed long long" => SOME TypeLLong | ||
100 : | | "signed long long int" => SOME TypeLLong | ||
101 : | | "int64" => SOME TypeLLong | ||
102 : | | "int64_t" => SOME TypeLLong | ||
103 : | | "ulonglong" => SOME TypeULLong | ||
104 : | | "unsigned long long" => SOME TypeULLong | ||
105 : | | "unsigned long long int" => SOME TypeULLong | ||
106 : | | "uint64" => SOME TypeULLong | ||
107 : | | "uint64_t" => SOME TypeULLong | ||
108 : | | "float" => SOME TypeFloat | ||
109 : | | "double" => SOME TypeDouble | ||
110 : | | _ => NONE | ||
111 : | (* end case *)) | ||
112 : | |||
113 : | (* convert a nrrd type to its nrrd enum constant *) | ||
114 : | jhr | 1790 | fun tyToEnum ty = (case ty |
115 : | jhr | 1789 | of TypeChar => "nrrdTypeChar" |
116 : | | TypeUChar => "nrrdTypeUChar" | ||
117 : | | TypeShort => "nrrdTypeShort" | ||
118 : | | TypeUShort => "nrrdTypeUShort" | ||
119 : | | TypeInt => "nrrdTypeInt" | ||
120 : | | TypeUInt => "nrrdTypeUInt" | ||
121 : | | TypeLLong => "nrrdTypeLLong" | ||
122 : | | TypeULLong => "nrrdTypeULLong" | ||
123 : | | TypeFloat => "nrrdTypeFloat" | ||
124 : | | TypeDouble => "nrrdTypeDouble" | ||
125 : | (* end case *)) | ||
126 : | |||
127 : | jhr | 1790 | (* convert a nrrd type to a RawType.ty *) |
128 : | fun tyToRaw ty = (case ty | ||
129 : | of TypeChar => RawTypes.RT_Int8 | ||
130 : | | TypeUChar => RawTypes.RT_UInt8 | ||
131 : | | TypeShort => RawTypes.RT_Int16 | ||
132 : | | TypeUShort => RawTypes.RT_UInt16 | ||
133 : | | TypeInt => RawTypes.RT_Int32 | ||
134 : | | TypeUInt => RawTypes.RT_UInt32 | ||
135 : | | TypeLLong => RawTypes.RT_Int64 | ||
136 : | | TypeULLong => RawTypes.RT_UInt64 | ||
137 : | | TypeFloat => RawTypes.RT_Float | ||
138 : | | TypeDouble => RawTypes.RT_Double | ||
139 : | (* end case *)) | ||
140 : | |||
141 : | fun rawToTy rty = (case rty | ||
142 : | of RawTypes.RT_Int8 => TypeChar | ||
143 : | | RawTypes.RT_UInt8 => TypeUChar | ||
144 : | | RawTypes.RT_Int16 => TypeShort | ||
145 : | | RawTypes.RT_UInt16 => TypeUShort | ||
146 : | | RawTypes.RT_Int32 => TypeInt | ||
147 : | | RawTypes.RT_UInt32 => TypeUInt | ||
148 : | | RawTypes.RT_Int64 => TypeLLong | ||
149 : | | RawTypes.RT_UInt64 => TypeULLong | ||
150 : | | RawTypes.RT_Float => TypeFloat | ||
151 : | | RawTypes.RT_Double => TypeDouble | ||
152 : | (* end case *)) | ||
153 : | |||
154 : | jhr | 1789 | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |