From 5de566481cadea0f1e258657ee2697ad643b77d5 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 15 Apr 2015 21:37:34 -0400 Subject: [PATCH] Import cleanup in Volumetric. --- src/Volumetric.hs | 65 ++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/src/Volumetric.hs b/src/Volumetric.hs index 24bc13b..5b24760 100644 --- a/src/Volumetric.hs +++ b/src/Volumetric.hs @@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts #-} + -- | The Volumetric module contains functions for manipulating the -- volumetric data files found at, -- @@ -13,21 +14,37 @@ module Volumetric ( swap_bytes, write_values_to_bmp, write_word16s, - z_slice - ) + z_slice ) where -import Data.Word -import Data.Bits -import Data.Array.Repa as R -import Data.Array.Repa.Eval as R (now) -import Data.Array.Repa.Repr.Unboxed as R -import Data.Array.Repa.IO.Binary as R -import Data.Array.Repa.Algorithms.ColorRamp as R -import Data.Array.Repa.Operators.Traversal as R (unsafeTraverse) -import Data.Array.Repa.IO.BMP as R (writeImageToBMP) +import Data.Word ( Word8, Word16 ) +import Data.Bits ( (.&.), (.|.), shift ) +import qualified Data.Array.Repa as Repa ( map ) +import Data.Array.Repa ( + (:.)( (:.) ), + Array, + D, + DIM2, + DIM3, + Shape, + Source, + U, + Z( Z ), + computeUnboxedP, + copyP, + slice ) +import Data.Array.Repa.Algorithms.ColorRamp ( rampColorHotToCold ) +import Data.Array.Repa.Eval ( now ) +import Data.Array.Repa.IO.Binary ( + readArrayFromStorableFile, + writeArrayToStorableFile ) +import Data.Array.Repa.IO.BMP ( writeImageToBMP ) +import Data.Array.Repa.Operators.Traversal ( unsafeTraverse ) +import Data.Array.Repa.Repr.Unboxed ( Unbox ) +import Data.Array.Repa.Slice ( All( All ), Any( Any ) ) + +import Values ( Values, Values2D ) -import Values -- | RawData is an array of words (16 bits), as contained in the -- volumetric data files. @@ -43,9 +60,9 @@ type ColorData sh = Array U sh RGB {-# INLINE read_word16s #-} read_word16s :: FilePath -> DIM3 -> IO RawData3D read_word16s path shape = do - arr <- R.readArrayFromStorableFile path shape - c <- R.copyP arr - now $ c + arr <- readArrayFromStorableFile path shape + c <- copyP arr + now c @@ -69,36 +86,36 @@ flip16 xx = swap_bytes :: (Shape sh, Source r Word16) => Array r sh Word16 -> Array D sh Word16 swap_bytes = - R.map flip16 + Repa.map flip16 bracket_array :: Shape sh => Double -> Double -> Values sh -> Array D sh Word16 bracket_array lt ut = - R.map (bracket lt ut) + Repa.map (bracket lt ut) {-# INLINE round_array #-} round_array :: Shape sh => Values sh -> Array D sh Word16 round_array = - R.map round + Repa.map round flip_y :: Source r Word16 => Int -> Array r DIM3 Word16 -> Array D DIM3 Word16 flip_y height arr = - R.unsafeTraverse arr id + unsafeTraverse arr id (\get (Z :. z :. y :. x) -> get (Z :. z :. (height - 1) - y :. x)) flip_x :: Source r Word16 => Int -> Array r DIM3 Word16 -> Array D DIM3 Word16 flip_x width arr = - R.unsafeTraverse arr id + unsafeTraverse arr id (\get (Z :. z :. y :. x) -> get (Z :. z :. y :. (width - 1) - x)) {-# INLINE write_word16s #-} write_word16s :: (Shape sh) => FilePath -> (RawData sh) -> IO () -write_word16s = R.writeArrayToStorableFile +write_word16s = writeArrayToStorableFile @@ -108,7 +125,7 @@ write_word16s = R.writeArrayToStorableFile -- values_to_colors :: (Shape sh) => (Values sh) -> IO (ColorData sh) values_to_colors arr = - R.computeUnboxedP $ R.map (truncate_rgb . ramp_it) arr + computeUnboxedP $ Repa.map (truncate_rgb . ramp_it) arr where ramp_it :: Double -> (Double, Double, Double) ramp_it x = @@ -129,9 +146,9 @@ values_to_colors arr = write_values_to_bmp :: FilePath -> Values2D -> IO () write_values_to_bmp path values = do colors <- values_to_colors values - R.writeImageToBMP path colors + writeImageToBMP path colors -z_slice :: (R.Unbox a, Source r a) => Int -> Array r DIM3 a -> Array D DIM2 a +z_slice :: (Unbox a, Source r a) => Int -> Array r DIM3 a -> Array D DIM2 a z_slice n arr = slice arr (Any :. n :. All :. All) -- 2.44.2