From 938c4491f8ef70565b124a7eeb4f9e69b1b9baba Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Wed, 19 Oct 2011 13:03:44 +0200 Subject: [PATCH] Add first version of RelativePositionAnalyzer --- itk/clitkRelativePositionAnalyzerFilter.h | 114 +++++++++++++++ itk/clitkRelativePositionAnalyzerFilter.txx | 135 ++++++++++++++++++ tools/CMakeLists.txt | 5 + tools/clitkRelativePositionAnalyzer.cxx | 45 ++++++ tools/clitkRelativePositionAnalyzer.ggo | 16 +++ ...itkRelativePositionAnalyzerGenericFilter.h | 75 ++++++++++ ...kRelativePositionAnalyzerGenericFilter.txx | 103 +++++++++++++ 7 files changed, 493 insertions(+) create mode 100644 itk/clitkRelativePositionAnalyzerFilter.h create mode 100644 itk/clitkRelativePositionAnalyzerFilter.txx create mode 100644 tools/clitkRelativePositionAnalyzer.cxx create mode 100644 tools/clitkRelativePositionAnalyzer.ggo create mode 100644 tools/clitkRelativePositionAnalyzerGenericFilter.h create mode 100644 tools/clitkRelativePositionAnalyzerGenericFilter.txx diff --git a/itk/clitkRelativePositionAnalyzerFilter.h b/itk/clitkRelativePositionAnalyzerFilter.h new file mode 100644 index 0000000..2933958 --- /dev/null +++ b/itk/clitkRelativePositionAnalyzerFilter.h @@ -0,0 +1,114 @@ +/*========================================================================= + 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 CLITKRELATIVEPOSITIONANALYZERFILTER_H +#define CLITKRELATIVEPOSITIONANALYZERFILTER_H + +// clitk +#include "clitkCommon.h" + +// itk +#include + +namespace clitk { + + //-------------------------------------------------------------------- + /* + TODO + */ + //-------------------------------------------------------------------- + + template + class ITK_EXPORT RelativePositionAnalyzerFilter: + public itk::ImageToImageFilter + { + + public: + /** Standard class typedefs. */ + typedef itk::ImageToImageFilter Superclass; + typedef RelativePositionAnalyzerFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(RelativePositionAnalyzerFilter, ImageToImageFilter); + + /** Some convenient typedefs. */ + typedef typename ImageType::ConstPointer ImageConstPointer; + typedef typename ImageType::Pointer ImagePointer; + typedef typename ImageType::RegionType RegionType; + typedef typename ImageType::PixelType PixelType; + typedef typename ImageType::SpacingType SpacingType; + typedef typename ImageType::SizeType SizeType; + typedef typename ImageType::IndexType IndexType; + typedef typename ImageType::PointType PointType; + + /** ImageDimension constants */ + itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension); + typedef itk::Image FloatImageType; + + /** Input : initial image and object */ + void SetInputSupport(const ImageType * image); + void SetInputObject(const ImageType * image); + void SetInputTarget(const ImageType * image); + + // Options + itkSetMacro(VerboseFlag, bool); + itkGetConstMacro(VerboseFlag, bool); + itkBooleanMacro(VerboseFlag); + + itkGetConstMacro(BackgroundValue, PixelType); + itkSetMacro(BackgroundValue, PixelType); + + itkGetConstMacro(ForegroundValue, PixelType); + itkSetMacro(ForegroundValue, PixelType); + + // For debug + void PrintOptions(); + + protected: + RelativePositionAnalyzerFilter(); + virtual ~RelativePositionAnalyzerFilter() {} + + bool m_VerboseFlag; + PixelType m_BackgroundValue; + PixelType m_ForegroundValue; + ImagePointer m_Support; + ImagePointer m_Object; + ImagePointer m_Target; + + virtual void GenerateData(); + + private: + RelativePositionAnalyzerFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + }; // end class + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkRelativePositionAnalyzerFilter.txx" +#endif + +#endif diff --git a/itk/clitkRelativePositionAnalyzerFilter.txx b/itk/clitkRelativePositionAnalyzerFilter.txx new file mode 100644 index 0000000..a732aab --- /dev/null +++ b/itk/clitkRelativePositionAnalyzerFilter.txx @@ -0,0 +1,135 @@ +/*========================================================================= + 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 + ===========================================================================**/ + +//-------------------------------------------------------------------- +template +clitk::RelativePositionAnalyzerFilter:: +RelativePositionAnalyzerFilter(): +itk::ImageToImageFilter() +{ + this->SetNumberOfRequiredInputs(3); // support, object, target + VerboseFlagOff(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::RelativePositionAnalyzerFilter:: +SetInputSupport(const ImageType * image) +{ + // Process object is not const-correct so the const casting is required. + this->SetNthInput(0, const_cast(image)); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::RelativePositionAnalyzerFilter:: +SetInputObject(const ImageType * image) +{ + // Process object is not const-correct so the const casting is required. + this->SetNthInput(1, const_cast(image)); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::RelativePositionAnalyzerFilter:: +SetInputTarget(const ImageType * image) +{ + // Process object is not const-correct so the const casting is required. + this->SetNthInput(1, const_cast(image)); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::RelativePositionAnalyzerFilter:: +PrintOptions() +{ + DD("TODO"); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void +clitk::RelativePositionAnalyzerFilter:: +GenerateData() +{ + DD("Update"); + // Get input pointer + m_Support = dynamic_cast(itk::ProcessObject::GetInput(0)); + m_Object = dynamic_cast(itk::ProcessObject::GetInput(1)); + m_Target = dynamic_cast(itk::ProcessObject::GetInput(2)); + static const unsigned int dim = ImageType::ImageDimension; + + /* + Prerequisite: + - target fully inside support ? + */ + + //for(int i=0; i analyze floating point values inside the target area (histo ?) + + // Set threshold and compute new support + + // Compute ratio of area before/after + // http://www.itk.org/Doxygen/html/classitk_1_1LabelStatisticsImageFilter.html#details + /* + typedef itk::LabelStatisticsImageFilter StatisticsImageFilterType; + typename StatisticsImageFilterType::Pointer statisticsFilter = StatisticsImageFilterType::New(); + statisticsFilter->SetInput(m_Input); + statisticsFilter->SetLabelInput(m_Input); + statisticsFilter->Update(); + int n = labelStatisticsImageFilter->GetCount(GetForegroundValue()); + DD(n); + statisticsFilter = StatisticsImageFilterType::New(); + statisticsFilter->SetInput(m_Output); + statisticsFilter->SetLabelInput(m_Output); + statisticsFilter->Update(); + int m = labelStatisticsImageFilter->GetCount(GetForegroundValue()); + DD(m); + */ + + // Print results + + //} + + + // Final Step -> set output TODO + // this->SetNthOutput(0, working_image); + // this->GraftOutput(working_image); +} +//-------------------------------------------------------------------- + diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 8bf0cbc..4ce6ac7 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -315,6 +315,11 @@ IF (CLITK_BUILD_TOOLS) TARGET_LINK_LIBRARIES(clitkRelativePosition clitkCommon ${ITK_LIBRARIES}) SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkRelativePosition) + WRAP_GGO(clitkRelativePositionAnalyzer_GGO_C clitkRelativePositionAnalyzer.ggo) + ADD_EXECUTABLE(clitkRelativePositionAnalyzer clitkRelativePositionAnalyzer.cxx ${clitkRelativePositionAnalyzer_GGO_C}) + TARGET_LINK_LIBRARIES(clitkRelativePositionAnalyzer clitkCommon ${ITK_LIBRARIES}) + SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkRelativePositionAnalyzer) + WRAP_GGO(clitkTransformLandmarks_GGO_C clitkTransformLandmarks.ggo) ADD_EXECUTABLE(clitkTransformLandmarks clitkTransformLandmarks.cxx ${clitkTransformLandmarks_GGO_C}) TARGET_LINK_LIBRARIES(clitkTransformLandmarks clitkCommon ${ITK_LIBRARIES}) diff --git a/tools/clitkRelativePositionAnalyzer.cxx b/tools/clitkRelativePositionAnalyzer.cxx new file mode 100644 index 0000000..9b16e51 --- /dev/null +++ b/tools/clitkRelativePositionAnalyzer.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 "clitkRelativePositionAnalyzer_ggo.h" +#include "clitkRelativePositionAnalyzerGenericFilter.h" + +//-------------------------------------------------------------------- +int main(int argc, char * argv[]) { + + // Init command line + GGO(clitkRelativePositionAnalyzer, args_info); + CLITK_INIT; + + // Filter + typedef clitk::RelativePositionAnalyzerGenericFilter 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_FAILURE; + } + + return EXIT_SUCCESS; +} // This is the end, my friend +//-------------------------------------------------------------------- diff --git a/tools/clitkRelativePositionAnalyzer.ggo b/tools/clitkRelativePositionAnalyzer.ggo new file mode 100644 index 0000000..982792c --- /dev/null +++ b/tools/clitkRelativePositionAnalyzer.ggo @@ -0,0 +1,16 @@ +#File clitkRelativePositionAnalyzer.ggo +package "clitkRelativePositionAnalyzer" +version "1.0" +purpose "Analyze relative position of a target according to structures" + +section "General options" +option "config" - "Config file" string no +option "verbose" v "Verbose" flag off +option "imagetypes" - "Display allowed image types" flag off + +section "Input/Output" +option "support" i "Input mask support" string yes +option "object" j "Input mask object" string yes +option "target" t "Input mask target" string yes +option "output" o "Output image " string yes + diff --git a/tools/clitkRelativePositionAnalyzerGenericFilter.h b/tools/clitkRelativePositionAnalyzerGenericFilter.h new file mode 100644 index 0000000..fb5648a --- /dev/null +++ b/tools/clitkRelativePositionAnalyzerGenericFilter.h @@ -0,0 +1,75 @@ +/*========================================================================= + 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 CLITKRELATIVEPOSITIONANALYZERGENERICFILTER_H +#define CLITKRELATIVEPOSITIONANALYZERGENERICFILTER_H + +// clitk +#include "clitkIO.h" +#include "clitkImageToImageGenericFilter.h" +#include "clitkRelativePositionAnalyzerFilter.h" + +//-------------------------------------------------------------------- +namespace clitk +{ + + template + class ITK_EXPORT RelativePositionAnalyzerGenericFilter: + public ImageToImageGenericFilter > + { + public: + //-------------------------------------------------------------------- + RelativePositionAnalyzerGenericFilter(); + + //-------------------------------------------------------------------- + typedef ImageToImageGenericFilter > Superclass; + typedef RelativePositionAnalyzerGenericFilter Self; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; + + //-------------------------------------------------------------------- + itkNewMacro(Self); + itkTypeMacro(RelativePositionAnalyzerGenericFilter, 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: + RelativePositionAnalyzerGenericFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + };// end class + //-------------------------------------------------------------------- +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkRelativePositionAnalyzerGenericFilter.txx" +#endif + +#endif // #define CLITKRELATIVEPOSITIONANALYZERGENERICFILTER_H diff --git a/tools/clitkRelativePositionAnalyzerGenericFilter.txx b/tools/clitkRelativePositionAnalyzerGenericFilter.txx new file mode 100644 index 0000000..4225c43 --- /dev/null +++ b/tools/clitkRelativePositionAnalyzerGenericFilter.txx @@ -0,0 +1,103 @@ +/*========================================================================= + 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 + ===========================================================================**/ + +//-------------------------------------------------------------------- +template +clitk::RelativePositionAnalyzerGenericFilter:: +RelativePositionAnalyzerGenericFilter(): + ImageToImageGenericFilter("RelativePositionAnalyzer") +{ + // Default values + cmdline_parser_clitkRelativePositionAnalyzer_init(&mArgsInfo); + InitializeImageType<3>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void clitk::RelativePositionAnalyzerGenericFilter:: +InitializeImageType() +{ + ADD_IMAGE_TYPE(Dim, uchar); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +void clitk::RelativePositionAnalyzerGenericFilter:: +SetArgsInfo(const ArgsInfoType & a) +{ + mArgsInfo=a; + SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + if (mArgsInfo.support_given) AddInputFilename(mArgsInfo.support_arg); + if (mArgsInfo.object_given) AddInputFilename(mArgsInfo.object_arg); + if (mArgsInfo.target_given) AddInputFilename(mArgsInfo.target_arg); + if (mArgsInfo.output_given) AddOutputFilename(mArgsInfo.output_arg); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::RelativePositionAnalyzerGenericFilter:: +SetOptionsFromArgsInfoToFilter(FilterType * f) +{ + +} + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::RelativePositionAnalyzerGenericFilter:: +UpdateWithInputImageType() +{ + // Reading input + typename ImageType::Pointer support = this->template GetInput(0); + typename ImageType::Pointer object = this->template GetInput(1); + typename ImageType::Pointer target = this->template GetInput(2); + + // Create filter + typedef clitk::RelativePositionAnalyzerFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); + + // Set global Options + filter->SetInputSupport(support); + filter->SetInputObject(object); + filter->SetInputTarget(target); + SetOptionsFromArgsInfoToFilter(filter); + + // Go ! + filter->Update(); + + // Write/Save results + // typename ImageType::Pointer output = filter->GetOutput(); + //this->template SetNextOutput(output); + +} +//-------------------------------------------------------------------- + + -- 2.45.1