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 (
35 import System.Console.CmdArgs.Explicit (process)
36 import System.Environment (getArgs, withArgs)
37 import System.Exit (ExitCode(..), exitWith)
38 import System.IO (hPutStrLn, stderr)
48 lower_threshold :: Int,
52 upper_threshold :: Int,
54 deriving (Show, Data, Typeable)
58 "Interpolate volumetric data according to \"Local quasi-interpolation " ++
59 "by cubic C^1 splines on type-6 tetrahedral partitions.\" The defaults " ++
60 "are tailored to the MRI data contained in data/mri.bin from the " ++
61 "Stanford volume data archive at http://graphics.stanford.edu/data/voldata/."
63 program_name :: String
64 program_name = "spline3"
66 spline3_summary :: String
68 program_name ++ "-" ++ (showVersion version)
75 "The size of the z dimension (default: " ++ (show depth_default) ++ ")"
82 "The size of the y dimension (default: " ++ (show height_default) ++ ")"
84 lower_threshold_default :: Int
85 lower_threshold_default = 1400
87 lower_threshold_help :: String
88 lower_threshold_help =
89 "The lower limit for voxel values, only used in 2D (default: " ++
90 (show lower_threshold_default) ++ ")"
97 "The magnification scale. A scale of 2 would result " ++
98 "in an image twice as large as the original. (default: " ++
99 (show scale_default) ++ ")"
103 "The index of the two-dimensional slice to use if no depth is specified"
105 upper_threshold_default :: Int
106 upper_threshold_default = 2500
108 upper_threshold_help :: String
109 upper_threshold_help =
110 "The upper limit for voxel values, only used in 2D (default: " ++
111 (show upper_threshold_default) ++ ")"
118 "The size of the x dimension (default: " ++ (show width_default) ++ ")"
120 arg_spec :: Mode (CmdArgs Args)
124 depth = depth_default &= groupname "Dimensions" &= help depth_help,
125 height = height_default &= groupname "Dimensions" &= help height_help,
126 input = def &= typ "INPUT" &= argPos 0,
128 lower_threshold = lower_threshold_default &= groupname "2D options"
129 &= help lower_threshold_help,
131 output = def &= typ "OUTPUT" &= argPos 1,
132 scale = scale_default &= help scale_help,
133 slice = Nothing &= groupname "2D options" &= help slice_help,
135 upper_threshold = upper_threshold_default &= groupname "2D options"
136 &= help upper_threshold_help,
138 width = width_default &= groupname "Dimensions" &= help width_help
140 &= program program_name
141 &= summary spline3_summary
142 &= details [description]
143 &= helpArg [groupname "Common flags"]
144 &= versionArg [groupname "Common flags"]
146 -- Infix notation won't work, the arguments are backwards!
147 is_missing_arg_error :: String -> Bool
148 is_missing_arg_error s =
149 startswith "Requires at least" s
153 show_help = withArgs ["--help"] apply_args
155 parse_args :: IO (CmdArgs Args)
158 let y = process arg_spec x
160 Right result -> return result
162 if (is_missing_arg_error err) then
163 -- Start this function over, pretending that --help was
165 withArgs ["--help"] parse_args
168 exitWith (ExitFailure exit_arg_parse_failed)
171 -- | Really get the command-line arguments. This calls 'parse_args'
172 -- first to replace the default "wrong number of arguments" error,
173 -- and then runs 'cmdArgsApply' on the result to do what the
174 -- 'cmdArgs' function usually does.
175 apply_args :: IO Args
177 parse_args >>= cmdArgsApply