r591: Added Center-Detector length to scanning and reconstruction
[ctsim.git] / libctsim / reconstruct.cpp
index 591aed28282888f9441c2e190b1a5a38093740d5..0c5cf0eb925c4e2a2a25028d637766856d422d2e 100644 (file)
@@ -6,9 +6,9 @@
 **   Date Started: Aug 84
 **
 **  This is part of the CTSim program
-**  Copyright (C) 1983-2000 Kevin Rosenberg
+**  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: reconstruct.cpp,v 1.3 2000/12/16 02:44:26 kevin Exp $
+**  $Id: reconstruct.cpp,v 1.15 2001/03/01 07:30:49 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
  */
 
 
-Reconstructor::Reconstructor (const Projections& rProj, ImageFile& rIF, const char* const filterName, double filt_param, const char* const filterMethodName, const int zeropad, const char* filterGenerationName, const char* const interpName, int interpFactor, const char* const backprojectName, const int iTrace, SGP* pSGP)
-  : m_rProj(rProj), m_rImagefile(rIF), m_pProcessSignal(0), m_pBackprojector(0), m_iTrace(iTrace), m_bFail(false), m_adPlotXAxis(0)
+Reconstructor::Reconstructor (const Projections& rProj, ImageFile& rIF, const char* const filterName, 
+                              double filt_param, const char* const filterMethodName, const int zeropad, 
+                              const char* filterGenerationName, const char* const interpName, 
+                              int interpFactor, const char* const backprojectName, const int iTrace, SGP* pSGP)
+  : m_rProj(rProj), m_rImagefile(rIF), m_pProcessSignal(0), m_pBackprojector(0), m_iTrace(iTrace), 
+    m_bFail(false), m_adPlotXAxis(0)
 {
   m_nFilteredProjections = m_rProj.nDet() * interpFactor;
 
@@ -65,7 +69,9 @@ Reconstructor::Reconstructor (const Projections& rProj, ImageFile& rIF, const ch
 #endif
 
   double filterBW = 1. / m_rProj.detInc();
-  m_pProcessSignal = new ProcessSignal (filterName, filterMethodName, filterBW, m_rProj.detInc(), m_rProj.nDet(), filt_param, "spatial", filterGenerationName, zeropad, interpFactor, iTrace, m_rProj.geometry(), m_rProj.focalLength(), pSGP);
+  m_pProcessSignal = new ProcessSignal (filterName, filterMethodName, filterBW, m_rProj.detInc(), 
+    m_rProj.nDet(), filt_param, "spatial", filterGenerationName, zeropad, interpFactor, iTrace, 
+    m_rProj.geometry(), m_rProj.focalLength(), m_rProj.sourceDetectorLength(), pSGP);
 
   if (m_pProcessSignal->fail()) {
     m_bFail = true;
@@ -85,7 +91,7 @@ Reconstructor::Reconstructor (const Projections& rProj, ImageFile& rIF, const ch
     return;
   }
 
-#if HAVE_SGP
+#ifdef HAVE_SGP
   m_adPlotXAxis = new double [m_rProj.nDet()];
   double x = - ((m_rProj.nDet() - 1) / 2) * m_rProj.detInc();
   double xInc = m_rProj.detInc();
@@ -106,7 +112,7 @@ Reconstructor::~Reconstructor ()
 void
 Reconstructor::plotFilter (SGP* pSGP)
 {
-#if HAVE_SGP
+#ifdef HAVE_SGP
   int nVecFilter = m_pProcessSignal->getNFilterPoints();
   double* adPlotXAxis = new double [nVecFilter];
 
@@ -117,13 +123,13 @@ Reconstructor::plotFilter (SGP* pSGP)
       adPlotXAxis[i] = f;
 
     if (m_pProcessSignal->getFilter()) {
-      EZPlot ezplot (*pSGP);
+      EZPlot ezplot;
 
       ezplot.ezset ("title Filter Response");
       ezplot.addCurve (adPlotXAxis, m_pProcessSignal->getFilter(), nVecFilter);
-      ezplot.plot();
+      ezplot.plot (pSGP);
     }
-  }\r
+  }
   delete adPlotXAxis;
 #endif
 }
@@ -133,12 +139,18 @@ void
 Reconstructor::reconstructAllViews ()
 {
   reconstructView (0, m_rProj.nView());
-  delete m_pBackprojector; m_pBackprojector = NULL;
+  postProcessing();
+}
+
+void
+Reconstructor::postProcessing()
+{
+  m_pBackprojector->PostProcessing();
 }
 
 
 void
-Reconstructor::reconstructView (int iStartView, int iViewCount, SGP* pSGP)
+Reconstructor::reconstructView (int iStartView, int iViewCount, SGP* pSGP, bool bBackprojectView, double dGraphWidth)
 {
   double* adFilteredProj = new double [m_nFilteredProjections];   // filtered projections
 
@@ -147,7 +159,7 @@ Reconstructor::reconstructView (int iStartView, int iViewCount, SGP* pSGP)
       
   for (int iView = iStartView; iView < (iStartView + iViewCount); iView++)  {
     if (m_iTrace == Trace::TRACE_CONSOLE) 
-      cout <<"Reconstructing view " << iView << " (last = " << m_rProj.nView() - 1 << ")\n";
+               std::cout <<"Reconstructing view " << iView << " (last = " << m_rProj.nView() - 1 << ")\n";
       
     const DetectorArray& rDetArray = m_rProj.getDetectorArray (iView);
     const DetectorValue* detval = rDetArray.detValues();
@@ -166,37 +178,59 @@ Reconstructor::reconstructView (int iStartView, int iViewCount, SGP* pSGP)
 #endif
 #endif
 
-    m_pBackprojector->BackprojectView (adFilteredProj, rDetArray.viewAngle());
+       if (bBackprojectView)
+      m_pBackprojector->BackprojectView (adFilteredProj, rDetArray.viewAngle());
 
 #ifdef HAVE_SGP
     if (m_iTrace >= Trace::TRACE_PLOT && pSGP) {
-      EZPlot ezplotProj (*pSGP);
+      EZPlot ezplotProj;
+
+      std::ostringstream osXLength;
+      osXLength << "xlength " << dGraphWidth;
 
       ezplotProj.ezset ("clear");
       ezplotProj.ezset ("title Raw Projection");
       ezplotProj.ezset ("xticks major 5");
+      ezplotProj.ezset ("yticks major 5");
       ezplotProj.ezset ("xlabel ");
       ezplotProj.ezset ("ylabel ");
-      ezplotProj.ezset ("yporigin .5");
-      ezplotProj.ezset ("ylength .5");
+      ezplotProj.ezset ("yporigin 0.55");
+      ezplotProj.ezset ("ylength 0.45");
+      ezplotProj.ezset (osXLength.str().c_str());
       ezplotProj.ezset ("box.");
       ezplotProj.ezset ("grid.");
+#if 0  // workaround c++ optimizer bug, now disabled by using /O1 in code
+      double* pdDetval = new double [m_rProj.nDet()];
+      for (unsigned int id = 0; id < m_rProj.nDet(); id++) {
+        pdDetval[id] = detval[id];
+      }
+      ezplotProj.addCurve (m_adPlotXAxis, pdDetval, m_rProj.nDet());
+      delete pdDetval;
+#else
       ezplotProj.addCurve (m_adPlotXAxis, detval, m_rProj.nDet());
-      ezplotProj.plot();
+#endif
+      pSGP->setTextPointSize (12);
+      ezplotProj.plot (pSGP);
+
       ezplotProj.ezset ("clear");
       ezplotProj.ezset ("title Filtered Projection");
       ezplotProj.ezset ("xticks major 5");
       ezplotProj.ezset ("xlabel ");
       ezplotProj.ezset ("ylabel ");
-      ezplotProj.ezset ("ylength .5");
+      ezplotProj.ezset ("yticks major 5");
+      ezplotProj.ezset ("yporigin 0.10");
+      ezplotProj.ezset ("ylength 0.45");
+      ezplotProj.ezset (osXLength.str().c_str());
       ezplotProj.ezset ("box");
       ezplotProj.ezset ("grid");
       ezplotProj.addCurve (m_adPlotXAxis, adFilteredProj,  m_nFilteredProjections);
-      ezplotProj.plot();
-    } 
+      pSGP->setTextPointSize (12);
+      ezplotProj.plot (pSGP);
+
+} 
 #endif  //HAVE_SGP
   }
-\r
-  delete adFilteredProj;\r
+
+  delete adFilteredProj;
 }