From 18383744683942aab80bfaf99600279c1854d151 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Wed, 15 Dec 2010 08:52:56 +0000 Subject: [PATCH] add relativeposition tool --- tools/CMakeLists.txt | 5 + tools/clitkRelativePosition.cxx | 44 ++++++ tools/clitkRelativePosition.ggo | 35 +++++ tools/clitkRelativePositionGenericFilter.h | 76 ++++++++++ tools/clitkRelativePositionGenericFilter.txx | 144 +++++++++++++++++++ 5 files changed, 304 insertions(+) create mode 100644 tools/clitkRelativePosition.cxx create mode 100644 tools/clitkRelativePosition.ggo create mode 100644 tools/clitkRelativePositionGenericFilter.h create mode 100644 tools/clitkRelativePositionGenericFilter.txx diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 8157242..9220413 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -242,4 +242,9 @@ IF (CLITK_BUILD_TOOLS) WRAP_GGO(clitkMIP_GGO_C clitkMIP.ggo) ADD_EXECUTABLE(clitkMIP clitkMIP.cxx clitkMIPGenericFilter.cxx ${clitkMIP_GGO_C}) TARGET_LINK_LIBRARIES(clitkMIP clitkCommon ITKIO) + + WRAP_GGO(clitkRelativePosition_GGO_C clitkRelativePosition.ggo) + ADD_EXECUTABLE(clitkRelativePosition clitkRelativePosition.cxx ${clitkRelativePosition_GGO_C}) + TARGET_LINK_LIBRARIES(clitkRelativePosition clitkCommon ITKIO) + ENDIF(CLITK_BUILD_TOOLS) diff --git a/tools/clitkRelativePosition.cxx b/tools/clitkRelativePosition.cxx new file mode 100644 index 0000000..4e2280a --- /dev/null +++ b/tools/clitkRelativePosition.cxx @@ -0,0 +1,44 @@ +/*========================================================================= + 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 "clitkRelativePosition_ggo.h" +#include "clitkRelativePositionGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkRelativePosition, args_info); + CLITK_INIT; + + // Filter + typedef clitk::RelativePositionGenericFilter 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; +} // This is the end, my friend +//-------------------------------------------------------------------- diff --git a/tools/clitkRelativePosition.ggo b/tools/clitkRelativePosition.ggo new file mode 100644 index 0000000..4f65fe2 --- /dev/null +++ b/tools/clitkRelativePosition.ggo @@ -0,0 +1,35 @@ +#File clitkRelativePosition.ggo +package "clitkRelativePosition" +version "1.0" +purpose "Constraint a given mask image relatively to another object and an orientation" + +section "General options" +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off +option "verboseStep" - "Verbose each step" flag off +option "writeStep" w "Write image at each step" flag off +option "verboseOption" - "Display options values" flag off +option "imagetypes" - "Display allowed image types" flag off + +section "Input/Output" +option "input" i "Input mask image filename" string yes +option "object" j "Input mask object filename" string yes +option "output" o "Output image filename" string yes + +section "Main options" +option "orientation" r "L R A P I S (LeftRightAntPostInfSup)" string no default="L" +option "angle1" a "Angle 1 (deg)" double no default="0" +option "angle2" b "Angle 2 (deg)" double no default="0" +option "spacing" s "Resample before (faster)" double no +option "threshold" t "Fuzzy threshold" double no default="0.6" +option "not" n "Not flag : inverse of the orientation" flag off +option "noAutoCrop" c "No auto crop at the end if set" flag off + +section "Slice by slice processing" +option "sliceBySlice" - "Slice by slice relative position" flag off +option "direction" d "If SbS, indicate the slice direction" int no default="2" + + + + + diff --git a/tools/clitkRelativePositionGenericFilter.h b/tools/clitkRelativePositionGenericFilter.h new file mode 100644 index 0000000..930c995 --- /dev/null +++ b/tools/clitkRelativePositionGenericFilter.h @@ -0,0 +1,76 @@ +/*========================================================================= + 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 CLITKEXTRACTPATIENTGENERICFILTER_H +#define CLITKEXTRACTPATIENTGENERICFILTER_H + +// clitk +#include "clitkIO.h" +#include "clitkImageToImageGenericFilter.h" +#include "clitkAddRelativePositionConstraintToLabelImageFilter.h" +#include "clitkSliceBySliceRelativePositionFilter.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + + template + class ITK_EXPORT RelativePositionGenericFilter: + public ImageToImageGenericFilter > + { + public: + //-------------------------------------------------------------------- + RelativePositionGenericFilter(); + + //-------------------------------------------------------------------- + typedef ImageToImageGenericFilter > Superclass; + typedef RelativePositionGenericFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //-------------------------------------------------------------------- + itkNewMacro(Self); + itkTypeMacro(RelativePositionGenericFilter, LightObject); + + //-------------------------------------------------------------------- + void SetArgsInfo(const ArgsInfoType & a); + template + void SetOptionsFromArgsInfoToFilter(FilterType * f) ; + + //-------------------------------------------------------------------- + // Main function called each time the filter is updated + template + void UpdateWithInputImageType(); + + protected: + template void InitializeImageType(); + ArgsInfoType mArgsInfo; + + private: + RelativePositionGenericFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + };// end class + //-------------------------------------------------------------------- +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkRelativePositionGenericFilter.txx" +#endif + +#endif // #define CLITKEXTRACTPATIENTGENERICFILTER_H diff --git a/tools/clitkRelativePositionGenericFilter.txx b/tools/clitkRelativePositionGenericFilter.txx new file mode 100644 index 0000000..2e62b42 --- /dev/null +++ b/tools/clitkRelativePositionGenericFilter.txx @@ -0,0 +1,144 @@ +/*========================================================================= + 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 + ======================================================================-====*/ + +#include "clitkImageCommon.h" + +//-------------------------------------------------------------------- +template +clitk::RelativePositionGenericFilter:: +RelativePositionGenericFilter(): + ImageToImageGenericFilter("RelativePosition") +{ + // Default values + cmdline_parser_clitkRelativePosition_init(&mArgsInfo); + InitializeImageType<3>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void clitk::RelativePositionGenericFilter:: +InitializeImageType() +{ + ADD_IMAGE_TYPE(Dim, uchar); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void clitk::RelativePositionGenericFilter:: +SetArgsInfo(const ArgsInfoType & a) +{ + mArgsInfo=a; + SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + if (mArgsInfo.input_given) AddInputFilename(mArgsInfo.input_arg); + if (mArgsInfo.object_given) AddInputFilename(mArgsInfo.object_arg); + if (mArgsInfo.output_given) AddOutputFilename(mArgsInfo.output_arg); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::RelativePositionGenericFilter:: +SetOptionsFromArgsInfoToFilter(FilterType * f) +{ + f->SetVerboseOption(mArgsInfo.verbose_flag); + f->SetVerboseStep(mArgsInfo.verboseStep_flag); + f->SetWriteStep(mArgsInfo.writeStep_flag); + + if (mArgsInfo.orientation_given) { + f->SetOrientationTypeString(mArgsInfo.orientation_arg); + } + + if (mArgsInfo.spacing_given) { + f->ResampleBeforeRelativePositionFilterOn(); + f->SetIntermediateSpacing(mArgsInfo.spacing_arg); + } + + f->SetFuzzyThreshold(mArgsInfo.threshold_arg); + f->SetNotFlag(mArgsInfo.not_flag); + f->SetAutoCropFlag(!mArgsInfo.noAutoCrop_flag); +} + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::RelativePositionGenericFilter:: +UpdateWithInputImageType() +{ + // Reading input + typename ImageType::Pointer input = this->template GetInput(0); + typename ImageType::Pointer object = this->template GetInput(1); + + if (mArgsInfo.sliceBySlice_flag) { + // Create filter + typedef clitk::SliceBySliceRelativePositionFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + + // Set the filter (needed for example for threaded monitoring) + this->SetFilterBase(filter); + + // Set global Options + filter->SetInput(input); + filter->SetInputObject(object); + SetOptionsFromArgsInfoToFilter(filter); + filter->SetDirection(mArgsInfo.direction_arg); // only for SliceBySliceRelativePositionFilter + + // Go ! + filter->Update(); + + // Write/Save results + typename ImageType::Pointer output = filter->GetOutput(); + this->template SetNextOutput(output); + } + else { + // Create filter + typedef clitk::AddRelativePositionConstraintToLabelImageFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + + // Set the filter (needed for example for threaded monitoring) + this->SetFilterBase(filter); + + // Set global Options + filter->SetInput(input); + filter->SetInputObject(object); + filter->SetAngle1(mArgsInfo.angle1_arg);// only for this filter + filter->SetAngle2(mArgsInfo.angle2_arg); + SetOptionsFromArgsInfoToFilter(filter); + + // Go ! + filter->Update(); + + // Write/Save results + typename ImageType::Pointer output = filter->GetOutput(); + this->template SetNextOutput(output); + } +} +//-------------------------------------------------------------------- + + -- 2.47.1