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

SCM Repository

[diderot] View of /trunk/src/compiler/fields/image-info.sml
ViewVC logotype

View of /trunk/src/compiler/fields/image-info.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 394 - (download) (annotate)
Thu Oct 14 16:30:29 2010 UTC (8 years, 10 months ago) by jhr
File size: 2813 byte(s)
  Added types to IL variables
(* image-info.sml
 *
 * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu)
 * All rights reserved.
 *
 * Information about a NRRD file
 *)

structure ImageInfo : sig

  (* Image samples are tensors of some raw representation type *)
    type sample_ty = (int list * RawTypes.ty)

    datatype info = ImgInfo of {
	    id : OS.FileSys.file_id,		(* ID of image file *)
	    dim : int,				(* dimension of space *)
	    ty : sample_ty,			(* types of image samples *)
	    origin : FloatLit.float list,	(* center of first sample *)
	    sizes : int list			(* number of samples along each axis *)
	  }

  (* are the underlying files the same? *)
    val same : info * info -> bool

  (* hash value (based on image file ID) *)
    val hash : info -> word

  (* get image info from a Nrrd file *)
    val getInfo : string -> info

    val toString : info -> string
    val dim : info -> int			(* dimension of space *)

  end = struct

  (* Image samples are tensors of some raw representation type *)
    type sample_ty = (int list * RawTypes.ty)

    datatype info = ImgInfo of {
	    id : OS.FileSys.file_id,		(* ID of image file *)
	    dim : int,				(* dimension of space *)
	    ty : sample_ty,			(* types of image samples *)
	    origin : FloatLit.float list,	(* center of first sample *)
	    sizes : int list			(* number of samples along each axis *)
	  }

    fun same (ImgInfo{id=a, ...}, ImgInfo{id=b, ...}) = (a = b)

    fun hash (ImgInfo{id, ...}) = OS.FileSys.hash id

    fun getInfo fileName = let
(* FIXME: check that file exists! *)
	  val {version, header} = RunDNorm.run fileName
	  fun set (r, v) = (r := SOME v)
	  fun get (tag, r) = (case !r of NONE => raise Fail("missing "^tag) | SOME v => v)
	  val ty = ref NONE
	  val totalDim = ref NONE
	  val dim = ref NONE
	  fun doValue ("type", v) = set(ty, RawTypes.fromString v)
	    | doValue ("dimension", v) = set (totalDim, valOf(Int.fromString v))
	    | doValue ("space dimension", v) = set (dim, valOf(Int.fromString v))
	    | doValue ("sizes", v) = ()
	    | doValue ("space directions", v) = ()
	    | doValue ("kinds", v) = ()
	    | doValue ("endian", v) = ()
	    | doValue ("encoding", v) = ()
	    | doValue ("space origin", v) = ()
	    | doValue _ = ()
	  in
	    Log.msg (concat[fileName, " file header:\n"]);
	    List.app (fn (tag, value) => Log.msg(concat["  ", tag, ": ", value, "\n"])) header;
	    List.app doValue header;
	    ImgInfo{
		id = OS.FileSys.fileId fileName,
		dim = get ("space dimension", dim),
(* FIXME: in general, the type is a tensor of raw values *)
		ty = ([], get ("type", ty)),
		origin = [],	(* FIXME *)
		sizes = []	(* FIXME *)
	      }
	  end

    fun toString (ImgInfo{dim, ...}) = concat["IMAGE", Int.toString dim, "D"] (* FIXME *)

    fun dim (ImgInfo{dim, ...}) = dim

  end

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