From: dsarrut Date: Thu, 22 Jul 2010 09:22:28 +0000 (+0000) Subject: remove argsinfo template X-Git-Tag: v1.2.0~505 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=51ed8f6ccb58c734bda9edfc31a9f0f80c3cc797;p=clitk.git remove argsinfo template --- diff --git a/tools/clitkResampleImage.cxx b/tools/clitkResampleImage.cxx index f289128..8eec6ae 100644 --- a/tools/clitkResampleImage.cxx +++ b/tools/clitkResampleImage.cxx @@ -29,7 +29,7 @@ int main(int argc, char * argv[]) GGO(clitkResampleImage, args_info); // Filter - typedef clitk::ResampleImageGenericFilter FilterType; + typedef clitk::ResampleImageGenericFilter FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetArgsInfo(args_info); diff --git a/tools/clitkResampleImage.ggo b/tools/clitkResampleImage.ggo new file mode 100644 index 0000000..491f366 --- /dev/null +++ b/tools/clitkResampleImage.ggo @@ -0,0 +1,28 @@ +#File clitkImageResample.ggo +package "clitkImageResample" +version "2.0" +purpose "Resample an image. You can specify the interpolation, you can apply a Gaussian filter before (automated if downsample)." + +section "Common" +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off +option "imagetypes" - "Verbose: allowed image types" flag off +option "thread" - "Nb of thread to use (default=max)" int no + +section "Input & Output options" +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "like" l "Resample like this image" string no +option "size" - "Number of pixels of each coordonate" int no multiple default="0" +option "spacing" - "Spacing in mm between pixels" float no multiple default="-1.0" +option "default" d "Default pixel value" float no default = "0.0" +option "time" t "Last Dimension Is Time -> do not resample it (auto on for 4D)" flag off + +section "Interpolation" +option "interp" - "Interpolation type: {nn, linear, bspline, blut}" string no default="nn" +option "order" b "BSpline ordre (range 0-5)" int no default="3" +option "sampling" s "BLUT sampling value" int no default="30" + +section "Gaussian filtering" +option "gauss" g "Apply Gaussian before (sigma in mm)" float no multiple default="0.0" +option "autogauss" a "Apply Gaussian with auto sigma when downsample" flag off diff --git a/tools/clitkResampleImageGenericFilter.cxx b/tools/clitkResampleImageGenericFilter.cxx new file mode 100644 index 0000000..1b5269d --- /dev/null +++ b/tools/clitkResampleImageGenericFilter.cxx @@ -0,0 +1,58 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +// clitk +#include "clitkResampleImageGenericFilter.h" +#include "clitkResampleImageWithOptionsFilter.h" + +//-------------------------------------------------------------------- +clitk::ResampleImageGenericFilter::ResampleImageGenericFilter(): + ImageToImageGenericFilter("Resample") +{ + InitializeImageType<2>(); + InitializeImageType<3>(); + InitializeImageType<4>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void clitk::ResampleImageGenericFilter::InitializeImageType() +{ + ADD_DEFAULT_IMAGE_TYPES(Dim); + ADD_IMAGE_TYPE(Dim, short); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void clitk::ResampleImageGenericFilter::SetArgsInfo(const ArgsInfoType & a) +{ + mArgsInfo=a; + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.input_given) { + SetInputFilename(mArgsInfo.input_arg); + } + if (mArgsInfo.output_given) { + SetOutputFilename(mArgsInfo.output_arg); + } +} +//-------------------------------------------------------------------- + diff --git a/tools/clitkResampleImageGenericFilter.h b/tools/clitkResampleImageGenericFilter.h new file mode 100644 index 0000000..12741c5 --- /dev/null +++ b/tools/clitkResampleImageGenericFilter.h @@ -0,0 +1,66 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ + +#ifndef CLITKIRESAMPLEIMAGEGENERICFILTER_H +#define CLITKIRESAMPLEIMAGEGENERICFILTER_H + +// clitk include +#include "clitkResampleImage_ggo.h" +#include "clitkImageToImageGenericFilter.h" + +namespace clitk { + + //-------------------------------------------------------------------- + class ITK_EXPORT ResampleImageGenericFilter: + public ImageToImageGenericFilter { + + public: + // Constructor + ResampleImageGenericFilter(); + + // Types + typedef ResampleImageGenericFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + typedef args_info_clitkResampleImage ArgsInfoType; + + // New + itkNewMacro(Self); + + // Args + void SetArgsInfo(const ArgsInfoType & a); + + // Main function + template void UpdateWithInputImageType(); + + protected: + ArgsInfoType mArgsInfo; + template void InitializeImageType(); + + }; // end class ResampleImageGenericFilter + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkResampleImageGenericFilter.txx" +#endif + +#endif /* end #define CLITKIRESAMPLEIMAGEGENERICFILTER_H */ + diff --git a/tools/clitkResampleImageGenericFilter.txx b/tools/clitkResampleImageGenericFilter.txx new file mode 100644 index 0000000..e1c2d43 --- /dev/null +++ b/tools/clitkResampleImageGenericFilter.txx @@ -0,0 +1,143 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +#ifndef CLITKRESAMPLEIMAGEGENERICFILTER_TXX +#define CLITKRESAMPLEIMAGEGENERICFILTER_TXX + +// clitk +#include "clitkResampleImageWithOptionsFilter.h" + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +void +clitk::ResampleImageGenericFilter::UpdateWithInputImageType() +{ + + // Reading input + typename InputImageType::Pointer input = this->template GetInput(0); + + // Main filter + typedef typename InputImageType::PixelType PixelType; + typedef InputImageType OutputImageType; // to change to float is user ask it (?) + + // Filter + typedef clitk::ResampleImageWithOptionsFilter ResampleImageFilterType; + typename ResampleImageFilterType::Pointer filter = ResampleImageFilterType::New(); + filter->SetInput(input); + + // Set Verbose + filter->SetVerboseOptions(mArgsInfo.verbose_flag); + + // Set size / spacing + static const unsigned int dim = OutputImageType::ImageDimension; + typename OutputImageType::SpacingType spacing; + typename OutputImageType::SizeType size; + + if (mArgsInfo.like_given) { + DD("like"); + + } + else { + if (mArgsInfo.spacing_given == 1) { + filter->SetOutputIsoSpacing(mArgsInfo.spacing_arg[0]); + } else { + if ((mArgsInfo.spacing_given != 0) && (mArgsInfo.size_given != 0)) { + std::cerr << "Error: use spacing or size, not both." << std::endl; + exit(0); + } + + if (!((mArgsInfo.spacing_given == 0) && (mArgsInfo.size_given == 0))) { + + if ((mArgsInfo.spacing_given != 0) && (mArgsInfo.spacing_given != dim)) { + std::cerr << "Error: spacing should have one or " << dim << " values." << std::endl; + exit(0); + } + if ((mArgsInfo.size_given != 0) && (mArgsInfo.size_given != dim)) { + std::cerr << "Error: size should have " << dim << " values." << std::endl; + exit(0); + } + if (mArgsInfo.spacing_given) + for(unsigned int i=0; iSetOutputSpacing(spacing); + filter->SetOutputSize(size); + } + } + } + + // Set temporal dimension + filter->SetLastDimensionIsTime(mArgsInfo.time_flag); + + // Set Gauss + filter->SetGaussianFilteringEnabled(mArgsInfo.autogauss_flag); + if (mArgsInfo.gauss_given != 0) { + typename ResampleImageFilterType::GaussianSigmaType g; + for(unsigned int i=0; iSetGaussianSigma(g); + } + + // Set Interpolation + std::string interp = std::string(mArgsInfo.interp_arg); + if (interp == "nn") { + filter->SetInterpolationType(ResampleImageFilterType::NearestNeighbor); + } else { + if (interp == "linear") { + filter->SetInterpolationType(ResampleImageFilterType::Linear); + } else { + if (interp == "bspline") { + filter->SetInterpolationType(ResampleImageFilterType::BSpline); + } else { + if (interp == "blut") { + filter->SetInterpolationType(ResampleImageFilterType::B_LUT); + } else { + if (interp == "windowed sinc") { + filter->SetInterpolationType(ResampleImageFilterType::WSINC); + } else { + std::cerr << "Error. I do not know interpolation '" << mArgsInfo.interp_arg + << "'. Choose among: nn, linear, bspline, blut, windowed sinc" << std::endl; + exit(0); + } + } + } + } + } + + // Set default pixel value + filter->SetDefaultPixelValue(mArgsInfo.default_arg); + + // Set thread + if (mArgsInfo.thread_given) { + filter->SetNumberOfThreads(mArgsInfo.thread_arg); + } + + // Go ! + filter->Update(); + typename OutputImageType::Pointer outputImage = filter->GetOutput(); + this->template SetNextOutput(outputImage); +} +//-------------------------------------------------------------------- + +#endif /* end #define CLITKRESAMPLEIMAGEGENERICFILTER_TXX */ +