From: tbaudier Date: Tue, 16 Oct 2018 08:41:26 +0000 (+0200) Subject: Add like option in clitkExtrude tool X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=22aac696ea46e2e4f989d8893bcb978f63715aef;p=clitk.git Add like option in clitkExtrude tool Before we had to set size, spacing and origin for the new dimension But we could want to have the same size, spacing and origin than another image. So I add the like option I remove the required for the size option because if like is set , size is not mandatory I controled that like and origin, size or spacing are not set at the same time --- diff --git a/tools/clitkExtrude.ggo b/tools/clitkExtrude.ggo index 680d188..f7a2263 100644 --- a/tools/clitkExtrude.ggo +++ b/tools/clitkExtrude.ggo @@ -8,6 +8,7 @@ option "verbose" v "Verbose" flag off option "input" i "Input image filename" string required option "output" o "Output image filename" string required -option "size" N "Size in pixel of extrusion" int yes +option "size" N "Size in pixel of extrusion" int no default="1" option "spacing" s "Spacing of the new dimension" double no default="1.0" option "origin" - "Origin of the new dimension" double no default="0.0" +option "like" l "Size, spacing and origin like this image" string no diff --git a/tools/clitkExtrudeGenericFilter.txx b/tools/clitkExtrudeGenericFilter.txx index 96c7dc1..30eafea 100644 --- a/tools/clitkExtrudeGenericFilter.txx +++ b/tools/clitkExtrudeGenericFilter.txx @@ -19,6 +19,7 @@ #define clitkExtrudeGenericFilter_txx // itk include +#include #include namespace clitk @@ -89,14 +90,46 @@ ExtrudeGenericFilter::UpdateWithInputImageType() start.Fill(0); + //Check if like is given and not size, origin and spacing int extrusionSize(1); - if (mArgsInfo.size_given) { - if (mArgsInfo.size_arg > 0) - extrusionSize = mArgsInfo.size_arg; - else { - std::cerr << "The size has to be > 0" << std::endl; + double extrusionOrigin(0.0), extrusionSpacing(1.0); + + if (mArgsInfo.like_given) { + if (mArgsInfo.size_given || mArgsInfo.spacing_given || mArgsInfo.origin_given) { + std::cerr << "You cannot set --like and --size, --origin or --spacing at the same time" << std::endl; return; } + + // Read the input like image + typedef itk::ImageFileReader LikeReaderType; + typename LikeReaderType::Pointer reader = LikeReaderType::New(); + reader->SetFileName(mArgsInfo.like_arg); + reader->Update(); + typename OutputImageType::Pointer likeImage = reader->GetOutput(); + + extrusionSize = likeImage->GetLargestPossibleRegion().GetSize()[Dim]; + extrusionSpacing = likeImage->GetSpacing()[Dim]; + extrusionOrigin = likeImage->GetOrigin()[Dim]; + } else { + if (mArgsInfo.size_given) { + if (mArgsInfo.size_arg > 0) + extrusionSize = mArgsInfo.size_arg; + else { + std::cerr << "The size has to be > 0" << std::endl; + return; + } + } + if (mArgsInfo.origin_given) { + extrusionOrigin = mArgsInfo.origin_arg; + } + if (mArgsInfo.spacing_given) { + if (mArgsInfo.spacing_arg > 0) + extrusionSpacing = mArgsInfo.spacing_arg; + else { + std::cerr << "The spacing has to be > 0" << std::endl; + return; + } + } } for (unsigned int i=0; i