--- args <- getArgs
--- let color = head args
- let in_file = "./data/mri.bin"
- let out_file = "output.bmp"
- arr <- read_word16s in_file
- let arrBrack = bracket_array arr
- let arrInv = flip_x $ flip_y arrBrack
- let arrSlice = z_slice 50 arrInv
+ args@Args{..} <- apply_args
+ -- validate_args will simply exit if there's a problem.
+ validate_args args
+
+ -- The first thing we do is set the number of processors. We get the
+ -- number of processors (cores) in the machine with
+ -- getNumProcessors, and set it with setNumCapabilities. This is so
+ -- we don't have to pass +RTS -Nfoo on the command line every time.
+ num_procs <- getNumProcessors
+ setNumCapabilities num_procs
+
+ -- Determine whether we're doing 2d or 3d. If we're given a slice,
+ -- assume 2d.
+ let mri_shape = (R.Z R.:. depth R.:. height R.:. width) :: R.DIM3
+
+ if (isJust slice) then
+ main2d args mri_shape
+ else
+ main3d args mri_shape
+
+ exitSuccess
+
+ where
+
+
+
+main3d :: Args -> R.DIM3 -> IO ()
+main3d Args{..} mri_shape = do
+ let zoom_factor = (scale, scale, scale)
+ arr <- read_word16s input mri_shape
+ let arr' = swap_bytes arr
+ let arrMRI = R.reshape mri_shape arr'
+ dbl_data <- R.computeUnboxedP $ R.map fromIntegral arrMRI
+ raw_output <- zoom dbl_data zoom_factor
+ word16_output <- R.computeUnboxedP $ round_array raw_output
+ write_word16s output word16_output
+
+
+main2d :: Args -> R.DIM3 -> IO ()
+main2d Args{..} mri_shape = do
+ let zoom_factor = (1, scale, scale)
+ arr <- read_word16s input mri_shape
+ arrSlice <- R.computeUnboxedP
+ $ z_slice (fromJust slice)
+ $ flip_x width
+ $ flip_y height
+ $ swap_bytes arr