From 546b81bfa268282f8c5d62ba6bf1aebe314f252d Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Thu, 7 Jun 2012 15:47:13 +0200 Subject: [PATCH] Add RemoveNegativeIndexFromRegion function --- itk/clitkSegmentationUtils.h | 8 +++++++- itk/clitkSegmentationUtils.txx | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/itk/clitkSegmentationUtils.h b/itk/clitkSegmentationUtils.h index 6972d15..6389ad1 100644 --- a/itk/clitkSegmentationUtils.h +++ b/itk/clitkSegmentationUtils.h @@ -28,6 +28,7 @@ // itk #include #include +#include /* According to @@ -486,7 +487,12 @@ namespace clitk { typename ImageType::PixelType & BG); //-------------------------------------------------------------------- - + //-------------------------------------------------------------------- + template + typename ImageType::Pointer + RemoveNegativeIndexFromRegion(ImageType * input); + //-------------------------------------------------------------------- + } // end clitk namespace diff --git a/itk/clitkSegmentationUtils.txx b/itk/clitkSegmentationUtils.txx index 6171030..b7a5de5 100644 --- a/itk/clitkSegmentationUtils.txx +++ b/itk/clitkSegmentationUtils.txx @@ -1392,6 +1392,30 @@ namespace clitk { //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + template + typename ImageType::Pointer + RemoveNegativeIndexFromRegion(ImageType * input) { + typedef itk::ChangeInformationImageFilter< ImageType > InfoFilterType; + typename InfoFilterType::Pointer indexChangeFilter = InfoFilterType::New(); + indexChangeFilter->ChangeRegionOn(); + // The next line is commented because not exist in itk 3 + // typename InfoFilterType::OutputImageOffsetValueType indexShift[3]; + long indexShift[3]; + typename ImageType::IndexType index = input->GetLargestPossibleRegion().GetIndex(); + for(uint i=0;iGetOrigin()[i] - indexShift[i]*input->GetSpacing()[i]; + indexChangeFilter->SetOutputOffset( indexShift ); + indexChangeFilter->SetInput(input); + indexChangeFilter->SetOutputOrigin(origin); + indexChangeFilter->ChangeOriginOn(); + indexChangeFilter->Update(); + return indexChangeFilter->GetOutput(); + } + //-------------------------------------------------------------------- } // end of namespace -- 2.47.1