r623: no message
[ctsim.git] / libctsim / imagefile.cpp
index 134a0c59f2ed525762ec893f118402c39511b452..7c9e91e267b42159474d8b3bbd67abceb330df9c 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: imagefile.cpp,v 1.38 2001/03/01 20:02:18 kevin Exp $
+**  $Id: imagefile.cpp,v 1.40 2001/03/07 16:34:47 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
@@ -26,6 +26,9 @@
 ******************************************************************************/
 
 #include "ct.h"
+#ifdef HAVE_CTN_DICOM
+#include "ctndicom.h"
+#endif
 
 const double ImageFile::s_dRedGrayscaleFactor = 0.299;
 const double ImageFile::s_dGreenGrayscaleFactor = 0.587;
@@ -644,7 +647,7 @@ bool
 ImageFile::log (ImageFile& result) const
 {
   if (m_nx != result.nx() || m_ny != result.ny()) {
-    sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");
+    sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::log]");
     return false;
   }
   
@@ -666,8 +669,12 @@ ImageFile::log (ImageFile& result) const
         std::complex<double> cResult = std::log (cLHS);
         vResult[ix][iy] = cResult.real();
         vResultImag[ix][iy] = cResult.imag();
-      } else
-        vResult[ix][iy] = ::log (vLHS[ix][iy]);
+      } else {
+        if (vLHS[ix][iy] > 0)
+          vResult[ix][iy] = ::log (vLHS[ix][iy]);
+        else
+          vResult[ix][iy] = 0;
+      }
     }
   }
   
@@ -1310,21 +1317,11 @@ ImageFile::importImage (const char* const pszFormat, const char* const pszFilena
   else if (iFormatID == IMPORT_FORMAT_PNG)
     return readImagePNG (pszFilename);
 #endif
-#ifdef HAVE_CTN_DICOM
-  else if (iFormatID == IMPORT_FORMAT_DICOM)
-    return readImageDicom (pszFilename);
-#endif
   
   sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::importImage]", pszFormat);
   return false;
 }
 
-bool
-ImageFile::readImageDicom (const char* const pszFile)
-{
-  return false;
-}
-
 void
 ImageFile::skipSpacePPM (FILE* fp)
 {
@@ -1571,7 +1568,16 @@ ImageFile::exportImage (const char* const pszFormat, const char* const pszFilena
     return writeImagePNG (pszFilename, 8, nxcell, nycell, densmin, densmax);
   else if (iFormatID == EXPORT_FORMAT_PNG16)
     return writeImagePNG (pszFilename, 16, nxcell, nycell, densmin, densmax);
-  
+#ifdef HAVE_CTN_DICOM
+  else if (iFormatID == EXPORT_FORMAT_DICOM) {
+    DicomExporter dicomExport (this);
+    bool bSuccess = dicomExport.writeFile (pszFilename);
+    if (! bSuccess) 
+      sys_error (ERR_SEVERE, dicomExport.failMessage().c_str());
+    return bSuccess;
+  }
+#endif
+
   sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::exportImage]", pszFormat);
   return false;
 }