From: mpech Date: Wed, 29 Jun 2011 11:34:41 +0000 (+0200) Subject: Merge branch 'master' of /home/dsarrut/clitk3.server X-Git-Tag: v1.3.0~300^2^2~8 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=1a8450d4940e31424315290bec3139418aadd87c;hp=3723847657852091f11f4e0dcd2490124239ec5e;p=clitk.git Merge branch 'master' of /home/dsarrut/clitk3.server --- diff --git a/common/clitkImageCommon.h b/common/clitkImageCommon.h index 3cd8ae5..fbddb20 100644 --- a/common/clitkImageCommon.h +++ b/common/clitkImageCommon.h @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr @@ -27,83 +27,93 @@ #include "itkImageSeriesReader.h" #include "itkImageFileWriter.h" -namespace clitk { - - //-------------------------------------------------------------------- - // New Image creation (no allocation) - template - typename itk::Image::Pointer NewImage1D(int size, double spacing=1.0); - template - typename itk::Image::Pointer NewImage2D(int sx, int sy, double dx=1.0, double dy=1.0); - template - typename itk::Image::Pointer NewImage3D(int sx, int sy, int sz, double dx=1.0, double dy=1.0, double dz=1.0); - template - typename itk::Image::Pointer NewImage4D(int sx, int sy, int sz, int st, double dx=1.0, double dy=1.0, double dz=1.0, double dt=1.0); - - template - typename ImageType::Pointer NewImageLike(const typename ImageType::Pointer input, bool allocate=true); - - template - void CopyValues(const typename ImageType::Pointer input, typename ImageType::Pointer output); - //-------------------------------------------------------------------- - // New Image creation (with allocation) - - //-------------------------------------------------------------------- - // Read an Write image - // template - // typename ImageType::Pointer ReadImage(const std::string & filename, const bool verbose=false); - template - typename ImageType::Pointer readImage(const std::string & filename, const bool verbose=false); - template - typename ImageType::Pointer readImage(const std::vector & filenames, const bool verbose=false); - template - void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose=false); -// template +namespace clitk +{ + +//-------------------------------------------------------------------- +// New Image creation (no allocation) +template +typename itk::Image::Pointer NewImage1D(int size, double spacing=1.0); +template +typename itk::Image::Pointer NewImage2D(int sx, int sy, double dx=1.0, double dy=1.0); +template +typename itk::Image::Pointer NewImage3D(int sx, int sy, int sz, double dx=1.0, double dy=1.0, double dz=1.0); +template +typename itk::Image::Pointer NewImage4D(int sx, int sy, int sz, int st, double dx=1.0, double dy=1.0, double dz=1.0, double dt=1.0); + +template +typename ImageType::Pointer NewImageLike(const typename ImageType::Pointer input, bool allocate=true); + +template +void CopyValues(const typename ImageType::Pointer input, typename ImageType::Pointer output); +//-------------------------------------------------------------------- +// New Image creation (with allocation) + +//-------------------------------------------------------------------- +// Read an Write image +// template +// typename ImageType::Pointer ReadImage(const std::string & filename, const bool verbose=false); +template +typename ImageType::Pointer readImage(const std::string & filename, const bool verbose=false); +template +typename ImageType::Pointer readImage(const std::vector & filenames, const bool verbose=false); +template +void writeImage(const typename ImageType::Pointer image, const std::string & filename, const bool verbose=false); +// template // void writeConstImage(const typename ImageType::ConstPointer image, const std::string & filename, const bool verbose=false); - template - void writeImage(const ImageType* image, const std::string & filename, const bool verbose=false); - - //-------------------------------------------------------------------- - // Read/print image header - itk::ImageIOBase::Pointer readImageHeader(const std::string & filename,bool exit_on_error=true); - void printImageHeader(itk::ImageIOBase::Pointer header, std::ostream & os, const int level=0); - - //-------------------------------------------------------------------- - // Determine pixetype and dimension of an image file - void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType); - - //-------------------------------------------------------------------- - // Determine pixetype, dimension and number of pixel components of an image file - void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType, int & components); - - //-------------------------------------------------------------------- - template - int ComputeHowManyDifferentIntensity(const typename ImageType::Pointer & image, - std::vector & listOfIntensities); - template - void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input, - const typename MaskImageType::Pointer & mask, - const std::vector & listOfIntensities, - std::map > & mapOfLabelsAndWeights); - - //-------------------------------------------------------------------- - template - bool HaveSameSizeAndSpacing(typename ImageType1::ConstPointer A, - typename ImageType2::ConstPointer B); - - template - bool HaveSameSizeAndSpacing(typename ImageType1::Pointer A, - typename ImageType2::Pointer B); - - //-------------------------------------------------------------------- - template - bool HaveSameSpacing(typename ImageType1::ConstPointer A, - typename ImageType2::ConstPointer B); - - template - bool HaveSameSpacing(typename ImageType1::Pointer A, - typename ImageType2::Pointer B); +template +void writeImage(const ImageType* image, const std::string & filename, const bool verbose=false); + +//-------------------------------------------------------------------- +// Read/print image header +itk::ImageIOBase::Pointer readImageHeader(const std::string & filename,bool exit_on_error=true); +void printImageHeader(itk::ImageIOBase::Pointer header, std::ostream & os, const int level=0); + +//-------------------------------------------------------------------- +// Determine pixetype and dimension of an image file +void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType); + +//-------------------------------------------------------------------- +// Determine pixetype, dimension and number of pixel components of an image file +void ReadImageDimensionAndPixelType(const std::string & filename, int & dimension, std::string & pixeType, int & components); + +//-------------------------------------------------------------------- +template +int ComputeHowManyDifferentIntensity(const typename ImageType::Pointer & image, + std::vector & listOfIntensities); +template +void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input, + const typename MaskImageType::Pointer & mask, + const std::vector & listOfIntensities, + std::map > & mapOfLabelsAndWeights); + +//-------------------------------------------------------------------- +template +bool HaveSameSpacing(typename ImageType1::ConstPointer A, + typename ImageType2::ConstPointer B); + +template +bool HaveSameSpacing(typename ImageType1::Pointer A, + typename ImageType2::Pointer B); + +//-------------------------------------------------------------------- +template +bool HaveSameSize(typename ImageType1::ConstPointer A, + typename ImageType2::ConstPointer B); + +template +bool HaveSameSize(typename ImageType1::Pointer A, + typename ImageType2::Pointer B); + +//-------------------------------------------------------------------- +template +bool HaveSameSizeAndSpacing(typename ImageType1::ConstPointer A, + typename ImageType2::ConstPointer B); + +template +bool HaveSameSizeAndSpacing(typename ImageType1::Pointer A, + typename ImageType2::Pointer B); #include "clitkImageCommon.txx" diff --git a/common/clitkImageCommon.txx b/common/clitkImageCommon.txx index 9d8d6e1..5aa3b2e 100644 --- a/common/clitkImageCommon.txx +++ b/common/clitkImageCommon.txx @@ -21,7 +21,7 @@ //-------------------------------------------------------------------- template -typename itk::Image::Pointer +typename itk::Image::Pointer NewImage1D(int vsize, double vspacing) { typedef itk::Image ImageType; @@ -40,7 +40,7 @@ NewImage1D(int vsize, double vspacing) //-------------------------------------------------------------------- template -typename itk::Image::Pointer +typename itk::Image::Pointer NewImage2D(int sx, int sy, double dx, double dy) { typedef itk::Image ImageType; @@ -62,7 +62,7 @@ NewImage2D(int sx, int sy, double dx, double dy) //-------------------------------------------------------------------- template -typename itk::Image::Pointer +typename itk::Image::Pointer NewImage3D(int sx, int sy, int sz, double dx, double dy, double dz) { typedef itk::Image ImageType; @@ -323,13 +323,12 @@ void ComputeWeightsOfEachClasses(const typename InputImageType::Pointer & input, //-------------------------------------------------------------------- template -bool HaveSameSizeAndSpacing(typename ImageType1::ConstPointer A, - typename ImageType2::ConstPointer B) +bool HaveSameSpacing(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; } @@ -337,13 +336,12 @@ bool HaveSameSizeAndSpacing(typename ImageType1::ConstPointer A, //-------------------------------------------------------------------- template -bool HaveSameSizeAndSpacing(typename ImageType1::Pointer A, - typename ImageType2::Pointer B) +bool HaveSameSpacing(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; } @@ -351,12 +349,12 @@ bool HaveSameSizeAndSpacing(typename ImageType1::Pointer A, //-------------------------------------------------------------------- template -bool HaveSameSpacing(typename ImageType1::ConstPointer A, - typename ImageType2::ConstPointer B) +bool HaveSameSize(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; } @@ -364,16 +362,36 @@ bool HaveSameSpacing(typename ImageType1::ConstPointer A, //-------------------------------------------------------------------- template -bool HaveSameSpacing(typename ImageType1::Pointer A, - typename ImageType2::Pointer B) +bool HaveSameSize(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; } //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +template +bool HaveSameSizeAndSpacing(typename ImageType1::ConstPointer A, + typename ImageType2::ConstPointer B) +{ + return ( HaveSameSize(A, B) && + HaveSameSpacing(A, B) ); +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +template +bool HaveSameSizeAndSpacing(typename ImageType1::Pointer A, + typename ImageType2::Pointer B) +{ + return ( HaveSameSize(A, B) && + HaveSameSpacing(A, B) ); +} +//-------------------------------------------------------------------- + #endif /* end #define CLITKIMAGECOMMON_TXX */ diff --git a/segmentation/clitkMorphoMathFilter.txx b/segmentation/clitkMorphoMathFilter.txx index 81356df..2eb3a02 100644 --- a/segmentation/clitkMorphoMathFilter.txx +++ b/segmentation/clitkMorphoMathFilter.txx @@ -85,15 +85,9 @@ template void clitk::MorphoMathFilter:: SetOperationType(int type) { - switch (type) { - case 0: m_OperationType = Erode; return; - case 1: m_OperationType = Dilate; return; - case 2: m_OperationType = Open; return; - case 3: m_OperationType = Close; return; - case 4: m_OperationType = CondErode; return; - case 5: m_OperationType = CondDilate; return; - default: clitkExceptionMacro("Operation type must be between 0-5 (0=Erode, 1=Dilate, 2=Close (erode(dilate(x))), 3=Open (dilate(erode(x))), 4=CondErode, 5=CondDilate)"); - } + if(type<0 || type>5) + clitkExceptionMacro("Operation type must be between 0-5 (0=Erode, 1=Dilate, 2=Close (erode(dilate(x))), 3=Open (dilate(erode(x))), 4=CondErode, 5=CondDilate)"); + m_OperationType = OperationTypeEnumeration(type); } //-------------------------------------------------------------------- diff --git a/tools/clitkAffineTransformGenericFilter.txx b/tools/clitkAffineTransformGenericFilter.txx index c758cb2..ef81fe2 100644 --- a/tools/clitkAffineTransformGenericFilter.txx +++ b/tools/clitkAffineTransformGenericFilter.txx @@ -168,7 +168,20 @@ AffineTransformGenericFilter::UpdateWithDimAndPixelType() typename itk::Matrix invRotMatrix( clitk::GetRotationalPartMatrix(invMatrix) ); typename itk::Vector invTrans = clitk::GetTranslationPartMatrix(invMatrix); - // Size is converted to double, transformed and converted back to size type + // Spacing is influenced by affine transform matrix and input direction + typename InputImageType::SpacingType outputSpacing; + outputSpacing = invRotMatrix * + input->GetDirection() * + input->GetSpacing(); + + // Origin is influenced by translation but not by input direction + typename InputImageType::PointType outputOrigin; + outputOrigin = invRotMatrix * + input->GetOrigin() + + invTrans; + + // Size is influenced by affine transform matrix and input direction + // Size is converted to double, transformed and converted back to size type. vnl_vector vnlOutputSize(Dimension); for(unsigned int i=0; i< Dimension; i++) { vnlOutputSize[i] = input->GetLargestPossibleRegion().GetSize()[i]; @@ -178,18 +191,18 @@ AffineTransformGenericFilter::UpdateWithDimAndPixelType() vnlOutputSize; typename OutputImageType::SizeType outputSize; for(unsigned int i=0; i< Dimension; i++) { + // If the size is negative, we have a flip and we must modify + // the origin and the spacing accordingly. + if(vnlOutputSize[i]<0.) { + vnlOutputSize[i] *= -1.; + outputOrigin[i] = outputOrigin[i] + outputSpacing[i] * (vnlOutputSize[i]-1); + outputSpacing[i] *= -1.; + } outputSize[i] = lrint(vnlOutputSize[i]); } resampler->SetSize( outputSize ); - - // Spacing can be dictly computed in the same way - resampler->SetOutputSpacing ( invRotMatrix * - input->GetDirection() * - input->GetSpacing() ); - // Origin is influenced by translation but not by direction - resampler->SetOutputOrigin ( invRotMatrix * - input->GetOrigin() + - invTrans ); + resampler->SetOutputSpacing( outputSpacing ); + resampler->SetOutputOrigin( outputOrigin ); } else { //Size typename OutputImageType::SizeType outputSize; diff --git a/tools/clitkImageArithmGenericFilter.txx b/tools/clitkImageArithmGenericFilter.txx index 38f7c50..24ebbbd 100644 --- a/tools/clitkImageArithmGenericFilter.txx +++ b/tools/clitkImageArithmGenericFilter.txx @@ -128,9 +128,12 @@ void ImageArithmGenericFilter::UpdateWithInputImageType() // Set input image iterator it2 = IteratorType(input2, input2->GetLargestPossibleRegion()); // Check dimension - if (!clitk::HaveSameSizeAndSpacing(input1, input2)) { - std::cerr << "* ERROR * the images (input and input2) must have the same size & spacing"; - return; + if (!clitk::HaveSameSize(input1, input2)) { + itkExceptionMacro(<< "The images (input and input2) must have the same size"); + } + if(!clitk::HaveSameSpacing(input1, input2)) { + itkWarningMacro(<< "The images (input and input2) do not have the same spacing. " + << "Using first input's information."); } } diff --git a/tools/clitkMakeSphereImage.cxx b/tools/clitkMakeSphereImage.cxx index f018b95..7f29dfe 100644 --- a/tools/clitkMakeSphereImage.cxx +++ b/tools/clitkMakeSphereImage.cxx @@ -8,10 +8,10 @@ int main(int argc, char** argv) { const unsigned int dim = 3; typedef char PixelType; typedef itk::Image ImageType; - typedef typename ImageType::IndexType IndexType; - typedef typename ImageType::PointType PointType; - typedef typename ImageType::SizeType SizeType; - typedef typename ImageType::RegionType RegionType; + typedef ImageType::IndexType IndexType; + typedef ImageType::PointType PointType; + typedef ImageType::SizeType SizeType; + typedef ImageType::RegionType RegionType; IndexType index; index.Fill(0); @@ -30,12 +30,12 @@ int main(int argc, char** argv) { region.SetIndex(index); region.SetSize(size); - typename ImageType::Pointer image = ImageType::New(); + ImageType::Pointer image = ImageType::New(); image->SetRegions(region); image->Allocate(); typedef itk::SphereSpatialFunction ShpereFunctionType; - typename ShpereFunctionType::Pointer sphere = ShpereFunctionType::New(); + ShpereFunctionType::Pointer sphere = ShpereFunctionType::New(); double radius = atof(argv[8])/2; sphere->SetCenter(origin); @@ -56,7 +56,7 @@ int main(int argc, char** argv) { } typedef itk::ImageFileWriter ImageWriterType; - typename ImageWriterType::Pointer writer = ImageWriterType::New(); + ImageWriterType::Pointer writer = ImageWriterType::New(); writer->SetInput(image); writer->SetFileName(argv[1]); writer->Update(); diff --git a/vv/vvSlicer.cxx b/vv/vvSlicer.cxx index 6b52ea1..302da7e 100644 --- a/vv/vvSlicer.cxx +++ b/vv/vvSlicer.cxx @@ -369,7 +369,8 @@ void vvSlicer::SetOverlay(vvImage::Pointer overlay) this->GetRenderer()->AddActor(mOverlayActor); //Synchronize orientation and slice - this->SetSliceOrientation(this->SliceOrientation); + AdjustResliceToSliceOrientation(mOverlayReslice); + this->UpdateDisplayExtent(); this->SetTSlice(mCurrentTSlice); } } @@ -412,7 +413,8 @@ void vvSlicer::SetFusion(vvImage::Pointer fusion) } //Synchronize orientation and slice - this->SetSliceOrientation(this->SliceOrientation); + AdjustResliceToSliceOrientation(mFusionReslice); + this->UpdateDisplayExtent(); this->SetTSlice(mCurrentTSlice); } }