From 54b8c7f94d9e9bef840ba88a7b195b51960f8220 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Mon, 19 Apr 2010 07:13:57 +0000 Subject: [PATCH] - add convenient method --- common/clitkImageCommon.h | 5 +++++ common/clitkImageCommon.txx | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/common/clitkImageCommon.h b/common/clitkImageCommon.h index e320e16..11bdb8f 100644 --- a/common/clitkImageCommon.h +++ b/common/clitkImageCommon.h @@ -52,6 +52,11 @@ namespace clitk { template typename itk::Image::Pointer NewImage4D(int sx, int sy, int sz, int st, double dx=1.0, double dy=1.0, double dz=1.0, double dt=1.0); + template + typename ImageType::Pointer NewImageLike(const typename ImageType::Pointer input, bool allocate=true); + + template + void CopyValues(const typename ImageType::Pointer input, typename ImageType::Pointer output); //-------------------------------------------------------------------- // New Image creation (with allocation) diff --git a/common/clitkImageCommon.txx b/common/clitkImageCommon.txx index b1d1122..547c2c7 100644 --- a/common/clitkImageCommon.txx +++ b/common/clitkImageCommon.txx @@ -96,6 +96,39 @@ typename itk::Image::Pointer NewImage4D(int sx, int sy, int sz, int } //-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +template +typename ImageType::Pointer NewImageLike(const typename ImageType::Pointer input, bool allocate) { + typename ImageType::Pointer output = ImageType::New(); + output->SetRegions(input->GetLargestPossibleRegion()); + output->SetOrigin(input->GetOrigin()); + output->SetSpacing(input->GetSpacing()); + if (allocate) output->Allocate(); + return output; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void CopyValues(const typename ImageType::Pointer input, + typename ImageType::Pointer output) { + typedef itk::ImageRegionConstIterator ConstIteratorType; + ConstIteratorType pi(input,input->GetLargestPossibleRegion()); + pi.GoToBegin(); + typedef itk::ImageRegionIterator IteratorType; + IteratorType po(output,input->GetLargestPossibleRegion()); + po.GoToBegin(); + while (!pi.IsAtEnd()) { + po.Set(pi.Get()); + ++pi; + ++po; + } +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- template typename ImageType::Pointer readImage(const std::string & filename, const bool verbose) { -- 2.47.1