X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=itk%2FclitkCropLikeImageFilter.txx;h=28772392ff7fff31a4b9b738b5a08e69909832e3;hb=6194949c0beb1589904e22381b9aba1bbface172;hp=8b90fe30e704a1b1b61454608b01c477ceda89d6;hpb=709d3deddba827afcff948a7ebfe8d4908e72f8f;p=clitk.git diff --git a/itk/clitkCropLikeImageFilter.txx b/itk/clitkCropLikeImageFilter.txx index 8b90fe3..2877239 100644 --- a/itk/clitkCropLikeImageFilter.txx +++ b/itk/clitkCropLikeImageFilter.txx @@ -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,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ======================================================================-====*/ + ===========================================================================**/ #ifndef CLITKCROPLIKEIMAGEFILTER_TXX #define CLITKCROPLIKEIMAGEFILTER_TXX @@ -93,8 +93,7 @@ GenerateInputRequestedRegion() { template void clitk::CropLikeImageFilter:: -GenerateOutputInformation() { - DD("GenerateOutputInformation"); +GenerateOutputInformation() { // Get input pointers ImageConstPointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); @@ -111,6 +110,7 @@ GenerateOutputInformation() { likeStart = m_LikeImage->GetLargestPossibleRegion().GetIndex(); likeOrigin = m_LikeImage->GetOrigin(); likeSpacing = m_LikeImage->GetSpacing(); + output->CopyInformation(m_LikeImage); } else { // Only load the header (allows to use 'like' with any image type) @@ -132,10 +132,20 @@ GenerateOutputInformation() { for(unsigned int i=0; iGetSpacing()[i]) { clitkExceptionMacro("Images must have the same spacing, but input's spacing(" << i - <<") is " << input->GetSpacing()[i] << " while like's spacing(" << i - << ") is " << likeSpacing[i] << "."); + <<") is " << input->GetSpacing()[i] << " while the spacing(" << i + << ") of 'like' is " << likeSpacing[i] << "."); } } + + // Check that we must crop along each dimension. If not, we use the + // size of the input image + for(unsigned int i=0; iGetLargestPossibleRegion().GetIndex()[i]; + likeSize[i] = input->GetLargestPossibleRegion().GetSize()[i]; + } + } + // Define output region m_OutputRegion.SetIndex(likeStart); m_OutputRegion.SetSize(likeSize); @@ -144,6 +154,7 @@ GenerateOutputInformation() { output->SetBufferedRegion(m_OutputRegion); output->SetSpacing(likeSpacing); output->SetOrigin(likeOrigin); + output->Allocate(); // Needed ? // get startpoint source/dest // for each dim @@ -199,6 +210,7 @@ GenerateOutputInformation() { for(int i=0; iGetOutput(0); - output->Allocate(); + output->FillBuffer(GetBackgroundValue()); // Paste image inside typedef itk::PasteImageFilter PasteFilterType; typename PasteFilterType::Pointer pasteFilter = PasteFilterType::New(); + //pasteFilter->ReleaseDataFlagOn(); // change nothing ? + // pasteFilter->InPlaceOn(); // makt it seg fault pasteFilter->SetSourceImage(input); pasteFilter->SetDestinationImage(output); pasteFilter->SetDestinationIndex(m_StartDestIndex); @@ -225,7 +239,6 @@ GenerateData() { pasteFilter->Update(); // Get (graft) output (SetNthOutput does not fit here because of Origin). - // this->GraftOutput(cropFilter->GetOutput()); this->GraftOutput(pasteFilter->GetOutput()); } //--------------------------------------------------------------------