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