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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/fields/image-info.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/fields/image-info.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 848, Mon Apr 18 21:37:37 2011 UTC revision 849, Tue Apr 19 14:43:56 2011 UTC
# Line 3  Line 3 
3   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)   * COPYRIGHT (c) 2010 The Diderot Project (http://diderot-language.cs.uchicago.edu)
4   * All rights reserved.   * All rights reserved.
5   *   *
6   * Information about a NRRD file   * Information about a NRRD file.
7     *
8     * TODO:
9     *      handle images where the symmetries are exploited.
10   *)   *)
11    
12  structure ImageInfo : sig  structure ImageInfo : sig
# Line 34  Line 37 
37    
38      val toString : info -> string      val toString : info -> string
39      val dim : info -> int                       (* dimension of space *)      val dim : info -> int                       (* dimension of space *)
40        val voxelShape : info -> int list   (* shape of voxels; empty list for scalars *)
41        val voxelSzB : info -> int          (* size in bytes of a voxel *)
42        val stride : info -> int            (* for non-scalar images, this returns the *)
43                                            (* number of samples between voxels *)
44    
45    end = struct    end = struct
46    
# Line 56  Line 63 
63    
64      fun hash (ImgInfo{id, ...}) = OS.FileSys.hash id      fun hash (ImgInfo{id, ...}) = OS.FileSys.hash id
65    
66      fun getInfo fileName = let      fun doHeader (fileName, header) = let
 (* FIXME: check that file exists! *)  
           val {version, header} = RunDNorm.run fileName  
67            fun fields s = String.tokens Char.isSpace s            fun fields s = String.tokens Char.isSpace s
68            fun set (r, v) = (r := SOME v)            fun set (r, v) = (r := SOME v)
69            fun get (tag, r) = (case !r of NONE => raise Fail("missing "^tag) | SOME v => v)            fun get (tag, r) = (case !r of NONE => raise Fail("missing "^tag) | SOME v => v)
# Line 89  Line 94 
94              Log.msg (concat[fileName, " file header:\n"]);              Log.msg (concat[fileName, " file header:\n"]);
95              List.app (fn (tag, value) => Log.msg(concat["  ", tag, ": ", value, "\n"])) header;              List.app (fn (tag, value) => Log.msg(concat["  ", tag, ": ", value, "\n"])) header;
96              List.app doValue header;              List.app doValue header;
97                let
98                val dim = get ("space dimension", dim)
99                val rngDim = get ("dimension", totalDim) - dim
100              (* split the sizes into those that control the shape of the voxels, which come first
101               * in the list, and those that span the image's dimensions.
102               *)
103                val (rngShape, sizes) = let
104                      fun split (0, l, prefix) = (List.rev prefix, l)
105                        | split (i, d::l, prefix) = split(i-1, l, d::prefix)
106                        | split _ = raise Fail "bogus dnorm output: too few sizes"
107                      in
108                        split (rngDim, get ("sizes", sizes), [])
109                      end
110                in
111              ImgInfo{              ImgInfo{
112                  id = OS.FileSys.fileId fileName,                  id = OS.FileSys.fileId fileName,
113                  dim = get ("space dimension", dim),                    dim = dim,
114  (* FIXME: in general, the type is a tensor of raw values *)                    ty = (rngShape, get ("type", ty)),
                 ty = ([], get ("type", ty)),  
115                  origin = [],    (* FIXME *)                  origin = [],    (* FIXME *)
116                  sizes = get ("sizes", sizes)                    sizes = sizes
117                }                }
118            end            end
119              end
120    
121      fun toString (ImgInfo{dim, ...}) = concat["IMAGE", Int.toString dim, "D"] (* FIXME *)      fun getInfo fileName = if OS.FileSys.access(fileName, [OS.FileSys.A_READ])
122              then let
123                val {version, header} = RunDNorm.run fileName
124                in
125                  doHeader (fileName, header)
126                end
127              else raise Fail(concat["Nrrd file \"", fileName, "\" does not exist"])
128    
129        fun toString (ImgInfo{dim, ty=(dd, rTy), ...}) = let
130              val shape = (case dd
131                     of [] => ""
132                      | [d] => concat["{", Int.toString d, "}"]
133                      | dd => concat["{", String.concatWith "," (List.map Int.toString dd), "}"]
134                    (* end case *))
135              in
136                concat[
137                    "IMAGE", Int.toString dim, "D<", RawTypes.toString rTy, shape, ">"
138                  ]
139              end
140    
141      fun dim (ImgInfo{dim, ...}) = dim      fun dim (ImgInfo{dim, ...}) = dim
142    
143        fun voxelShape (ImgInfo{ty=(dd, _), ...}) = dd
144    
145        fun voxelSzB (ImgInfo{ty=(dd, rTy), ...}) = let
146              val nSamples = List.foldl (op * ) 1 dd
147              in
148                nSamples * RawTypes.sizeb rTy
149              end
150    
151        fun stride (ImgInfo{ty=(dd, rTy), ...}) = List.foldl (op * ) 1 dd
152    
153    end    end

Legend:
Removed from v.848  
changed lines
  Added in v.849

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