From: dsarrut Date: Wed, 30 Jun 2010 05:55:57 +0000 (+0000) Subject: add "HasSameSize" utils X-Git-Tag: v1.2.0~603 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=83de28515d7bbb3898d5adee7a900146c2c15d89;p=clitk.git add "HasSameSize" utils --- diff --git a/common/clitkImageCommon.cxx b/common/clitkImageCommon.cxx index 03aa9b6..d2ab867 100644 --- a/common/clitkImageCommon.cxx +++ b/common/clitkImageCommon.cxx @@ -38,7 +38,7 @@ void clitk::ReadImageDimensionAndPixelType(const std::string & filename, 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; + std::cerr << "Image file format unknown while reading file <" << filename << ">" << std::endl; exit(0); } genericReader->SetFileName(filename.c_str()); @@ -137,6 +137,7 @@ void clitk::printImageHeader(itk::ImageIOBase::Pointer header, std::ostream & os 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; diff --git a/common/clitkImageCommon.h b/common/clitkImageCommon.h index 11bdb8f..294c19a 100644 --- a/common/clitkImageCommon.h +++ b/common/clitkImageCommon.h @@ -17,15 +17,6 @@ ======================================================================-====*/ #ifndef CLITKIMAGECOMMON_H #define CLITKIMAGECOMMON_H -/** - ------------------------------------------------------------------- - * @file clitkImageCommon.h - * @author David Sarrut - * @date 07 Sep 2007 11:30:10 - - * @brief - - -------------------------------------------------------------------*/ // clitk #include "clitkCommon.h" @@ -103,6 +94,15 @@ namespace clitk { std::map > & mapOfLabelsAndWeights); + //-------------------------------------------------------------------- + template + bool HasSameSizeAndSpacing(typename ImageType1::ConstPointer A, + typename ImageType2::ConstPointer B); + + template + bool HasSameSizeAndSpacing(typename ImageType1::Pointer A, + typename ImageType2::Pointer B); + #include "clitkImageCommon.txx" } // end namespace diff --git a/common/clitkImageCommon.txx b/common/clitkImageCommon.txx index 5fb4b86..7b6badf 100644 --- a/common/clitkImageCommon.txx +++ b/common/clitkImageCommon.txx @@ -181,6 +181,7 @@ typename ImageType::Pointer readImage(const std::vector & filenames } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- template void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose) @@ -202,6 +203,7 @@ void writeImage(const typename ImageType::Pointer image, const std::string & fil } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- template void writeImage(const ImageType* image, const std::string & filename, const bool verbose) @@ -278,6 +280,7 @@ int ComputeHowManyDifferentIntensity(const typename ImageType::Pointer & image, } //-------------------------------------------------------------------- + //-------------------------------------------------------------------- template void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input, @@ -313,5 +316,34 @@ void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input, } //-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +template +bool HasSameSizeAndSpacing(typename ImageType1::ConstPointer A, + typename ImageType2::ConstPointer B) +{ + if (A->GetImageDimension() != B->GetImageDimension()) return false; + for(unsigned int i=0; iGetImageDimension(); i++) { + if (A->GetSpacing()[i] != B->GetSpacing()[i]) return false; + if (A->GetLargestPossibleRegion().GetSize()[i] != B->GetLargestPossibleRegion().GetSize()[i]) return false; + } + return true; +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +template +bool HasSameSizeAndSpacing(typename ImageType1::Pointer A, + typename ImageType2::Pointer B) +{ + if (A->GetImageDimension() != B->GetImageDimension()) return false; + for(unsigned int i=0; iGetImageDimension(); i++) { + if (A->GetSpacing()[i] != B->GetSpacing()[i]) return false; + if (A->GetLargestPossibleRegion().GetSize()[i] != B->GetLargestPossibleRegion().GetSize()[i]) return false; + } + return true; +} +//-------------------------------------------------------------------- + #endif /* end #define CLITKIMAGECOMMON_TXX */