r164: *** empty log message ***
[ctsim.git] / libctsim / projections.cpp
index 3a071b478bceb2f25761068260791512d3f32ca7..7d3e814967394d885dd3b494ea0c626f351157df 100644 (file)
@@ -8,7 +8,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: projections.cpp,v 1.7 2000/06/29 12:39:46 kevin Exp $
+**  $Id: projections.cpp,v 1.18 2000/07/29 19:50:08 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
@@ -208,7 +208,6 @@ Projections::headerRead (fnetorderstream& fs)
   if (! fs)
       return false;
 
-  off_t testPos;
   fs.readInt16 (_hsize);
   fs.readInt16 (_signature);
   fs.readInt32 (_nView);
@@ -366,7 +365,7 @@ Projections::detarrayRead (fnetorderstream& fs, DetectorArray& darray, const int
   darray.setViewAngle (view_angle);
   //  darray.setNDet ( nDet);
   
-  for (int i = 0; i < nDet; i++) {
+  for (unsigned int i = 0; i < nDet; i++) {
       kfloat32 detval;
       fs.readFloat32 (detval);
       detval_ptr[i] = detval;
@@ -412,7 +411,7 @@ Projections::detarrayWrite (fnetorderstream& fs, const DetectorArray& darray, co
   fs.writeFloat64 (view_angle);
   fs.writeInt32 (nDet);
 
-  for (int i = 0; i < nDet; i++) {
+  for (unsigned int i = 0; i < nDet; i++) {
     kfloat32 detval = detval_ptr[i];
     fs.writeFloat32 (detval);
   }
@@ -487,30 +486,26 @@ Projections::printScanInfo (void) const
  */
 
 bool
-Projections::reconstruct (ImageFile& im, const char* const filterName, double filt_param, const char* const filterMethodName, const char* const interpName, int interp_param, const char* const backprojectName, const int trace)
+Projections::reconstruct (ImageFile& im, const char* const filterName, double filt_param, const char* const filterMethodName, const int zeropad, const char* const interpName, int interpFactor, const char* const backprojectName, const int trace) const
 {
-  int nview = m_nView;
-  double det_inc = m_detInc;
-  double detlen = (m_nDet - 1) * det_inc;
-  int n_filtered_proj = m_nDet;
-  double filtered_proj [n_filtered_proj];   // convolved result
+  double detInc = m_detInc;
+  int n_filteredProj = m_nDet * interpFactor;
+  double filteredProj [n_filteredProj];   // filtered projections
 
 #ifdef HAVE_BSPLINE_INTERP
   int spline_order = 0, zoom_factor = 0;
   if (interp_type == I_BSPLINE) {
-    zoom_factor = interp_param;
+    zoom_factor = interpFactor;
     spline_order = 3;
     zoom_factor = 3;
-    n_filtered_proj = (m_nDet - 1) * (zoom_factor + 1) + 1;
+    n_filteredProj = (m_nDet - 1) * (zoom_factor + 1) + 1;
   }
 #endif
 
-  int n_vec_filter = 2 * m_nDet - 1;
-  double filterBW = 1. / det_inc;
-  double filterMin = -detlen;
-  double filterMax = detlen;
+  double filterBW = 1. / detInc;
+  SignalFilter filter (filterName, filterMethodName, filterBW, m_detInc, m_nDet, filt_param, "spatial", zeropad, interpFactor);
+  filter.setTraceLevel(trace);
 
-  SignalFilter filter (filterName, filterBW, filterMin, filterMax, n_vec_filter, filt_param, "spatial", 0);
   if (filter.fail()) {
       sys_error (ERR_SEVERE, "%s [Projections::reconstruct]", filter.failMessage().c_str());
       return false;
@@ -520,27 +515,34 @@ Projections::reconstruct (ImageFile& im, const char* const filterName, double fi
     cout << "Reconstruct: filter="<<filterName<< ", interp="<<interpName<<", backproject="<<backprojectName<<endl;
 
 #if HAVE_SGP
-  SGP_ID gid;
-  double plot_xaxis [n_vec_filter];                    // array for plotting 
+  int nVecFilter = filter.getNFilterPoints();
+  double plot_xaxis [nVecFilter];                      // array for plotting 
 
-  if (trace > TRACE_TEXT)  {
+  if (trace > TRACE_TEXT && nVecFilter > 0)  {
     int i;
     double f;
-    double filterInc = (filterMax - filterMin) / (n_vec_filter - 1);
-    for (i = 0, f = filterMin; i < n_vec_filter; i++, f += filterInc)
+    double filterInc = filter.getFilterIncrement();
+    for (i = 0, f = filter.getFilterMin(); i < nVecFilter; i++, f += filterInc)
       plot_xaxis[i] = f;
-      
-    gid = ezplot (plot_xaxis, filter.getFilter(), n_vec_filter);
-    cio_put_str ("Press any key to continue");
-    cio_kb_getc ();
-    sgp2_close (gid);
+
+    if (filter.getFilter()) {
+      SGPDriver sgpDriver ("Filter Function");
+      SGP sgp (sgpDriver);
+      EZPlot ezplot (sgp);
+
+      ezplot.ezset ("title Filter Response");
+      ezplot.addCurve (plot_xaxis, filter.getFilter(), nVecFilter);
+      ezplot.plot();
+      cio_put_str ("Press any key to continue");
+      cio_kb_getc ();
+    }
   }
   if (trace >= TRACE_TEXT) {
-    printf ("nview=%d, ndet=%d, det_start=%.4f, det_inc=%.4f\n", m_nView, m_nDet, m_detStart, m_detInc);
+    printf ("nview=%d, ndet=%d, det_start=%.4f, detInc=%.4f\n", m_nView, m_nDet, m_detStart, m_detInc);
   }
 #endif  //HAVE_SGP
 
-  Backprojector bj (*this, im, backprojectName, interpName);
+  Backprojector bj (*this, im, backprojectName, interpName, interpFactor);
   if (bj.fail()) {
     sys_error (ERR_SEVERE, "%s [Projections::reconstruct]", bj.failMessage().c_str());
     return false;
@@ -550,56 +552,57 @@ Projections::reconstruct (ImageFile& im, const char* const filterName, double fi
     if (trace >= TRACE_TEXT) 
       printf ("Reconstructing view %d (last = %d)\n",  iview, m_nView - 1);
       
-    DetectorArray& darray = getDetectorArray (iview);
-    DetectorValue* detval = darray.detValues();
+    const DetectorArray& darray = getDetectorArray (iview);
+    const DetectorValue* detval = darray.detValues();
+
+    filter.filterSignal (detval, filteredProj);
 
-    for (int j = 0; j < m_nDet; j++)
-      filtered_proj[j] = filter.convolve (detval, det_inc, j, m_nDet);
 
-#ifdef HAVE_SGP
-    if (trace >= TRACE_PLOT)  {
-      ezset  ("clear.");
-      ezset  ("xticks major 5.");
-      ezset  ("xlabel ");
-      ezset  ("ylabel ");
-      ezset  ("xlength .5.");
-      ezset  ("box.");
-      ezset  ("grid.");
-      ezset  ("ufinish yes.");
-      ezplot (detval, plot_xaxis, m_nDet);
-      ezset  ("clear.");
-      ezset  ("xticks major 5.");
-      ezset  ("xlabel ");
-      ezset  ("ylabel ");
-      ezset  ("ustart yes.");
-      ezset  ("xporigin .5.");
-      ezset  ("xlength .5.");
-      ezset ("box");
-      ezset ("grid");
-      gid = ezplot (filtered_proj, plot_xaxis, m_nDet);
-    }
-#endif  //HAVE_SGP
 
 #ifdef HAVE_BSPLINE_INTERP
     if (interp_type == I_BSPLINE) 
-       bspline (m_nDet, zoom_factor, spline_order, filtered_proj, filtered_proj);
+       bspline (m_nDet, zoom_factor, spline_order, filteredProj, filteredProj);
     
 #ifdef HAVE_SGP
     if (trace >= TRACE_PLOT && interp_type == I_BSPLINE) {
-       bspline (m_nDet, zoom_factor, spline_order, filtered_proj, filtered_proj);
-      ezplot_1d (filtered_proj, n_filtered_proj);
+       bspline (m_nDet, zoom_factor, spline_order, filteredProj, filteredProj);
+      ezplot_1d (filteredProj, n_filteredProj);
     }
 #endif
 #endif
 
-    bj.BackprojectView (filtered_proj, darray.viewAngle());
+    bj.BackprojectView (filteredProj, darray.viewAngle());
 
 #ifdef HAVE_SGP
     if (trace >= TRACE_PLOT) {
+      SGPDriver sgpDriverProj ("Projection");
+      SGP sgpProj (sgpDriverProj);
+      EZPlot ezplotProj (sgpProj);
+
+      ezplotProj.ezset  ("clear");
+      ezplotProj.ezset ("title Filtered Projection");
+      ezplotProj.ezset  ("xticks major 5.");
+      ezplotProj.ezset  ("xlabel ");
+      ezplotProj.ezset  ("ylabel ");
+      ezplotProj.ezset  ("yporigin .5.");
+      ezplotProj.ezset  ("ylength .5.");
+      ezplotProj.ezset  ("box.");
+      ezplotProj.ezset  ("grid.");
+      ezplotProj.addCurve (plot_xaxis, detval, m_nDet);
+      ezplotProj.plot();
+      ezplotProj.ezset  ("clear");
+      ezplotProj.ezset  ("xticks major 5.");
+      ezplotProj.ezset  ("xlabel ");
+      ezplotProj.ezset  ("ylabel ");
+      ezplotProj.ezset  ("ylength .5.");
+      ezplotProj.ezset ("box");
+      ezplotProj.ezset ("grid");
+      ezplotProj.addCurve (plot_xaxis, filteredProj,  n_filteredProj);
+      ezplotProj.plot();
+
+      cout << "Do you want to exit with current pic (y/n)? " << flush;
       char str[256];
-      printf ("Do you want to exit with current pic (y/n) -- ");
       fgets(str, sizeof(str), stdin);
-      sgp2_close (sgp2_get_active_win());
       if (tolower(str[0]) == 'y') {
        break;
       }