r631: no message
[ctsim.git] / libctsim / backprojectors.cpp
index bfd594e8697ef0075b98ce6bce5b325261b4b082..06ad159b9d9577d73f099aee7a9586a3e19b6052 100644 (file)
@@ -8,7 +8,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: backprojectors.cpp,v 1.30 2001/03/07 19:02:44 kevin Exp $
+**  $Id: backprojectors.cpp,v 1.31 2001/03/11 15:27:30 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
@@ -98,12 +98,13 @@ const int Backprojector::s_iInterpCount = sizeof(s_aszInterpName) / sizeof(const
 
 
 
-Backprojector::Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor)
+Backprojector::Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, 
+                              const char* const interpName, const int interpFactor, const ReconstructionROI* pROI)
 {
   m_fail = false;
   m_pBackprojectImplem = NULL;
   
-  initBackprojector (proj, im, backprojName, interpName, interpFactor);
+  initBackprojector (proj, im, backprojName, interpName, interpFactor, pROI);
 }
 
 void 
@@ -133,7 +134,8 @@ Backprojector::~Backprojector ()
 //     and initializes the backprojector
 
 bool
-Backprojector::initBackprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor)
+Backprojector::initBackprojector (const Projections& proj, ImageFile& im, const char* const backprojName, 
+                                  const char* const interpName, const int interpFactor, const ReconstructionROI* pROI)
 {
   m_nameBackproject = backprojName;
   m_nameInterpolation = interpName;
@@ -157,18 +159,18 @@ Backprojector::initBackprojector (const Projections& proj, ImageFile& im, const
   }
   
   if (proj.geometry() == Scanner::GEOMETRY_EQUILINEAR)
-    m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectEquilinear(proj, im, m_idInterpolation, interpFactor));
+    m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectEquilinear(proj, im, m_idInterpolation, interpFactor, pROI));
   else if (proj.geometry() == Scanner::GEOMETRY_EQUIANGULAR) 
-    m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectEquiangular(proj, im, m_idInterpolation, interpFactor));
+    m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectEquiangular(proj, im, m_idInterpolation, interpFactor, pROI));
   else if (proj.geometry() == Scanner::GEOMETRY_PARALLEL) {
     if (m_idBackproject == BPROJ_TRIG)
-      m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectTrig (proj, im, m_idInterpolation, interpFactor));
+      m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectTrig (proj, im, m_idInterpolation, interpFactor, pROI));
     else if (m_idBackproject == BPROJ_TABLE)
-      m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectTable (proj, im, m_idInterpolation, interpFactor));
+      m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectTable (proj, im, m_idInterpolation, interpFactor, pROI));
     else if (m_idBackproject == BPROJ_DIFF)
-      m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectDiff (proj, im, m_idInterpolation, interpFactor));
+      m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectDiff (proj, im, m_idInterpolation, interpFactor, pROI));
     else if (m_idBackproject == BPROJ_IDIFF)
-      m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectIntDiff (proj, im, m_idInterpolation, interpFactor));
+      m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectIntDiff (proj, im, m_idInterpolation, interpFactor, pROI));
   } else {
     m_fail = true;
     m_failMessage = "Unable to select a backprojection method [Backprojector::initBackprojector]";
@@ -260,7 +262,8 @@ Backprojector::convertInterpIDToTitle (const int interpID)
 // PURPOSE
 //   Pure virtual base class for all backprojectors.
 
-Backproject::Backproject (const Projections& proj, ImageFile& im, int interpType, const int interpFactor)
+Backproject::Backproject (const Projections& proj, ImageFile& im, int interpType, const int interpFactor, 
+                          const ReconstructionROI* pROI)
 : proj(proj), im(im), interpType(interpType), m_interpFactor(interpFactor), m_bPostProcessingDone(false)
 {
   detInc = proj.detInc();
@@ -285,6 +288,28 @@ Backproject::Backproject (const Projections& proj, ImageFile& im, int interpType
   yMin = -proj.phmLen() / 2;
   yMax = yMin + proj.phmLen();
   
+  if (pROI) {
+    if (pROI->m_dXMin > xMin)
+      xMin = pROI->m_dXMin;
+    if (pROI->m_dXMax < xMax)
+      xMax = pROI->m_dXMax;
+    if (pROI->m_dYMin > yMin)
+      yMin = pROI->m_dYMin;
+    if (pROI->m_dYMax < yMax)
+      yMax = pROI->m_dYMax;
+
+    if (xMin > xMax) {
+      double temp = xMin;
+      xMin = xMax;
+      xMax = temp;
+    }
+    if (yMin > yMax) {
+      double temp = yMin;
+      yMin = yMax;
+      yMax = temp;
+    }
+  }
+
   xInc = (xMax - xMin) / nx;   // size of cells
   yInc = (yMax - yMin) / ny;
   
@@ -384,8 +409,9 @@ BackprojectTrig::BackprojectView (const double* const filteredProj, const double
 // PURPOSE
 //   Precalculates trigometric function value for each point in image for backprojection.
 
-BackprojectTable::BackprojectTable (const Projections& proj, ImageFile& im, int interpType, const int interpFactor)
-: Backproject (proj, im, interpType, interpFactor)
+BackprojectTable::BackprojectTable (const Projections& proj, ImageFile& im, int interpType, 
+                                    const int interpFactor, const ReconstructionROI* pROI)
+: Backproject (proj, im, interpType, interpFactor, pROI)
 {
   arrayR.initSetSize (im.nx(), im.ny());
   arrayPhi.initSetSize (im.nx(), im.ny());
@@ -461,8 +487,9 @@ BackprojectTable::BackprojectView (const double* const filteredProj, const doubl
 //   Backprojects by precalculating the change in L position for each x & y step in the image.
 //   Iterates in x & y direction by adding difference in L position
 
-BackprojectDiff::BackprojectDiff (const Projections& proj, ImageFile& im, int interpType, const int interpFactor)
-:  Backproject (proj, im, interpType, interpFactor)
+BackprojectDiff::BackprojectDiff (const Projections& proj, ImageFile& im, int interpType, 
+                                  const int interpFactor, const ReconstructionROI* pROI)
+:  Backproject (proj, im, interpType, interpFactor, pROI)
 {
   // calculate center of first pixel v[0][0] 
   double x = xMin + xInc / 2;