r99: *** empty log message ***
[ctsim.git] / libctsim / dialogs.cpp
diff --git a/libctsim/dialogs.cpp b/libctsim/dialogs.cpp
new file mode 100644 (file)
index 0000000..de12d98
--- /dev/null
@@ -0,0 +1,212 @@
+/*****************************************************************************
+**  This is part of the CTSim program
+**  Copyright (C) 1983-2000 Kevin Rosenberg
+**
+**  $Id: dialogs.cpp,v 1.1 2000/06/19 02:59:34 kevin Exp $
+**
+**  This program is free software; you can redistribute it and/or modify
+**  it under the terms of the GNU General Public License (version 2) as
+**  published by the Free Software Foundation.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+**
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+******************************************************************************/
+
+#include "ct.h"
+
+
+/* NAME
+ *   phm_add_pelem_kb                  Let user specify pelem, and add it to the pic
+ *
+ * SYNOPSIS
+ *   phm_add_pelem_kb (phm)
+ *   Phantom& pic                      PHANTOM that we are to add pelem to
+ *
+ * RETURNS
+ *   true if user added an pelem to PHANTOM
+ *   false if user decided not to add an pelem to the PHANTOM
+ */
+
+bool
+phm_add_pelem_kb (Phantom& phm)
+{
+  int retval = false;
+
+  do {
+    int pelemtype;
+
+    crt_clrline (1);
+    crt_clrline (2);
+    crt_set_cpos (1, 2);
+    crt_put_str ("1 = Rectangle, 2 = Triangle, 3 = Ellipse, 4 = Sector, 5 = Segment");
+    crt_set_cpos (1, 1);
+    crt_put_str ("Enter pelem type (1-5, 0 = no pelem) -- ");
+    scanf ("%d", &pelemtype);
+    crt_clrline (1);
+    crt_clrline (2);
+
+    if (pelemtype < 1) {
+      retval = false;
+    } else {
+      double cx, cy, u, v, rot, dens;
+
+      retval = true;
+      crt_set_cpos (1, 1);
+      crt_put_str ("Enter pelem specs (cx, cy, u, v, rot, density) -- ");
+      scanf ("%lf %lf %lf %lf %lf %lf %*c", &cx, &cy, &u, &v, &rot, &dens);
+      crt_clrline (1);
+      phm.addPelem (phm, pelemtype, cx, cy, u, v, rot, dens);
+    }
+  } while (retval == true);
+  
+  return (true);
+}
+
+const Phantom& phm_select (Phantom& phm)
+{
+  string fname;
+  int phmnum;
+
+  printf ("Which phantom do you want to compile into pixels:\n");
+  printf ("   1 - Herman head phantom\n");
+  printf ("   2 - Rowland head phantom\n");
+  printf ("   3 - \n");
+  printf ("   4 - Rowland head phantom (Bordered)\n");
+  printf ("   6 - A Filter\n");
+  printf ("   7 - Unit pulse\n");
+  printf ("   8 - Enter PHANTOM from file\n");
+  printf ("   9 - Enter PHANTOM from keyboard\n");
+  printf ("Enter the number corresponding to your choice: ");
+  scanf ("%d%*c", &phmnum);
+
+  switch (phmnum) {
+  case 1:
+    phm.std_herman ();
+    break;
+  case 2:
+    phm.std_rowland ();
+    break;
+  case 4:
+    phm.std_rowland_bordered ();
+    break;
+  case 6:
+    phm.setComposition (P_FILTER);
+    break; 
+  case 7:
+    phm.setComposition (P_UNIT_PULSE);
+    phm.addPelem (1, 0., 0., 100., 100., 0., 0.);      /* outline */
+    phm.addPelem (3, 0., 0., 1., 1., 0., 1.);  /* pulse */
+    break;
+  case 8:
+    printf ("Enter name of file: ");
+    scanf ("%s %*c", fname);
+    phm.setComposition (P_PELEMS);
+    if (phm.createFromFile (fname) == false)
+      cerr << "File " << fname << " doesn't contain valid Phantom declaration" << endl;
+    break;
+  case 9:
+    crt_clrscrn ();
+    phm_add_pelem_kb (phm);
+    crt_clrscrn ();
+    break;
+  default:
+    sys_error (ERR_FATAL, "Illegal Phantom number %d\n", phmnum);
+    break;
+  }
+  
+  return (phm);
+}
+
+/* NAME
+ *   interpolation_select              Let user select an interpolation method
+ *
+ * SYNOPSIS
+ *   interpolation_type = interpolation_select()
+ *   int interpolation_type            Method of interpolation to use
+ */
+
+int interpolation_select (void)
+{
+  bool got_it = false;
+
+  do {
+    int interp_type;
+
+    printf ("What interpolation method do you want to use:\n");
+    printf ("   %2d - Nearest neighbor\n", I_NEAREST);
+    printf ("   %2d - Linear\n",           I_LINEAR);
+    printf ("   %2d - B-Spline\n",         I_BSPLINE);
+    printf ("Enter number corresponding to desired method: ");
+    scanf  ("%d", &interp_type);
+    printf ("\n");
+    
+    if (interp_name_of (interp_type) == NULL) {
+      cout << endl;
+      cio_beep ();
+    } else
+      got_it = true;
+    
+  } while (! got_it);
+  
+  return (interp_type);
+}
+
+
+/* NAME
+ *   filter_select                     Let user select a filter
+ *
+ * SYNOPSIS
+ *   filter_type = filt_select (filt_param)
+ *   int filt_type                     Type of filter to use
+ *   double *filt_param                        Returns parameter to filter
+ *                                     Currently, only used with Hamming filters
+ */
+
+int
+filter_select (double *filt_param)
+{
+  bool got_it = false;
+
+  do {
+    int filt_type;
+
+    printf ("Which filter would you like to use:\n");
+    printf ("   %2d - Bandlimiting\n",    FILTER_BANDLIMIT);
+    printf ("   %2d - Sinc\n",            FILTER_SINC);
+    printf ("   %2d - Hamming\n",         FILTER_G_HAMMING);
+    printf ("   %2d - Cosine\n",          FILTER_COSINE);
+    printf ("   %2d - Triangle\n",        FILTER_TRIANGLE);
+    printf ("   %2d - Abs * Bandlimit\n", FILTER_ABS_BANDLIMIT);
+    printf ("   %2d - Abs * Sinc\n",      FILTER_ABS_SINC);
+    printf ("   %2d - Abs * Hamming \n",  FILTER_ABS_G_HAMMING);
+    printf ("   %2d - Abs * Cosine\n",    FILTER_ABS_COSINE);
+    printf ("   %2d - Shepp-Logan\n",     FILTER_SHEPP);
+    printf ("Enter number corresponding to desired filter: ");
+    scanf ("%d", &filt_type);
+
+    if (filter_name_of (filt_type) == NULL) {
+      printf ("\n");
+      cio_beep ();
+    } else
+      got_it = true;
+    
+  } while (! got_it);
+  
+  if (filt_type == FILTER_G_HAMMING || filt_type == FILTER_ABS_G_HAMMING) {
+    cout << "Enter alpha (0-1): " << flush;
+    cin >> *filt_param;
+  } else
+    *filt_param = 0.0;
+
+  return (filt_type);
+}
+
+
+
+