]> Creatis software - clitk.git/blobdiff - common/clitkImageCommon.cxx
changes in license header
[clitk.git] / common / clitkImageCommon.cxx
index d3cd8d897ac87ff6e7978f85a1bf1e0777662873..4c66654cc11ad1e1e2ddd271c2910bc2a97ad004 100644 (file)
@@ -3,7 +3,7 @@
 
   Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   This software is distributed WITHOUT ANY WARRANTY; without even
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
+  ===========================================================================**/
+
 #ifndef CLITKIMAGECOMMON_CXX
 #define CLITKIMAGECOMMON_CXX
-/**
-   ------------------------------------------------=
-   * @file   clitkImageCommon.cxx
-   * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
-   * @date   02 Oct 2007 14:30:47
-   *
-   * @brief
-   *
-   *
-   ------------------------------------------------=*/
 
 #include "clitkImageCommon.h"
+#include "clitkCommon.h"
 
 //--------------------------------------------------------------------
 void clitk::ReadImageDimensionAndPixelType(const std::string & filename,
-    int & dimension,
-    std::string & pixeType)
+                                           int & dimension,
+                                           std::string & pixeType)
 {
   itk::ImageIOBase::Pointer genericReader =
     itk::ImageIOFactory::CreateImageIO(filename.c_str(), itk::ImageIOFactory::ReadMode);
   if (!genericReader) {
-    std::cerr << "Image file format unknown while reading file <" << filename << ">" << std::endl;
-    exit(0);
+    clitkExceptionMacro("Image file format unknown while reading file <" << filename << ">");
   }
   genericReader->SetFileName(filename.c_str());
   genericReader->ReadImageInformation();
@@ -51,14 +42,13 @@ void clitk::ReadImageDimensionAndPixelType(const std::string & filename,
 
 //--------------------------------------------------------------------
 void clitk::ReadImageDimensionAndPixelType(const std::string & filename,
-    int & dimension,
-    std::string & pixeType, int & components)
+                                           int & dimension,
+                                           std::string & pixeType, int & components)
 {
   itk::ImageIOBase::Pointer genericReader =
     itk::ImageIOFactory::CreateImageIO(filename.c_str(), itk::ImageIOFactory::ReadMode);
   if (!genericReader) {
-    std::cerr << "Image file format unknown while reading " << filename << std::endl;
-    exit(0);
+    clitkExceptionMacro("Image file format unknown while reading file <" << filename << ">");
   }
   genericReader->SetFileName(filename.c_str());
   genericReader->ReadImageInformation();
@@ -73,6 +63,13 @@ void clitk::ReadImageDimensionAndPixelType(const std::string & filename,
 gdcm::File * clitk::readDicomHeader(const std::string & filename,
                                     const bool verbose)
 {
+#if GDCM_MAJOR_VERSION == 2
+  gdcm::Reader hreader;
+  hreader.SetFileName(filename.c_str());
+  hreader.Read();
+  gdcm::SmartPointer<gdcm::File> p = hreader.GetFile();
+  return p;
+#else
   if (verbose) {
     std::cout << "Reading DICOM <" << filename << ">" << std::endl;
   }
@@ -81,6 +78,7 @@ gdcm::File * clitk::readDicomHeader(const std::string & filename,
   header->SetMaxSizeLoadEntry(16384); // required ?
   header->Load();
   return header;
+#endif
 }
 ///--------------------------------------------------------------------
 
@@ -91,10 +89,8 @@ itk::ImageIOBase::Pointer clitk::readImageHeader(const std::string & filename, b
     itk::ImageIOFactory::CreateImageIO(filename.c_str(), itk::ImageIOFactory::ReadMode);
   if (!reader) {
     if (exit_on_error) { //default behavior for tools who don't handle the problem
-      std::cerr << "Error reading file " << filename << ", exiting immediately" << std::endl;
-      std::exit(-1);
-    } else
-      return NULL;
+      clitkExceptionMacro("Error reading file " << filename << ", exiting immediately");
+    } else return NULL;
   }
   reader->SetFileName(filename);
   reader->ReadImageInformation();