f = polynomial t
-zoom :: Values3D -> ScaleFactor -> Values3D
+--
+-- Instead of IO, we could get away with a generic monad 'm'
+-- here. However, /we/ only call this function from within IO.
+--
+zoom :: Values3D -> ScaleFactor -> IO Values3D
zoom v3d scale_factor
- | xsize == 0 || ysize == 0 || zsize == 0 = empty3d
+ | xsize == 0 || ysize == 0 || zsize == 0 = return empty3d
| otherwise =
- R.computeS $ R.unsafeTraverse v3d transExtent f
- where
- (xsize, ysize, zsize) = dims v3d
- transExtent = zoom_shape scale_factor
- f = zoom_lookup v3d scale_factor
+ R.computeUnboxedP $ R.unsafeTraverse v3d transExtent f
+ where
+ (xsize, ysize, zsize) = dims v3d
+ transExtent = zoom_shape scale_factor
+ f = zoom_lookup v3d scale_factor
-- | Check all coefficients of tetrahedron0 belonging to the cube
read_word16s :: FilePath -> IO RawData3D
read_word16s path = do
arr <- R.readArrayFromStorableFile path mri_shape
- now $ R.copyS arr
+ c <- R.copyP arr
+ now $ c
-values_to_colors :: (Shape sh) => (Values sh) -> (ColorData sh)
+--
+-- Instead of IO, we could get away with a generic monad 'm'
+-- here. However, /we/ only call this function from within IO.
+--
+values_to_colors :: (Shape sh) => (Values sh) -> IO (ColorData sh)
values_to_colors arr =
- R.computeS $ R.map (truncate_rgb . ramp_it) arr
+ R.computeUnboxedP $ R.map (truncate_rgb . ramp_it) arr
where
ramp_it :: Double -> (Double, Double, Double)
ramp_it x =
write_values_slice_to_bitmap :: Values2D -> FilePath -> IO ()
-write_values_slice_to_bitmap v3d path =
+write_values_slice_to_bitmap v3d path = do
+ values <- R.computeUnboxedP $ R.map fromIntegral arr_bracketed
+ colors <- values_to_colors $ values
R.writeImageToBMP path colors
where
arr_bracketed = bracket_array v3d
- colors = values_to_colors $ R.computeS $ R.map fromIntegral arr_bracketed
arr <- read_word16s in_file
let arr' = swap_bytes arr
let arrMRI = R.reshape mri_shape arr'
- let dbl_data = R.computeS $ R.map fromIntegral arrMRI
- let output = zoom dbl_data zoom_factor
- let word16_output = R.computeS $ round_array output
+ dbl_data <- R.computeUnboxedP $ R.map fromIntegral arrMRI
+ output <- zoom dbl_data zoom_factor
+ word16_output <- R.computeUnboxedP $ round_array output
write_word16s out_file word16_output
+ return ()
main2d :: IO ()
let scale = read s :: Int
let zoom_factor = (1, scale, scale)
let out_file = "output.bmp"
- arr <- read_word16s in_file
- let arrSlice = R.computeUnboxedS $ z_slice 50 $ flip_x $ flip_y $ swap_bytes arr
+ arr <- read_word16s in_file
+ arrSlice <- R.computeUnboxedP $ z_slice 50 $ flip_x $ flip_y $ swap_bytes arr
let arrSlice' = R.reshape mri_slice3d arrSlice
-- If zoom isn't being inlined we need to extract the slice before hand,
-- and convert it to the require formed.
- let dbl_data = R.computeS $ R.map fromIntegral arrSlice'
- let output = zoom dbl_data zoom_factor
- let arrSlice0 = R.computeUnboxedS $ z_slice 0 output
+ dbl_data <- R.computeUnboxedP $ R.map fromIntegral arrSlice'
+ output <- zoom dbl_data zoom_factor
+ arrSlice0 <- R.computeUnboxedP $ z_slice 0 output
write_values_slice_to_bitmap arrSlice0 out_file