r118: *** empty log message ***
[ctsim.git] / libctsim / dialogs.cpp
1 /*****************************************************************************
2 **  This is part of the CTSim program
3 **  Copyright (C) 1983-2000 Kevin Rosenberg
4 **
5 **  $Id: dialogs.cpp,v 1.2 2000/06/22 10:42:39 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
21 #include "ct.h"
22
23 /*************************************************************************
24  *  FUNCTION DECLARATIONS
25  ************************************************************************/
26
27 // dialogs.cpp 
28 bool phm_add_pelem_kb (Phantom& phm);
29 const Phantom& phm_select (Phantom& phm);
30 int interpolation_select (void);
31 int filter_select (double *filter_param);
32
33
34 /* NAME
35  *   phm_add_pelem_kb                   Let user specify pelem, and add it to the pic
36  *
37  * SYNOPSIS
38  *   phm_add_pelem_kb (phm)
39  *   Phantom& pic                       PHANTOM that we are to add pelem to
40  *
41  * RETURNS
42  *   true if user added an pelem to PHANTOM
43  *   false if user decided not to add an pelem to the PHANTOM
44  */
45
46 bool
47 phm_add_pelem_kb (Phantom& phm)
48 {
49   int retval = false;
50
51   do {
52     int pelemtype;
53
54     crt_clrline (1);
55     crt_clrline (2);
56     crt_set_cpos (1, 2);
57     crt_put_str ("1 = Rectangle, 2 = Triangle, 3 = Ellipse, 4 = Sector, 5 = Segment");
58     crt_set_cpos (1, 1);
59     crt_put_str ("Enter pelem type (1-5, 0 = no pelem) -- ");
60     scanf ("%d", &pelemtype);
61     crt_clrline (1);
62     crt_clrline (2);
63
64     if (pelemtype < 1) {
65       retval = false;
66     } else {
67       double cx, cy, u, v, rot, dens;
68
69       retval = true;
70       crt_set_cpos (1, 1);
71       crt_put_str ("Enter pelem specs (cx, cy, u, v, rot, density) -- ");
72       scanf ("%lf %lf %lf %lf %lf %lf %*c", &cx, &cy, &u, &v, &rot, &dens);
73       crt_clrline (1);
74       phm.addPelem (phm, pelemtype, cx, cy, u, v, rot, dens);
75     }
76   } while (retval == true);
77   
78   return (true);
79 }
80
81 const Phantom& phm_select (Phantom& phm)
82 {
83   string fname;
84   int phmnum;
85
86   printf ("Which phantom do you want to compile into pixels:\n");
87   printf ("   1 - Herman head phantom\n");
88   printf ("   2 - Rowland head phantom\n");
89   printf ("   3 - \n");
90   printf ("   4 - Rowland head phantom (Bordered)\n");
91   printf ("   6 - A Filter\n");
92   printf ("   7 - Unit pulse\n");
93   printf ("   8 - Enter PHANTOM from file\n");
94   printf ("   9 - Enter PHANTOM from keyboard\n");
95   printf ("Enter the number corresponding to your choice: ");
96   scanf ("%d%*c", &phmnum);
97
98   switch (phmnum) {
99   case 1:
100     phm.std_herman ();
101     break;
102   case 2:
103     phm.std_rowland ();
104     break;
105   case 4:
106     phm.std_rowland_bordered ();
107     break;
108   case 6:
109     phm.setComposition (P_FILTER);
110     break; 
111   case 7:
112     phm.setComposition (P_UNIT_PULSE);
113     phm.addPelem (1, 0., 0., 100., 100., 0., 0.);       /* outline */
114     phm.addPelem (3, 0., 0., 1., 1., 0., 1.);   /* pulse */
115     break;
116   case 8:
117     printf ("Enter name of file: ");
118     scanf ("%s %*c", fname);
119     phm.setComposition (P_PELEMS);
120     if (phm.createFromFile (fname) == false)
121       cerr << "File " << fname << " doesn't contain valid Phantom declaration" << endl;
122     break;
123   case 9:
124     crt_clrscrn ();
125     phm_add_pelem_kb (phm);
126     crt_clrscrn ();
127     break;
128   default:
129     sys_error (ERR_FATAL, "Illegal Phantom number %d\n", phmnum);
130     break;
131   }
132   
133   return (phm);
134 }
135
136 /* NAME
137  *   interpolation_select               Let user select an interpolation method
138  *
139  * SYNOPSIS
140  *   interpolation_type = interpolation_select()
141  *   int interpolation_type             Method of interpolation to use
142  */
143
144 int interpolation_select (void)
145 {
146   bool got_it = false;
147
148   do {
149     int interp_type;
150
151     printf ("What interpolation method do you want to use:\n");
152     printf ("   %2d - Nearest neighbor\n", I_NEAREST);
153     printf ("   %2d - Linear\n",           I_LINEAR);
154     printf ("   %2d - B-Spline\n",         I_BSPLINE);
155     printf ("Enter number corresponding to desired method: ");
156     scanf  ("%d", &interp_type);
157     printf ("\n");
158     
159     if (interp_name_of (interp_type) == NULL) {
160       cout << endl;
161       cio_beep ();
162     } else
163       got_it = true;
164     
165   } while (! got_it);
166   
167   return (interp_type);
168 }
169
170
171 /* NAME
172  *   filter_select                      Let user select a filter
173  *
174  * SYNOPSIS
175  *   filter_type = filt_select (filt_param)
176  *   int filt_type                      Type of filter to use
177  *   double *filt_param                 Returns parameter to filter
178  *                                      Currently, only used with Hamming filters
179  */
180
181 int
182 filter_select (double *filt_param)
183 {
184   bool got_it = false;
185
186   do {
187     int filt_type;
188
189     printf ("Which filter would you like to use:\n");
190     printf ("   %2d - Bandlimiting\n",    FILTER_BANDLIMIT);
191     printf ("   %2d - Sinc\n",            FILTER_SINC);
192     printf ("   %2d - Hamming\n",         FILTER_G_HAMMING);
193     printf ("   %2d - Cosine\n",          FILTER_COSINE);
194     printf ("   %2d - Triangle\n",        FILTER_TRIANGLE);
195     printf ("   %2d - Abs * Bandlimit\n", FILTER_ABS_BANDLIMIT);
196     printf ("   %2d - Abs * Sinc\n",      FILTER_ABS_SINC);
197     printf ("   %2d - Abs * Hamming \n",  FILTER_ABS_G_HAMMING);
198     printf ("   %2d - Abs * Cosine\n",    FILTER_ABS_COSINE);
199     printf ("   %2d - Shepp-Logan\n",     FILTER_SHEPP);
200     printf ("Enter number corresponding to desired filter: ");
201     scanf ("%d", &filt_type);
202
203     if (filter_name_of (filt_type) == NULL) {
204       printf ("\n");
205       cio_beep ();
206     } else
207       got_it = true;
208     
209   } while (! got_it);
210   
211   if (filt_type == FILTER_G_HAMMING || filt_type == FILTER_ABS_G_HAMMING) {
212     cout << "Enter alpha (0-1): " << flush;
213     cin >> *filt_param;
214   } else
215     *filt_param = 0.0;
216
217   return (filt_type);
218 }
219
220
221
222