From: David Sarrut Date: Thu, 7 Jun 2012 13:47:13 +0000 (+0200) Subject: Add RemoveNegativeIndexFromRegion function X-Git-Tag: v1.3.0~27^2~16 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=546b81bfa268282f8c5d62ba6bf1aebe314f252d;p=clitk.git Add RemoveNegativeIndexFromRegion function --- 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