9bbb5853aa8869185268ce7118c9f821bd33134c
[ctsim.git] / libctsim / options.cpp
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: options.cpp,v 1.1 2000/06/19 02:59:34 kevin Exp $
6 **
7 **  This program is free software; you can redistribute it and/or modify
8 **  it under the terms of the GNU General Public License (version 2) as
9 **  published by the Free Software Foundation.
10 **
11 **  This program is distributed in the hope that it will be useful,
12 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 **  GNU General Public License for more details.
15 **
16 **  You should have received a copy of the GNU General Public License
17 **  along with this program; if not, write to the Free Software
18 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 ******************************************************************************/
20 #include "ct.h"
21
22 int 
23 opt_set_trace (const char *optarg)
24 {
25   int opt;
26
27   if (strcmp(optarg, O_TRACE_NONE_STR) == 0)
28     opt = TRACE_NONE;
29   else if (strcmp(optarg, O_TRACE_TEXT_STR) == 0)
30     opt = TRACE_TEXT;
31   else if (strcmp(optarg, O_TRACE_PHM_STR) == 0)
32     opt = TRACE_PHM;
33   else if (strcmp(optarg, O_TRACE_PLOT_STR) == 0)
34     opt = TRACE_PLOT;
35   else if (strcmp(optarg, O_TRACE_CLIPPING_STR) == 0)
36     opt = TRACE_CLIPPING;
37   else if (strcmp(optarg, O_TRACE_RAYS_STR) == 0)
38     opt = TRACE_RAYS;
39   else {
40     sys_error(ERR_WARNING,"Invalid trace option %s\n", optarg);
41     opt = -1;
42   }
43
44   return (opt);
45 }
46
47 const char *
48 name_of_phantom (const int phmnum)
49 {
50   const char *name = "Unknown phantom";
51
52   if (phmnum == O_PHM_HERMAN)
53     name = O_PHM_HERMAN_STR;
54   else if (phmnum == O_PHM_ROWLAND)
55     name = O_PHM_ROWLAND_STR;
56   else if (phmnum == O_PHM_BROWLAND)
57     name = O_PHM_BROWLAND_STR;
58   else if (phmnum == O_PHM_UNITPULSE)
59     name = O_PHM_UNITPULSE_STR;
60
61   return (name);
62 }
63       
64 int 
65 opt_set_phantom (const char *optarg)
66 {
67   int opt;
68
69   if (strcmp(optarg, O_PHM_HERMAN_STR) == 0)
70     opt = O_PHM_HERMAN;
71   else if (strcmp(optarg, O_PHM_ROWLAND_STR) == 0)
72     opt = O_PHM_ROWLAND;
73   else if (strcmp(optarg, O_PHM_BROWLAND_STR) == 0)
74     opt = O_PHM_BROWLAND;
75   else if (strcmp(optarg, O_PHM_UNITPULSE_STR) == 0)
76     opt = O_PHM_UNITPULSE;
77   else {
78     sys_error(ERR_WARNING,"Invalid phantom option %s\n", optarg);
79     opt = -1;
80   }
81
82   return (opt);
83
84 }
85   
86 InterpolationType 
87 opt_set_interpolation (const char *optarg)
88 {
89   InterpolationType opt;
90
91   if (strcmp(optarg, O_INTERP_NEAREST_STR) == 0)
92     opt = I_NEAREST;
93   else if (strcmp(optarg, O_INTERP_LINEAR_STR) == 0)
94     opt = I_LINEAR;
95 #if HAVE_BSPLINE_INTERP
96   else if (strcmp(optarg, O_INTERP_BSPLINE_STR) == 0)
97     opt = I_BSPLINE;
98 #endif
99   else {
100     sys_error(ERR_WARNING, "Invalid interpolation type %s\n", optarg);
101     opt = static_cast<InterpolationType>(-1);
102   }
103     
104   return (opt);
105 }
106
107 FilterType 
108 opt_set_filter (const char *optarg)
109 {
110   FilterType opt;
111
112   if (strcmp(optarg, O_FILTER_BANDLIMIT_STR) == 0)
113     opt = FILTER_BANDLIMIT;
114   else if (strcmp(optarg, O_FILTER_HAMMING_STR) == 0)
115     opt = FILTER_G_HAMMING;
116   else if (strcmp(optarg, O_FILTER_SINC_STR) == 0)
117     opt = FILTER_SINC;
118   else if (strcmp(optarg, O_FILTER_COS_STR) == 0)
119     opt = FILTER_COSINE;
120   else if (strcmp(optarg, O_FILTER_TRIANGLE_STR) == 0)
121     opt = FILTER_TRIANGLE;
122   else if (strcmp(optarg, O_FILTER_ABS_BANDLIMIT_STR) == 0)
123     opt = FILTER_ABS_BANDLIMIT;
124   else if (strcmp(optarg, O_FILTER_ABS_HAMMING_STR) == 0)
125     opt = FILTER_ABS_G_HAMMING;
126   else if (strcmp(optarg, O_FILTER_ABS_SINC_STR) == 0)
127     opt = FILTER_ABS_SINC;
128   else if (strcmp(optarg, O_FILTER_ABS_COS_STR) == 0)
129     opt = FILTER_ABS_COSINE;
130   else if (strcmp(optarg, O_FILTER_SHEPP_STR) == 0)
131     opt = FILTER_SHEPP;
132   else {
133     sys_error(ERR_WARNING, "Invalid filter type %s\n", optarg);
134     opt = static_cast<FilterType>(-1);
135   }
136
137   return (opt);
138 }
139
140 const char *
141 name_of_filter (const int filter)
142 {
143   const char *name = "Unknown filter";
144
145   if (filter == FILTER_SHEPP)
146     name = O_FILTER_SHEPP_STR;
147   else if (filter == FILTER_ABS_COSINE)
148     name = O_FILTER_ABS_COS_STR;
149   else if (filter == FILTER_ABS_SINC)
150     name = O_FILTER_ABS_SINC_STR;
151   else if (filter == FILTER_ABS_G_HAMMING)
152     name = O_FILTER_ABS_HAMMING_STR;
153   else if (filter == FILTER_ABS_BANDLIMIT)
154     name = O_FILTER_ABS_BANDLIMIT_STR;
155   else if (filter == FILTER_COSINE)
156     name = O_FILTER_COS_STR;
157   else if (filter == FILTER_SINC)
158     name = O_FILTER_SINC_STR;
159   else if (filter == FILTER_G_HAMMING)
160     name = O_FILTER_HAMMING_STR;
161   else if (filter == FILTER_BANDLIMIT)
162     name = O_FILTER_BANDLIMIT_STR;
163   else if (filter == FILTER_TRIANGLE)
164     name = O_FILTER_TRIANGLE_STR;
165             
166   return (name);
167 }
168       
169 DomainType
170 opt_set_filter_domain (const char *optarg)
171 {
172   DomainType opt;
173
174   if (strcmp(optarg, D_SPATIAL_STR) == 0)
175     opt = D_SPATIAL;
176   else if (strcmp(optarg, D_FREQ_STR) == 0)
177     opt = D_FREQ;
178   else {
179     sys_error(ERR_WARNING, "Invalid filter domain %s\n", optarg);
180     opt = static_cast<DomainType>(-1);
181   }
182
183   return (opt);
184 }
185
186 const char *
187 name_of_filter_domain (const DomainType domain)
188 {
189   const char *name = "Unknown domain";
190
191   if (domain == D_SPATIAL)
192     return(D_SPATIAL_STR);
193   else if (domain == D_FREQ)
194     return(D_FREQ_STR);
195
196   return (name);
197 }
198
199
200 BackprojType
201 opt_set_backproj (const char *optarg)
202 {
203   BackprojType opt;
204
205   if (strcmp(optarg, O_BPROJ_TRIG_STR) == 0)
206     opt = O_BPROJ_TRIG;
207   else if (strcmp(optarg, O_BPROJ_TABLE_STR) == 0)
208     opt = O_BPROJ_TABLE;
209   else if (strcmp(optarg, O_BPROJ_DIFF_STR) == 0)
210     opt = O_BPROJ_DIFF;
211   else if (strcmp(optarg, O_BPROJ_DIFF2_STR) == 0)
212     opt = O_BPROJ_DIFF2;
213   else if (strcmp(optarg, O_BPROJ_IDIFF2_STR) == 0)
214     opt = O_BPROJ_IDIFF2;
215   else {
216     sys_error(ERR_WARNING, "Invalid backprojection method %s\n", optarg);
217     opt = static_cast<BackprojType>(-1);
218   }
219
220   return (opt);
221 }
222
223 const char *
224 name_of_backproj(const BackprojType bproj)
225 {
226   const char *name = "Unknown backprojection method";
227
228   if (bproj == O_BPROJ_TRIG)
229     name = O_BPROJ_TRIG_STR;
230   else if (bproj == O_BPROJ_TABLE)
231     name = O_BPROJ_TABLE_STR;
232   else if (bproj == O_BPROJ_DIFF)
233     name = O_BPROJ_DIFF_STR;
234   else if (bproj == O_BPROJ_DIFF2)
235     name = O_BPROJ_DIFF2_STR;
236   else if (bproj == O_BPROJ_IDIFF2)
237     name = O_BPROJ_IDIFF2_STR;
238
239   return (name);
240 }
241
242
243
244 /* NAME
245  *      name_of_interp                  Return name of interpolation method
246  *
247  * SYNOPSIS
248  *      name = name_of_interp (interp_type)
249  *      char *name                      Name of interpolation method
250  *      int interp_type                 Method of interpolation
251  *
252  * NOTES
253  *      Returns NULL if interp_type is invalid
254  */
255
256 const char *
257 name_of_interpolation (int interp_type)
258 {
259   if (interp_type == I_NEAREST)
260     return (O_INTERP_NEAREST_STR);
261   else if (interp_type == I_LINEAR)
262     return (O_INTERP_LINEAR_STR);
263 #if HAVE_BSPLINE_INTERP
264   else if (interp_type == I_BSPLINE)
265     return (O_INTERP_BSPLINE_STR);
266 #endif
267   else
268     return ("Unknown interpolation method");
269 }
270
271