From 786489951ba13c4daaf7f8541dce5ac369fd3a7b Mon Sep 17 00:00:00 2001 From: tbaudier Date: Mon, 15 Oct 2018 12:08:35 +0200 Subject: [PATCH] Add clitkExtrude tool With this tool, you can copy the image i N times along the last dimension --- tools/CMakeLists.txt | 5 + tools/clitkExtrude.cxx | 45 ++++++++ tools/clitkExtrude.ggo | 13 +++ tools/clitkExtrudeGenericFilter.h | 69 ++++++++++++ tools/clitkExtrudeGenericFilter.txx | 157 ++++++++++++++++++++++++++++ 5 files changed, 289 insertions(+) create mode 100644 tools/clitkExtrude.cxx create mode 100644 tools/clitkExtrude.ggo create mode 100644 tools/clitkExtrudeGenericFilter.h create mode 100644 tools/clitkExtrudeGenericFilter.txx diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 468bc36..4259e19 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -304,6 +304,11 @@ if(CLITK_BUILD_TOOLS) target_link_libraries(clitkSum clitkCommon) set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkSum) + WRAP_GGO(clitkExtrude_GGO_C clitkExtrude.ggo) + add_executable(clitkExtrude clitkExtrude.cxx ${clitkExtrude_GGO_C}) + target_link_libraries(clitkExtrude clitkCommon) + set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkExtrude) + WRAP_GGO(clitkTransformLandmarks_GGO_C clitkTransformLandmarks.ggo) add_executable(clitkTransformLandmarks clitkTransformLandmarks.cxx ${clitkTransformLandmarks_GGO_C}) target_link_libraries(clitkTransformLandmarks clitkCommon) diff --git a/tools/clitkExtrude.cxx b/tools/clitkExtrude.cxx new file mode 100644 index 0000000..f860f58 --- /dev/null +++ b/tools/clitkExtrude.cxx @@ -0,0 +1,45 @@ +/*========================================================================= + 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://www.centreleonberard.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 "clitkExtrude_ggo.h" +#include "clitkExtrudeGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) +{ + + // Init command line + GGO(clitkExtrude, args_info); + CLITK_INIT; + + // Filter + typedef clitk::ExtrudeGenericFilter FilterType; + FilterType::Pointer filter = FilterType::New(); + + filter->SetArgsInfo(args_info); + try { + filter->Update(); + } catch(std::runtime_error e) { + std::cout << e.what() << std::endl; + } + + return EXIT_SUCCESS; +}// end main + +//-------------------------------------------------------------------- diff --git a/tools/clitkExtrude.ggo b/tools/clitkExtrude.ggo new file mode 100644 index 0000000..680d188 --- /dev/null +++ b/tools/clitkExtrude.ggo @@ -0,0 +1,13 @@ +#File clitkExtrude.ggo +package "clitkExtrude" +version "1.0" +purpose "Extrude an image i along the last+1 dimension repeating the image N times. So the output has 1 dimension more than the input." + +option "config" - "Config file" string optional +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 "spacing" s "Spacing of the new dimension" double no default="1.0" +option "origin" - "Origin of the new dimension" double no default="0.0" diff --git a/tools/clitkExtrudeGenericFilter.h b/tools/clitkExtrudeGenericFilter.h new file mode 100644 index 0000000..73f512f --- /dev/null +++ b/tools/clitkExtrudeGenericFilter.h @@ -0,0 +1,69 @@ +/*========================================================================= + 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://www.centreleonberard.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 clitkExtrudeGenericFilter_h +#define clitkExtrudeGenericFilter_h +#include "clitkIO.h" +#include "clitkImageToImageGenericFilter.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + +template +class ITK_EXPORT ExtrudeGenericFilter: + public ImageToImageGenericFilter > +{ + +public: + + //-------------------------------------------------------------------- + ExtrudeGenericFilter(); + + //-------------------------------------------------------------------- + typedef ExtrudeGenericFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //-------------------------------------------------------------------- + // Method for creation through the object factory + // and Run-time type information (and related methods) + itkNewMacro(Self); + itkTypeMacro(ExtrudeGenericFilter, LightObject); + + //-------------------------------------------------------------------- + void SetArgsInfo(const args_info_type & a); + + //-------------------------------------------------------------------- + // Main function called each time the filter is updated + template + void UpdateWithInputImageType(); + +protected: + template void InitializeImageType(); + args_info_type mArgsInfo; + +}; // end class +//-------------------------------------------------------------------- + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkExtrudeGenericFilter.txx" +#endif + +#endif // #define clitkExtrudeGenericFilter_h diff --git a/tools/clitkExtrudeGenericFilter.txx b/tools/clitkExtrudeGenericFilter.txx new file mode 100644 index 0000000..96c7dc1 --- /dev/null +++ b/tools/clitkExtrudeGenericFilter.txx @@ -0,0 +1,157 @@ +/*========================================================================= + 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://www.centreleonberard.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 clitkExtrudeGenericFilter_txx +#define clitkExtrudeGenericFilter_txx + +// itk include +#include + +namespace clitk +{ + +//-------------------------------------------------------------------- +template +ExtrudeGenericFilter::ExtrudeGenericFilter(): + ImageToImageGenericFilter("Extrude") +{ + InitializeImageType<2>(); + InitializeImageType<3>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void ExtrudeGenericFilter::InitializeImageType() +{ + ADD_DEFAULT_IMAGE_TYPES(Dim); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void ExtrudeGenericFilter::SetArgsInfo(const args_info_type & a) +{ + mArgsInfo=a; + this->SetIOVerbose(mArgsInfo.verbose_flag); + + if (mArgsInfo.input_given) { + this->SetInputFilename(mArgsInfo.input_arg); + } + if (mArgsInfo.output_given) { + this->SetOutputFilename(mArgsInfo.output_arg); + } +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void +ExtrudeGenericFilter::UpdateWithInputImageType() +{ + + // Reading input + typename InputImageType::Pointer input = this->template GetInput(0); + + // Main filter + typedef typename InputImageType::PixelType PixelType; + const int Dim = InputImageType::ImageDimension; + typedef itk::Image ImageType; + typedef itk::Image OutputImageType; + + //Create the output + typename OutputImageType::IndexType start; + typename OutputImageType::SizeType size; + typename OutputImageType::PointType origin; + typename OutputImageType::SpacingType spacing; + typename OutputImageType::DirectionType direction; + typename OutputImageType::Pointer output = OutputImageType::New(); + + start.Fill(0); + + 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; + return; + } + } + + for (unsigned int i=0; iGetLargestPossibleRegion().GetSize()[i]; + size[Dim] = extrusionSize; + + for (unsigned int i=0; iGetOrigin()[i]; + if (mArgsInfo.origin_given) + origin[Dim] = mArgsInfo.origin_arg; + else + origin[Dim] = 0; + + for (unsigned int i=0; iGetSpacing()[i]; + if (mArgsInfo.spacing_given) + spacing[Dim] = mArgsInfo.spacing_arg; + else + spacing[Dim] = 1; + + for (unsigned int i=0; iGetDirection()[i][j]; + direction[i][Dim] = 0; + } + for (unsigned int i=0; iSetRegions(region); + output->Allocate(); + output->FillBuffer(0); + output->SetOrigin(origin); + output->SetSpacing(spacing); + output->SetDirection(direction); + + itk::ImageRegionIteratorWithIndex inputIterator(input, input->GetLargestPossibleRegion()); + while(!inputIterator.IsAtEnd()) { + typename OutputImageType::IndexType pixelIndex; + for (unsigned int i=0; iSetPixel(pixelIndex, inputIterator.Get()); + } + ++inputIterator; + } + + this->template SetNextOutput(output); + +} +//-------------------------------------------------------------------- + + +}//end clitk + +#endif //#define clitkExtrudeGenericFilter_txx -- 2.45.0