From: Romulo Pinho Date: Thu, 9 Jun 2011 09:52:31 +0000 (+0200) Subject: still on bug 375 X-Git-Tag: v1.3.0~321^2~3^2~2^2 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=606cf49ef078c2e81206ee2b4fef3e156682207b;p=clitk.git still on bug 375 - image origin is now also updated to cope with crop --- diff --git a/tools/clitkCropImageGenericFilter.cxx b/tools/clitkCropImageGenericFilter.cxx index 5c78d4e..aeae1f9 100644 --- a/tools/clitkCropImageGenericFilter.cxx +++ b/tools/clitkCropImageGenericFilter.cxx @@ -165,14 +165,21 @@ namespace clitk output->SetOrigin(origin); } - // force index to zero - typename ImageType::RegionType region; - region = output->GetLargestPossibleRegion(); - typename ImageType::IndexType index; + // adjust image origin and force index to zero + typename ImageType::RegionType region = output->GetLargestPossibleRegion(); + typename ImageType::IndexType index = region.GetIndex(); + typename ImageType::PointType origin = output->GetOrigin(); + typename ImageType::SpacingType spacing = output->GetSpacing(); + if (mArgsInfo.verbose_flag) std::cout << "origin before crop " << origin << std::endl; + for (unsigned int i = 0; i < output->GetImageDimension(); i++) + origin[i] += index[i]*spacing[i]; + if (mArgsInfo.verbose_flag) std::cout << "origin after crop " << origin << std::endl; + output->SetOrigin(origin); + index.Fill(itk::NumericTraits::Zero); region.SetIndex(index); output->SetRegions(region); - + // Write/Save results this->template SetNextOutput(output); }