1 {-# LANGUAGE DeriveDataTypeable #-}
10 -- Get the version from Cabal.
11 import Paths_spline3 ( version )
12 import Data.Version ( showVersion )
14 import Data.String.Utils ( startswith )
15 import System.Console.CmdArgs (
33 import System.Console.CmdArgs.Explicit ( process )
34 import System.Environment ( getArgs, withArgs )
35 import System.Exit ( ExitCode( ExitFailure ), exitWith )
36 import System.IO ( hPutStrLn, stderr )
38 import ExitCodes ( exit_arg_parse_failed )
46 lower_threshold :: Int,
50 upper_threshold :: Int,
56 "Interpolate volumetric data according to \"Local quasi-interpolation " ++
57 "by cubic C^1 splines on type-6 tetrahedral partitions.\" The defaults " ++
58 "are tailored to the MRI data contained in data/mri.bin from the " ++
59 "Stanford volume data archive at http://graphics.stanford.edu/data/voldata/."
61 program_name :: String
62 program_name = "spline3"
64 spline3_summary :: String
66 program_name ++ "-" ++ (showVersion version)
73 "The size of the z dimension (default: " ++ (show depth_default) ++ ")"
80 "The size of the y dimension (default: " ++ (show height_default) ++ ")"
82 lower_threshold_default :: Int
83 lower_threshold_default = 1400
85 lower_threshold_help :: String
86 lower_threshold_help =
87 "The lower limit for voxel values, only used in 2D (default: " ++
88 (show lower_threshold_default) ++ ")"
95 "The magnification scale. A scale of 2 would result " ++
96 "in an image twice as large as the original. (default: " ++
97 (show scale_default) ++ ")"
101 "The index of the two-dimensional slice to use if no depth is specified"
103 upper_threshold_default :: Int
104 upper_threshold_default = 2500
106 upper_threshold_help :: String
107 upper_threshold_help =
108 "The upper limit for voxel values, only used in 2D (default: " ++
109 (show upper_threshold_default) ++ ")"
116 "The size of the x dimension (default: " ++ (show width_default) ++ ")"
118 arg_spec :: Mode (CmdArgs Args)
122 depth = depth_default &= groupname "Dimensions" &= help depth_help,
123 height = height_default &= groupname "Dimensions" &= help height_help,
124 input = def &= typ "INPUT" &= argPos 0,
126 lower_threshold = lower_threshold_default &= groupname "2D options"
127 &= help lower_threshold_help,
129 output = def &= typ "OUTPUT" &= argPos 1,
130 scale = scale_default &= help scale_help,
131 slice = Nothing &= groupname "2D options" &= help slice_help,
133 upper_threshold = upper_threshold_default &= groupname "2D options"
134 &= help upper_threshold_help,
136 width = width_default &= groupname "Dimensions" &= help width_help
138 &= program program_name
139 &= summary spline3_summary
140 &= details [description]
141 &= helpArg [groupname "Common flags"]
142 &= versionArg [groupname "Common flags"]
144 -- Infix notation won't work, the arguments are backwards!
145 is_missing_arg_error :: String -> Bool
146 is_missing_arg_error =
147 startswith "Requires at least"
151 show_help = withArgs ["--help"] apply_args
153 parse_args :: IO (CmdArgs Args)
156 let y = process arg_spec x
158 Right result -> return result
160 if (is_missing_arg_error err) then
161 -- Start this function over, pretending that --help was
163 withArgs ["--help"] parse_args
166 exitWith (ExitFailure exit_arg_parse_failed)
169 -- | Really get the command-line arguments. This calls 'parse_args'
170 -- first to replace the default "wrong number of arguments" error,
171 -- and then runs 'cmdArgsApply' on the result to do what the
172 -- 'cmdArgs' function usually does.
173 apply_args :: IO Args
175 parse_args >>= cmdArgsApply