Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /trunk/src/compiler/nrrd/nrrd-enums.sml
ViewVC logotype

Annotation of /trunk/src/compiler/nrrd/nrrd-enums.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3349 - (view) (download)

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

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