r384: Added first vesion of EZPlotDialog
[ctsim.git] / libctsim / projections.cpp
index 22171504420064543e7d958bb168e461f9f9f79c..995c1649ec5327da84ad3890d3d6ad12e003b622 100644 (file)
@@ -8,7 +8,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: projections.cpp,v 1.38 2001/01/06 15:33:15 kevin Exp $
+**  $Id: projections.cpp,v 1.43 2001/01/12 16:41:56 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
@@ -404,10 +404,16 @@ Projections::copyViewData (const std::string& filename, std::ostream& os, int st
 bool 
 Projections::copyViewData (const char* const filename, std::ostream& os, int startView, int endView)
 {
-  frnetorderstream is (filename, ios::in | ios::binary);
+  frnetorderstream is (filename, std::ios::in | std::ios::binary);
   kuint16 sizeHeader, signature;
   kuint32 _nView, _nDet;
   
+  is.seekg (0);
+  if (is.fail()) {
+    sys_error (ERR_SEVERE, "Unable to read projection file %s", filename);
+    return false;
+  }
+
   is.readInt16 (sizeHeader);
   is.readInt16 (signature);
   is.readInt32 (_nView);
@@ -416,7 +422,7 @@ Projections::copyViewData (const char* const filename, std::ostream& os, int sta
   int nDet = _nDet;
   
   if (signature != m_signature) {
-    sys_error (ERR_FATAL, "Illegal signature in projection file %s", filename);
+    sys_error (ERR_SEVERE, "Illegal signature in projection file %s", filename);
     return false;
   }
   
@@ -446,9 +452,9 @@ Projections::copyViewData (const char* const filename, std::ostream& os, int sta
   
   delete pViewData;
   if (is.fail()) 
-    sys_error (ERR_FATAL, "Error reading projection file");
+    sys_error (ERR_SEVERE, "Error reading projection file");
   if (os.fail()) 
-    sys_error (ERR_FATAL, "Error writing projection file");
+    sys_error (ERR_SEVERE, "Error writing projection file");
   
   return (! (is.fail() | os.fail()));
 }
@@ -468,20 +474,20 @@ Projections::copyHeader (const char* const filename, std::ostream& os)
   is.readInt16 (signature);
   is.seekg (0);
   if (signature != m_signature) {
-    sys_error (ERR_FATAL, "Illegal signature in projection file %s", filename);
+    sys_error (ERR_SEVERE, "Illegal signature in projection file %s", filename);
     return false;
   }
   
   unsigned char* pHdrData = new unsigned char [sizeHeader];
   is.read (reinterpret_cast<char*>(pHdrData), sizeHeader);
   if (is.fail()) {
-    sys_error (ERR_FATAL, "Error reading header");
+    sys_error (ERR_SEVERE, "Error reading header");
     return false;
   }
   
   os.write (reinterpret_cast<char*>(pHdrData), sizeHeader);
   if (os.fail()) {
-    sys_error (ERR_FATAL, "Error writing header");
+    sys_error (ERR_SEVERE, "Error writing header");
     return false;
   }
   
@@ -710,6 +716,9 @@ Projections::convertFFTPolar (ImageFile& rIF, int iInterpolationID, int iZeropad
   if (! v || nx == 0 || ny == 0)
     return false;
   
+#ifndef HAVE_FFT
+  return false;
+#else
   Array2d<double> adView (nx, ny);
   Array2d<double> adDet (nx, ny);
   double** ppdView = adView.getArray();
@@ -722,16 +731,16 @@ Projections::convertFFTPolar (ImageFile& rIF, int iInterpolationID, int iZeropad
   fftw_plan plan = fftw_create_plan (m_nDet, FFTW_FORWARD, FFTW_IN_PLACE);
 
   for (iView = 0; iView < m_nView; iView++) {
-    ppcDetValue[iView] = new std::complex<double> [m_nDet];
     unsigned int iDet;
     for (iDet = 0; iDet < m_nDet; iDet++) {
       pcIn[iDet].re = getDetectorArray(iView).detValues()[iDet];
       pcIn[iDet].im = 0;
     }
     fftw_one (plan, pcIn, NULL);
+    ppcDetValue[iView] = new std::complex<double> [m_nDet];
     for (iDet = 0; iDet < m_nDet; iDet++)
-      ppcDetValue[iView][iDet] = std::complex<double> (pcIn[iDet].re, pcIn[iDet].im);
-   Fourier::shuffleFourierToNaturalOrder (ppcDetValue[iView], m_nDet);
+      ppcDetValue[iView][iDet] = std::complex<double> (pcIn[iDet].re, pcIn[iDet].im); 
+    Fourier::shuffleFourierToNaturalOrder (ppcDetValue[iView], m_nDet);
   }
 
   fftw_destroy_plan (plan);  
@@ -746,8 +755,10 @@ Projections::convertFFTPolar (ImageFile& rIF, int iInterpolationID, int iZeropad
   delete [] ppcDetValue;
 
   return true;
+#endif
 }
 
+
 void
 Projections::calcArrayPolarCoordinates (unsigned int nx, unsigned int ny, double** ppdView, double** ppdDet)
 {
@@ -763,8 +774,10 @@ Projections::calcArrayPolarCoordinates (unsigned int nx, unsigned int ny, double
 
   if (m_geometry != Scanner::GEOMETRY_PARALLEL) {
     sys_error (ERR_WARNING, "convertPolar supports Parallel only");
+    return;
   }
   
+  // Calculates polar coordinates (view#, det#) for each point on phantom grid
   double x = xMin + xInc / 2;  // Rectang coords of center of pixel 
   for (unsigned int ix = 0; ix < nx; x += xInc, ix++) {
     double y = yMin + yInc / 2;
@@ -809,9 +822,9 @@ Projections::interpolatePolar (ImageFileArray& v, ImageFileArray& vImag,
           v[ix][iy] = 0;
         }
       } else if (iInterpolationID == POLAR_INTERP_BILINEAR) {
-        int iFloorView = ppdView[ix][iy];
+        int iFloorView = static_cast<int>(ppdView[ix][iy]);
         double dFracView = ppdView[ix][iy] - iFloorView;
-        int iFloorDet = ppdDet[ix][iy];
+        int iFloorDet = static_cast<int>(ppdDet[ix][iy]);
         double dFracDet = ppdDet[ix][iy] - iFloorDet;
 
         if (iFloorDet >= 0 && iFloorView >= 0) {