From 606cf49ef078c2e81206ee2b4fef3e156682207b Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Thu, 9 Jun 2011 11:52:31 +0200 Subject: [PATCH] still on bug 375 - image origin is now also updated to cope with crop --- tools/clitkCropImageGenericFilter.cxx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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); } -- 2.47.1