- putStrLn $ show $ find_point_value (0,0,0)
- putStrLn $ show $ find_point_value (1,0,0)
- putStrLn $ show $ find_point_value (2,0,0)
- putStrLn $ show $ find_point_value (0,1,0)
- putStrLn $ show $ find_point_value (1,1,0)
- putStrLn $ show $ find_point_value (2,1,0)
- putStrLn $ show $ find_point_value (0,2,0)
- putStrLn $ show $ find_point_value (1,2,0)
- putStrLn $ show $ find_point_value (2,2,0)
- putStrLn $ show $ find_point_value (0,0,1)
- putStrLn $ show $ find_point_value (1,0,1)
- putStrLn $ show $ find_point_value (2,0,1)
- putStrLn $ show $ find_point_value (0,1,1)
- putStrLn $ show $ find_point_value (1,1,1)
- putStrLn $ show $ find_point_value (2,1,1)
- putStrLn $ show $ find_point_value (0,2,1)
- putStrLn $ show $ find_point_value (1,2,1)
- putStrLn $ show $ find_point_value (2,2,1)
- putStrLn $ show $ find_point_value (0,0,2)
- putStrLn $ show $ find_point_value (1,0,2)
- putStrLn $ show $ find_point_value (2,0,2)
- putStrLn $ show $ find_point_value (0,1,2)
- putStrLn $ show $ find_point_value (1,1,2)
- putStrLn $ show $ find_point_value (2,1,2)
- putStrLn $ show $ find_point_value (0,2,2)
- putStrLn $ show $ find_point_value (1,2,2)
- putStrLn $ show $ find_point_value (2,2,2)
- -- let g0 = make_grid 1 trilinear
- -- let the_cubes = flatten (cubes g0)
- -- putStrLn $ show $ the_cubes
- -- let p = (2, 0, 0)
- -- let target_cubes = filter ((flip contains_point) p) the_cubes
- -- putStrLn $ show $ target_cubes
- -- let target_cube = (take 1 target_cubes) !! 0
- -- putStrLn $ show $ target_cube
- -- let target_tetrahedra = filter ((flip contains_point) p) (tetrahedrons target_cube)
- -- let target_tetrahedron = (take 1 target_tetrahedra) !! 0
- -- putStrLn $ show $ target_tetrahedron
- -- let poly = polynomial target_tetrahedron
- -- putStrLn $ show $ poly
- -- putStrLn $ show $ poly p
+ 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
+
+ let shape = (R.Z R.:. depth R.:. height R.:. width) :: R.DIM3
+
+ -- Determine whether we're doing 2d or 3d. If we're given a slice,
+ -- assume 2d.
+ let main_function = case slice of
+ Nothing -> main3d
+ Just _ -> main2d
+
+ main_function args shape
+ exitSuccess
+
+
+main3d :: Args -> R.DIM3 -> IO ()
+main3d Args{..} shape = do
+ let zoom_factor = (scale, scale, scale)
+ arr <- read_word16s input shape
+ let arr_swapped = swap_bytes arr
+ let arr_shaped = R.reshape shape arr_swapped
+ dbl_data <- R.computeUnboxedP $ R.map fromIntegral arr_shaped
+ raw_output <- zoom dbl_data zoom_factor
+ let word16_output = round_array raw_output
+ -- Switch the bytes order back to what it was. This lets us use the
+ -- same program to view the input/output data.
+ swapped_output <- R.computeUnboxedP $ swap_bytes word16_output
+ write_word16s output swapped_output
+
+
+main2d :: Args -> R.DIM3 -> IO ()
+main2d Args{..} shape = do
+ let zoom_factor = (1 :: Int, scale, scale)
+ arr <- read_word16s input shape
+ arrSlice <- R.computeUnboxedP
+ $ z_slice (fromJust slice)
+ $ flip_x width
+ $ flip_y height
+ $ swap_bytes arr
+ let arrSlice' = R.reshape slice3d arrSlice
+
+ -- If zoom isn't being inlined we need to extract the slice before hand,
+ -- and convert it to the require formed.
+ dbl_data <- R.computeUnboxedP $ R.map fromIntegral arrSlice'
+ raw_output <- zoom dbl_data zoom_factor
+ arrSlice0 <- R.computeUnboxedP $ z_slice 0 raw_output
+
+ -- Make doubles from the thresholds which are given as Ints.
+ let lt = fromIntegral lower_threshold :: Double
+ let ut = fromIntegral upper_threshold :: Double
+
+ let arr_bracketed = bracket_array lt ut arrSlice0
+ values <- R.computeUnboxedP $ R.map fromIntegral arr_bracketed
+ write_values_to_bmp output values
+
+ where
+ slice3d :: R.DIM3
+ slice3d = (R.Z R.:. 1 R.:. height R.:. width)