From 45b13896fee9554eaab3826e5e012a2f297977c6 Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Thu, 6 Jun 2013 19:04:19 +0200 Subject: [PATCH] New clitkAnistropicDiffusionFilter for ESRF team --- tools/CMakeLists.txt | 7 ++ tools/clitkAnisotropicDiffusion.cxx | 41 +++++++ tools/clitkAnisotropicDiffusion.ggo | 15 +++ ...clitkAnisotropicDiffusionGenericFilter.cxx | 107 ++++++++++++++++++ .../clitkAnisotropicDiffusionGenericFilter.h | 66 +++++++++++ 5 files changed, 236 insertions(+) create mode 100644 tools/clitkAnisotropicDiffusion.cxx create mode 100644 tools/clitkAnisotropicDiffusion.ggo create mode 100644 tools/clitkAnisotropicDiffusionGenericFilter.cxx create mode 100644 tools/clitkAnisotropicDiffusionGenericFilter.h diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 98489ad..5077acc 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -258,6 +258,13 @@ IF (CLITK_BUILD_TOOLS) TARGET_LINK_LIBRARIES(clitkCatImage clitkCommon) SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkCatImage) + WRAP_GGO(clitkAnisotropicDiffusion_GGO_C clitkAnisotropicDiffusion.ggo) + ADD_EXECUTABLE(clitkAnisotropicDiffusion clitkAnisotropicDiffusion.cxx + clitkAnisotropicDiffusionGenericFilter.cxx + ${clitkAnisotropicDiffusion_GGO_C}) + TARGET_LINK_LIBRARIES(clitkAnisotropicDiffusion clitkCommon) + SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkAnisotropicDiffusion) + IF(CLITK_EXPERIMENTAL) WRAP_GGO(clitkBinaryImageToMesh_GGO_C clitkBinaryImageToMesh.ggo) ADD_EXECUTABLE(clitkBinaryImageToMesh clitkBinaryImageToMesh.cxx ${clitkBinaryImageToMesh_GGO_C}) diff --git a/tools/clitkAnisotropicDiffusion.cxx b/tools/clitkAnisotropicDiffusion.cxx new file mode 100644 index 0000000..08d36c3 --- /dev/null +++ b/tools/clitkAnisotropicDiffusion.cxx @@ -0,0 +1,41 @@ +/*========================================================================= + 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 "clitkAnisotropicDiffusion_ggo.h" +#include "clitkAnisotropicDiffusionGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) +{ + + // Init command line + GGO(clitkAnisotropicDiffusion, args_info); + CLITK_INIT; + + // Filter + typedef clitk::AnisotropicDiffusionGenericFilter FilterType; + FilterType::Pointer filter = FilterType::New(); + + filter->SetArgsInfo(args_info); + + CLITK_TRY_CATCH_EXIT(filter->Update()); + + return EXIT_SUCCESS; +} // This is the end, my friend +//-------------------------------------------------------------------- diff --git a/tools/clitkAnisotropicDiffusion.ggo b/tools/clitkAnisotropicDiffusion.ggo new file mode 100644 index 0000000..61964f3 --- /dev/null +++ b/tools/clitkAnisotropicDiffusion.ggo @@ -0,0 +1,15 @@ +#File clitkAnisotropicDiffusion.ggo +package "clitkAnisotropicDiffusion" +version "1.0" +purpose "Performs gradient or curvature anisotropic diffusion filtering" + +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off +option "imagetypes" - "Display allowed image types" flag off + +option "input" i "Input image filename" string yes +option "output" o "Output image filename" string yes +option "type" - "Type of filtering" values="Gradient","Curvature" enum no default="Gradient" +option "niterations" n "Number of iterations" int no default="5" +option "conductance" c "Conductance" double no default="3" +option "timestep" t "Time step" double no default="0.01" diff --git a/tools/clitkAnisotropicDiffusionGenericFilter.cxx b/tools/clitkAnisotropicDiffusionGenericFilter.cxx new file mode 100644 index 0000000..e020d54 --- /dev/null +++ b/tools/clitkAnisotropicDiffusionGenericFilter.cxx @@ -0,0 +1,107 @@ +/*========================================================================= + 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 clitkAnisotropicDiffusionGenericFilter_cxx +#define clitkAnisotropicDiffusionGenericFilter_cxx + +#include "clitkAnisotropicDiffusionGenericFilter.h" + +// itk include +#include +#include + +//#include + +namespace clitk +{ + +//-------------------------------------------------------------------- +AnisotropicDiffusionGenericFilter::AnisotropicDiffusionGenericFilter(): + ImageToImageGenericFilter("AnisotropicDiffusion") +{ + InitializeImageType<2>(); + InitializeImageType<3>(); + InitializeImageType<4>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void AnisotropicDiffusionGenericFilter::InitializeImageType() +{ + ADD_DEFAULT_IMAGE_TYPES(Dim); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +void AnisotropicDiffusionGenericFilter::SetArgsInfo(const args_info_type & a) +{ + mArgsInfo=a; + if (mArgsInfo.verbose_given) + SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_given && mArgsInfo.imagetypes_flag) + this->PrintAvailableImageTypes(); + if (mArgsInfo.input_given) { + SetInputFilename(mArgsInfo.input_arg); + } + if (mArgsInfo.output_given) { + SetOutputFilename(mArgsInfo.output_arg); + } +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +void +AnisotropicDiffusionGenericFilter::UpdateWithInputImageType() +{ + // Reading input + typename InputImageType::Pointer input = this->template GetInput(0); + + // Filter + typedef itk::CurvatureAnisotropicDiffusionImageFilter CADIFType; + typename CADIFType::Pointer cadFilter = CADIFType::New(); + typedef itk::GradientAnisotropicDiffusionImageFilter GADIFType; + typename GADIFType::Pointer gadFilter = GADIFType::New(); + switch(mArgsInfo.type_arg) { + case type_arg_Gradient: + gadFilter->SetInput(input); + gadFilter->SetNumberOfIterations(mArgsInfo.niterations_arg); + gadFilter->SetTimeStep(mArgsInfo.timestep_arg); + gadFilter->SetConductanceParameter(mArgsInfo.conductance_arg); + gadFilter->Update(); + this->template SetNextOutput(gadFilter->GetOutput()); + case type_arg_Curvature: + cadFilter->SetInput(input); + cadFilter->SetNumberOfIterations(mArgsInfo.niterations_arg); + cadFilter->SetTimeStep(mArgsInfo.timestep_arg); + cadFilter->SetConductanceParameter(mArgsInfo.conductance_arg); + cadFilter->Update(); + this->template SetNextOutput(cadFilter->GetOutput()); + } +} +//-------------------------------------------------------------------- + + +}//end clitk + +#endif //#define clitkAnisotropicDiffusionGenericFilter_cxx diff --git a/tools/clitkAnisotropicDiffusionGenericFilter.h b/tools/clitkAnisotropicDiffusionGenericFilter.h new file mode 100644 index 0000000..855fa0e --- /dev/null +++ b/tools/clitkAnisotropicDiffusionGenericFilter.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://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 clitkAnisotropicDiffusionGenericFilter_h +#define clitkAnisotropicDiffusionGenericFilter_h + +#include "clitkIO.h" +#include "clitkImageToImageGenericFilter.h" +#include "clitkAnisotropicDiffusion_ggo.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + + class ITK_EXPORT AnisotropicDiffusionGenericFilter: + public ImageToImageGenericFilter + { + + public: + //-------------------------------------------------------------------- + typedef AnisotropicDiffusionGenericFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + typedef args_info_clitkAnisotropicDiffusion args_info_type; + + //-------------------------------------------------------------------- + // Method for creation through the object factory + // and Run-time type information (and related methods) + itkNewMacro(Self); + itkTypeMacro(AnisotropicDiffusionGenericFilter, LightObject); + + //-------------------------------------------------------------------- + void SetArgsInfo(const args_info_type & a); + + //-------------------------------------------------------------------- + // Main function called each time the filter is updated + template + void UpdateWithInputImageType(); + + protected: + AnisotropicDiffusionGenericFilter(); + template void InitializeImageType(); + args_info_type mArgsInfo; + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#endif // #define clitkAnisotropicDiffusionGenericFilter_h -- 2.47.1