From ae2e1c75a6d57bc14e30e3205b6b1f2d8e5cf50c Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Mon, 7 Dec 2015 13:07:19 +0100 Subject: [PATCH] Added clitkSum to take the sum in one direction, corrected clitkFooImage and removed it from compilation --- tools/CMakeLists.txt | 10 +-- tools/clitkFooImage.cxx | 9 --- tools/clitkFooImage.ggo | 5 -- tools/clitkFooImageGenericFilter.h | 4 +- tools/clitkFooImageGenericFilter.txx | 48 ++------------ tools/clitkSum.cxx | 45 +++++++++++++ tools/clitkSum.ggo | 13 ++++ tools/clitkSumGenericFilter.h | 69 ++++++++++++++++++++ tools/clitkSumGenericFilter.txx | 97 ++++++++++++++++++++++++++++ 9 files changed, 236 insertions(+), 64 deletions(-) create mode 100644 tools/clitkSum.cxx create mode 100644 tools/clitkSum.ggo create mode 100644 tools/clitkSumGenericFilter.h create mode 100644 tools/clitkSumGenericFilter.txx diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 6bd72a3..3bf8948 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -153,11 +153,6 @@ if(CLITK_BUILD_TOOLS) target_link_libraries(clitkUnsharpMask clitkCommon ) set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkUnsharpMask) - WRAP_GGO(clitkFooImage_GGO_C clitkFooImage.ggo) - add_executable(clitkFooImage clitkFooImage.cxx ${clitkFooImage_GGO_C}) - target_link_libraries(clitkFooImage clitkCommon ) - set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkFooImage) - WRAP_GGO(clitkMedianImageFilter_GGO_C clitkMedianImageFilter.ggo) add_executable(clitkMedianImageFilter clitkMedianImageFilter.cxx ${clitkMedianImageFilter_GGO_C}) target_link_libraries(clitkMedianImageFilter clitkMedianImageFilterLib clitkCommon) @@ -251,6 +246,11 @@ if(CLITK_BUILD_TOOLS) target_link_libraries(clitkMIP clitkMIPLib clitkCommon) set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkMIP) + WRAP_GGO(clitkSum_GGO_C clitkSum.ggo) + add_executable(clitkSum clitkSum.cxx ${clitkSum_GGO_C}) + target_link_libraries(clitkSum clitkCommon) + set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkSum) + WRAP_GGO(clitkTransformLandmarks_GGO_C clitkTransformLandmarks.ggo) add_executable(clitkTransformLandmarks clitkTransformLandmarks.cxx ${clitkTransformLandmarks_GGO_C}) target_link_libraries(clitkTransformLandmarks clitkCommon) diff --git a/tools/clitkFooImage.cxx b/tools/clitkFooImage.cxx index 51d00ba..046f6aa 100644 --- a/tools/clitkFooImage.cxx +++ b/tools/clitkFooImage.cxx @@ -16,15 +16,6 @@ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ===========================================================================**/ -/* ================================================= - * @file clitkFooImageGenericFilter.txx - * @author xxx - * @date 29 June 2029 - * - * @brief FooImage an image - * - ===================================================*/ - // clitk #include "clitkFooImage_ggo.h" #include "clitkFooImageGenericFilter.h" diff --git a/tools/clitkFooImage.ggo b/tools/clitkFooImage.ggo index 3d0c8db..d859773 100644 --- a/tools/clitkFooImage.ggo +++ b/tools/clitkFooImage.ggo @@ -10,9 +10,4 @@ option "imagetypes" - "Display allowed image types" flag off option "input" i "Input image filename" string required option "output" o "Output image filename" string required -option "lower" l "Lower intensity (default=min), fg is greater than this value" double optional -option "upper" u "Upper intensity (default=max), fg is lower than this value" double optional -option "fg" - "Foreground (FG) or 'inside' value" double optional default="1" -option "bg" - "Background (BG) or 'ouside' value" double optional default="0" -option "mode" - "Use FG and/or BG values (if FG, the BG is replaced by the input image values)" values="FG","BG","both" default="both" optional diff --git a/tools/clitkFooImageGenericFilter.h b/tools/clitkFooImageGenericFilter.h index e230f91..7578411 100644 --- a/tools/clitkFooImageGenericFilter.h +++ b/tools/clitkFooImageGenericFilter.h @@ -15,8 +15,8 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ===========================================================================**/ -#ifndef CLITKFooIMAGEGENERICFILTER_H -#define CLITKFooIMAGEGENERICFILTER_H +#ifndef clitkFooImageGenericFilter_h +#define clitkFooImageGenericFilter_h #include "clitkIO.h" #include "clitkImageToImageGenericFilter.h" diff --git a/tools/clitkFooImageGenericFilter.txx b/tools/clitkFooImageGenericFilter.txx index 88473a0..1724454 100644 --- a/tools/clitkFooImageGenericFilter.txx +++ b/tools/clitkFooImageGenericFilter.txx @@ -18,15 +18,6 @@ #ifndef clitkFooImageGenericFilter_txx #define clitkFooImageGenericFilter_txx -/* ================================================= - * @file clitkFooImageGenericFilter.txx - * @author Jef Vandemeulebroucke - * @date 29 june 2009 - * - * @brief - * - ===================================================*/ - // itk include #include "itkBinaryThresholdImageFilter.h" #include "itkMaskImageFilter.h" @@ -95,40 +86,11 @@ FooImageGenericFilter::UpdateWithInputImageType() typedef itk::BinaryThresholdImageFilter BinaryThresholdImageFilterType; typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New(); thresholdFilter->SetInput(input); - thresholdFilter->SetInsideValue(mArgsInfo.fg_arg); - - if (mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast(mArgsInfo.lower_arg)); - if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast(mArgsInfo.upper_arg)); - - if (mArgsInfo.mode_arg == std::string("both")) { - thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg); - thresholdFilter->Update(); - - typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput(); - this->template SetNextOutput(outputImage); - } else { - typename InputImageType::Pointer outputImage; - thresholdFilter->SetOutsideValue(0); - if (mArgsInfo.mode_arg == std::string("BG")) { - typedef itk::MaskImageFilter maskFilterType; - typename maskFilterType::Pointer maskFilter = maskFilterType::New(); - maskFilter->SetInput1(input); - maskFilter->SetInput2(thresholdFilter->GetOutput()); - maskFilter->SetOutsideValue(mArgsInfo.bg_arg); - maskFilter->Update(); - outputImage = maskFilter->GetOutput(); - } else { - typedef itk::MaskNegatedImageFilter maskFilterType; - typename maskFilterType::Pointer maskFilter = maskFilterType::New(); - maskFilter->SetInput1(input); - maskFilter->SetInput2(thresholdFilter->GetOutput()); - maskFilter->SetOutsideValue(mArgsInfo.fg_arg); - maskFilter->Update(); - outputImage = maskFilter->GetOutput(); - } - // Write/Save results - this->template SetNextOutput(outputImage); - } + // Set filter members + + // Write/Save results + typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput(); + this->template SetNextOutput(outputImage); } //-------------------------------------------------------------------- diff --git a/tools/clitkSum.cxx b/tools/clitkSum.cxx new file mode 100644 index 0000000..6a4e185 --- /dev/null +++ b/tools/clitkSum.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 "clitkSum_ggo.h" +#include "clitkSumGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) +{ + + // Init command line + GGO(clitkSum, args_info); + CLITK_INIT; + + // Filter + typedef clitk::SumGenericFilter 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/clitkSum.ggo b/tools/clitkSum.ggo new file mode 100644 index 0000000..e9938f2 --- /dev/null +++ b/tools/clitkSum.ggo @@ -0,0 +1,13 @@ +#File clitkSum.ggo +package "clitkSum" +version "1.0" +purpose "" + +option "config" - "Config file" string optional +option "verbose" v "Verbose" flag off + +option "imagetypes" - "Display allowed image types" flag off + +option "input" i "Input image filename" string required +option "output" o "Output image filename" string required +option "dimension" d "Dimension along which to sum" int yes diff --git a/tools/clitkSumGenericFilter.h b/tools/clitkSumGenericFilter.h new file mode 100644 index 0000000..acebb90 --- /dev/null +++ b/tools/clitkSumGenericFilter.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 clitkSumGenericFilter_h +#define clitkSumGenericFilter_h +#include "clitkIO.h" +#include "clitkImageToImageGenericFilter.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + +template +class ITK_EXPORT SumGenericFilter: + public ImageToImageGenericFilter > +{ + +public: + + //-------------------------------------------------------------------- + SumGenericFilter(); + + //-------------------------------------------------------------------- + typedef SumGenericFilter 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(SumGenericFilter, 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 "clitkSumGenericFilter.txx" +#endif + +#endif // #define clitkSumGenericFilter_h diff --git a/tools/clitkSumGenericFilter.txx b/tools/clitkSumGenericFilter.txx new file mode 100644 index 0000000..f7fb5f0 --- /dev/null +++ b/tools/clitkSumGenericFilter.txx @@ -0,0 +1,97 @@ +/*========================================================================= + 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 clitkSumGenericFilter_txx +#define clitkSumGenericFilter_txx + +// itk include +#include +#include + +namespace clitk +{ + +//-------------------------------------------------------------------- +template +SumGenericFilter::SumGenericFilter(): + ImageToImageGenericFilter("Sum") +{ + InitializeImageType<3>(); + InitializeImageType<4>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void SumGenericFilter::InitializeImageType() +{ + ADD_DEFAULT_IMAGE_TYPES(Dim); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void SumGenericFilter::SetArgsInfo(const args_info_type & a) +{ + mArgsInfo=a; + this->SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + + 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 +SumGenericFilter::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; + + // Filter + typedef itk::SumProjectionImageFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + filter->SetProjectionDimension(mArgsInfo.dimension_arg); + filter->SetInput(input); + filter->Update(); + this->template SetNextOutput(filter->GetOutput()); +} +//-------------------------------------------------------------------- + + +}//end clitk + +#endif //#define clitkSumGenericFilter_txx -- 2.47.1