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 (
34 import System.Console.CmdArgs.Explicit ( process )
35 import System.Environment ( getArgs, withArgs )
36 import System.Exit ( ExitCode(..), exitWith )
37 import System.IO ( hPutStrLn, stderr )
39 import ExitCodes ( exit_arg_parse_failed )
47 lower_threshold :: Int,
51 upper_threshold :: Int,
53 deriving (Show, Data, Typeable)
57 "Interpolate volumetric data according to \"Local quasi-interpolation " ++
58 "by cubic C^1 splines on type-6 tetrahedral partitions.\" The defaults " ++
59 "are tailored to the MRI data contained in data/mri.bin from the " ++
60 "Stanford volume data archive at http://graphics.stanford.edu/data/voldata/."
62 program_name :: String
63 program_name = "spline3"
65 spline3_summary :: String
67 program_name ++ "-" ++ (showVersion version)
74 "The size of the z dimension (default: " ++ (show depth_default) ++ ")"
81 "The size of the y dimension (default: " ++ (show height_default) ++ ")"
83 lower_threshold_default :: Int
84 lower_threshold_default = 1400
86 lower_threshold_help :: String
87 lower_threshold_help =
88 "The lower limit for voxel values, only used in 2D (default: " ++
89 (show lower_threshold_default) ++ ")"
96 "The magnification scale. A scale of 2 would result " ++
97 "in an image twice as large as the original. (default: " ++
98 (show scale_default) ++ ")"
102 "The index of the two-dimensional slice to use if no depth is specified"
104 upper_threshold_default :: Int
105 upper_threshold_default = 2500
107 upper_threshold_help :: String
108 upper_threshold_help =
109 "The upper limit for voxel values, only used in 2D (default: " ++
110 (show upper_threshold_default) ++ ")"
117 "The size of the x dimension (default: " ++ (show width_default) ++ ")"
119 arg_spec :: Mode (CmdArgs Args)
123 depth = depth_default &= groupname "Dimensions" &= help depth_help,
124 height = height_default &= groupname "Dimensions" &= help height_help,
125 input = def &= typ "INPUT" &= argPos 0,
127 lower_threshold = lower_threshold_default &= groupname "2D options"
128 &= help lower_threshold_help,
130 output = def &= typ "OUTPUT" &= argPos 1,
131 scale = scale_default &= help scale_help,
132 slice = Nothing &= groupname "2D options" &= help slice_help,
134 upper_threshold = upper_threshold_default &= groupname "2D options"
135 &= help upper_threshold_help,
137 width = width_default &= groupname "Dimensions" &= help width_help
139 &= program program_name
140 &= summary spline3_summary
141 &= details [description]
142 &= helpArg [groupname "Common flags"]
143 &= versionArg [groupname "Common flags"]
145 -- Infix notation won't work, the arguments are backwards!
146 is_missing_arg_error :: String -> Bool
147 is_missing_arg_error =
148 startswith "Requires at least"
152 show_help = withArgs ["--help"] apply_args
154 parse_args :: IO (CmdArgs Args)
157 let y = process arg_spec x
159 Right result -> return result
161 if (is_missing_arg_error err) then
162 -- Start this function over, pretending that --help was
164 withArgs ["--help"] parse_args
167 exitWith (ExitFailure exit_arg_parse_failed)
170 -- | Really get the command-line arguments. This calls 'parse_args'
171 -- first to replace the default "wrong number of arguments" error,
172 -- and then runs 'cmdArgsApply' on the result to do what the
173 -- 'cmdArgs' function usually does.
174 apply_args :: IO Args
176 parse_args >>= cmdArgsApply