From b6ce041d136d56fb3d0638c4abadbae64b94b2e5 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 17 Apr 2012 00:01:40 -0400 Subject: [PATCH] Fix all of the sequential operations with the caveat that it now segfaults. --- src/Grid.hs | 18 +++++++++++------- src/MRI.hs | 16 +++++++++++----- src/Main.hs | 17 +++++++++-------- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/Grid.hs b/src/Grid.hs index 192bbaf..953c6a3 100644 --- a/src/Grid.hs +++ b/src/Grid.hs @@ -118,15 +118,19 @@ zoom_result v3d (sfx, sfy, sfz) (R.Z R.:. m R.:. n R.:. o) = 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 diff --git a/src/MRI.hs b/src/MRI.hs index 094991c..d741091 100644 --- a/src/MRI.hs +++ b/src/MRI.hs @@ -66,7 +66,8 @@ type ColorData sh = Array U sh RGB 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 @@ -123,9 +124,13 @@ write_word16s = R.writeArrayToStorableFile -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 = @@ -149,8 +154,9 @@ z_slice n arr = 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 diff --git a/src/Main.hs b/src/Main.hs index c1456f4..1a71683 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -34,10 +34,11 @@ main3d = do 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 () @@ -46,14 +47,14 @@ main2d = do 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 -- 2.44.2