X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FclitkImageCommon.cxx;h=83b9435854ef3f7bec71e764ccee787ba314e0f9;hb=28730d74d4cf69edc5bc0186d0f1a751591ef384;hp=03aa9b6a5d687469e179fe5ddc37d4c86189d3ca;hpb=1e034c70105f0926939acaaa27ddb46e904ae8bf;p=clitk.git diff --git a/common/clitkImageCommon.cxx b/common/clitkImageCommon.cxx index 03aa9b6..83b9435 100644 --- a/common/clitkImageCommon.cxx +++ b/common/clitkImageCommon.cxx @@ -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 @@ -14,32 +14,23 @@ - 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 - * @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 " << 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(); @@ -68,22 +58,6 @@ void clitk::ReadImageDimensionAndPixelType(const std::string & filename, } //-------------------------------------------------------------------- -//-------------------------------------------------------------------- -// Read a dicom header -gdcm::File * clitk::readDicomHeader(const std::string & filename, - const bool verbose) -{ - if (verbose) { - std::cout << "Reading DICOM <" << filename << ">" << std::endl; - } - gdcm::File *header = new gdcm::File(); - header->SetFileName(filename); - header->SetMaxSizeLoadEntry(16384); // required ? - header->Load(); - return header; -} -//-------------------------------------------------------------------- - //-------------------------------------------------------------------- itk::ImageIOBase::Pointer clitk::readImageHeader(const std::string & filename, bool exit_on_error) { @@ -91,10 +65,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(); @@ -129,14 +101,15 @@ void clitk::printImageHeader(itk::ImageIOBase::Pointer header, std::ostream & os for(unsigned int i=0; i< dim-1; i++) os << inputSize[i] << "x"; os << inputSize[dim-1] - << " "; + << " "; for(unsigned int i=0; i< dim-1; i++) os << inputSpacing[i] << "x"; os << inputSpacing[dim-1] - << " "; + << " "; for(unsigned int i=0; i< dim-1; i++) os << inputOrigin[i] << "x"; os << inputOrigin[dim-1] << " "; + os << header->GetImageSizeInPixels() << " "; } else { os << "Dim = " << dim << "D" << std::endl; os << "PixelType = " << pixelTypeName << std::endl;