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

SCM Repository

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

Annotation of /branches/vis12/src/compiler/nrrd/nrrd-enums.sml

Parent Directory Parent Directory | Revision Log Revision Log


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

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